mirror of
https://github.com/ratspeak/rsLXMF
synced 2026-11-27 23:00:32 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df3a500c4f | ||
|
|
8a22f7e951 | ||
|
|
98aa927e1d | ||
|
|
7caacbb382 | ||
|
|
f959b200d8 | ||
|
|
49a1f2a182 | ||
|
|
a48ee9c6a3 |
No files matched your search
@@ -10,7 +10,7 @@ permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
RSLXMF_RSRETICULUM_COMMIT: 49aa33db1bbe8c7d93b12c4e8fa378ba5060376e
|
||||
RSLXMF_RSRETICULUM_COMMIT: d4183434fcb969799c208ddcf140bae7550c14fe
|
||||
|
||||
jobs:
|
||||
api-compat:
|
||||
|
||||
@@ -18,7 +18,7 @@ env:
|
||||
PACKAGE_ROOT: rsLXMF
|
||||
LXMF_BINS: lxmd-rs
|
||||
RSLXMF_RSRETICULUM_VERSION: 1.3.0
|
||||
RSLXMF_RSRETICULUM_COMMIT: 49aa33db1bbe8c7d93b12c4e8fa378ba5060376e
|
||||
RSLXMF_RSRETICULUM_COMMIT: d4183434fcb969799c208ddcf140bae7550c14fe
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
|
||||
+14
-7
@@ -2,15 +2,22 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Encode propagation-control peer addresses explicitly as binary data, avoiding
|
||||
intermittent sync/unpeer failures for hashes that resemble MessagePack values.
|
||||
### Added
|
||||
|
||||
- Adopt rsReticulum 1.3 with a patch-line (`~1.3.0`) requirement so the next
|
||||
breaking core minor release is not admitted implicitly.
|
||||
- Added delivery readiness hooks so applications can react promptly to incoming Link traffic and local send completion.
|
||||
- Added support for updating pending Direct-message compression as peer capabilities become known.
|
||||
|
||||
### Fixed and improved
|
||||
|
||||
- Kept active attachment transfers alive while data is moving and reduced delays between delivery steps.
|
||||
- Corrected progress reporting for transfers split across multiple Resources by weighting each part by its payload size.
|
||||
- Fixed intermittent propagation-node sync and unpeer failures caused by incorrectly encoded peer addresses.
|
||||
|
||||
### Build and compatibility
|
||||
|
||||
- Restricted rsReticulum compatibility to the 1.3 patch line so a later breaking minor release requires an explicit update.
|
||||
- Updated the Python interoperability baseline to Reticulum 1.4.2 and LXMF 1.0.1, with separate LXMF 1.1.0 checks.
|
||||
|
||||
- Promote exact Python RNS 1.4.2 to the complete release baseline while
|
||||
retaining LXMF 1.0.1 for the main corpus and live matrix; the LXMF 1.1.0
|
||||
supplemental lane remains separate and RNS 1.5.0 remains deferred.
|
||||
|
||||
## 1.2.0 - 2026-08-17
|
||||
|
||||
|
||||
@@ -27,6 +27,15 @@ and an explicit version decision.
|
||||
|
||||
## Delivery-owner integration
|
||||
|
||||
`LinkDeliveryManager::poll_ready` lets one embedding task wait for inbound
|
||||
delivery packets, local admission acknowledgements, endpoint lifecycle changes,
|
||||
and staged-transport capacity. On readiness, call `drain_events` and `tick`.
|
||||
Keep periodic ticks for protocol deadlines, but schedule application maintenance
|
||||
separately. Drains are bounded and may leave another ready turn. Cancelling the
|
||||
wait does not discard a packet or publish an unread endpoint binding; existing
|
||||
periodic consumers remain supported. The API is provisional delivery-owner
|
||||
integration (LXMF-02/03, RET-05/07), not a new wire protocol or success signal.
|
||||
|
||||
`LinkDeliveryManager::set_link_endpoint_dispatch_handle` opts Direct packet
|
||||
sends into the Reticulum owner's exact local-admission receipts. Supply the
|
||||
handle from the same runtime that owns the manager's transport channel.
|
||||
@@ -59,6 +68,14 @@ Queued messages without an active protocol owner receive no
|
||||
blanket timeout exemption. Explicit rejection and cancellation are not evidence
|
||||
of a failed route.
|
||||
|
||||
When an authenticated recipient announcement rules out compression, call
|
||||
`LinkDeliveryManager::disable_pending_direct_compression` before advancing
|
||||
ready delivery events. It updates unconstructed Direct Resources and queued
|
||||
messages, including Link setup waits. Constructed Resources and split plans
|
||||
remain immutable, and propagation envelopes keep their independent policy.
|
||||
The call only disables compression; new submissions still carry their policy.
|
||||
This additive API remains provisional delivery-owner integration.
|
||||
|
||||
Applications that reserve inbound attachment memory can opt into
|
||||
`set_inbound_resource_completion_handler`. It receives one owned completed
|
||||
payload before the ordinary conclusion callback, so an application can move
|
||||
|
||||
@@ -473,6 +473,7 @@ pub fn lxmf_core::link_delivery::LinkDeliveryManager::backchannel_link_snapshot(
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::cancel_delivery_by_message_hash(&mut self, [u8; 32]) -> bool
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::delivery_link_available(&self, &[u8; 16]) -> bool
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::direct_link_snapshot(&self, [u8; 16]) -> core::option::Option<lxmf_core::link_delivery::DirectLinkSnapshot>
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::disable_pending_direct_compression(&mut self, [u8; 16])
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::drain_events(&mut self, &std::collections::hash::map::HashMap<alloc::string::String, [u8; 64]>)
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::fail_backchannel_link(&mut self, [u8; 16], &str) -> alloc::vec::Vec<lxmf_core::link_delivery::DeliveryResult>
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::fail_delivery_by_message_hash(&mut self, [u8; 32], &str) -> alloc::vec::Vec<lxmf_core::link_delivery::DeliveryResult>
|
||||
@@ -491,6 +492,7 @@ pub fn lxmf_core::link_delivery::LinkDeliveryManager::new(tokio::sync::mpsc::bou
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::observe_backchannel_packet_wait(&mut self, [u8; 16], [u8; 32], std::time::Instant, core::time::Duration, bool, core::option::Option<rns_transport::link_endpoint_dispatch::LinkEndpointDispatchCancellation>) -> bool
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::observe_backchannel_resource_wait(&mut self, [u8; 16], [u8; 32], std::time::Instant, core::time::Duration) -> bool
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::pending_count(&self) -> usize
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::poll_ready(&mut self, &mut core::task::wake::Context<'_>) -> core::task::poll::Poll<()>
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::register_backchannel(&mut self, [u8; 16], [u8; 16])
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::remove_backchannel(&mut self, &[u8; 16]) -> core::option::Option<[u8; 16]>
|
||||
pub fn lxmf_core::link_delivery::LinkDeliveryManager::session_count(&self) -> usize
|
||||
|
||||
+20
-9
@@ -19,15 +19,17 @@
|
||||
"sourceCommit": "b8d7afce73f7f098706029361568e63f22888ea3"
|
||||
},
|
||||
"snapshotSource": {
|
||||
"commit": "8db95825c568ace467c99d2011cefe618e1c60fc",
|
||||
"capturedOn": "2026-09-08",
|
||||
"commit": "98aa927e1d2da3ebcc42ebe25f635dcbb503faf7",
|
||||
"capturedOn": "2026-09-24",
|
||||
"review": {
|
||||
"areas": [
|
||||
"Exact local packet admission and proof-clock ownership",
|
||||
"Finite original Resource windows and bounded external observation grace",
|
||||
"Cancellation-aware backchannel adapters with legacy compatibility",
|
||||
"Generation-safe cleanup, settlement and queued-message preservation",
|
||||
"Owned reverse Resource completion handoff"
|
||||
"Owned reverse Resource completion handoff",
|
||||
"LXMF-02/03 and RET-05/07 event-driven delivery readiness (September 24)",
|
||||
"LXMF-02/03: late authenticated compression capability on pending Direct delivery"
|
||||
],
|
||||
"canonicalPath": "lxmf_core::link_delivery::LinkDeliveryManager",
|
||||
"retainedPaths": [
|
||||
@@ -44,19 +46,21 @@
|
||||
],
|
||||
"classification": "compatible additive opt-in provisional delivery-owner integration; existing message facade and public signatures remain unchanged",
|
||||
"publicApiDiff": {
|
||||
"added": 93,
|
||||
"added": 95,
|
||||
"removed": 0
|
||||
},
|
||||
"semver": "compatible additive APIs included in version 1.2.0",
|
||||
"deprecations": "none",
|
||||
"wirePersistenceRuntimeImpact": "No wire-format, cryptography, message identity or persisted-layout change. Exact local Link admission precedes RTT proof timing. Resource owner windows retain original timestamps; only externally observed Resources receive a finite 180-second accounting allowance after the original protocol deadline. Cancellation-aware adapters close and drain unpublished receipts while legacy sender installation retains its previous behavior. Exact cleanup is bounded and cannot erase replacement Links or lose uncancelled queued messages; authenticated settlement remains owned after Link closure. Optional reverse Resource completion hands off the single owned payload before conclusion cleanup, without changing legacy consumers.",
|
||||
"wirePersistenceRuntimeImpact": "No wire-format, cryptography, message identity or persisted-layout change. Exact local Link admission precedes RTT proof timing. Resource owner windows retain original timestamps; only externally observed Resources receive a finite 180-second accounting allowance after the original protocol deadline. Cancellation-aware adapters close and drain unpublished receipts while legacy sender installation retains its previous behavior. Exact cleanup is bounded and cannot erase replacement Links or lose uncancelled queued messages; authenticated settlement remains owned after Link closure. Optional reverse Resource completion hands off the single owned payload before conclusion cleanup, without changing legacy consumers. Authenticated no-compression announcements can now disable compression for unconstructed Direct Resources and queued payloads. Constructed Resources, split plans and propagation envelopes stay immutable; no wire fields or signatures change.",
|
||||
"platformEvidence": [
|
||||
"clean committed-source all-feature Apple ARM64 snapshot: seven added methods, zero removed; cumulative compatibility-floor diff is 93 additions and zero removals",
|
||||
"564 LXMF core and 55 daemon tests passed on the final implementation checkpoint; strict all-target Clippy and core Rustdoc passed",
|
||||
"independent actual-actor cancellation, captured legacy/aware policy, 256-owner reservation and replacement-Link/settlement review controls passed",
|
||||
"actual encrypted Resource final-proof expiry and same-message retry produced one receiver publication; signed Link reuse/loss/recovery and completion-lease controls passed",
|
||||
"default/all-feature external consumer fixtures and final working app runtime suite passed; no feature/MSRV/native-export changes",
|
||||
"final clean combined host/MSRV/native/interop and artifact qualification remain separately required; focused software evidence is not physical fading-radio or mobile acceptance"
|
||||
"final clean combined host/MSRV/native/interop and artifact qualification remain separately required; focused software evidence is not physical fading-radio or mobile acceptance",
|
||||
"September 24: additive poll_ready method; 75 focused delivery tests, encrypted 65 KB/750 KB/2.6 MB/8 MB readiness-driven transfers, and strict stable/MSRV Clippy passed. Physical radio speed remains separately qualified.",
|
||||
"September 24 first-contact correction: 577 lxmf-core tests and strict all-target Clippy passed; the new API is additive provisional owner integration. Small/Micro native first-contact and full app runtime qualification are retained by the cross-repo maintainer harness."
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -67,8 +71,8 @@
|
||||
"tier": "candidate-stable",
|
||||
"compatibility": "reviewed-snapshot",
|
||||
"snapshot": "api/snapshots/lxmf-core.txt",
|
||||
"itemCount": 1645,
|
||||
"sha256": "65aebd34c72bb2b621d515331bba1f4d85234c448d1c7039132f24c0a95bbe4a"
|
||||
"itemCount": 1647,
|
||||
"sha256": "b7b1d52406e2c97a204a5fb567abc6a216733594a7abd63797ff55a70d8d3b73"
|
||||
},
|
||||
{
|
||||
"name": "lxmf-tools",
|
||||
@@ -79,5 +83,12 @@
|
||||
"itemCount": 185,
|
||||
"sha256": "0427d0fab38f8061cbf7f11b701f29f438490478f133524b0a8e4e7cfe6f3924"
|
||||
}
|
||||
]
|
||||
],
|
||||
"deliveryReadinessReview": {
|
||||
"reviewedOn": "2026-09-24",
|
||||
"classification": "Compatible additive provisional integration method; no removed signatures, dependency requirement, MSRV, wire or persistence changes. No release-version bump in this implementation commit.",
|
||||
"ownership": "Input and local receipt lookahead remain owned on cancellation; exact bind readiness does not publish the endpoint. One polling task; periodic deadline ticks remain required.",
|
||||
"scheduling": "Bounded input drain; readiness covers packets, endpoint lifecycle/acknowledgements, backchannel receipts and staged-transport capacity. Existing lxmd-rs periodic consumers remain supported.",
|
||||
"diagnostics": "Aggregate Resource request/part/repeated-part/byte action counts under a closed content-free target; dispatch is not driver admission or recipient delivery."
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@
|
||||
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use bytes::Bytes;
|
||||
@@ -168,6 +171,50 @@ struct InboundResourceLifecycle {
|
||||
inter_segment_deadline: Option<Instant>,
|
||||
}
|
||||
|
||||
/// A non-publishing lookahead for local acknowledgements. Registering a waker
|
||||
/// may receive the value, but the original owner must still consume or drain it.
|
||||
struct ReadyReceipt<T> {
|
||||
receiver: oneshot::Receiver<T>,
|
||||
ready: Option<Result<T, oneshot::error::RecvError>>,
|
||||
}
|
||||
impl<T> From<oneshot::Receiver<T>> for ReadyReceipt<T> {
|
||||
fn from(receiver: oneshot::Receiver<T>) -> Self {
|
||||
Self {
|
||||
receiver,
|
||||
ready: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T> ReadyReceipt<T> {
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> bool {
|
||||
if self.ready.is_none() {
|
||||
if let Poll::Ready(result) = Pin::new(&mut self.receiver).poll(cx) {
|
||||
self.ready = Some(result);
|
||||
}
|
||||
}
|
||||
self.ready.is_some()
|
||||
}
|
||||
fn try_recv(&mut self) -> Result<T, oneshot::error::TryRecvError> {
|
||||
match self.ready.take() {
|
||||
Some(result) => result.map_err(|_| oneshot::error::TryRecvError::Closed),
|
||||
None => self.receiver.try_recv(),
|
||||
}
|
||||
}
|
||||
fn close(&mut self) {
|
||||
self.receiver.close();
|
||||
}
|
||||
fn is_terminated(&self) -> bool {
|
||||
self.ready.is_none() && self.receiver.is_terminated()
|
||||
}
|
||||
}
|
||||
|
||||
type TransportReady = Pin<
|
||||
Box<
|
||||
dyn Future<Output = Result<mpsc::OwnedPermit<TransportMessage>, mpsc::error::SendError<()>>>
|
||||
+ Send,
|
||||
>,
|
||||
>;
|
||||
|
||||
struct PendingEndpointBind {
|
||||
interface_id: InterfaceId,
|
||||
rtt_request: OutboundRequest,
|
||||
@@ -175,11 +222,18 @@ struct PendingEndpointBind {
|
||||
}
|
||||
|
||||
enum EndpointBindReceiver {
|
||||
Legacy(oneshot::Receiver<LinkEndpointBindResult>),
|
||||
Legacy(ReadyReceipt<LinkEndpointBindResult>),
|
||||
Exact(LinkEndpointDispatchBindReceipt),
|
||||
}
|
||||
|
||||
impl EndpointBindReceiver {
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> bool {
|
||||
match self {
|
||||
Self::Legacy(rx) => rx.poll_ready(cx),
|
||||
Self::Exact(rx) => rx.poll_ready(cx).is_ready(),
|
||||
}
|
||||
}
|
||||
|
||||
fn try_recv(
|
||||
&mut self,
|
||||
) -> Result<
|
||||
@@ -199,7 +253,7 @@ impl EndpointBindReceiver {
|
||||
struct PendingPacketDispatch {
|
||||
link_id: [u8; 16],
|
||||
packet_hash: [u8; 32],
|
||||
result_rx: oneshot::Receiver<LinkEndpointDispatchOutcome>,
|
||||
result_rx: ReadyReceipt<LinkEndpointDispatchOutcome>,
|
||||
}
|
||||
|
||||
enum EndpointSendSuccess {
|
||||
@@ -213,12 +267,12 @@ struct PendingEndpointSend {
|
||||
link_id: [u8; 16],
|
||||
final_send: bool,
|
||||
success: EndpointSendSuccess,
|
||||
result_rx: oneshot::Receiver<LinkEndpointSendResult>,
|
||||
result_rx: ReadyReceipt<LinkEndpointSendResult>,
|
||||
}
|
||||
|
||||
struct PendingEndpointCleanup {
|
||||
link_id: [u8; 16],
|
||||
result_rx: oneshot::Receiver<LinkEndpointUnbindResult>,
|
||||
result_rx: ReadyReceipt<LinkEndpointUnbindResult>,
|
||||
}
|
||||
|
||||
/// State of a link-based delivery.
|
||||
@@ -366,7 +420,7 @@ impl BackchannelProofKey {
|
||||
}
|
||||
|
||||
struct PendingBackchannelStart {
|
||||
receiver: oneshot::Receiver<Result<BackchannelSendReceipt, BackchannelSendError>>,
|
||||
receiver: ReadyReceipt<Result<BackchannelSendReceipt, BackchannelSendError>>,
|
||||
message: LxMessage,
|
||||
dest_hash: [u8; 16],
|
||||
link_id: [u8; 16],
|
||||
@@ -730,6 +784,14 @@ fn start_error_from_reserve(err: TrySendError<()>) -> LinkDeliveryStartError {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ResourceDispatchCounters {
|
||||
requests: u64,
|
||||
part_actions: u64,
|
||||
repeated_part_actions: u64,
|
||||
part_bytes: u64,
|
||||
}
|
||||
|
||||
/// Driver for outbound link-based LXMF deliveries.
|
||||
///
|
||||
/// Callers invoke [`Self::start_delivery`] to begin, [`Self::drain_events`] to route inbound
|
||||
@@ -781,7 +843,11 @@ pub struct LinkDeliveryManager {
|
||||
identity_key: Option<Ed25519PrivateKey>,
|
||||
event_tx: mpsc::Sender<DestinationEvent>,
|
||||
event_rx: mpsc::Receiver<DestinationEvent>,
|
||||
ready_event: Option<DestinationEvent>,
|
||||
ready_lifecycle: Option<LinkEndpointLifecycleEvent>,
|
||||
transport_ready: Option<TransportReady>,
|
||||
delivery_events: VecDeque<LxmfDeliveryEvent>,
|
||||
resource_counters: ResourceDispatchCounters,
|
||||
}
|
||||
|
||||
impl LinkDeliveryManager {
|
||||
@@ -824,7 +890,65 @@ impl LinkDeliveryManager {
|
||||
identity_key,
|
||||
event_tx,
|
||||
event_rx,
|
||||
ready_event: None,
|
||||
ready_lifecycle: None,
|
||||
transport_ready: None,
|
||||
delivery_events: VecDeque::new(),
|
||||
resource_counters: ResourceDispatchCounters::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Register the embedding task's waker for inbound delivery events and
|
||||
/// local admission/lifecycle acknowledgements. `Ready` means call
|
||||
/// [`Self::drain_events`] and [`Self::tick`]; it is not delivery success.
|
||||
///
|
||||
/// Cancellation-safe: lookahead values remain with this manager and exact
|
||||
/// bind ownership stays unpublished until normal processing consumes it.
|
||||
/// Use one polling task per manager and retain periodic ticks for protocol
|
||||
/// deadlines. A bounded drain may leave more input ready for the next turn.
|
||||
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<()> {
|
||||
if self.ready_event.is_none() {
|
||||
if let Poll::Ready(event) = self.event_rx.poll_recv(cx) {
|
||||
self.ready_event = event;
|
||||
}
|
||||
}
|
||||
if self.ready_lifecycle.is_none() {
|
||||
if let Poll::Ready(event) = self.endpoint_lifecycle_rx.poll_recv(cx) {
|
||||
self.ready_lifecycle = event;
|
||||
}
|
||||
}
|
||||
let mut ready = self.ready_event.is_some() || self.ready_lifecycle.is_some();
|
||||
for pending in self.pending_endpoint_binds.values_mut() {
|
||||
ready |= pending.result_rx.poll_ready(cx);
|
||||
}
|
||||
for pending in &mut self.pending_endpoint_sends {
|
||||
ready |= pending.result_rx.poll_ready(cx);
|
||||
}
|
||||
for pending in &mut self.pending_endpoint_cleanups {
|
||||
ready |= pending.result_rx.poll_ready(cx);
|
||||
}
|
||||
for pending in &mut self.pending_packet_dispatches {
|
||||
ready |= pending.result_rx.poll_ready(cx);
|
||||
}
|
||||
for pending in &mut self.pending_backchannel_starts {
|
||||
ready |= pending.receiver.poll_ready(cx);
|
||||
}
|
||||
if self.pending_transport.is_empty() {
|
||||
self.transport_ready = None;
|
||||
} else {
|
||||
let reserve = self
|
||||
.transport_ready
|
||||
.get_or_insert_with(|| Box::pin(self.transport_tx.clone().reserve_owned()));
|
||||
if reserve.as_mut().poll(cx).is_ready() {
|
||||
// Drop the temporary permit before the normal FIFO flush.
|
||||
self.transport_ready = None;
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
if ready {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
||||
@@ -835,6 +959,30 @@ impl LinkDeliveryManager {
|
||||
self.endpoint_dispatch = Some(handle);
|
||||
}
|
||||
|
||||
/// Disable compression for Direct payloads that have not constructed their
|
||||
/// Resource yet, including payloads queued behind another delivery.
|
||||
///
|
||||
/// Embedders call this when an authenticated recipient announcement reports
|
||||
/// unsupported compression. Existing Resource bytes, advertisements and split
|
||||
/// segments remain immutable. This never enables compression or changes the
|
||||
/// propagation-node envelope. New submissions still carry their own policy.
|
||||
pub fn disable_pending_direct_compression(&mut self, destination: [u8; 16]) {
|
||||
for delivery in self
|
||||
.pending
|
||||
.values_mut()
|
||||
.filter(|delivery| delivery.reusable && delivery.dest_hash == destination)
|
||||
{
|
||||
if delivery.transfer.is_none() && delivery.remaining_segments.is_none() {
|
||||
delivery.message.auto_compress = false;
|
||||
delivery.auto_compress = false;
|
||||
}
|
||||
for queued in &mut delivery.queued {
|
||||
queued.message.auto_compress = false;
|
||||
queued.auto_compress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Install the adapter used to send LXMF payloads over inbound
|
||||
/// authenticated backchannel Links owned by the embedding runtime.
|
||||
pub fn set_backchannel_sender(&mut self, tx: mpsc::Sender<BackchannelSendCommand>) {
|
||||
@@ -1235,7 +1383,7 @@ impl LinkDeliveryManager {
|
||||
});
|
||||
self.pending_backchannel_starts
|
||||
.push(PendingBackchannelStart {
|
||||
receiver: result_rx,
|
||||
receiver: result_rx.into(),
|
||||
message,
|
||||
dest_hash,
|
||||
link_id,
|
||||
@@ -1688,7 +1836,11 @@ impl LinkDeliveryManager {
|
||||
|
||||
fn poll_endpoint_control(&mut self) {
|
||||
self.poll_endpoint_send_results();
|
||||
while let Ok(event) = self.endpoint_lifecycle_rx.try_recv() {
|
||||
while let Some(event) = self
|
||||
.ready_lifecycle
|
||||
.take()
|
||||
.or_else(|| self.endpoint_lifecycle_rx.try_recv().ok())
|
||||
{
|
||||
if event.binding.role != LinkEndpointRole::Initiator {
|
||||
continue;
|
||||
}
|
||||
@@ -1796,8 +1948,14 @@ impl LinkDeliveryManager {
|
||||
/// and `ResourcePrf` contexts to their handlers.
|
||||
pub fn drain_events(&mut self, known_identities: &HashMap<String, [u8; 64]>) {
|
||||
self.poll_endpoint_control();
|
||||
let mut events = Vec::new();
|
||||
while let Ok(event) = self.event_rx.try_recv() {
|
||||
let mut events = Vec::with_capacity(32);
|
||||
if let Some(event) = self.ready_event.take() {
|
||||
events.push(event);
|
||||
}
|
||||
while events.len() < 32 {
|
||||
let Ok(event) = self.event_rx.try_recv() else {
|
||||
break;
|
||||
};
|
||||
events.push(event);
|
||||
}
|
||||
|
||||
@@ -1950,10 +2108,7 @@ impl LinkDeliveryManager {
|
||||
self.handle_inbound_resource_part(&link_id, data);
|
||||
}
|
||||
rns_wire::context::PacketContext::ResourceHmu => {
|
||||
let plaintext = self
|
||||
.pending
|
||||
.get(&link_id)
|
||||
.and_then(|d| d.link.decrypt(data).ok());
|
||||
let plaintext = self.decrypt_resource_control(&link_id, data);
|
||||
if let Some(pt) = plaintext {
|
||||
if !self.handle_inbound_resource_hmu(&link_id, &pt) {
|
||||
self.handle_hmu(&link_id, &pt);
|
||||
@@ -1963,10 +2118,7 @@ impl LinkDeliveryManager {
|
||||
rns_wire::context::PacketContext::ResourceReq => {
|
||||
// Python `Resource.request_next` may arrive before any HMU and be the
|
||||
// only signal to advance the transfer, so drive it here directly.
|
||||
let plaintext = self
|
||||
.pending
|
||||
.get(&link_id)
|
||||
.and_then(|d| d.link.decrypt(data).ok());
|
||||
let plaintext = self.decrypt_resource_control(&link_id, data);
|
||||
if let Some(pt) = plaintext {
|
||||
self.handle_request(&link_id, &pt);
|
||||
}
|
||||
@@ -1979,19 +2131,13 @@ impl LinkDeliveryManager {
|
||||
rns_wire::context::PacketContext::ResourceRcl => {
|
||||
// Receiver-cancel/reject packets are link-encrypted and carry
|
||||
// the rejected resource_hash.
|
||||
let plaintext = self
|
||||
.pending
|
||||
.get(&link_id)
|
||||
.and_then(|d| d.link.decrypt(data).ok());
|
||||
let plaintext = self.decrypt_resource_control(&link_id, data);
|
||||
if let Some(pt) = plaintext {
|
||||
self.handle_resource_reject(&link_id, &pt);
|
||||
}
|
||||
}
|
||||
rns_wire::context::PacketContext::ResourceIcl => {
|
||||
let plaintext = self
|
||||
.pending
|
||||
.get(&link_id)
|
||||
.and_then(|d| d.link.decrypt(data).ok());
|
||||
let plaintext = self.decrypt_resource_control(&link_id, data);
|
||||
if let Some(pt) = plaintext {
|
||||
self.handle_inbound_resource_cancel(&link_id, &pt);
|
||||
}
|
||||
@@ -2087,7 +2233,7 @@ impl LinkDeliveryManager {
|
||||
delivery.failure_reason = Some(reason.to_string());
|
||||
return false;
|
||||
}
|
||||
EndpointBindReceiver::Legacy(result_rx)
|
||||
EndpointBindReceiver::Legacy(result_rx.into())
|
||||
};
|
||||
self.pending_endpoint_binds.insert(
|
||||
*link_id,
|
||||
@@ -2103,6 +2249,18 @@ impl LinkDeliveryManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Authenticated Resource control traffic is peer liveness even when no
|
||||
/// ordinary Link packet or keepalive is exchanged during a long transfer.
|
||||
/// Keep the Resource progress watchdog separate: a valid control packet
|
||||
/// does not by itself mean new parts were delivered.
|
||||
fn decrypt_resource_control(&mut self, link_id: &[u8; 16], data: &[u8]) -> Option<Vec<u8>> {
|
||||
let delivery = self.pending.get_mut(link_id)?;
|
||||
let plaintext = delivery.link.decrypt(data).ok()?;
|
||||
delivery.link.record_inbound();
|
||||
delivery.link.record_rx(data.len());
|
||||
Some(plaintext)
|
||||
}
|
||||
|
||||
fn handle_inbound_link_packet(
|
||||
&mut self,
|
||||
link_id: &[u8; 16],
|
||||
@@ -3407,7 +3565,30 @@ impl LinkDeliveryManager {
|
||||
let Some(ref mut transfer) = delivery.transfer else {
|
||||
return;
|
||||
};
|
||||
let previously_sent = transfer.sent_parts;
|
||||
let actions = transfer.handle_request(request_data);
|
||||
let counters = &mut self.resource_counters;
|
||||
counters.requests = counters.requests.saturating_add(1);
|
||||
let mut requested_parts = 0u64;
|
||||
for action in &actions {
|
||||
if let TransferAction::SendPart(_, data) = action {
|
||||
requested_parts += 1;
|
||||
counters.part_bytes = counters.part_bytes.saturating_add(data.len() as u64);
|
||||
}
|
||||
}
|
||||
counters.part_actions = counters.part_actions.saturating_add(requested_parts);
|
||||
counters.repeated_part_actions = counters.repeated_part_actions.saturating_add(
|
||||
requested_parts
|
||||
.saturating_sub(transfer.sent_parts.saturating_sub(previously_sent) as u64),
|
||||
);
|
||||
if counters.requests == 1 || counters.requests.is_multiple_of(64) {
|
||||
tracing::debug!(target: "lxmf_core::delivery::transfer",
|
||||
resource_requests = counters.requests,
|
||||
part_actions = counters.part_actions,
|
||||
repeated_part_actions = counters.repeated_part_actions,
|
||||
part_bytes = counters.part_bytes,
|
||||
"Resource dispatch counters");
|
||||
}
|
||||
for action in actions {
|
||||
match dispatch_action(
|
||||
link_id,
|
||||
@@ -3458,6 +3639,8 @@ impl LinkDeliveryManager {
|
||||
.as_mut()
|
||||
.is_some_and(|transfer| transfer.handle_proof(proof_data))
|
||||
{
|
||||
delivery.link.record_inbound();
|
||||
delivery.link.record_rx(proof_data.len());
|
||||
let progress = delivery_resource_proof_progress(delivery).unwrap_or(1.0);
|
||||
delivery.message.progress = progress;
|
||||
event = Some(delivery_event(
|
||||
@@ -3586,6 +3769,8 @@ impl LinkDeliveryManager {
|
||||
.link
|
||||
.validate_packet_proof(&packet_hash, proof_data)
|
||||
{
|
||||
delivery.link.record_inbound();
|
||||
delivery.link.record_rx(proof_data.len());
|
||||
delivery.state = DeliveryState::Complete;
|
||||
return true;
|
||||
}
|
||||
@@ -4719,19 +4904,30 @@ fn fail_backchannel_start_in_place(
|
||||
}
|
||||
}
|
||||
|
||||
fn resource_payload_progress(transfer: &OutboundTransfer, segment_progress: f64) -> f64 {
|
||||
let resource = &transfer.resource;
|
||||
// LXMF builds payload-only MAX_EFFICIENT_SIZE segments. The advertisement
|
||||
// retains the full logical size even after the lazy plan is released;
|
||||
// data holds this segment's uncompressed bytes. Equal segment weights
|
||||
// would make a short final segment race through a full segment's percent.
|
||||
let completed_bytes = resource
|
||||
.segment_index
|
||||
.saturating_sub(1)
|
||||
.saturating_mul(MAX_EFFICIENT_SIZE);
|
||||
((completed_bytes as f64 + resource.data.len() as f64 * segment_progress)
|
||||
/ resource.advertisement_data_size.max(1) as f64)
|
||||
.clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
fn delivery_resource_progress(delivery: &PendingDelivery) -> Option<f64> {
|
||||
let transfer = delivery.transfer.as_ref()?;
|
||||
let total_segments = transfer.resource.total_segments.max(1);
|
||||
let completed_segments = transfer.resource.segment_index.saturating_sub(1);
|
||||
let aggregate = (completed_segments as f64 + transfer.progress()) / total_segments as f64;
|
||||
let aggregate = resource_payload_progress(transfer, transfer.progress());
|
||||
Some((0.10 + aggregate * 0.90).clamp(0.10, 0.99))
|
||||
}
|
||||
|
||||
fn delivery_resource_proof_progress(delivery: &PendingDelivery) -> Option<f64> {
|
||||
let transfer = delivery.transfer.as_ref()?;
|
||||
let total_segments = transfer.resource.total_segments.max(1);
|
||||
let completed_segments = transfer.resource.segment_index.min(total_segments);
|
||||
let aggregate = completed_segments as f64 / total_segments as f64;
|
||||
let aggregate = resource_payload_progress(transfer, 1.0);
|
||||
Some((0.10 + aggregate * 0.90).clamp(0.10, 1.0))
|
||||
}
|
||||
|
||||
@@ -5197,7 +5393,7 @@ fn stage_link_endpoint_with_success(
|
||||
link_id,
|
||||
final_send: false,
|
||||
success,
|
||||
result_rx,
|
||||
result_rx: result_rx.into(),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -5218,7 +5414,10 @@ fn stage_link_endpoint_unbind(
|
||||
result_tx,
|
||||
},
|
||||
)?;
|
||||
pending_cleanups.push(PendingEndpointCleanup { link_id, result_rx });
|
||||
pending_cleanups.push(PendingEndpointCleanup {
|
||||
link_id,
|
||||
result_rx: result_rx.into(),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5244,7 +5443,7 @@ fn stage_link_endpoint_and_unbind(
|
||||
link_id,
|
||||
final_send: true,
|
||||
success: EndpointSendSuccess::None,
|
||||
result_rx,
|
||||
result_rx: result_rx.into(),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -5569,7 +5768,7 @@ fn send_link_packet(
|
||||
pending_packet_dispatches.push(PendingPacketDispatch {
|
||||
link_id: *link_id,
|
||||
packet_hash,
|
||||
result_rx,
|
||||
result_rx: result_rx.into(),
|
||||
});
|
||||
delivery.link.record_tx(encrypted.len());
|
||||
return Ok(packet_hash);
|
||||
@@ -5789,6 +5988,74 @@ fn dispatch_action(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
#[test]
|
||||
fn delivery_readiness_retains_input_and_drains_bounded_turns() {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
struct Counter(AtomicUsize);
|
||||
impl std::task::Wake for Counter {
|
||||
fn wake(self: Arc<Self>) {
|
||||
self.0.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
fn wake_by_ref(self: &Arc<Self>) {
|
||||
self.0.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
let (tx, _rx) = mpsc::channel(16);
|
||||
let mut mgr = LinkDeliveryManager::new(tx, None, None);
|
||||
let counter = Arc::new(Counter(AtomicUsize::new(0)));
|
||||
let waker = std::task::Waker::from(counter.clone());
|
||||
let mut cx = Context::from_waker(&waker);
|
||||
assert!(mgr.poll_ready(&mut cx).is_pending());
|
||||
for _ in 0..40 {
|
||||
mgr.event_tx
|
||||
.try_send(DestinationEvent::LinkClosed { link_id: [0; 16] })
|
||||
.unwrap();
|
||||
}
|
||||
assert!(counter.0.load(Ordering::SeqCst) > 0);
|
||||
assert!(mgr.poll_ready(&mut cx).is_ready());
|
||||
// Dropping a caller's wait must not lose its lookahead event.
|
||||
assert!(mgr.poll_ready(&mut cx).is_ready());
|
||||
mgr.drain_events(&HashMap::new());
|
||||
assert_eq!(mgr.event_rx.len(), 8);
|
||||
assert!(mgr.poll_ready(&mut cx).is_ready());
|
||||
mgr.drain_events(&HashMap::new());
|
||||
assert!(mgr.poll_ready(&mut cx).is_pending());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn receipt_readiness_preserves_close_and_drain_cancellation() {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let mut receipt = ReadyReceipt::from(rx);
|
||||
let mut cx = Context::from_waker(std::task::Waker::noop());
|
||||
assert!(!receipt.poll_ready(&mut cx));
|
||||
tx.send(42).unwrap();
|
||||
assert!(receipt.poll_ready(&mut cx));
|
||||
receipt.close();
|
||||
assert!(!receipt.is_terminated());
|
||||
assert_eq!(receipt.try_recv().unwrap(), 42);
|
||||
assert!(receipt.is_terminated());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delivery_readiness_wakes_for_transport_capacity_without_idle_spin() {
|
||||
let (tx, mut rx) = mpsc::channel(1);
|
||||
tx.try_send(TransportMessage::DeregisterDestination { hash: [1; 16] })
|
||||
.unwrap();
|
||||
let mut mgr = LinkDeliveryManager::new(tx, None, None);
|
||||
mgr.pending_transport
|
||||
.push_back(TransportMessage::DeregisterDestination { hash: [2; 16] });
|
||||
let mut cx = Context::from_waker(std::task::Waker::noop());
|
||||
assert!(mgr.poll_ready(&mut cx).is_pending());
|
||||
rx.recv().await.unwrap();
|
||||
assert!(mgr.poll_ready(&mut cx).is_ready());
|
||||
mgr.tick();
|
||||
assert!(
|
||||
matches!(rx.recv().await, Some(TransportMessage::DeregisterDestination { hash }) if hash == [2;16])
|
||||
);
|
||||
assert!(mgr.poll_ready(&mut cx).is_pending());
|
||||
}
|
||||
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
@@ -9748,6 +10015,172 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_progress_weights_payload_bytes_including_short_final_segment() {
|
||||
for (size, compress) in [
|
||||
(4_000, false),
|
||||
(MAX_EFFICIENT_SIZE + 128, false),
|
||||
(3_500_000, false),
|
||||
(3_500_000, true),
|
||||
] {
|
||||
let (tx, mut rx) = mpsc::channel(64);
|
||||
let mut mgr = LinkDeliveryManager::new(tx, None, None);
|
||||
let mut message = LxMessage::new(
|
||||
[0xA5; 16],
|
||||
[0xB5; 16],
|
||||
"byte progress",
|
||||
&"x".repeat(size),
|
||||
crate::constants::DeliveryMethod::Direct,
|
||||
);
|
||||
message.auto_compress = compress;
|
||||
message.sign(&Ed25519PrivateKey::generate()).unwrap();
|
||||
let (link_id, _) = establish_active_delivery(
|
||||
&mut mgr,
|
||||
&mut rx,
|
||||
message,
|
||||
&Ed25519PrivateKey::generate(),
|
||||
[0xC5; 16],
|
||||
);
|
||||
assert!(mgr.tick().is_empty());
|
||||
let mut completed_bytes = 0;
|
||||
let mut last_progress = 0.10;
|
||||
loop {
|
||||
let (proof, segment_bytes, total_bytes, final_segment) = {
|
||||
let delivery = mgr.pending.get_mut(&link_id).unwrap();
|
||||
let transfer = delivery.transfer.as_ref().unwrap();
|
||||
let segment_bytes = transfer.resource.data.len();
|
||||
let total_bytes = transfer.resource.advertisement_data_size;
|
||||
let parts = transfer.resource.num_parts();
|
||||
for sent in [0, parts / 2, parts] {
|
||||
delivery.transfer.as_mut().unwrap().sent_parts = sent;
|
||||
let fraction = sent as f64 / parts as f64;
|
||||
let expected = (0.10
|
||||
+ 0.90 * (completed_bytes as f64 + segment_bytes as f64 * fraction)
|
||||
/ total_bytes as f64)
|
||||
.clamp(0.10, 0.99);
|
||||
let actual = delivery_resource_progress(delivery).unwrap();
|
||||
assert!(
|
||||
(actual - expected).abs() < 1e-9,
|
||||
"payload {size}, completed {completed_bytes}: {actual} != {expected}"
|
||||
);
|
||||
}
|
||||
let transfer = delivery.transfer.as_ref().unwrap();
|
||||
let mut proof = transfer.resource.resource_hash.to_vec();
|
||||
proof.extend_from_slice(&transfer.resource.expected_proof);
|
||||
(
|
||||
proof,
|
||||
segment_bytes,
|
||||
total_bytes,
|
||||
delivery.remaining_segments.is_none(),
|
||||
)
|
||||
};
|
||||
assert!(mgr.handle_resource_proof(&link_id, &proof));
|
||||
completed_bytes += segment_bytes;
|
||||
let progress = mgr.pending[&link_id].message.progress;
|
||||
let expected = 0.10 + 0.90 * completed_bytes as f64 / total_bytes as f64;
|
||||
assert!((progress - expected).abs() < 1e-9);
|
||||
assert!(progress >= last_progress);
|
||||
last_progress = progress;
|
||||
if final_segment {
|
||||
assert_eq!(completed_bytes, total_bytes);
|
||||
assert_eq!(progress, 1.0);
|
||||
break;
|
||||
}
|
||||
assert!(progress < 1.0, "only the final proof completes delivery");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authenticated_resource_requests_keep_active_and_stale_links_alive() {
|
||||
for stale in [false, true] {
|
||||
let (tx, mut rx) = mpsc::channel(64);
|
||||
let mut mgr = LinkDeliveryManager::new(tx, None, None);
|
||||
let mut message = LxMessage::new(
|
||||
[0xA4; 16],
|
||||
[0xB4; 16],
|
||||
"resource liveness",
|
||||
&"x".repeat(4_000),
|
||||
crate::constants::DeliveryMethod::Direct,
|
||||
);
|
||||
message.auto_compress = false;
|
||||
message.sign(&Ed25519PrivateKey::generate()).unwrap();
|
||||
let (link_id, responder) = establish_active_delivery(
|
||||
&mut mgr,
|
||||
&mut rx,
|
||||
message,
|
||||
&Ed25519PrivateKey::generate(),
|
||||
[0xC4; 16],
|
||||
);
|
||||
assert!(mgr.tick().is_empty());
|
||||
assert!(mgr.tick().is_empty());
|
||||
let _advertisement = next_outbound(&mut rx);
|
||||
let request = {
|
||||
let delivery = mgr.pending.get_mut(&link_id).unwrap();
|
||||
let old = Instant::now() - Duration::from_secs(900);
|
||||
delivery.link.keepalive.last_inbound = old;
|
||||
delivery.link.keepalive.last_proof = Some(old);
|
||||
delivery.link.keepalive.activated_at = Some(old);
|
||||
delivery.link.keepalive.last_keepalive_sent = Some(Instant::now());
|
||||
if stale {
|
||||
delivery.link.state = LinkState::Stale;
|
||||
delivery.link.stale_since = Some(old);
|
||||
}
|
||||
let transfer = delivery.transfer.as_ref().unwrap();
|
||||
let mut request = vec![rns_protocol::resource::HASHMAP_IS_NOT_EXHAUSTED];
|
||||
request.extend_from_slice(&transfer.resource.resource_hash);
|
||||
request.extend_from_slice(&transfer.resource.map_hashes[0]);
|
||||
request
|
||||
};
|
||||
let encrypted = responder.encrypt(&request).unwrap();
|
||||
let original_inbound = mgr.pending[&link_id].link.keepalive.last_inbound;
|
||||
let original_rx = mgr.pending[&link_id].link.rx_count;
|
||||
// Neither corrupt ciphertext nor a different interface owns this Link.
|
||||
for (payload, interface_id) in [(vec![0; encrypted.len()], 0), (encrypted.clone(), 9)] {
|
||||
mgr.event_tx
|
||||
.try_send(DestinationEvent::InboundPacket {
|
||||
raw: link_data_packet(
|
||||
link_id,
|
||||
rns_wire::context::PacketContext::ResourceReq,
|
||||
&payload,
|
||||
),
|
||||
interface_id,
|
||||
metrics: Default::default(),
|
||||
})
|
||||
.unwrap();
|
||||
mgr.drain_events(&HashMap::new());
|
||||
assert_eq!(
|
||||
mgr.pending[&link_id].link.keepalive.last_inbound,
|
||||
original_inbound
|
||||
);
|
||||
assert_eq!(mgr.pending[&link_id].link.rx_count, original_rx);
|
||||
}
|
||||
mgr.event_tx
|
||||
.try_send(DestinationEvent::InboundPacket {
|
||||
raw: link_data_packet(
|
||||
link_id,
|
||||
rns_wire::context::PacketContext::ResourceReq,
|
||||
&encrypted,
|
||||
),
|
||||
interface_id: 0,
|
||||
metrics: Default::default(),
|
||||
})
|
||||
.unwrap();
|
||||
mgr.drain_events(&HashMap::new());
|
||||
assert_eq!(mgr.pending[&link_id].link.rx_count, original_rx + 1);
|
||||
assert!(mgr.pending[&link_id].transfer.as_ref().unwrap().sent_parts > 0);
|
||||
assert!(
|
||||
mgr.tick().is_empty(),
|
||||
"live Resource must not lose its Link"
|
||||
);
|
||||
assert_eq!(
|
||||
mgr.pending[&link_id].link.state,
|
||||
LinkState::Active,
|
||||
"authenticated Resource requests are inbound liveness, including recovery from stale"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progressive_direct_resource_uses_watchdog_not_absolute_delivery_age() {
|
||||
let (tx, mut rx) = mpsc::channel(64);
|
||||
@@ -9785,6 +10218,93 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn late_no_compression_announcement_reaches_unconstructed_and_queued_resources() {
|
||||
let (tx, mut rx) = mpsc::channel(512);
|
||||
let mut mgr = LinkDeliveryManager::new(tx, None, None);
|
||||
let sign_key = Ed25519PrivateKey::generate();
|
||||
let message = |text: &str| {
|
||||
let mut msg = LxMessage::new(
|
||||
[0xAA; 16],
|
||||
[0xBB; 16],
|
||||
text,
|
||||
&"x".repeat(600),
|
||||
crate::constants::DeliveryMethod::Direct,
|
||||
);
|
||||
msg.sign(&sign_key).unwrap();
|
||||
msg
|
||||
};
|
||||
let dest = [0xCC; 16];
|
||||
let responder_key = Ed25519PrivateKey::generate();
|
||||
let (link, _) =
|
||||
establish_active_delivery(&mut mgr, &mut rx, message("first"), &responder_key, dest);
|
||||
mgr.start_delivery(message("queued"), dest, 1).unwrap();
|
||||
mgr.disable_pending_direct_compression(dest);
|
||||
let delivery = mgr.pending.get(&link).unwrap();
|
||||
assert!(!delivery.auto_compress);
|
||||
assert!(!delivery.message.auto_compress);
|
||||
assert_eq!(delivery.queued.len(), 1);
|
||||
assert!(!delivery.queued[0].auto_compress);
|
||||
assert!(!delivery.queued[0].message.auto_compress);
|
||||
mgr.tick();
|
||||
assert!(
|
||||
!mgr.pending[&link]
|
||||
.transfer
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.resource
|
||||
.flags
|
||||
.compressed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compression_refresh_does_not_rewrite_constructed_resources_or_relay_envelopes() {
|
||||
let (tx, mut rx) = mpsc::channel(512);
|
||||
let mut mgr = LinkDeliveryManager::new(tx, None, None);
|
||||
let key = Ed25519PrivateKey::generate();
|
||||
let mut msg = LxMessage::new(
|
||||
[0xAA; 16],
|
||||
[0xBB; 16],
|
||||
"first",
|
||||
&"x".repeat(600),
|
||||
crate::constants::DeliveryMethod::Direct,
|
||||
);
|
||||
msg.sign(&key).unwrap();
|
||||
let responder_key = Ed25519PrivateKey::generate();
|
||||
let dest = [0xCC; 16];
|
||||
let (link, _) =
|
||||
establish_active_delivery(&mut mgr, &mut rx, msg.clone(), &responder_key, dest);
|
||||
mgr.tick();
|
||||
assert!(
|
||||
mgr.pending[&link]
|
||||
.transfer
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.resource
|
||||
.flags
|
||||
.compressed
|
||||
);
|
||||
mgr.disable_pending_direct_compression(dest);
|
||||
assert!(mgr.pending[&link].auto_compress);
|
||||
assert!(
|
||||
mgr.pending[&link]
|
||||
.transfer
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.resource
|
||||
.flags
|
||||
.compressed
|
||||
);
|
||||
let relay = [0xDD; 16];
|
||||
let relay_link = mgr
|
||||
.start_packed_delivery(msg, relay, 1, vec![7; 600], true)
|
||||
.unwrap();
|
||||
mgr.disable_pending_direct_compression(relay);
|
||||
assert!(mgr.pending[&relay_link].auto_compress);
|
||||
assert!(mgr.pending[&relay_link].packed_override.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_message_delivery_snapshot_reports_active_resource() {
|
||||
let (tx, mut rx) = mpsc::channel(512);
|
||||
|
||||
Reference in new issue
Block a user