From ea09b0e10548cbfef63d1f6c2149d9856ee128dd Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Sun, 25 Oct 2026 02:51:46 -0600 Subject: [PATCH] router: fall back to direct delivery above Python's 287-byte opportunistic limit --- CHANGELOG.md | 1 + api/migrations/1.4.md | 5 +++++ api/snapshots/lxmf-core.txt | 1 + api/stability.json | 4 ++-- crates/lxmf-core/src/constants.rs | 10 +++++++++ crates/lxmf-core/src/router.rs | 34 ++++++++++++++++++++++++++++--- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7266ab7..3c6ef15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Start a propagation node without rereading and flushing every stored message, so restarts with large stores no longer delay announces and hosting. Each message is still verified when it is served. - Space `lxmd` announces like Python lxmd: the propagation and control announces follow their trigger by 20 seconds instead of going out together with the delivery announce, so Python transport nodes no longer hold the control announce after a restart. A node set not to announce at start now waits a full interval before its first periodic announce. +- Fall back from opportunistic to direct delivery whenever a message's content does not fit one encrypted packet, over 287 bytes, as in Python LXMF 1.2.0. ## 1.4.0 - 2026-10-12 diff --git a/api/migrations/1.4.md b/api/migrations/1.4.md index d3a48c5..ea11086 100644 --- a/api/migrations/1.4.md +++ b/api/migrations/1.4.md @@ -156,6 +156,11 @@ is not silently interpreted. Use `unique_map` before acting on recognized map keys. Text/media projections borrow where possible; repaired UTF8 allocates only the exact replacement length. +`constants::ENCRYPTED_PACKET_MAX_CONTENT` is LXMF 1.2.0's single-packet +content limit, 287 bytes, which `LxmRouter::try_send` applies to opportunistic +messages. Applications that choose a delivery method themselves should compare +against it rather than a hard-coded limit. + The API ledger retains its original compatibility floor and lists exact removed rendered lines. Metadata fields moved under `MessageMetadata` retain ordinary field access through Deref; duplicate `message_api` snapshot paths describe the diff --git a/api/snapshots/lxmf-core.txt b/api/snapshots/lxmf-core.txt index 28aa596..ac0abc6 100644 --- a/api/snapshots/lxmf-core.txt +++ b/api/snapshots/lxmf-core.txt @@ -196,6 +196,7 @@ pub const lxmf_core::constants::DELIVERY_LIMIT: usize pub const lxmf_core::constants::DELIVERY_RETRY_WAIT: u64 pub const lxmf_core::constants::DESTINATION_LENGTH: usize pub const lxmf_core::constants::DUPLICATE_SIGNAL: &str +pub const lxmf_core::constants::ENCRYPTED_PACKET_MAX_CONTENT: usize pub const lxmf_core::constants::FASTEST_N_RANDOM_POOL: usize pub const lxmf_core::constants::FIELD_AUDIO: u8 pub const lxmf_core::constants::FIELD_COMMANDS: u8 diff --git a/api/stability.json b/api/stability.json index b2d115d..5f5acf8 100644 --- a/api/stability.json +++ b/api/stability.json @@ -24,8 +24,8 @@ "tier": "candidate-stable", "compatibility": "reviewed-snapshot", "snapshot": "api/snapshots/lxmf-core.txt", - "itemCount": 2208, - "sha256": "e25c207398c8124dbd73cd800d2eb53d5f5615ae47485e654dc39c56d955f653" + "itemCount": 2209, + "sha256": "3983790769c9ae44c1b2665cbf894720b39fa03635575a04b3d0f19e412de83e" }, { "name": "lxmf-tools", diff --git a/crates/lxmf-core/src/constants.rs b/crates/lxmf-core/src/constants.rs index ad92371..87c7c71 100644 --- a/crates/lxmf-core/src/constants.rs +++ b/crates/lxmf-core/src/constants.rs @@ -152,6 +152,10 @@ pub const STRUCT_OVERHEAD: usize = 8; /// 2 * dest(16) + sig(64) + timestamp(8) + struct(8) = 112. pub const LXMF_OVERHEAD: usize = 2 * DESTINATION_LENGTH + SIGNATURE_LENGTH + TIMESTAMP_SIZE + STRUCT_OVERHEAD; +/// Largest content an opportunistic message carries in one encrypted packet; +/// the packet's destination supplies the destination hash. 383 - 112 + 16 = 287. +pub const ENCRYPTED_PACKET_MAX_CONTENT: usize = + rns_wire::constants::SINGLE_PACKET_ENCRYPTED_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH; pub const PAPER_MDU: usize = 2210; pub const TICKET_EXPIRY: u64 = 21 * 24 * 60 * 60; @@ -292,6 +296,12 @@ mod tests { assert_eq!(LXMF_OVERHEAD, 112); } + /// LXMF 1.2.0 `ENCRYPTED_PACKET_MAX_CONTENT` (LXMessage.py:64-79, 3fc60af). + #[test] + fn encrypted_packet_max_content_is_lxmf_1_2_0s() { + assert_eq!(ENCRYPTED_PACKET_MAX_CONTENT, 287); + } + #[test] fn test_message_states_distinct() { assert_ne!(MessageState::Generating as u8, MessageState::Outbound as u8); diff --git a/crates/lxmf-core/src/router.rs b/crates/lxmf-core/src/router.rs index 3a30d39..e48910a 100644 --- a/crates/lxmf-core/src/router.rs +++ b/crates/lxmf-core/src/router.rs @@ -576,9 +576,7 @@ impl LxmRouter { let content_size = packed .len() .saturating_sub(TIMESTAMP_SIZE + STRUCT_OVERHEAD); - // Approximates ENCRYPTED_PACKET_MAX_CONTENT for default RNS parameters. - let max_content = 295; - if content_size > max_content { + if content_size > ENCRYPTED_PACKET_MAX_CONTENT { message.method = DeliveryMethod::Direct; } } @@ -3487,6 +3485,36 @@ mod tests { assert_eq!(router.pending_outbound[0].state, MessageState::Outbound); } + /// LXMF 1.2.0 keeps a message opportunistic only while its content fits + /// one encrypted packet, 287 bytes (LXMessage.py:64-79, :402-406). + #[test] + fn opportunistic_content_over_one_packet_falls_back_to_direct() { + let mut router = LxmRouter::new(RouterConfig::default()); + for (content_size, method) in [ + (287, DeliveryMethod::Opportunistic), + (288, DeliveryMethod::Direct), + ] { + let message = crate::message::test_message( + [0xAA; 16], + [0xBB; 16], + "", + &"x".repeat(content_size), + DeliveryMethod::Opportunistic, + ); + let packed = message.pack_payload().unwrap(); + assert_eq!( + packed.len() - TIMESTAMP_SIZE - STRUCT_OVERHEAD, + content_size + ); + router.try_send(message).unwrap(); + assert_eq!( + router.pending_outbound.last().unwrap().method, + method, + "content of {content_size} bytes" + ); + } + } + #[test] fn test_try_send_propagated_without_node_fails_immediately() { let mut router = LxmRouter::new(RouterConfig::default());