mirror of
https://github.com/ratspeak/rsLXMF
synced 2026-11-22 23:10:35 +00:00
lxmf: align outbound retry cadence and fail boundary with upstream
This commit is contained in:
1 parent
9262a8ac5e
commit
bf9db7d71a
3 files changed
+52
-44
No files matched your search
@@ -148,8 +148,6 @@ pub const PEERING_COST: u8 = 18;
|
||||
pub const MAX_PEERING_COST: u8 = 26;
|
||||
pub const MAX_PEERS: usize = 20;
|
||||
pub const PN_STAMP_THROTTLE: u64 = 180;
|
||||
/// Propagation retrieval path timeout (seconds).
|
||||
pub const PR_PATH_TIMEOUT: u64 = 10;
|
||||
|
||||
pub const AUTOPEER: bool = true;
|
||||
pub const AUTOPEER_MAXDEPTH: usize = 4;
|
||||
@@ -168,26 +166,6 @@ pub const PR_ALL_MESSAGES: u32 = 0x00;
|
||||
/// Signal value for duplicate detection during sync.
|
||||
pub const DUPLICATE_SIGNAL: &str = "lxmf_duplicate";
|
||||
|
||||
/// Client-side state machine for retrieving messages from a propagation node.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[repr(u8)]
|
||||
pub enum PropagationRetrievalState {
|
||||
Idle = 0x00,
|
||||
PathRequested = 0x01,
|
||||
LinkEstablishing = 0x02,
|
||||
LinkEstablished = 0x03,
|
||||
RequestSent = 0x04,
|
||||
Receiving = 0x05,
|
||||
ResponseReceived = 0x06,
|
||||
Complete = 0x07,
|
||||
NoPath = 0xF0,
|
||||
LinkFailed = 0xF1,
|
||||
TransferFailed = 0xF2,
|
||||
NoIdentityReceived = 0xF3,
|
||||
NoAccess = 0xF4,
|
||||
Failed = 0xFE,
|
||||
}
|
||||
|
||||
pub const OFFER_REQUEST_PATH: &str = "/offer";
|
||||
pub const MESSAGE_GET_PATH: &str = "/get";
|
||||
/// Maximum time a peer can be unreachable before removal (14 days).
|
||||
@@ -337,17 +315,6 @@ mod tests {
|
||||
assert_eq!(DeliveryRepresentation::Paper as u8, 0x05);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_propagation_retrieval_states() {
|
||||
assert_eq!(PropagationRetrievalState::Idle as u8, 0x00);
|
||||
assert_eq!(PropagationRetrievalState::Complete as u8, 0x07);
|
||||
assert_eq!(PropagationRetrievalState::NoPath as u8, 0xF0);
|
||||
assert_eq!(PropagationRetrievalState::Failed as u8, 0xFE);
|
||||
// Ordering must support range comparisons.
|
||||
assert!(PropagationRetrievalState::Idle < PropagationRetrievalState::LinkEstablished);
|
||||
assert!(PropagationRetrievalState::Complete < PropagationRetrievalState::NoPath);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_router_constants_match_python() {
|
||||
assert_eq!(PROCESSING_INTERVAL, 4);
|
||||
|
||||
@@ -85,6 +85,12 @@ pub struct LxMessage {
|
||||
pub delivery_attempts: u32,
|
||||
/// Unix timestamp of the last delivery attempt; 0.0 means never attempted.
|
||||
pub last_delivery_attempt: f64,
|
||||
/// Absolute Unix timestamp before which the message must not be re-attempted.
|
||||
/// Mirrors Python LXMF `LXMessage.next_delivery_attempt`: set to
|
||||
/// `now + PATH_REQUEST_WAIT` after a path request, `now + DELIVERY_RETRY_WAIT`
|
||||
/// after a link attempt. 0.0 = no explicit deadline (router falls back to
|
||||
/// `last_delivery_attempt + DELIVERY_RETRY_WAIT`).
|
||||
pub next_delivery_attempt: f64,
|
||||
/// SHA-256 of the packed message.
|
||||
pub hash: Option<[u8; 32]>,
|
||||
/// Alias for [`hash`](Self::hash) set after packing.
|
||||
@@ -150,6 +156,7 @@ impl LxMessage {
|
||||
ratchet_id: None,
|
||||
delivery_attempts: 0,
|
||||
last_delivery_attempt: 0.0,
|
||||
next_delivery_attempt: 0.0,
|
||||
hash: None,
|
||||
message_id: None,
|
||||
transient_id: None,
|
||||
@@ -460,6 +467,7 @@ impl LxMessage {
|
||||
ratchet_id: None,
|
||||
delivery_attempts: 0,
|
||||
last_delivery_attempt: 0.0,
|
||||
next_delivery_attempt: 0.0,
|
||||
hash: Some(hash),
|
||||
message_id: Some(hash),
|
||||
transient_id: None,
|
||||
|
||||
@@ -160,7 +160,6 @@ pub struct LxmRouter {
|
||||
pub propagation_start_time: Option<f64>,
|
||||
pub processing_count: u64,
|
||||
pub outbound_propagation_node: Option<[u8; 16]>,
|
||||
pub propagation_transfer_state: PropagationRetrievalState,
|
||||
/// Progress in the range 0.0..=1.0.
|
||||
pub propagation_transfer_progress: f64,
|
||||
pub client_propagation_messages_received: u64,
|
||||
@@ -214,7 +213,6 @@ impl LxmRouter {
|
||||
propagation_start_time: None,
|
||||
processing_count: 0,
|
||||
outbound_propagation_node: None,
|
||||
propagation_transfer_state: PropagationRetrievalState::Idle,
|
||||
propagation_transfer_progress: 0.0,
|
||||
client_propagation_messages_received: 0,
|
||||
client_propagation_messages_served: 0,
|
||||
@@ -1124,7 +1122,9 @@ impl LxmRouter {
|
||||
|
||||
let now = now_f64();
|
||||
|
||||
if msg.delivery_attempts >= MAX_DELIVERY_ATTEMPTS {
|
||||
// Python fails only when delivery_attempts > MAX (outer guard is
|
||||
// `<= MAX`, LXMRouter.py:2597/2671); match that boundary exactly.
|
||||
if msg.delivery_attempts > MAX_DELIVERY_ATTEMPTS {
|
||||
let mut msg = self.pending_outbound.remove(i);
|
||||
msg.mark_failed();
|
||||
actions.push(OutboundAction::Failed(msg));
|
||||
@@ -1132,12 +1132,20 @@ impl LxmRouter {
|
||||
continue;
|
||||
}
|
||||
|
||||
if msg.last_delivery_attempt > 0.0 {
|
||||
let since_last = now - msg.last_delivery_attempt;
|
||||
if since_last < DELIVERY_RETRY_WAIT as f64 {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
// Python LXMF gates on an absolute `next_delivery_attempt`. Honor an
|
||||
// explicit deadline when set (path request -> now+7s, etc.);
|
||||
// otherwise fall back to the legacy
|
||||
// last_delivery_attempt + DELIVERY_RETRY_WAIT (10s) rule.
|
||||
let due_at = if msg.next_delivery_attempt > 0.0 {
|
||||
msg.next_delivery_attempt
|
||||
} else if msg.last_delivery_attempt > 0.0 {
|
||||
msg.last_delivery_attempt + DELIVERY_RETRY_WAIT as f64
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
if now < due_at {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let age = now - msg.timestamp;
|
||||
@@ -1786,8 +1794,30 @@ mod tests {
|
||||
assert!(router.pending_outbound.is_empty());
|
||||
}
|
||||
|
||||
/// Python fails a message only when delivery_attempts > MAX_DELIVERY_ATTEMPTS
|
||||
/// (outer guard is `<= MAX`, LXMRouter.py:2597/2671). Pin that boundary.
|
||||
#[test]
|
||||
fn test_process_outbound_max_attempts() {
|
||||
fn test_process_outbound_fails_only_above_max_attempts() {
|
||||
let mut router = LxmRouter::new(RouterConfig::default());
|
||||
let mut msg = LxMessage::new(
|
||||
[0xAA; 16],
|
||||
[0xBB; 16],
|
||||
"Test",
|
||||
"Content",
|
||||
DeliveryMethod::Direct,
|
||||
);
|
||||
msg.delivery_attempts = MAX_DELIVERY_ATTEMPTS + 1;
|
||||
router.send(msg);
|
||||
|
||||
let actions = router.process_outbound();
|
||||
assert_eq!(actions.len(), 1);
|
||||
assert!(matches!(actions[0], OutboundAction::Failed(_)));
|
||||
assert!(router.pending_outbound.is_empty());
|
||||
}
|
||||
|
||||
/// At exactly MAX the message is still attempted (dispatched), not failed.
|
||||
#[test]
|
||||
fn test_process_outbound_at_max_attempts_not_failed() {
|
||||
let mut router = LxmRouter::new(RouterConfig::default());
|
||||
let mut msg = LxMessage::new(
|
||||
[0xAA; 16],
|
||||
@@ -1801,7 +1831,10 @@ mod tests {
|
||||
|
||||
let actions = router.process_outbound();
|
||||
assert_eq!(actions.len(), 1);
|
||||
assert!(router.pending_outbound.is_empty());
|
||||
assert!(
|
||||
!matches!(actions[0], OutboundAction::Failed(_)),
|
||||
"at exactly MAX the message is still attempted, not failed"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user