mirror of
https://github.com/jmcorgan/fips.git
synced 2026-07-30 19:46:15 +00:00
COORDS_PRESENT warmup-then-reactive for DataPackets
Include source and destination coordinates on the first N DataPackets of each session (default 5, configurable via node.session.coords_warmup_packets). This warms transit node coord_caches so multi-hop forwarding and error signal routing work after SessionSetup cache entries expire. On CoordsRequired receipt, reset the counter to re-enable coordinate inclusion for the next N packets, handling mid-session cache expiry and path changes. Changes: - SessionConfig: add coords_warmup_packets field (default 5) - SessionEntry: add coords_warmup_remaining counter, initialized on Established transition (both initiator and responder paths) - send_session_data(): attach coords via DataPacket::with_coords() while counter > 0, decrement per send - handle_coords_required(): reset counter for affected session - 4 new unit tests for counter lifecycle and config default
This commit is contained in:
@@ -1299,6 +1299,90 @@ fn test_purge_idle_sessions_disabled_when_zero() {
|
||||
assert_eq!(node.session_count(), 1, "Sessions should not be purged when idle timeout is disabled");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Unit tests: COORDS_PRESENT warmup counter
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_coords_warmup_counter_default_zero_on_new() {
|
||||
use crate::noise::HandshakeState;
|
||||
|
||||
let identity_a = Identity::generate();
|
||||
let identity_b = Identity::generate();
|
||||
|
||||
let handshake = HandshakeState::new_initiator(
|
||||
identity_a.keypair(),
|
||||
identity_b.pubkey_full(),
|
||||
);
|
||||
|
||||
let entry = crate::node::session::SessionEntry::new(
|
||||
*identity_b.node_addr(),
|
||||
identity_b.pubkey_full(),
|
||||
EndToEndState::Initiating(handshake),
|
||||
1000,
|
||||
);
|
||||
|
||||
assert_eq!(entry.coords_warmup_remaining(), 0,
|
||||
"Counter should be 0 for non-Established sessions");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_coords_warmup_counter_set_and_get() {
|
||||
let node = make_node();
|
||||
let remote = Identity::generate();
|
||||
let remote_addr = *remote.node_addr();
|
||||
|
||||
let session = make_noise_session(node.identity(), &remote);
|
||||
let mut entry = crate::node::session::SessionEntry::new(
|
||||
remote_addr,
|
||||
remote.pubkey_full(),
|
||||
EndToEndState::Established(session),
|
||||
1000,
|
||||
);
|
||||
|
||||
assert_eq!(entry.coords_warmup_remaining(), 0);
|
||||
|
||||
entry.set_coords_warmup_remaining(5);
|
||||
assert_eq!(entry.coords_warmup_remaining(), 5);
|
||||
|
||||
entry.set_coords_warmup_remaining(0);
|
||||
assert_eq!(entry.coords_warmup_remaining(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_coords_warmup_counter_decrement() {
|
||||
let node = make_node();
|
||||
let remote = Identity::generate();
|
||||
let remote_addr = *remote.node_addr();
|
||||
|
||||
let session = make_noise_session(node.identity(), &remote);
|
||||
let mut entry = crate::node::session::SessionEntry::new(
|
||||
remote_addr,
|
||||
remote.pubkey_full(),
|
||||
EndToEndState::Established(session),
|
||||
1000,
|
||||
);
|
||||
|
||||
entry.set_coords_warmup_remaining(3);
|
||||
|
||||
// Simulate the decrement pattern used in send_session_data
|
||||
for expected in (0..3).rev() {
|
||||
assert!(entry.coords_warmup_remaining() > 0);
|
||||
entry.set_coords_warmup_remaining(entry.coords_warmup_remaining() - 1);
|
||||
assert_eq!(entry.coords_warmup_remaining(), expected);
|
||||
}
|
||||
|
||||
assert_eq!(entry.coords_warmup_remaining(), 0,
|
||||
"Counter should reach 0 after N decrements");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_coords_warmup_config_default() {
|
||||
let config = crate::config::Config::new();
|
||||
assert_eq!(config.node.session.coords_warmup_packets, 5,
|
||||
"Default coords_warmup_packets should be 5");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Unit tests: Identity cache
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user