adjust AEAD-2022 client & server remembered session count

This commit is contained in:
zonyitoo
2022-04-20 00:30:36 +08:00
parent c90da4e340
commit f97ab97afe
4 changed files with 39 additions and 5 deletions
@@ -6,4 +6,4 @@ pub use self::{
};
mod tcp;
mod udp;
pub(crate) mod udp;
@@ -187,10 +187,26 @@ struct ServerSessionContext {
server_session_map: LruCache<u64, ServerContext>,
}
// Server shouldn't be remembered too long.
//
// Server session will only changed if
// 1. Association expired
// 2. Server restarted
//
// Normally there should only be 1 unqiue server session.
pub const SERVER_SESSION_REMEMBER_DURATION: Duration = Duration::from_secs(60);
// Remember 2 server sessions. When server restarts,
// some of the packet on wire may be received later then those new ones.
pub const SERVER_SESSION_REMEMBER_COUNT: usize = 2;
impl ServerSessionContext {
fn new() -> ServerSessionContext {
ServerSessionContext {
server_session_map: LruCache::with_expiry_duration_and_capacity(Duration::from_secs(30 * 60), 5),
server_session_map: LruCache::with_expiry_duration_and_capacity(
SERVER_SESSION_REMEMBER_DURATION,
SERVER_SESSION_REMEMBER_COUNT,
),
}
}
}
@@ -25,7 +25,11 @@ use shadowsocks::{
use tokio::{net::UdpSocket, sync::mpsc, task::JoinHandle, time};
use crate::{
local::{context::ServiceContext, loadbalancing::PingBalancer},
local::{
context::ServiceContext,
loadbalancing::PingBalancer,
net::udp::association::{SERVER_SESSION_REMEMBER_COUNT, SERVER_SESSION_REMEMBER_DURATION},
},
net::{
packet_window::PacketWindowFilter,
MonProxySocket,
@@ -217,7 +221,10 @@ struct ServerSessionContext {
impl ServerSessionContext {
fn new() -> ServerSessionContext {
ServerSessionContext {
server_session_map: LruCache::with_expiry_duration_and_capacity(Duration::from_secs(30 * 60), 5),
server_session_map: LruCache::with_expiry_duration_and_capacity(
SERVER_SESSION_REMEMBER_DURATION,
SERVER_SESSION_REMEMBER_COUNT,
),
}
}
}
@@ -324,9 +324,20 @@ struct ClientSessionContext {
impl ClientSessionContext {
fn new(client_session_id: u64) -> ClientSessionContext {
// Client shouldn't be remembered too long.
// If a client was switching between networks (like Wi-Fi and Cellular),
// when it switched back from another, the packet filter window will be too old.
const CLIENT_SESSION_REMEMBER_DURATION: Duration = Duration::from_secs(60);
// Wi-Fi & Cellular network device, so it is 2 for most users
const CLIENT_SESSION_REMEMBER_COUNT: usize = 2;
ClientSessionContext {
client_session_id,
client_context_map: LruCache::with_expiry_duration_and_capacity(Duration::from_secs(30 * 60), 10),
client_context_map: LruCache::with_expiry_duration_and_capacity(
CLIENT_SESSION_REMEMBER_DURATION,
CLIENT_SESSION_REMEMBER_COUNT,
),
}
}
}