File tree Expand file tree Collapse file tree 4 files changed +39
-5
lines changed
crates/shadowsocks-service/src Expand file tree Collapse file tree 4 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ pub use self::{
66} ;
77
88mod tcp;
9- mod udp;
9+ pub ( crate ) mod udp;
Original file line number Diff line number Diff line change @@ -187,10 +187,26 @@ struct ServerSessionContext {
187187 server_session_map : LruCache < u64 , ServerContext > ,
188188}
189189
190+ // Server shouldn't be remembered too long.
191+ //
192+ // Server session will only changed if
193+ // 1. Association expired
194+ // 2. Server restarted
195+ //
196+ // Normally there should only be 1 unqiue server session.
197+ pub const SERVER_SESSION_REMEMBER_DURATION : Duration = Duration :: from_secs ( 60 ) ;
198+
199+ // Remember 2 server sessions. When server restarts,
200+ // some of the packet on wire may be received later then those new ones.
201+ pub const SERVER_SESSION_REMEMBER_COUNT : usize = 2 ;
202+
190203impl ServerSessionContext {
191204 fn new ( ) -> ServerSessionContext {
192205 ServerSessionContext {
193- server_session_map : LruCache :: with_expiry_duration_and_capacity ( Duration :: from_secs ( 30 * 60 ) , 5 ) ,
206+ server_session_map : LruCache :: with_expiry_duration_and_capacity (
207+ SERVER_SESSION_REMEMBER_DURATION ,
208+ SERVER_SESSION_REMEMBER_COUNT ,
209+ ) ,
194210 }
195211 }
196212}
Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ use shadowsocks::{
2525use tokio:: { net:: UdpSocket , sync:: mpsc, task:: JoinHandle , time} ;
2626
2727use crate :: {
28- local:: { context:: ServiceContext , loadbalancing:: PingBalancer } ,
28+ local:: {
29+ context:: ServiceContext ,
30+ loadbalancing:: PingBalancer ,
31+ net:: udp:: association:: { SERVER_SESSION_REMEMBER_COUNT , SERVER_SESSION_REMEMBER_DURATION } ,
32+ } ,
2933 net:: {
3034 packet_window:: PacketWindowFilter ,
3135 MonProxySocket ,
@@ -217,7 +221,10 @@ struct ServerSessionContext {
217221impl ServerSessionContext {
218222 fn new ( ) -> ServerSessionContext {
219223 ServerSessionContext {
220- server_session_map : LruCache :: with_expiry_duration_and_capacity ( Duration :: from_secs ( 30 * 60 ) , 5 ) ,
224+ server_session_map : LruCache :: with_expiry_duration_and_capacity (
225+ SERVER_SESSION_REMEMBER_DURATION ,
226+ SERVER_SESSION_REMEMBER_COUNT ,
227+ ) ,
221228 }
222229 }
223230}
Original file line number Diff line number Diff line change @@ -324,9 +324,20 @@ struct ClientSessionContext {
324324
325325impl ClientSessionContext {
326326 fn new ( client_session_id : u64 ) -> ClientSessionContext {
327+ // Client shouldn't be remembered too long.
328+ // If a client was switching between networks (like Wi-Fi and Cellular),
329+ // when it switched back from another, the packet filter window will be too old.
330+ const CLIENT_SESSION_REMEMBER_DURATION : Duration = Duration :: from_secs ( 60 ) ;
331+
332+ // Wi-Fi & Cellular network device, so it is 2 for most users
333+ const CLIENT_SESSION_REMEMBER_COUNT : usize = 2 ;
334+
327335 ClientSessionContext {
328336 client_session_id,
329- client_context_map : LruCache :: with_expiry_duration_and_capacity ( Duration :: from_secs ( 30 * 60 ) , 10 ) ,
337+ client_context_map : LruCache :: with_expiry_duration_and_capacity (
338+ CLIENT_SESSION_REMEMBER_DURATION ,
339+ CLIENT_SESSION_REMEMBER_COUNT ,
340+ ) ,
330341 }
331342 }
332343}
You can’t perform that action at this time.
0 commit comments