mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
transport: defer Link cleanup until teardown drains
This commit is contained in:
1 parent
a9d26472d0
commit
2fd604b4aa
3 files changed
+26
-11
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -452,9 +452,10 @@ pub enum TransportMessage {
|
||||
request: OutboundRequest,
|
||||
result_tx: tokio::sync::oneshot::Sender<LinkEndpointSendResult>,
|
||||
},
|
||||
/// 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,
|
||||
|
||||
Reference in new issue
Block a user