diff --git a/crates/rns-transport/src/actor/maintenance.rs b/crates/rns-transport/src/actor/maintenance.rs index d561179..3575719 100644 --- a/crates/rns-transport/src/actor/maintenance.rs +++ b/crates/rns-transport/src/actor/maintenance.rs @@ -363,7 +363,8 @@ impl TransportActor { should_request = true; } else if !path_request_throttle { if expired_link.taken_hops == 0 { - should_request = true; + // Transport.py: a local client's Link to a 0-hop destination asks nothing. + should_request = self.path_table.hops_to(&destination_hash) != Some(0); } else if self.path_table.hops_to(&destination_hash) == Some(1) || expired_link.taken_hops == 1 { @@ -863,6 +864,34 @@ mod cleanup_tests { assert_eq!(actor.pending_discovery_prs.len(), 2); } + /// Transport.py 1.6.1 (5bd93ad9): a local client's unproven Link to a + /// 0-hop destination neither asks for a path nor expires it. + #[test] + fn local_client_link_to_a_local_destination_asks_nothing() { + let now = now_f64(); + for (hops, asks) in [(0, false), (2, true)] { + let (mut actor, _tx) = TransportActor::new(); + let dest = [0x33; 16]; + actor + .path_table + .insert(dest, PathEntry::new(None, hops, 1, InterfaceMode::Full)); + actor.handle_expired_unvalidated_link( + crate::link_table::ExpiredLink { + next_hop: None, + interface_id: 1, + remaining_hops: hops, + destination_hash: dest, + receiving_interface: 2, + taken_hops: 0, + }, + now, + ); + assert_eq!(!actor.pending_discovery_prs.is_empty(), asks, "hops {hops}"); + // A leaf drops the path it asks for. + assert_eq!(actor.path_table.has_path(&dest), !asks, "hops {hops}"); + } + } + /// Transport.py: one cull pass removes every /// reverse entry past REVERSE_TIMEOUT, with no batch cap. #[test] diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index db2a682..326783e 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -1823,8 +1823,9 @@ impl TransportActor { /// Transport.py: a Link that was never established expires /// the path on a non-transport instance and, unless this is a - /// shared-instance client, queues a throttled rediscovery request. - /// Unlike upstream, a route newer than the one the request used is kept. + /// shared-instance client, queues a throttled rediscovery request. A + /// 0-hop path is left alone. Unlike upstream, a route newer than the one + /// the request used is kept. fn rediscover_after_failed_link( &mut self, destination: [u8; 16], @@ -1834,7 +1835,7 @@ impl TransportActor { return; } if let Some(path) = self.path_table.get(&destination) - && Some(path_recovery::RouteVersion::from_path(path)) != route + && (path.hops == 0 || Some(path_recovery::RouteVersion::from_path(path)) != route) { return; } diff --git a/crates/rns-transport/src/actor/path_recovery.rs b/crates/rns-transport/src/actor/path_recovery.rs index af19851..d568e4c 100644 --- a/crates/rns-transport/src/actor/path_recovery.rs +++ b/crates/rns-transport/src/actor/path_recovery.rs @@ -124,6 +124,11 @@ impl TransportActor { return; } let now = now_f64(); + // Transport.py: a failed Link never drops or rediscovers a 0-hop path. + let local = self + .path_table + .get_live(&request.destination_hash) + .is_some_and(|path| path.hops == 0); let mut path_dropped = false; let mut observed = false; if let Some(attempt) = request.failed_attempt.and_then(|link_id| { @@ -140,6 +145,7 @@ impl TransportActor { }) { observed = now - attempt.observed_at < LOCAL_LINK_ROUTE_LIFETIME; if observed + && !local && self .path_table .get_live(&request.destination_hash) @@ -155,7 +161,7 @@ impl TransportActor { // A failed attempt's fresh replacement needs no new discovery flood. // Unknown attempts and explicit discovery can ask even if a cached // route exists, but all callers share the destination throttle/FIFO. - let should_request = path_dropped || !has_path || !observed; + let should_request = !local && (path_dropped || !has_path || !observed); let recent = self .path_requests .get(&request.destination_hash) @@ -280,6 +286,20 @@ mod tests { assert!(!again.path_dropped && again.has_path); } + /// Transport.py 1.6.1 (5bd93ad9): a failed Link to a 0-hop destination + /// neither expires its path nor asks for one. + #[test] + fn failed_link_to_a_local_destination_keeps_its_path() { + let (mut actor, handle, _radio) = fixture(); + actor.path_table.get_mut(&[0xDD; 16]).unwrap().hops = 0; + let link = dispatch(&mut actor); + let result = recover(&mut actor, &handle, [0xDD; 16], Some(link)); + assert!(!result.path_dropped && result.has_path && !result.request_scheduled); + assert!(actor.pending_discovery_prs.is_empty()); + let explicit = recover(&mut actor, &handle, [0xDD; 16], None); + assert!(!explicit.request_scheduled); + } + #[test] fn old_link_failure_preserves_fresh_same_radio_and_alternate_routes() { for interface in [1, 2] { diff --git a/crates/rns-transport/tests/fixtures/path_table_lifecycle/generate.py b/crates/rns-transport/tests/fixtures/path_table_lifecycle/generate.py index 4cc5eaa..427a6fb 100644 --- a/crates/rns-transport/tests/fixtures/path_table_lifecycle/generate.py +++ b/crates/rns-transport/tests/fixtures/path_table_lifecycle/generate.py @@ -209,7 +209,7 @@ out = { "outbound": [outbound(1), outbound(3)], "pending_link_rediscovery": [pending_link(False, False, None), pending_link(False, False, 10), pending_link(False, False, 25), pending_link(False, True, None), - pending_link(True, False, None)], + pending_link(True, False, None), pending_link(False, False, None, 0)], } with open(OUT, "w") as f: f.write("{\n") diff --git a/crates/rns-transport/tests/fixtures/path_table_lifecycle/path_table_lifecycle.json b/crates/rns-transport/tests/fixtures/path_table_lifecycle/path_table_lifecycle.json index f68f37f..dea3e80 100644 --- a/crates/rns-transport/tests/fixtures/path_table_lifecycle/path_table_lifecycle.json +++ b/crates/rns-transport/tests/fixtures/path_table_lifecycle/path_table_lifecycle.json @@ -52,6 +52,7 @@ {"transport_enabled": false, "shared_client": false, "last_request_age_s": 10, "hops": 1, "path_kept": false, "rediscovery_queued": false}, {"transport_enabled": false, "shared_client": false, "last_request_age_s": 25, "hops": 1, "path_kept": false, "rediscovery_queued": true}, {"transport_enabled": false, "shared_client": true, "last_request_age_s": null, "hops": 1, "path_kept": false, "rediscovery_queued": false}, - {"transport_enabled": true, "shared_client": false, "last_request_age_s": null, "hops": 1, "path_kept": true, "rediscovery_queued": false} + {"transport_enabled": true, "shared_client": false, "last_request_age_s": null, "hops": 1, "path_kept": true, "rediscovery_queued": false}, + {"transport_enabled": false, "shared_client": false, "last_request_age_s": null, "hops": 0, "path_kept": true, "rediscovery_queued": false} ] }