mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
runtime: Link endpoint cleanup after the transport stops has nothing left to do
This commit is contained in:
1 parent
70e3d99279
commit
0b295761c7
1 file changed
+20
-6
@@ -451,18 +451,21 @@ async fn cleanup_registered_link(
|
||||
role: LinkEndpointRole,
|
||||
endpoint_bound: bool,
|
||||
) -> Result<(), LinkEndpointError> {
|
||||
// A stopped transport took the registration down with it.
|
||||
if endpoint_bound {
|
||||
match unbind(transport_tx, link_id, role).await? {
|
||||
LinkEndpointUnbindResult::Unbound | LinkEndpointUnbindResult::NotBound => {}
|
||||
result @ LinkEndpointUnbindResult::RoleMismatch => {
|
||||
match unbind(transport_tx, link_id, role).await {
|
||||
Ok(LinkEndpointUnbindResult::Unbound | LinkEndpointUnbindResult::NotBound) => {}
|
||||
Ok(result @ LinkEndpointUnbindResult::RoleMismatch) => {
|
||||
return Err(LinkEndpointError::Unbind(result));
|
||||
}
|
||||
Err(LinkEndpointError::TransportUnavailable) => return Ok(()),
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
transport_tx
|
||||
let _ = transport_tx
|
||||
.send(TransportMessage::DeregisterDestination { hash: link_id })
|
||||
.await
|
||||
.map_err(|_| LinkEndpointError::TransportUnavailable)
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn send_message(
|
||||
@@ -678,6 +681,17 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cleanup_after_transport_stopped_leaves_nothing_to_retry() {
|
||||
let (transport_tx, transport_rx) = mpsc::channel(1);
|
||||
drop(transport_rx);
|
||||
let mut guard =
|
||||
LinkEndpointCleanupGuard::new(transport_tx, [0xC4; 16], LinkEndpointRole::Initiator);
|
||||
guard.endpoint_bound();
|
||||
assert!(guard.cleanup().await.is_ok());
|
||||
assert!(!guard.armed);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn role_mismatch_never_deregisters_another_endpoint_owner() {
|
||||
let link_id = [0xC2; 16];
|
||||
|
||||
Reference in new issue
Block a user