diff --git a/crates/rns-transport/src/actor/path_recovery.rs b/crates/rns-transport/src/actor/path_recovery.rs index fe3a9d7..1979bbd 100644 --- a/crates/rns-transport/src/actor/path_recovery.rs +++ b/crates/rns-transport/src/actor/path_recovery.rs @@ -168,7 +168,8 @@ impl TransportActor { // extend an already-admitted interface's ordinary discovery cooldown. // Once that cooldown expires, enqueue the new intent; per-interface // admission coalesces still-refused targets without replaying them. - let request_scheduled = should_request + let request_scheduled = request.schedule_discovery + && should_request && (queued || (!recent && self.queue_discovery_path_request(request.destination_hash, None, now)) @@ -426,4 +427,38 @@ mod tests { assert!(actor.path_interface_suppressions.is_empty()); } } + + #[test] + fn packet_invalidation_requires_exact_live_attempt_and_never_discovers() { + for changed in [false, true] { + let (mut actor, handle, mut radio) = fixture(); + let dest = [0xDD; 16]; + let packet = [0x73; 32]; + actor.record_route_attempt(FailedRouteAttempt::Packet(packet), dest); + if changed { + actor.path_table.insert(dest, path(1, 2)); + } + // Wrong destination cannot consume the original attempt. + let mut wrong = handle.try_invalidate_packet([0xCC; 16], packet).unwrap(); + let request = actor.path_recovery_rx.try_recv().unwrap(); + actor.recover_local_link_path(request); + assert!(!wrong.try_recv().unwrap().path_dropped); + // Cancelling before actor execution cannot consume it either. + drop(handle.try_invalidate_packet(dest, packet).unwrap()); + let request = actor.path_recovery_rx.try_recv().unwrap(); + actor.recover_local_link_path(request); + for consumed in [false, true] { + let mut reply = handle.try_invalidate_packet(dest, packet).unwrap(); + let request = actor.path_recovery_rx.try_recv().unwrap(); + actor.recover_local_link_path(request); + let outcome = reply.try_recv().unwrap(); + assert_eq!(outcome.path_dropped, !changed && !consumed); + assert_eq!(outcome.has_path, changed); + assert!(!outcome.request_scheduled); + assert!(actor.pending_discovery_prs.is_empty()); + assert!(actor.pending_path_request_admissions.is_empty()); + assert!(radio.try_recv().is_err()); + } + } + } } diff --git a/crates/rns-transport/src/path_recovery.rs b/crates/rns-transport/src/path_recovery.rs index 268630c..0626012 100644 --- a/crates/rns-transport/src/path_recovery.rs +++ b/crates/rns-transport/src/path_recovery.rs @@ -41,6 +41,7 @@ impl std::error::Error for PathRecoveryError {} pub(crate) struct PathRecoveryRequest { pub destination_hash: [u8; 16], pub failed_attempt: Option, + pub schedule_discovery: bool, pub result_tx: oneshot::Sender, } @@ -71,7 +72,11 @@ impl PathRecoveryHandle { destination_hash: [u8; 16], failed_link: Option<[u8; 16]>, ) -> Result, PathRecoveryError> { - self.try_recover_attempt(destination_hash, failed_link.map(FailedRouteAttempt::Link)) + self.try_recover_attempt( + destination_hash, + failed_link.map(FailedRouteAttempt::Link), + true, + ) } /// Recover only the unchanged route used by an atomically tracked local @@ -84,6 +89,30 @@ impl PathRecoveryHandle { self.try_recover_attempt( destination_hash, Some(FailedRouteAttempt::Packet(packet_hash)), + true, + ) + } + + /// Invalidate only the unchanged local route used by a tracked packet, + /// without scheduling discovery. Unknown, consumed, cancelled or replaced + /// attempts cannot invalidate a route. The returned `path_dropped` flag is + /// evidence of this local comparison, not permission or an atomic guarantee + /// for another process' route table. + /// + /// Shared-client coordinators can use this before an authenticated owner + /// reset, then call [`Self::try_recover`] with no failed Link to discover. + /// Separating these steps avoids querying a stale owner cache before its + /// reset. Callers must bound the intervening work and handle reset failure; + /// this method neither contacts the owner nor implicitly retries discovery. + pub fn try_invalidate_packet( + &self, + destination_hash: [u8; 16], + packet_hash: [u8; 32], + ) -> Result, PathRecoveryError> { + self.try_recover_attempt( + destination_hash, + Some(FailedRouteAttempt::Packet(packet_hash)), + false, ) } @@ -91,12 +120,14 @@ impl PathRecoveryHandle { &self, destination_hash: [u8; 16], failed_attempt: Option, + schedule_discovery: bool, ) -> Result, PathRecoveryError> { let (result_tx, result_rx) = oneshot::channel(); self.tx .try_send(PathRecoveryRequest { destination_hash, failed_attempt, + schedule_discovery, result_tx, }) .map_err(|error| match error {