diff --git a/tuic-client/src/connection.rs b/tuic-client/src/connection.rs index 8d4365e..9ee3fdd 100644 --- a/tuic-client/src/connection.rs +++ b/tuic-client/src/connection.rs @@ -19,7 +19,7 @@ use socks5_proto::Address as Socks5Address; use std::{ net::{Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket}, sync::{ - atomic::{AtomicUsize, Ordering}, + atomic::{AtomicU32, Ordering}, Arc, }, time::Duration, @@ -36,8 +36,8 @@ static ENDPOINT: OnceCell> = OnceCell::new(); static CONNECTION: AsyncOnceCell> = AsyncOnceCell::const_new(); static TIMEOUT: AtomicCell = AtomicCell::new(Duration::from_secs(0)); -pub const CONNECTION_CLOSE_ERROR_CODE: VarInt = VarInt::from_u32(0); -const DEFAULT_CONCURRENT_STREAMS: usize = 32; +pub const ERROR_CODE: VarInt = VarInt::from_u32(0); +const DEFAULT_CONCURRENT_STREAMS: u32 = 32; pub struct Endpoint { ep: QuinnEndpoint, @@ -197,8 +197,8 @@ pub struct Connection { udp_relay_mode: UdpRelayMode, remote_uni_stream_cnt: Counter, remote_bi_stream_cnt: Counter, - max_concurrent_uni_streams: Arc, - max_concurrent_bi_streams: Arc, + max_concurrent_uni_streams: Arc, + max_concurrent_bi_streams: Arc, } impl Connection { @@ -252,8 +252,8 @@ impl Connection { udp_relay_mode, remote_uni_stream_cnt: Counter::new(), remote_bi_stream_cnt: Counter::new(), - max_concurrent_uni_streams: Arc::new(AtomicUsize::new(DEFAULT_CONCURRENT_STREAMS)), - max_concurrent_bi_streams: Arc::new(AtomicUsize::new(DEFAULT_CONCURRENT_STREAMS)), + max_concurrent_uni_streams: Arc::new(AtomicU32::new(DEFAULT_CONCURRENT_STREAMS)), + max_concurrent_bi_streams: Arc::new(AtomicU32::new(DEFAULT_CONCURRENT_STREAMS)), }; tokio::spawn(conn.clone().init(heartbeat, gc_interval, gc_lifetime)); @@ -346,12 +346,12 @@ impl Connection { async fn accept_uni_stream(&self) -> Result<(RecvStream, Register), Error> { let max = self.max_concurrent_uni_streams.load(Ordering::Relaxed); - if self.remote_uni_stream_cnt.count() == max { + if self.remote_uni_stream_cnt.count() as u32 == max { self.max_concurrent_uni_streams .store(max * 2, Ordering::Relaxed); self.conn - .set_max_concurrent_uni_streams(VarInt::from((max * 2) as u32)); + .set_max_concurrent_uni_streams(VarInt::from(max * 2)); } let recv = self.conn.accept_uni().await?; @@ -362,12 +362,12 @@ impl Connection { async fn accept_bi_stream(&self) -> Result<(SendStream, RecvStream, Register), Error> { let max = self.max_concurrent_bi_streams.load(Ordering::Relaxed); - if self.remote_bi_stream_cnt.count() == max { + if self.remote_bi_stream_cnt.count() as u32 == max { self.max_concurrent_bi_streams .store(max * 2, Ordering::Relaxed); self.conn - .set_max_concurrent_bi_streams(VarInt::from((max * 2) as u32)); + .set_max_concurrent_bi_streams(VarInt::from(max * 2)); } let (send, recv) = self.conn.accept_bi().await?; @@ -386,7 +386,7 @@ impl Connection { Err(err) => Err(Error::Model(err)), Ok(Task::Packet(pkt)) => match self.udp_relay_mode { UdpRelayMode::Quic => { - log::debug!( + log::info!( "[relay] [packet] [{assoc_id:#06x}] [from-quic] [{pkt_id:#06x}] {frag_id}/{frag_total}", assoc_id = pkt.assoc_id(), pkt_id = pkt.pkt_id(), @@ -428,7 +428,7 @@ impl Connection { Err(err) => Err(Error::Model(err)), Ok(Task::Packet(pkt)) => match self.udp_relay_mode { UdpRelayMode::Native => { - log::debug!( + log::info!( "[relay] [packet] [{assoc_id:#06x}] [from-native] [{pkt_id:#06x}] {frag_id}/{frag_total}", assoc_id = pkt.assoc_id(), pkt_id = pkt.pkt_id(), diff --git a/tuic-client/src/socks5.rs b/tuic-client/src/socks5.rs index b71afa2..1b41e76 100644 --- a/tuic-client/src/socks5.rs +++ b/tuic-client/src/socks5.rs @@ -1,6 +1,6 @@ use crate::{ config::Local, - connection::{Connection as TuicConnection, CONNECTION_CLOSE_ERROR_CODE}, + connection::{Connection as TuicConnection, ERROR_CODE}, Error, }; use bytes::Bytes; @@ -314,7 +314,7 @@ impl Server { Ok(_) => {} Err(err) => { let _ = conn.shutdown().await; - let _ = relay.get_mut().reset(CONNECTION_CLOSE_ERROR_CODE); + let _ = relay.get_mut().reset(ERROR_CODE); log::warn!("[socks5] [{peer_addr}] [connect] [{target_addr}] TCP stream relaying error: {err}"); } }, diff --git a/tuic-server/src/server.rs b/tuic-server/src/server.rs index 046e727..33bec66 100644 --- a/tuic-server/src/server.rs +++ b/tuic-server/src/server.rs @@ -21,7 +21,7 @@ use std::{ net::{Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket as StdUdpSocket}, pin::Pin, sync::{ - atomic::{AtomicUsize, Ordering}, + atomic::{AtomicU32, Ordering}, Arc, }, task::{Context, Poll, Waker}, @@ -42,7 +42,7 @@ use tuic_quinn::{side, Authenticate, Connect, Connection as Model, Packet, Task} use uuid::Uuid; const ERROR_CODE: VarInt = VarInt::from_u32(0); -const DEFAULT_CONCURRENT_STREAMS: usize = 32; +const DEFAULT_CONCURRENT_STREAMS: u32 = 32; pub struct Server { ep: Endpoint, @@ -186,8 +186,8 @@ struct Connection { max_external_pkt_size: usize, remote_uni_stream_cnt: Counter, remote_bi_stream_cnt: Counter, - max_concurrent_uni_streams: Arc, - max_concurrent_bi_streams: Arc, + max_concurrent_uni_streams: Arc, + max_concurrent_bi_streams: Arc, } #[allow(clippy::too_many_arguments)] @@ -283,8 +283,8 @@ impl Connection { max_external_pkt_size, remote_uni_stream_cnt: Counter::new(), remote_bi_stream_cnt: Counter::new(), - max_concurrent_uni_streams: Arc::new(AtomicUsize::new(DEFAULT_CONCURRENT_STREAMS)), - max_concurrent_bi_streams: Arc::new(AtomicUsize::new(DEFAULT_CONCURRENT_STREAMS)), + max_concurrent_uni_streams: Arc::new(AtomicU32::new(DEFAULT_CONCURRENT_STREAMS)), + max_concurrent_bi_streams: Arc::new(AtomicU32::new(DEFAULT_CONCURRENT_STREAMS)), } } @@ -319,12 +319,12 @@ impl Connection { let max = self.max_concurrent_uni_streams.load(Ordering::Relaxed); - if self.remote_uni_stream_cnt.count() == max { + if self.remote_uni_stream_cnt.count() as u32 == max { self.max_concurrent_uni_streams .store(max * 2, Ordering::Relaxed); self.inner - .set_max_concurrent_uni_streams(VarInt::from((max * 2) as u32)); + .set_max_concurrent_uni_streams(VarInt::from(max * 2)); } let pre_process = async { @@ -371,12 +371,12 @@ impl Connection { let max = self.max_concurrent_bi_streams.load(Ordering::Relaxed); - if self.remote_bi_stream_cnt.count() == max { + if self.remote_bi_stream_cnt.count() as u32 == max { self.max_concurrent_bi_streams .store(max * 2, Ordering::Relaxed); self.inner - .set_max_concurrent_bi_streams(VarInt::from((max * 2) as u32)); + .set_max_concurrent_bi_streams(VarInt::from(max * 2)); } let pre_process = async {