diff --git a/crates/rns-transport/src/actor/link_endpoint.rs b/crates/rns-transport/src/actor/link_endpoint.rs index 4104315..fc91683 100644 --- a/crates/rns-transport/src/actor/link_endpoint.rs +++ b/crates/rns-transport/src/actor/link_endpoint.rs @@ -154,11 +154,13 @@ impl TransportActor { match result { LinkEndpointSendResult::Sent => { if let Some(entry) = self.link_endpoints.remove(&key) { + let destination_hash = entry.binding.link_id; self.notify_link_endpoint_terminal( entry, LinkEndpointTerminalReason::Unbound, 0, ); + self.deregister_destination(destination_hash); } } LinkEndpointSendResult::Queued { .. } => { @@ -350,11 +352,13 @@ impl TransportActor { } if entry.unbind_after_drain { + let destination_hash = entry.binding.link_id; self.notify_link_endpoint_terminal( entry, crate::messages::LinkEndpointTerminalReason::Unbound, 0, ); + self.deregister_destination(destination_hash); } else { self.link_endpoints.insert(key, entry); } diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index 207bb2d..ff9123a 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -632,14 +632,7 @@ impl TransportActor { } } TransportMessage::DeregisterDestination { hash } => { - self.local_destinations.remove(&hash); - self.destination_channels.remove(&hash); - if self.local_link_routes.remove(&hash).is_some() { - self.terminate_link_endpoints_for_link( - hash, - crate::messages::LinkEndpointTerminalReason::InterfaceRemoved, - ); - } + self.deregister_destination(hash); } TransportMessage::CacheRequest { packet_hash, @@ -1404,6 +1397,17 @@ impl TransportActor { } } + fn deregister_destination(&mut self, hash: [u8; 16]) { + self.local_destinations.remove(&hash); + self.destination_channels.remove(&hash); + if self.local_link_routes.remove(&hash).is_some() { + self.terminate_link_endpoints_for_link( + hash, + crate::messages::LinkEndpointTerminalReason::InterfaceRemoved, + ); + } + } + fn cull_path_interface_suppressions(&mut self, now: f64) { self.path_interface_suppressions .retain(|_, until| now < *until); @@ -4189,6 +4193,9 @@ mod tests { actor.interfaces.insert(14, target); let link_id = [0xBC; 16]; + actor.local_destinations.insert(link_id); + let (destination_tx, _destination_rx) = mpsc::channel(1); + actor.destination_channels.insert(link_id, destination_tx); let binding = LinkEndpointBinding { link_id, interface_id: 14, @@ -4233,6 +4240,7 @@ mod tests { .link_endpoints .contains_key(&(link_id, LinkEndpointRole::Initiator)) ); + assert!(actor.local_destinations.contains(&link_id)); assert_eq!( actor.send_link_endpoint( link_id, @@ -4265,6 +4273,8 @@ mod tests { .link_endpoints .contains_key(&(link_id, LinkEndpointRole::Initiator)) ); + assert!(!actor.local_destinations.contains(&link_id)); + assert!(!actor.destination_channels.contains_key(&link_id)); let terminal = lifecycle_rx.try_recv().unwrap(); assert_eq!(terminal.binding, binding); assert_eq!(terminal.reason, LinkEndpointTerminalReason::Unbound); diff --git a/crates/rns-transport/src/messages.rs b/crates/rns-transport/src/messages.rs index 4dd80fe..8efbee2 100644 --- a/crates/rns-transport/src/messages.rs +++ b/crates/rns-transport/src/messages.rs @@ -452,9 +452,10 @@ pub enum TransportMessage { request: OutboundRequest, result_tx: tokio::sync::oneshot::Sender, }, - /// Reliably admit a final packet, then remove the endpoint only after its - /// ordered FIFO has drained. This prevents a queued LINKCLOSE from being - /// discarded by an immediately following unbind. + /// Reliably admit a final packet, then remove the endpoint and temporary + /// Link destination only after its ordered FIFO has drained. This prevents + /// a queued LINKCLOSE from being discarded by an immediately following + /// unbind or destination deregistration. SendLinkEndpointAndUnbind { link_id: [u8; 16], role: LinkEndpointRole,