diff --git a/RNS/Interfaces/BackboneInterface.py b/RNS/Interfaces/BackboneInterface.py index 47a30ac3..1d75b9a3 100644 --- a/RNS/Interfaces/BackboneInterface.py +++ b/RNS/Interfaces/BackboneInterface.py @@ -155,6 +155,7 @@ class BackboneInterface(Interface): self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL self.spawned_interfaces = [] self.supports_discovery = True + self.tunnels_allowed = True self.client_limit = client_limit or self.CLIENT_LIMIT self.block_fast_flapping = flap_block self.fast_flap_threshold = flap_threshold @@ -883,6 +884,7 @@ class BackboneClientInterface(Interface): self.OUT = False self.socket = None self.parent_interface = None + self.tunnels_allowed = True self.name = name self.initiator = False self.reconnecting = False @@ -936,8 +938,7 @@ class BackboneClientInterface(Interface): thread = threading.Thread(target=self.reconnect) thread.daemon = True thread.start() - else: - self.wants_tunnel = True + else: self.wants_tunnel = True def set_timeouts_linux(self): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, int(BackboneClientInterface.TCP_USER_TIMEOUT * 1000)) diff --git a/RNS/Interfaces/I2PInterface.py b/RNS/Interfaces/I2PInterface.py index 892420e4..da052f83 100644 --- a/RNS/Interfaces/I2PInterface.py +++ b/RNS/Interfaces/I2PInterface.py @@ -353,6 +353,7 @@ class I2PInterfacePeer(Interface): self.online = False self.detached = False self.kiss_framing = False + self.tunnels_allowed = True self.i2p_tunneled = True self.i2p_dest = None self.i2p_tunnel_ready = False @@ -738,6 +739,7 @@ class I2PInterface(Interface): self.owner = owner self.connectable = connectable self.i2p_tunneled = True + self.tunnels_allowed = True self.peers = peers self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL diff --git a/RNS/Interfaces/Interface.py b/RNS/Interfaces/Interface.py index 4c16b65e..44de9681 100755 --- a/RNS/Interfaces/Interface.py +++ b/RNS/Interfaces/Interface.py @@ -130,6 +130,8 @@ class Interface: self.spawned_interfaces = None self.tunnel_id = None self.local_tunnel_id = None + self.tunnels_allowed = False + self.remote_transport = None self.ingress_control = True self.phy_keepalive = False self.shared_medium = False diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 2ffbd4bc..a44625e4 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -126,6 +126,7 @@ class TCPClientInterface(Interface): self.writing = False self.online = False self.detached = False + self.tunnels_allowed = True self.kiss_framing = kiss_framing self.i2p_tunneled = i2p_tunneled self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL @@ -529,6 +530,7 @@ class TCPServerInterface(Interface): self.OUT = False self.name = name self.detached = False + self.tunnels_allowed = True self.i2p_tunneled = i2p_tunneled self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 4b3ea5ea..84b9baa3 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -1794,7 +1794,6 @@ class Reticulum: ifstats["name"] = str(interface) ifstats["short_name"] = str(interface.name) - ifstats["tunnel_id"] = interface.tunnel_id or interface.local_tunnel_id ifstats["hash"] = interface.get_hash() ifstats["type"] = str(type(interface).__name__) ifstats["mtu"] = interface.HW_MTU @@ -1836,6 +1835,8 @@ class Reticulum: ifstats["protocol_violations"] = interface.protocol_violations ifstats["ifac_violations"] = interface.ifac_violations ifstats["packet_filter_hits"] = interface.packet_filter_hits + ifstats["tunnel_id"] = interface.tunnel_id or interface.local_tunnel_id + ifstats["remote_transport_id"] = interface.remote_transport.hash if interface.remote_transport else None interfaces.append(ifstats) diff --git a/RNS/Transport.py b/RNS/Transport.py index b1c6829a..9de414b4 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -3125,6 +3125,11 @@ class Transport: @staticmethod def tunnel_synthesize_handler(data, packet): try: + if not packet.receiving_interface.tunnels_allowed: return + if packet.receiving_interface.remote_transport: + RNS.log(f"Tunnel already synthesized on {packet.receiving_interface}, ignoring synthesis packet", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None + return + expected_length = RNS.Identity.KEYSIZE//8+RNS.Identity.HASHLENGTH//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8+RNS.Identity.SIGLENGTH//8 if len(data) == expected_length: public_key = data[:RNS.Identity.KEYSIZE//8] @@ -3140,6 +3145,7 @@ class Transport: remote_transport_identity.load_public_key(public_key) if remote_transport_identity.validate(signature, signed_data): + packet.receiving_interface.remote_transport = remote_transport_identity Transport.handle_tunnel(tunnel_id, packet.receiving_interface) else: diff --git a/RNS/Utilities/rnstatus.py b/RNS/Utilities/rnstatus.py index bef8be60..6ed7c791 100644 --- a/RNS/Utilities/rnstatus.py +++ b/RNS/Utilities/rnstatus.py @@ -559,6 +559,9 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json= if tstats and "tunnel_id" in ifstat: print(f" Tunnel ID : {RNS.prettyhexrep(ifstat['tunnel_id']) if ifstat['tunnel_id'] else 'None'}") + if tstats and "remote_transport_id" in ifstat: + print(f" Rem.Tr.ID : {RNS.prettyhexrep(ifstat['remote_transport_id']) if ifstat['remote_transport_id'] else 'Unknown'}") + if "noise_floor" in ifstat: if not "interference" in ifstat: nstr = "" else: