From ba856ea1c4db414dfb2b5748e01b254ba1a7dfbe Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 21 Sep 2024 19:04:28 +0200 Subject: [PATCH] Handle link transport edge case --- RNS/Link.py | 4 ++-- RNS/Transport.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index cac791c..01641b1 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -125,7 +125,7 @@ class Link: link.last_inbound = time.time() link.start_watchdog() - RNS.log("Incoming link request "+str(link)+" accepted", RNS.LOG_DEBUG) + RNS.log("Incoming link request "+str(link)+" accepted on "+str(link.attached_interface), RNS.LOG_DEBUG) return link except Exception as e: @@ -762,7 +762,7 @@ class Link: self.watchdog_lock = True if not self.status == Link.CLOSED and not (self.initiator and packet.context == RNS.Packet.KEEPALIVE and packet.data == bytes([0xFF])): if packet.receiving_interface != self.attached_interface: - RNS.log("Link-associated packet received on unexpected interface! Someone might be trying to manipulate your communication!", RNS.LOG_ERROR) + RNS.log(f"Link-associated packet received on unexpected interface {packet.receiving_interface} instead of {self.attached_interface}! Someone might be trying to manipulate your communication!", RNS.LOG_ERROR) else: self.last_inbound = time.time() if packet.context != RNS.Packet.KEEPALIVE: diff --git a/RNS/Transport.py b/RNS/Transport.py index 1d5c158..1ffd332 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -1736,8 +1736,19 @@ class Transport: if packet.destination_type == RNS.Destination.LINK: for link in Transport.active_links: if link.link_id == packet.destination_hash: - packet.link = link - link.receive(packet) + if link.attached_interface == packet.receiving_interface: + packet.link = link + link.receive(packet) + else: + # In the strange and rare case that an interface + # is partly malfunctioning, and a link-associated + # packet is being received on an interface that + # has failed sending, and transport has failed over + # to another path, we remove this packet hash from + # the filter hashlist so the link can receive the + # packet when it finally arrives over another path. + while packet.packet_hash in Transport.packet_hashlist: + Transport.packet_hashlist.remove(packet.packet_hash) else: for destination in Transport.destinations: if destination.hash == packet.destination_hash and destination.type == packet.destination_type: