router: fall back to direct delivery above Python's 287-byte opportunistic limit

This commit is contained in:
DeFiDude committed 2026-10-25 02:51:46 -06:00
1 parent 769d0eb0a3
commit ea09b0e105
6 files changed
+50 -5

No files matched your search

+1
View File
@@ -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
+5
View File
@@ -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
+1
View File
@@ -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
+2 -2
View File
@@ -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",
+10
View File
@@ -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);
+31 -3
View File
@@ -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());