From ead1652fdabdce6dc41fbd9ebda6938f2f82adad Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Tue, 13 Oct 2026 17:47:25 -0600 Subject: [PATCH] telephony: retire handshakes refused by the transport queue --- .github/workflows/ci.yml | 2 +- crates/lxst-telephony/src/lib.rs | 39 +++++--- crates/lxst-telephony/src/tests.rs | 153 +++++++++++++++++++++++++++++ tools/check-source-release.py | 2 +- 4 files changed, 181 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16485ff..eb4cc12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ permissions: env: RSLXST_RSRETICULUM_VERSION: 1.4.0 - RSLXST_RSRETICULUM_COMMIT: 817a640ed1e11e3ff3e0ff048d8de13662bfdd78 + RSLXST_RSRETICULUM_COMMIT: 8fcf0b678a4bed778b29690b85b378d05684eaf1 RSLXST_PYTHON_LXST_COMMIT: 1194c9011fe6402edc7aebe7ffe9650ea3b1afee RSLXST_PYTHON_RNS_COMMIT: b48b96e61676504e0a4e527b33b9a0b4495c6872 diff --git a/crates/lxst-telephony/src/lib.rs b/crates/lxst-telephony/src/lib.rs index 08df235..eb021d6 100644 --- a/crates/lxst-telephony/src/lib.rs +++ b/crates/lxst-telephony/src/lib.rs @@ -3527,19 +3527,32 @@ impl TelephonyRnsEndpoint { metrics.q.map(f64::from), ); - // Bind and emit LRRTT in actor order. Reserving both slots before - // publishing either operation prevents a valid handshake from being - // left half-transitioned by transport mailbox pressure. - let bind_permit = self - .transport_tx - .clone() - .try_reserve_owned() - .map_err(map_transport_try_send_error)?; - let rtt_permit = self - .transport_tx - .clone() - .try_reserve_owned() - .map_err(map_transport_try_send_error)?; + // Authenticate before treating mailbox pressure as terminal. A valid + // proof has already activated this Link, so failure to reserve the + // complete bind/LRRTT transaction must retire the attempt. The closure + // drops a first permit before cleanup if the second reservation fails. + let permits = (|| -> Result<_, Error> { + let bind_permit = self + .transport_tx + .clone() + .try_reserve_owned() + .map_err(map_transport_try_send_error)?; + let rtt_permit = self + .transport_tx + .clone() + .try_reserve_owned() + .map_err(map_transport_try_send_error)?; + Ok((bind_permit, rtt_permit)) + })(); + let (bind_permit, rtt_permit) = match permits { + Ok(permits) => permits, + Err(error) => { + self.close_outgoing_link_locally(link_id)?; + self.pending_outgoing_events + .push_back(TelephonyLinkEvent::LinkClosed { link_id }); + return Err(error); + } + }; let (lifecycle_tx, lifecycle_rx) = mpsc::unbounded_channel(); let (bind_result_tx, bind_result_rx) = oneshot::channel(); bind_permit.send(TransportMessage::BindLinkEndpoint { diff --git a/crates/lxst-telephony/src/tests.rs b/crates/lxst-telephony/src/tests.rs index a7757e9..2cbd04d 100644 --- a/crates/lxst-telephony/src/tests.rs +++ b/crates/lxst-telephony/src/tests.rs @@ -2971,6 +2971,159 @@ async fn telephony_service_soaks_bidirectional_opus_stream_loop() { )); } +#[test] +fn outgoing_authenticated_proof_retires_attempt_when_handshake_queue_is_full() { + for free_slots in [0, 1] { + let local_identity = Identity::new(); + let remote_identity = Identity::new(); + let destination_hash = telephony_destination_hash(&remote_identity.hash); + let (transport_tx, mut transport_rx) = mpsc::channel(8); + let mut endpoint = TelephonyRnsEndpoint::register(transport_tx, &local_identity).unwrap(); + transport_rx.try_recv().unwrap(); + let (link, request_data) = Link::new_initiator(destination_hash, 1); + let link_id = link.link_id; + let (_, proof_data) = Link::new_responder( + &request_data, + &remote_identity.get_signing_key().unwrap(), + destination_hash, + 1, + ) + .unwrap(); + let (_event_tx, event_rx) = mpsc::channel(4); + endpoint.outgoing_attempts.insert( + link_id, + OutgoingLinkAttempt { + dispatch_result: None, + link, + remote_public_key: remote_identity.get_public_key(), + event_rx, + }, + ); + for _ in 0..8 - free_slots { + endpoint + .transport_tx + .try_send(TransportMessage::Shutdown) + .unwrap(); + } + + let event = |proof: &[u8]| DestinationEvent::InboundPacket { + interface_owner: None, + raw: Bytes::from(link_proof_packet(link_id, proof)), + interface_id: 7, + metrics: PacketMetrics::default(), + }; + let mut invalid_proof = proof_data.clone(); + invalid_proof[0] ^= 1; + assert_eq!( + endpoint + .handle_outgoing_attempt_event(link_id, event(&invalid_proof)) + .unwrap(), + None + ); + assert_eq!( + endpoint.outgoing_attempts[&link_id].link.state, + LinkState::Pending + ); + assert!(endpoint.pending_outgoing_events.is_empty()); + + assert!(matches!( + endpoint.handle_outgoing_attempt_event(link_id, event(&proof_data)), + Err(Error::TransportFull) + )); + assert!(!endpoint.outgoing_attempts.contains_key(&link_id)); + assert!(!endpoint.outgoing_links.contains_key(&link_id)); + assert_eq!(endpoint.pending_outgoing_events.len(), 1); + + let mut unbinds = 0; + let mut deregistrations = 0; + while let Ok(message) = transport_rx.try_recv() { + match message { + TransportMessage::Shutdown => (), + TransportMessage::UnbindLinkEndpoint { + link_id: closed_id, .. + } => { + assert_eq!(closed_id, link_id); + unbinds += 1; + } + other => panic!("unexpected partial handshake: {other:?}"), + } + } + endpoint.flush_outgoing_cleanup(); + while let Ok(message) = transport_rx.try_recv() { + match message { + TransportMessage::UnbindLinkEndpoint { + link_id: closed_id, .. + } => { + assert_eq!(closed_id, link_id); + unbinds += 1; + } + TransportMessage::DeregisterDestination { hash } => { + assert_eq!(hash, link_id); + deregistrations += 1; + } + other => panic!("unexpected cleanup: {other:?}"), + } + } + assert_eq!(unbinds, 1); + assert_eq!(deregistrations, 1); + assert!(endpoint.pending_outgoing_cleanup.is_empty()); + assert_eq!( + endpoint.try_recv_link_event().unwrap(), + Some(TelephonyLinkEvent::LinkClosed { link_id }) + ); + assert_eq!(endpoint.try_recv_link_event().unwrap(), None); + } +} + +#[test] +fn outgoing_authenticated_proof_retires_attempt_when_transport_closes() { + let local_identity = Identity::new(); + let remote_identity = Identity::new(); + let destination_hash = telephony_destination_hash(&remote_identity.hash); + let (transport_tx, transport_rx) = mpsc::channel(8); + let mut endpoint = TelephonyRnsEndpoint::register(transport_tx, &local_identity).unwrap(); + let (link, request_data) = Link::new_initiator(destination_hash, 1); + let link_id = link.link_id; + let (_, proof_data) = Link::new_responder( + &request_data, + &remote_identity.get_signing_key().unwrap(), + destination_hash, + 1, + ) + .unwrap(); + let (_event_tx, event_rx) = mpsc::channel(4); + endpoint.outgoing_attempts.insert( + link_id, + OutgoingLinkAttempt { + dispatch_result: None, + link, + remote_public_key: remote_identity.get_public_key(), + event_rx, + }, + ); + drop(transport_rx); + assert!(matches!( + endpoint.handle_outgoing_attempt_event( + link_id, + DestinationEvent::InboundPacket { + interface_owner: None, + raw: Bytes::from(link_proof_packet(link_id, &proof_data)), + interface_id: 7, + metrics: PacketMetrics::default(), + }, + ), + Err(Error::TransportClosed) + )); + assert!(!endpoint.outgoing_attempts.contains_key(&link_id)); + assert!(!endpoint.outgoing_links.contains_key(&link_id)); + assert!(endpoint.pending_outgoing_cleanup.is_empty()); + assert_eq!( + endpoint.try_recv_link_event().unwrap(), + Some(TelephonyLinkEvent::LinkClosed { link_id }) + ); + assert_eq!(endpoint.try_recv_link_event().unwrap(), None); +} + #[test] fn outgoing_link_attempt_promotes_after_proof_and_drives_available_signal() { let local_identity = Identity::new(); diff --git a/tools/check-source-release.py b/tools/check-source-release.py index a3340f5..7a102f6 100644 --- a/tools/check-source-release.py +++ b/tools/check-source-release.py @@ -15,7 +15,7 @@ EXPECTED_PACKAGES = {"lxst-core", "lxst-codec2", "lxst-embedded", "lxst-rns", "l EXPECTED_MSRV = "1.89" EMBEDDED_MSRV = {"lxst-codec2": "1.87", "lxst-embedded": "1.87"} EXPECTED_RETICULUM_VERSION = "1.4.0" -EXPECTED_RETICULUM_COMMIT = "817a640ed1e11e3ff3e0ff048d8de13662bfdd78" +EXPECTED_RETICULUM_COMMIT = "8fcf0b678a4bed778b29690b85b378d05684eaf1" EXPECTED_OPUS_DEPENDENCY = ( 'opus-rs = { version = "=0.1.29", default-features = false, ' 'features = ["heap"] }'