Ensure early tunnel synthesis on BackboneInterface

This commit is contained in:
Mark Qvist 2026-11-14 18:35:10 +01:00
parent 096e6726b4
commit f361a354ba
No known key found for this signature in database
3 changed files with 25 additions and 4 deletions

View file

@ -938,7 +938,6 @@ class BackboneClientInterface(Interface):
thread = threading.Thread(target=self.reconnect)
thread.daemon = True
thread.start()
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))
@ -966,6 +965,15 @@ class BackboneClientInterface(Interface):
self.socket = None
def early_synthesis(self, packet):
if not self.detached:
if not packet.packed: packet.pack()
frame = HDLC.frame(packet.raw)
if not self.transmit_buffer.append(frame, self.tx_hwm):
raise IOError("Transmit buffer overflow at early tunnel synthesis")
BackboneInterface.tx_ready(self)
def connect(self, initial=False):
try:
if initial:
@ -989,7 +997,9 @@ class BackboneClientInterface(Interface):
# TODO: Check missing setblocking(0)
self.socket.settimeout(None)
self.wants_tunnel = True
BackboneInterface.add_client_socket(self.socket, self)
RNS.Transport.synthesize_tunnel(self)
self.online = True
if initial:
@ -1036,7 +1046,6 @@ class BackboneClientInterface(Interface):
RNS.log("Reconnected socket for "+str(self)+".", RNS.LOG_INFO)
self.reconnecting = False
RNS.Transport.synthesize_tunnel(self)
else:
RNS.log("Attempt to reconnect on a non-initiator TCP interface. This should not happen.", RNS.LOG_ERROR)

View file

@ -131,6 +131,7 @@ class Interface:
self.tunnel_id = None
self.local_tunnel_id = None
self.tunnels_allowed = False
self.wants_tunnel = False
self.remote_transport = None
self.ingress_control = True
self.phy_keepalive = False

View file

@ -690,6 +690,10 @@ class Transport:
Transport.ready = True
# Synthesize tunnels for any interfaces wanting it
# TODO: This is, in practice deprecated, since
# interfaces requiring tunnels are now early-
# init synthesizing on connect. Clean up at
# opportune moment.
for interface in Transport.interfaces:
interface.tunnel_id = None
if hasattr(interface, "wants_tunnel") and interface.wants_tunnel:
@ -1384,6 +1388,7 @@ class Transport:
interface.should_ingress_limit_pr()
interface.process_held_announces()
if interface.phy_keepalive: interface.send_keepalive()
if interface.wants_tunnel and interface.online: Transport.synthesize_tunnel(interface)
Transport.interface_last_jobs = time.time()
except Exception as e:
RNS.log(f"Error while processing held per-interface announces: {e}", RNS.LOG_WARNING)
@ -3115,9 +3120,12 @@ class Transport:
@staticmethod
def synthesize_tunnel(interface):
if not Transport.identity: return
if not interface.wants_tunnel: return
try:
interface_hash = interface.get_hash()
public_key = RNS.Transport.identity.get_public_key()
public_key = Transport.identity.get_public_key()
random_hash = RNS.Identity.get_random_hash()
tunnel_id_data = public_key+interface_hash
@ -3131,7 +3139,10 @@ class Transport:
tnl_snth_dst = RNS.Destination(None, RNS.Destination.OUT, RNS.Destination.PLAIN, Transport.APP_NAME, "tunnel", "synthesize")
packet = RNS.Packet(tnl_snth_dst, data, packet_type = RNS.Packet.DATA, transport_type = RNS.Transport.BROADCAST, header_type = RNS.Packet.HEADER_1, attached_interface = interface)
packet.send()
if interface.online: packet.send()
elif hasattr(interface, "early_synthesis"): interface.early_synthesis(packet)
else: return
interface.wants_tunnel = False
interface.local_tunnel_id = tunnel_id