Cache architecture: identity fix, cache merge, parent-change flush

Identity cache: remove TTL-based expiry (60s TTL broke active sessions
after expiry since handle_tun_outbound checks identity_cache before
session table). Replace with LRU-only eviction bounded by configurable
identity_size (default 10K). Lookup now touches timestamp for LRU
freshness.

Cache merge: unify coord_cache and route_cache into single coordinate
cache. Both stored NodeAddr→TreeCoordinate; the layer distinction was
conceptual, not functional. Discovery-sourced entries now get the same
TTL+refresh treatment as session-sourced entries. Simplifies
find_next_hop() to single cache lookup.

Parent-change flush: clear coord_cache after recompute_coords() in both
parent-switch paths of handle_tree_announce(). Stale coordinates after
tree reconvergence cause dead-end routing that's more expensive than
re-discovery.

Tested: 493 unit tests passed, clippy clean, Docker mesh 20/20,
Docker chain 6/6.
This commit is contained in:
Johnathan Corgan
2026-02-16 22:56:34 +00:00
parent 852f561fa0
commit f374370e5c
11 changed files with 108 additions and 479 deletions
+5 -10
View File
@@ -116,12 +116,9 @@ pub struct CacheConfig {
/// Coord cache entry TTL in seconds (`node.cache.coord_ttl_secs`).
#[serde(default = "CacheConfig::default_coord_ttl_secs")]
pub coord_ttl_secs: u64,
/// Max entries in route cache (`node.cache.route_size`).
#[serde(default = "CacheConfig::default_route_size")]
pub route_size: usize,
/// Identity cache entry TTL in seconds (`node.cache.identity_ttl_secs`).
#[serde(default = "CacheConfig::default_identity_ttl_secs")]
pub identity_ttl_secs: u64,
/// Max entries in identity cache (`node.cache.identity_size`).
#[serde(default = "CacheConfig::default_identity_size")]
pub identity_size: usize,
}
impl Default for CacheConfig {
@@ -129,8 +126,7 @@ impl Default for CacheConfig {
Self {
coord_size: 50_000,
coord_ttl_secs: 300,
route_size: 10_000,
identity_ttl_secs: 60,
identity_size: 10_000,
}
}
}
@@ -138,8 +134,7 @@ impl Default for CacheConfig {
impl CacheConfig {
fn default_coord_size() -> usize { 50_000 }
fn default_coord_ttl_secs() -> u64 { 300 }
fn default_route_size() -> usize { 10_000 }
fn default_identity_ttl_secs() -> u64 { 60 }
fn default_identity_size() -> usize { 10_000 }
}
/// Discovery protocol (`node.discovery.*`).