diff --git a/api/migrations/1.4.md b/api/migrations/1.4.md index d003348..235f1ba 100644 --- a/api/migrations/1.4.md +++ b/api/migrations/1.4.md @@ -53,13 +53,19 @@ is gone. `TunnelSynthesisData::unpack` accepts exactly 176 bytes. Announces join the tunnel named by their interface's latest synthesis, which `handle_tunnel` and `TunnelTable::insert` record and `TunnelTable::void_interface` clears; writing -`interface_id` directly no longer rebinds an interface. +`interface_id` directly no longer rebinds an interface. `handle_tunnel` no +longer takes a timeout: a tunnel expires `TUNNEL_TIMEOUT` after its synthesis, +as in Python. `TunnelTable::cull_expired` and `cull_expired_batch` also drop +tunnels set to expire more than twice `TUNNEL_TIMEOUT` ahead. `TcpClientConfig`, `BackboneClientConfig` and `I2PClientConfig` gain `tunnel_identity`. With a `TunnelIdentity` set, the client opens every connection with a tunnel synthesis signed by it; the runtime sets it from `ReticulumHandle::transport_identity`. Build these configs with `new` so the -field defaults to `None`. +field defaults to `None`. A KISS-framed TCP client never synthesizes. Every +TCP, Backbone and I2P client, the shared-instance TCP client included, drops +its queued traffic when a connection opens after an outage or a failed +attempt, and the Unix shared-instance client drops it when it reconnects. Interface stats carry Python 1.5's per-interface counters. `IngressController` counts announces and path requests received and sent; diff --git a/api/snapshots/rns-transport.txt b/api/snapshots/rns-transport.txt index c5df9d7..67d5f57 100644 --- a/api/snapshots/rns-transport.txt +++ b/api/snapshots/rns-transport.txt @@ -1887,7 +1887,7 @@ pub fn rns_transport::tunnel::TunnelTable::void_interface(&mut self, rns_transpo impl core::default::Default for rns_transport::tunnel::TunnelTable pub fn rns_transport::tunnel::TunnelTable::default() -> Self pub fn rns_transport::tunnel::build_tunnel_synthesis_packet(&rns_identity::identity::Identity, [u8; 32]) -> core::option::Option> -pub fn rns_transport::tunnel::handle_tunnel(&mut rns_transport::tunnel::TunnelTable, [u8; 32], rns_transport::messages::InterfaceId, f64) +pub fn rns_transport::tunnel::handle_tunnel(&mut rns_transport::tunnel::TunnelTable, [u8; 32], rns_transport::messages::InterfaceId) pub fn rns_transport::tunnel::interface_hash(&str) -> [u8; 32] pub enum rns_transport::InterfaceCapacityError pub rns_transport::InterfaceCapacityError::Empty diff --git a/api/stability.json b/api/stability.json index 46566f7..5062536 100644 --- a/api/stability.json +++ b/api/stability.json @@ -52,7 +52,7 @@ "compatibility": "reviewed-snapshot", "snapshot": "api/snapshots/rns-transport.txt", "itemCount": 1944, - "sha256": "17482aaa9841b518a977d549534c7328ca73aec60e6dc1b977d6e54c246c1cb7" + "sha256": "cc186fce5185f4b3a3a71f4629ac59b609538be81fa7e8948c74382e25b2820f" }, { "name": "rns-link", @@ -114,6 +114,7 @@ "migrationGuide": "api/migrations/1.4.md", "removed": { "rns-transport": [ + "pub fn rns_transport::tunnel::handle_tunnel(&mut rns_transport::tunnel::TunnelTable, [u8; 32], rns_transport::messages::InterfaceId, f64)", "pub rns_transport::actor::DiscoveryPathRequest::requesting_interface: rns_transport::messages::InterfaceId", "pub rns_transport::actor::DiscoveryPathRequest::timeout: f64", "pub rns_transport::actor::TransportActor::discovery_path_requests: std::collections::hash::map::HashMap<[u8; 16], rns_transport::actor::DiscoveryPathRequest>", diff --git a/crates/rns-transport/src/actor/inbound.rs b/crates/rns-transport/src/actor/inbound.rs index afba0c3..c3f26dc 100644 --- a/crates/rns-transport/src/actor/inbound.rs +++ b/crates/rns-transport/src/actor/inbound.rs @@ -881,7 +881,6 @@ impl TransportActor { &mut self.tunnel_table, tunnel_id, interface_id, - TUNNEL_TIMEOUT as f64, ); self.state_dirty = true; self.restore_tunnel_paths(&tunnel_id, interface_id); diff --git a/crates/rns-transport/src/actor/tests/tunnels.rs b/crates/rns-transport/src/actor/tests/tunnels.rs index 349b49e..341d2aa 100644 --- a/crates/rns-transport/src/actor/tests/tunnels.rs +++ b/crates/rns-transport/src/actor/tests/tunnels.rs @@ -147,7 +147,7 @@ fn losing_a_tunnel_interface_keeps_paths_through_other_interfaces() { let _tunnel_rx = attach(&mut actor, 1, "hub/client_1"); let _uplink_rx = attach(&mut actor, 2, "uplink"); let tunnel_id = [0x77; 32]; - handle_tunnel(&mut actor.tunnel_table, tunnel_id, 1, TUNNEL_TIMEOUT as f64); + handle_tunnel(&mut actor.tunnel_table, tunnel_id, 1); let identity = Identity::new(); let emitted = now_f64() as u64; @@ -192,7 +192,7 @@ fn a_replacement_registration_does_not_inherit_the_tunnel_binding() { let (entry, _old_rx) = make_test_interface("hub/client_4"); actor.handle_message(TransportMessage::RegisterInterface { id: 4, entry }); let tunnel_id = [0x66; 32]; - handle_tunnel(&mut actor.tunnel_table, tunnel_id, 4, TUNNEL_TIMEOUT as f64); + handle_tunnel(&mut actor.tunnel_table, tunnel_id, 4); let (replacement, _new_rx) = make_test_interface("hub/client_4"); actor.handle_message(TransportMessage::RegisterInterface { @@ -220,7 +220,7 @@ fn an_unbound_tunnel_persists_without_an_interface_hash() { let _listener_rx = attach(&mut actor, 0, "SharedInstanceServer"); let _client_rx = attach(&mut actor, 7, "hub/client_7"); let tunnel_id = [0x55; 32]; - handle_tunnel(&mut actor.tunnel_table, tunnel_id, 7, TUNNEL_TIMEOUT as f64); + handle_tunnel(&mut actor.tunnel_table, tunnel_id, 7); actor.deregister_interface(7); actor.save_routing_state(); @@ -291,7 +291,7 @@ fn a_cache_request_replay_adds_no_tunnel_path() { actor.storage_dir = Some(dir.clone()); let _rx = attach(&mut actor, 1, "hub/client_1"); let tunnel_id = [0x44; 32]; - handle_tunnel(&mut actor.tunnel_table, tunnel_id, 1, TUNNEL_TIMEOUT as f64); + handle_tunnel(&mut actor.tunnel_table, tunnel_id, 1); actor.deregister_interface(1); let (announce, dest) = make_valid_announce("wp4.cache.tunnel", 1); @@ -319,12 +319,7 @@ fn persisted_tunnels_load_unbound_even_when_their_interface_returns() { let mut writer = hub(); writer.storage_dir = Some(dir.clone()); let _rx = attach(&mut writer, 5, "uplink"); - handle_tunnel( - &mut writer.tunnel_table, - tunnel_id, - 5, - TUNNEL_TIMEOUT as f64, - ); + handle_tunnel(&mut writer.tunnel_table, tunnel_id, 5); let (announce, dest) = make_valid_announce("wp4.load.unbound", 0); inbound(&mut writer, announce, 5); assert!(carries(&writer, &tunnel_id, &dest)); @@ -361,12 +356,7 @@ fn tunnels_without_an_interface_survive_a_reload() { let mut writer = hub(); writer.storage_dir = Some(dir.clone()); let _rx = attach(&mut writer, 5, "hub/client_5"); - handle_tunnel( - &mut writer.tunnel_table, - tunnel_id, - 5, - TUNNEL_TIMEOUT as f64, - ); + handle_tunnel(&mut writer.tunnel_table, tunnel_id, 5); let now = now_f64(); writer .tunnel_table diff --git a/crates/rns-transport/src/tunnel.rs b/crates/rns-transport/src/tunnel.rs index 40f3ecc..2190ac7 100644 --- a/crates/rns-transport/src/tunnel.rs +++ b/crates/rns-transport/src/tunnel.rs @@ -212,7 +212,8 @@ impl TunnelSynthesisData { } /// Install or refresh a tunnel from a validated tunnel-synthesis announce, -/// making it the receiving interface's tunnel (Transport.py:2819-2834). +/// making it the receiving interface's tunnel and expiring it +/// `TUNNEL_TIMEOUT` later (Transport.py:2819-2834). /// A reappearing tunnel keeps its existing path set — only the interface /// binding and expiry move forward, so in-flight routes aren't lost when the /// underlying link flaps. @@ -220,10 +221,8 @@ pub fn handle_tunnel( tunnel_table: &mut TunnelTable, tunnel_id: [u8; 32], interface_id: crate::messages::InterfaceId, - destination_timeout: f64, ) { - let now = crate::now_f64(); - let expires = now + destination_timeout; + let expires = crate::now_f64() + crate::constants::TUNNEL_TIMEOUT as f64; if let Some(existing) = tunnel_table.get_mut(&tunnel_id) { existing.interface_id = Some(interface_id); @@ -373,7 +372,7 @@ mod tests { fn test_handle_tunnel_new() { let mut table = TunnelTable::new(); let tunnel_id = [0xFF; 32]; - handle_tunnel(&mut table, tunnel_id, 1, 604800.0); + handle_tunnel(&mut table, tunnel_id, 1); assert!(table.get(&tunnel_id).is_some()); assert_eq!(table.get(&tunnel_id).unwrap().interface_id, Some(1)); } @@ -382,9 +381,9 @@ mod tests { fn test_handle_tunnel_reappear() { let mut table = TunnelTable::new(); let tunnel_id = [0xFF; 32]; - handle_tunnel(&mut table, tunnel_id, 1, 604800.0); + handle_tunnel(&mut table, tunnel_id, 1); - handle_tunnel(&mut table, tunnel_id, 2, 604800.0); + handle_tunnel(&mut table, tunnel_id, 2); assert_eq!(table.get(&tunnel_id).unwrap().interface_id, Some(2)); assert_eq!(table.len(), 1); } @@ -393,8 +392,8 @@ mod tests { fn an_interface_keeps_naming_the_tunnel_of_its_latest_synthesis() { let mut table = TunnelTable::new(); let (older, newer) = ([0x0A; 32], [0x0B; 32]); - handle_tunnel(&mut table, older, 1, 600.0); - handle_tunnel(&mut table, newer, 1, 600.0); + handle_tunnel(&mut table, older, 1); + handle_tunnel(&mut table, newer, 1); assert_eq!( table.get_mut_by_interface(1).map(|tunnel| tunnel.tunnel_id), Some(newer) @@ -405,7 +404,7 @@ mod tests { "the superseded tunnel keeps its own binding (Transport.py:2827-2834)" ); - handle_tunnel(&mut table, newer, 2, 600.0); + handle_tunnel(&mut table, newer, 2); assert_eq!( table.get_mut_by_interface(1).map(|tunnel| tunnel.tunnel_id), Some(newer), @@ -422,6 +421,18 @@ mod tests { ); } + /// Python expires a tunnel TUNNEL_TIMEOUT after its synthesis + /// (Transport.py:2821), so the next cull keeps it. + #[test] + fn a_handled_tunnel_expires_after_tunnel_timeout_and_survives_the_cull() { + let mut table = TunnelTable::new(); + handle_tunnel(&mut table, [0x0C; 32], 1); + let expires = table.get(&[0x0C; 32]).unwrap().expires; + let timeout = crate::constants::TUNNEL_TIMEOUT as f64; + assert!((expires - crate::now_f64() - timeout).abs() < 5.0); + assert_eq!(table.cull_expired(), 0); + } + #[test] fn test_tunnel_cull_expired() { let mut table = TunnelTable::new();