Skip to content

Commit f97ab97

Browse files
committed
adjust AEAD-2022 client & server remembered session count
1 parent c90da4e commit f97ab97

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

crates/shadowsocks-service/src/local/net/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ pub use self::{
66
};
77

88
mod tcp;
9-
mod udp;
9+
pub(crate) mod udp;

crates/shadowsocks-service/src/local/net/udp/association.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
190203
impl 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
}

crates/shadowsocks-service/src/local/tunnel/udprelay.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ use shadowsocks::{
2525
use tokio::{net::UdpSocket, sync::mpsc, task::JoinHandle, time};
2626

2727
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+
},
2933
net::{
3034
packet_window::PacketWindowFilter,
3135
MonProxySocket,
@@ -217,7 +221,10 @@ struct ServerSessionContext {
217221
impl 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
}

crates/shadowsocks-service/src/server/udprelay.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,20 @@ struct ClientSessionContext {
324324

325325
impl 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
}

0 commit comments

Comments
 (0)