From 84709ccf09fddf23a9723c6904c7678159e878af Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 27 Sep 2026 20:44:38 +0200 Subject: [PATCH] Prepared TCP and UDP interfaces for live detach/attach --- RNS/Interfaces/TCPInterface.py | 17 ++++++----------- RNS/Interfaces/UDPInterface.py | 10 +++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index cb83fd3a..a587a0ce 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -1,6 +1,6 @@ # Reticulum License # -# Copyright (c) 2016-2025 Mark Qvist +# Copyright (c) 2016-2026 Mark Qvist # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -427,7 +427,7 @@ class TCPClientInterface(Interface): self.online = False RNS.log("An interface error occurred for "+str(self)+", the contained exception was: "+str(e), RNS.LOG_WARNING) - if self.initiator: + if self.initiator and not self.detached: RNS.log("Attempting to reconnect...", RNS.LOG_WARNING) self.reconnect() else: @@ -453,12 +453,9 @@ class TCPClientInterface(Interface): if not self.initiator: RNS.Transport.remove_interface(self) - def __str__(self): - if ":" in self.target_ip: - ip_str = f"[{self.target_ip}]" - else: - ip_str = f"{self.target_ip}" + if ":" in self.target_ip: ip_str = f"[{self.target_ip}]" + else: ip_str = f"{self.target_ip}" return "TCPInterface["+str(self.name)+"/"+ip_str+":"+str(self.target_port)+"]" @@ -687,10 +684,8 @@ class TCPServerInterface(Interface): def __str__(self): - if ":" in self.bind_ip: - ip_str = f"[{self.bind_ip}]" - else: - ip_str = f"{self.bind_ip}" + if ":" in self.bind_ip: ip_str = f"[{self.bind_ip}]" + else: ip_str = f"{self.bind_ip}" return "TCPServerInterface["+self.name+"/"+ip_str+":"+str(self.bind_port)+"]" diff --git a/RNS/Interfaces/UDPInterface.py b/RNS/Interfaces/UDPInterface.py index 43411466..e2baecac 100644 --- a/RNS/Interfaces/UDPInterface.py +++ b/RNS/Interfaces/UDPInterface.py @@ -1,6 +1,6 @@ # Reticulum License # -# Copyright (c) 2016-2025 Mark Qvist +# Copyright (c) 2016-2026 Mark Qvist # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -113,6 +113,14 @@ class UDPInterface(Interface): self.forward_ip = forwardip self.forward_port = forwardport + def detach(self): + self.detached = True + self.online = False + if self.server: + try: + self.server.server_close() + self.server.shutdown() + except Exception as e: RNS.log(f"Could not shut down UDP listener for {self}: {e}", RNS.LOG_ERROR) def process_incoming(self, data): if not data: return