mirror of
https://github.com/markqvist/Reticulum.git
synced 2025-01-18 16:30:33 +00:00
Improved interface detach on shared instance shutdown
This commit is contained in:
parent
1b48f43a0d
commit
4f4961257c
@ -456,6 +456,7 @@ class AutoInterface(Interface):
|
||||
self.peers[addr][1] = time.time()
|
||||
|
||||
def process_incoming(self, data):
|
||||
if self.online:
|
||||
data_hash = RNS.Identity.full_hash(data)
|
||||
deque_hit = False
|
||||
if data_hash in self.mif_deque:
|
||||
@ -471,6 +472,7 @@ class AutoInterface(Interface):
|
||||
self.owner.inbound(data, self)
|
||||
|
||||
def process_outgoing(self,data):
|
||||
if self.online:
|
||||
for peer in self.peers:
|
||||
try:
|
||||
if self.outbound_udp_socket == None:
|
||||
@ -492,6 +494,9 @@ class AutoInterface(Interface):
|
||||
def should_ingress_limit(self):
|
||||
return False
|
||||
|
||||
def detach(self):
|
||||
self.online = False
|
||||
|
||||
def __str__(self):
|
||||
return "AutoInterface["+self.name+"]"
|
||||
|
||||
|
@ -70,6 +70,7 @@ class Interface:
|
||||
self.rxb = 0
|
||||
self.txb = 0
|
||||
self.created = time.time()
|
||||
self.detached = False
|
||||
self.online = False
|
||||
self.bitrate = 62500
|
||||
self.HW_MTU = None
|
||||
|
@ -185,6 +185,7 @@ class RNodeInterface(Interface):
|
||||
self.online = False
|
||||
self.detached = False
|
||||
self.reconnecting= False
|
||||
self.hw_errors = []
|
||||
|
||||
self.use_ble = False
|
||||
self.ble_name = ble_name
|
||||
|
@ -195,10 +195,10 @@ class TCPClientInterface(Interface):
|
||||
self.socket.setsockopt(socket.IPPROTO_TCP, TCP_KEEPIDLE, int(TCPClientInterface.I2P_PROBE_AFTER))
|
||||
|
||||
def detach(self):
|
||||
self.online = False
|
||||
if self.socket != None:
|
||||
if hasattr(self.socket, "close"):
|
||||
if callable(self.socket.close):
|
||||
RNS.log("Detaching "+str(self), RNS.LOG_DEBUG)
|
||||
self.detached = True
|
||||
|
||||
try:
|
||||
@ -288,6 +288,7 @@ class TCPClientInterface(Interface):
|
||||
raise IOError("Attempt to reconnect on a non-initiator TCP interface")
|
||||
|
||||
def process_incoming(self, data):
|
||||
if self.online and not self.detached:
|
||||
self.rxb += len(data)
|
||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||
self.parent_interface.rxb += len(data)
|
||||
@ -295,7 +296,7 @@ class TCPClientInterface(Interface):
|
||||
self.owner.inbound(data, self)
|
||||
|
||||
def process_outgoing(self, data):
|
||||
if self.online:
|
||||
if self.online and not self.detached:
|
||||
# while self.writing:
|
||||
# time.sleep(0.01)
|
||||
|
||||
|
@ -162,13 +162,15 @@ class Reticulum:
|
||||
|
||||
__instance = None
|
||||
|
||||
__interface_detach_ran = False
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
# This exit handler is called whenever Reticulum is asked to
|
||||
# shut down, and will in turn call exit handlers in other
|
||||
# classes, saving necessary information to disk and carrying
|
||||
# out cleanup operations.
|
||||
|
||||
if not Reticulum.__interface_detach_ran:
|
||||
RNS.Transport.detach_interfaces()
|
||||
RNS.Transport.exit_handler()
|
||||
RNS.Identity.exit_handler()
|
||||
|
||||
@ -178,15 +180,15 @@ class Reticulum:
|
||||
@staticmethod
|
||||
def sigint_handler(signal, frame):
|
||||
RNS.Transport.detach_interfaces()
|
||||
Reticulum.__interface_detach_ran = True
|
||||
RNS.exit()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def sigterm_handler(signal, frame):
|
||||
RNS.Transport.detach_interfaces()
|
||||
Reticulum.__interface_detach_ran = True
|
||||
RNS.exit()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_instance():
|
||||
"""
|
||||
|
@ -2662,7 +2662,7 @@ class Transport:
|
||||
# Currently no rules are being applied
|
||||
# here, and all interfaces will be sent
|
||||
# the detach call on RNS teardown.
|
||||
if True:
|
||||
if not interface.detached:
|
||||
detachable_interfaces.append(interface)
|
||||
else:
|
||||
pass
|
||||
@ -2671,17 +2671,44 @@ class Transport:
|
||||
# Currently no rules are being applied
|
||||
# here, and all interfaces will be sent
|
||||
# the detach call on RNS teardown.
|
||||
if True:
|
||||
if not interface.detached:
|
||||
detachable_interfaces.append(interface)
|
||||
else:
|
||||
pass
|
||||
|
||||
shared_instance_master = None
|
||||
local_interfaces = []
|
||||
detach_threads = []
|
||||
for interface in detachable_interfaces:
|
||||
try:
|
||||
if type(interface) == RNS.Interfaces.LocalInterface.LocalServerInterface:
|
||||
shared_instance_master = interface
|
||||
elif type(interface) == RNS.Interfaces.LocalInterface.LocalClientInterface:
|
||||
local_interfaces.append(interface)
|
||||
else:
|
||||
def detach_job():
|
||||
RNS.log(f"Detaching {interface}", RNS.LOG_DEBUG)
|
||||
interface.detach()
|
||||
dt = threading.Thread(target=detach_job, daemon=True)
|
||||
dt.start()
|
||||
detach_threads.append(dt)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("An error occurred while detaching "+str(interface)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
for dt in detach_threads:
|
||||
dt.join()
|
||||
|
||||
RNS.log("Detaching local clients", RNS.LOG_DEBUG)
|
||||
for li in local_interfaces:
|
||||
li.detach()
|
||||
|
||||
RNS.log("Detaching shared instance", RNS.LOG_DEBUG)
|
||||
if shared_instance_master != None:
|
||||
shared_instance_master.detach()
|
||||
|
||||
RNS.log("All interfaces detached", RNS.LOG_DEBUG)
|
||||
|
||||
@staticmethod
|
||||
def shared_connection_disappeared():
|
||||
for link in Transport.active_links:
|
||||
|
Loading…
Reference in New Issue
Block a user