fix friends connection

This commit is contained in:
Maple 2026-04-11 21:59:37 +02:00
commit 8164317b19

View file

@ -6,7 +6,6 @@ use std::{
Arc, LazyLock, Weak, Arc, LazyLock, Weak,
atomic::{AtomicBool, AtomicU32}, atomic::{AtomicBool, AtomicU32},
}, },
thread::sleep,
time::Duration, time::Duration,
}; };
@ -30,7 +29,7 @@ use tokio::{
net::{TcpSocket, UdpSocket}, net::{TcpSocket, UdpSocket},
spawn, spawn,
sync::{Mutex, RwLock}, sync::{Mutex, RwLock},
time::Instant, time::{Instant, sleep},
}; };
use crate::{ use crate::{
@ -170,7 +169,7 @@ impl<C: Crypto> Server<C> {
async fn timeout_thread(self: Arc<Self>, conn: Weak<Connection<C::Instance>>) { async fn timeout_thread(self: Arc<Self>, conn: Weak<Connection<C::Instance>>) {
loop { loop {
let Some(conn) = conn.upgrade() else { break }; let Some(conn) = conn.upgrade() else { break };
sleep(Duration::from_secs(3)); sleep(Duration::from_secs(3)).await;
let mut inner = conn.inner.lock().await; let mut inner = conn.inner.lock().await;
if (Instant::now() - inner.last_action).as_secs() > 5 { if (Instant::now() - inner.last_action).as_secs() > 5 {
@ -259,6 +258,7 @@ impl<C: Crypto> Server<C> {
}; };
let pid = ci.get_user_id(); let pid = ci.get_user_id();
println!("user with pid {} is connecting", pid);
let buf_conn = new_backend_connection(&self.param, addr, pid).await; let buf_conn = new_backend_connection(&self.param, addr, pid).await;
let Some(buf_conn) = buf_conn else { let Some(buf_conn) = buf_conn else {
error!("unable to connect to backend"); error!("unable to connect to backend");