transport: a cached announce reports the emission time of the packet that last refreshed it

This commit is contained in:
DeFiDude committed 2026-11-20 12:42:36 -07:00
1 parent 54c85253e3
commit f6d0d698dd
10 files changed
+73 -4

No files matched your search

+2
View File
@@ -17,6 +17,7 @@ pub async fn rns_transport::actor::PersistenceTrigger::request(&self) -> bool
pub struct rns_transport::actor::RecentAnnounce
pub rns_transport::actor::RecentAnnounce::app_data: core::option::Option<alloc::vec::Vec<u8>>
pub rns_transport::actor::RecentAnnounce::dest_hash: [u8; 16]
pub rns_transport::actor::RecentAnnounce::emitted: core::option::Option<u64>
pub rns_transport::actor::RecentAnnounce::facts_known: bool
pub rns_transport::actor::RecentAnnounce::hops: u8
pub rns_transport::actor::RecentAnnounce::is_path_response: bool
@@ -1363,6 +1364,7 @@ pub struct rns_transport::messages::AnnounceHandlerId(_)
#[non_exhaustive] pub struct rns_transport::messages::AnnounceRpcEntry
pub rns_transport::messages::AnnounceRpcEntry::app_data: core::option::Option<alloc::vec::Vec<u8>>
pub rns_transport::messages::AnnounceRpcEntry::dest_hash: [u8; 16]
pub rns_transport::messages::AnnounceRpcEntry::emitted: core::option::Option<u64>
pub rns_transport::messages::AnnounceRpcEntry::facts_known: bool
pub rns_transport::messages::AnnounceRpcEntry::hops: u8
pub rns_transport::messages::AnnounceRpcEntry::is_path_response: bool
+2 -2
View File
@@ -51,8 +51,8 @@
"tier": "provisional",
"compatibility": "reviewed-snapshot",
"snapshot": "api/snapshots/rns-transport.txt",
"itemCount": 2271,
"sha256": "ec003696e642b1b5696c04d65f885a0abce2888e820e8e88be121135af71706a"
"itemCount": 2273,
"sha256": "7894fdab76428a6fd8cd7097e60058409a6a593d8c4970c01c5d440e98613fa1"
},
{
"name": "rns-link",
+3 -2
View File
@@ -845,6 +845,7 @@ impl TransportActor {
let announce_identity_hash = Some(validated.identity_hash);
let announce_random_hash = announce_data.random_hash;
let announce_stamp_value = validated.stamp_value.unwrap_or(0.0);
let announce_emitted = announce_timebase(&announce_random_hash);
// Python remembers every freshly validated announce, replays included,
// before it decides whether the path changes; a validation-cache hit
@@ -868,6 +869,7 @@ impl TransportActor {
e.is_path_response = is_path_response;
e.name_hash = announce_name_hash;
e.facts_known = true;
e.emitted = Some(announce_emitted);
self.kd.pending.mark_dirty(header.destination_hash);
self.remember_received_ratchet(header.destination_hash, announce_ratchet);
}
@@ -891,6 +893,7 @@ impl TransportActor {
stamp_value: announce_stamp_value,
lr_cost: validated.lr_cost,
facts_known: true,
emitted: Some(announce_emitted),
});
self.state_dirty = true;
self.kd.pending.mark_dirty(header.destination_hash);
@@ -915,8 +918,6 @@ impl TransportActor {
.map(|e| e.mode)
.unwrap_or(InterfaceMode::Gateway);
let announce_emitted = announce_timebase(&announce_random_hash);
// Cancel our queued rebroadcast when a neighbor already carried it.
// Same-hop neighbor rebroadcast counts toward the local cap;
// strict hops+1 forward drops our queued copy outright.
@@ -762,6 +762,7 @@ mod cleanup_tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
};
actor.recent_announces.insert(entry.dest_hash, entry);
}
+53
View File
@@ -391,6 +391,10 @@ pub struct RecentAnnounce {
/// False for an entry restored from a row that carries no announce facts:
/// `hops`, `name_hash`, and `is_path_response` are then unknown, not zero.
pub facts_known: bool,
/// Emission time stamped into the random hash of the packet that last
/// refreshed this entry, which may be an older announce heard late; `None`
/// once restored from storage.
pub emitted: Option<u64>,
}
impl RecentAnnounce {
@@ -3328,6 +3332,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -3401,6 +3406,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
}
@@ -3500,6 +3506,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
}
@@ -3526,6 +3533,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
let mut target_path =
@@ -6349,6 +6357,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -6404,6 +6413,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
}
@@ -8651,6 +8661,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
actor.blackhole_table.add_with_reason(
@@ -9364,6 +9375,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
}];
let dir = std::env::temp_dir().join("reticulum_rs_test_announce_cache");
@@ -9667,6 +9679,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -9931,6 +9944,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -11660,6 +11674,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -12308,6 +12323,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -12570,6 +12586,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -12661,6 +12678,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -12809,6 +12827,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
@@ -13291,6 +13310,39 @@ mod tests {
assert_eq!(hrx.try_recv().unwrap().emitted, emitted);
}
/// Once the path is gone an older announce is accepted again (Transport.py)
/// and refreshes the cache, so the entry carries its own, older emission.
#[test]
fn cached_announce_reports_the_emission_of_the_packet_that_refreshed_it() {
let (mut actor, _tx) = TransportActor::new();
let (entry, _rx) = make_test_interface("test_iface");
actor.interfaces.insert(1, entry);
let identity = rns_identity::identity::Identity::new();
for (prefix, emitted) in [(0x41, 1_700_000_100), (0x42, 1_700_000_000)] {
let (raw, dest_hash) = make_announce_for_with_random_blob(
&identity,
"test.emitted",
1,
random_blob(prefix, emitted),
);
actor.on_inbound(crate::messages::InboundPacket {
raw,
interface_id: 1,
rssi: None,
snr: None,
q: None,
});
let crate::messages::TransportQueryResponse::Announces(entries) =
actor.handle_query(crate::messages::TransportQuery::GetRecentAnnounces)
else {
panic!("expected Announces");
};
let cached = entries.iter().find(|e| e.dest_hash == dest_hash).unwrap();
assert_eq!(cached.emitted, Some(emitted));
actor.path_table.remove(&dest_hash);
}
}
#[test]
fn path_response_bypasses_announce_rate_limit() {
let (mut actor, _tx) = TransportActor::new();
@@ -13586,6 +13638,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
}
@@ -43,6 +43,7 @@ fn recent_announce_from_cached_packet(
stamp_value: 0.0,
lr_cost: None,
facts_known: false,
emitted: None,
};
if let Ok((header, offset)) = rns_wire::header::PacketHeader::unpack(&raw_packet)
@@ -1282,6 +1283,7 @@ mod announce_clean_tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
actor
@@ -1527,6 +1529,7 @@ mod async_save_tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
},
);
let now = crate::now_f64();
+1
View File
@@ -243,6 +243,7 @@ impl TransportActor {
is_path_response,
retained: a.retained,
facts_known: a.facts_known,
emitted: a.emitted,
}
})
.collect();
@@ -1289,6 +1289,7 @@ pub(super) fn recent_from_row(row: KnownDestinationRow) -> RecentAnnounce {
stamp_value: row.stamp_value,
lr_cost: row.lr_cost,
facts_known: facts.is_some(),
emitted: None,
}
}
@@ -1372,6 +1373,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: Some(3.0),
facts_known: true,
emitted: None,
}
}
+4
View File
@@ -1618,6 +1618,10 @@ pub struct AnnounceRpcEntry {
/// `hops`, `name_hash`, and `is_path_response` are then unknown, and hold
/// zero and `false` only as placeholders.
pub facts_known: bool,
/// Unix seconds the announcer stamped into the cached announce's random
/// hash. A copy of an older announce accepted late carries its own, older
/// time; `None` for an entry restored from storage.
pub emitted: Option<u64>,
}
/// Identity-bearing metadata returned by [`TransportQuery::RecallDestination`].
+2
View File
@@ -2296,6 +2296,7 @@ mod tests {
stamp_value: 0.0,
lr_cost: None,
facts_known: true,
emitted: None,
}];
let dir = std::env::temp_dir().join("reticulum_rs_test_announce_persist");
@@ -2336,6 +2337,7 @@ mod tests {
stamp_value: 25.5,
lr_cost: Some(12.5),
facts_known: true,
emitted: None,
};
let dir =
std::env::temp_dir().join(format!("rns_announce_stamp_fields_{}", std::process::id()));