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::{
6
6
} ;
7
7
8
8
mod 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 {
187
187
server_session_map : LruCache < u64 , ServerContext > ,
188
188
}
189
189
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
+
190
203
impl ServerSessionContext {
191
204
fn new ( ) -> ServerSessionContext {
192
205
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
+ ) ,
194
210
}
195
211
}
196
212
}
Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ use shadowsocks::{
25
25
use tokio:: { net:: UdpSocket , sync:: mpsc, task:: JoinHandle , time} ;
26
26
27
27
use 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
+ } ,
29
33
net:: {
30
34
packet_window:: PacketWindowFilter ,
31
35
MonProxySocket ,
@@ -217,7 +221,10 @@ struct ServerSessionContext {
217
221
impl ServerSessionContext {
218
222
fn new ( ) -> ServerSessionContext {
219
223
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
+ ) ,
221
228
}
222
229
}
223
230
}
Original file line number Diff line number Diff line change @@ -324,9 +324,20 @@ struct ClientSessionContext {
324
324
325
325
impl ClientSessionContext {
326
326
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
+
327
335
ClientSessionContext {
328
336
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
+ ) ,
330
341
}
331
342
}
332
343
}
You can’t perform that action at this time.
0 commit comments