mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
transport: admit routed packets before dedup and relay shared radios
This commit is contained in:
1 parent
9bc7ee5ff9
commit
62e144ed27
3 files changed
+56
-33
No files matched your search
@@ -68,6 +68,27 @@ impl TransportActor {
|
||||
return;
|
||||
}
|
||||
|
||||
// The canonical packet hash excludes the next-hop transport address
|
||||
// and survives final-hop H2-to-H1 rewriting. An overheard packet for
|
||||
// another transport must therefore not enter our accepted hashlist:
|
||||
// its later, correctly routed copy has exactly the same hash. Keep
|
||||
// this admission before repeat-context and known-Link exceptions too.
|
||||
// Only ingress from our attached shared owner delegates this filter;
|
||||
// a local client or an unrelated radio is not that trust boundary.
|
||||
let from_shared_owner =
|
||||
self.is_shared_instance && self.is_shared_instance_peer_interface(packet.interface_id);
|
||||
if parsed.flags.packet_type != rns_wire::flags::PacketType::Announce
|
||||
&& parsed.transport_id.is_some()
|
||||
&& parsed.transport_id != self.transport_identity_hash
|
||||
&& !from_shared_owner
|
||||
{
|
||||
trace!(
|
||||
interface_id = packet.interface_id,
|
||||
"packet for another transport dropped before hash admission"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Dedup via the packet hashlist. A handful of contexts legitimately
|
||||
// repeat (keepalives, resource transfer frames, channel traffic) and
|
||||
// must bypass the check.
|
||||
@@ -767,7 +788,6 @@ impl TransportActor {
|
||||
if let Some((target_interface, forwarded)) = self.transport_forward_candidate(
|
||||
raw,
|
||||
header,
|
||||
interface_id,
|
||||
from_local_client,
|
||||
for_local_client,
|
||||
to_local_client,
|
||||
@@ -809,17 +829,9 @@ impl TransportActor {
|
||||
.is_some_and(|entry| self.is_local_client_interface(entry.receiving_interface));
|
||||
let to_local_client = for_local_client || proof_for_local_client;
|
||||
|
||||
let link_request_for_this_instance = header.transport_id.is_none()
|
||||
|| header
|
||||
.transport_id
|
||||
.zip(self.transport_identity_hash)
|
||||
.is_some_and(|(packet_transport_id, our_transport_id)| {
|
||||
packet_transport_id == our_transport_id
|
||||
});
|
||||
|
||||
if self.local_destinations.contains(&header.destination_hash)
|
||||
&& link_request_for_this_instance
|
||||
{
|
||||
// on_inbound already established transport ownership (or the exact
|
||||
// attached shared-owner ingress) before admitting this packet's hash.
|
||||
if self.local_destinations.contains(&header.destination_hash) {
|
||||
if let Some(tx) = self.destination_channels.get(&header.destination_hash) {
|
||||
if let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::LinkRequest {
|
||||
raw: raw.clone(),
|
||||
@@ -837,7 +849,6 @@ impl TransportActor {
|
||||
if let Some((target_interface, forwarded)) = self.transport_forward_candidate(
|
||||
raw,
|
||||
header,
|
||||
interface_id,
|
||||
from_local_client,
|
||||
for_local_client,
|
||||
to_local_client,
|
||||
@@ -894,15 +905,11 @@ impl TransportActor {
|
||||
&self,
|
||||
raw: &[u8],
|
||||
header: &rns_wire::header::PacketHeader,
|
||||
interface_id: InterfaceId,
|
||||
from_local_client: bool,
|
||||
for_local_client: bool,
|
||||
to_local_client: bool,
|
||||
) -> Option<(InterfaceId, Vec<u8>)> {
|
||||
let path = self.path_table.get_live(&header.destination_hash)?;
|
||||
if path.interface_id == interface_id && !for_local_client {
|
||||
return None;
|
||||
}
|
||||
|
||||
let may_forward_for_shared_client = from_local_client || for_local_client;
|
||||
let addressed_to_us = header
|
||||
@@ -924,6 +931,10 @@ impl TransportActor {
|
||||
return None;
|
||||
}
|
||||
|
||||
// One broadcast interface can reach multiple neighbors that cannot
|
||||
// hear each other. Once routing ownership is established, the next
|
||||
// hop may legitimately use the ingress radio. Deduplication and the
|
||||
// next-hop address, not interface inequality, prevent packet loops.
|
||||
let mut forwarded =
|
||||
self.rewrite_forwarded_transport_packet(raw, header, path, to_local_client)?;
|
||||
// Python 1.3.8 Transport.py:1687: substitute the delta for
|
||||
|
||||
@@ -98,8 +98,9 @@ impl TransportActor {
|
||||
entry.retries += 1;
|
||||
entry.retransmit_timeout = now + PATHFINDER_G + rand_window();
|
||||
}
|
||||
// Never retransmit back out the interface the announce came
|
||||
// in on — that's just loopback and will cause dedup churn.
|
||||
// The helper excludes an exact shared IPC peer and applies
|
||||
// mode policy. A broadcast radio may need same-interface
|
||||
// retransmission to reach a different physical neighbor.
|
||||
if let Some((raw, source_iface, _, _)) = send_info {
|
||||
self.broadcast_announce_on_interfaces(&raw, source_iface);
|
||||
}
|
||||
|
||||
@@ -1640,13 +1640,13 @@ impl TransportActor {
|
||||
if !entry.direction.outbound {
|
||||
return false;
|
||||
}
|
||||
// Normally an announce is never sent back out its source interface
|
||||
// (loopback / dedup churn on a shared medium). A multipoint interface
|
||||
// (e.g. BLE Peer) is the exception: its peers can't hear each other, so
|
||||
// relaying back out reaches the ones the source peer couldn't. The
|
||||
// driver's per-peer anti-loop filter keeps it off the source peer, and
|
||||
// the announce-table dedup + hop cap bound propagation.
|
||||
if except == Some(id) && !entry.multipoint {
|
||||
// A physical broadcast interface can have hidden neighbors, so an
|
||||
// announce may need to leave through the same radio it arrived on.
|
||||
// Announce scheduling/rebroadcast observation bounds propagation;
|
||||
// the mode gates below still exclude AP and same-Roaming relaying.
|
||||
// Shared IPC edges, unlike a radio, each name one peer and must not
|
||||
// echo that peer's announce straight back to it.
|
||||
if except == Some(id) && entry.role != InterfaceRole::Normal {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2503,13 +2503,12 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multipoint_interface_relays_announce_to_source() {
|
||||
fn test_broadcast_interface_relays_announce_to_hidden_neighbors() {
|
||||
let (mut actor, _tx) = TransportActor::new();
|
||||
let dest = [0xAB; 16];
|
||||
|
||||
// Point-to-multipoint medium whose peers can't hear each other:
|
||||
// an announce arriving here must be allowed back out the same
|
||||
// interface. A normal interface must still exclude its source.
|
||||
// A normal radio and a driver with per-peer fan-out can both have
|
||||
// neighbors that cannot hear each other.
|
||||
let (normal, _rx) = make_test_interface("normal");
|
||||
actor.interfaces.insert(1, normal);
|
||||
let (mut mp, _rx2) = make_test_interface("ble");
|
||||
@@ -2521,13 +2520,21 @@ mod tests {
|
||||
.insert(dest, PathEntry::new(None, 1, 2, InterfaceMode::Gateway));
|
||||
|
||||
assert!(
|
||||
!actor.interface_allows_announce(1, &dest, Some(1)),
|
||||
"normal interface must not relay an announce back to its source"
|
||||
actor.interface_allows_announce(1, &dest, Some(1)),
|
||||
"normal broadcast interface must reach hidden neighbors"
|
||||
);
|
||||
assert!(
|
||||
actor.interface_allows_announce(2, &dest, Some(2)),
|
||||
"multipoint interface must relay an announce back to its other peers"
|
||||
);
|
||||
|
||||
for role in [InterfaceRole::LocalClient, InterfaceRole::SharedInstancePeer] {
|
||||
actor.interfaces.get_mut(&1).unwrap().role = role;
|
||||
assert!(
|
||||
!actor.interface_allows_announce(1, &dest, Some(1)),
|
||||
"a shared IPC edge must not echo to its only peer"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -5874,6 +5881,7 @@ mod tests {
|
||||
actor.interfaces.insert(1, entry1);
|
||||
|
||||
let transport_id = [0xAA; 16];
|
||||
actor.transport_identity_hash = Some(transport_id);
|
||||
let dest_hash = [0xBB; 16];
|
||||
actor.local_destinations.insert(dest_hash);
|
||||
|
||||
@@ -6665,9 +6673,12 @@ mod tests {
|
||||
// Flush deferred announces (rebroadcast is now deferred via announce table)
|
||||
hub.flush_pending_announces();
|
||||
|
||||
// Hub rebroadcasts announce on other interfaces.
|
||||
// Hub rebroadcasts on both normal interfaces: the source interface
|
||||
// may also have neighbors that could not hear the original sender.
|
||||
let rebroadcast = hub_rx1.try_recv().unwrap();
|
||||
assert_eq!(rebroadcast[1], 1); // hub's inbound-adjusted announce hops
|
||||
let source_rebroadcast = hub_rx2.try_recv().unwrap();
|
||||
assert_eq!(source_rebroadcast, rebroadcast);
|
||||
|
||||
// Peer receives the rebroadcast.
|
||||
peer.on_inbound(InboundPacket {
|
||||
|
||||
Reference in new issue
Block a user