kopia lustrzana https://github.com/markqvist/reticulum
				
				
				
			Improved interface detach on shared instance shutdown
							rodzic
							
								
									1b48f43a0d
								
							
						
					
					
						commit
						4f4961257c
					
				|  | @ -456,21 +456,23 @@ class AutoInterface(Interface): | |||
|         self.peers[addr][1] = time.time() | ||||
| 
 | ||||
|     def process_incoming(self, data): | ||||
|         data_hash = RNS.Identity.full_hash(data) | ||||
|         deque_hit = False | ||||
|         if data_hash in self.mif_deque: | ||||
|             for te in self.mif_deque_times: | ||||
|                 if te[0] == data_hash and time.time() < te[1]+AutoInterface.MULTI_IF_DEQUE_TTL: | ||||
|                     deque_hit = True | ||||
|                     break | ||||
|         if self.online: | ||||
|             data_hash = RNS.Identity.full_hash(data) | ||||
|             deque_hit = False | ||||
|             if data_hash in self.mif_deque: | ||||
|                 for te in self.mif_deque_times: | ||||
|                     if te[0] == data_hash and time.time() < te[1]+AutoInterface.MULTI_IF_DEQUE_TTL: | ||||
|                         deque_hit = True | ||||
|                         break | ||||
| 
 | ||||
|         if not deque_hit: | ||||
|             self.mif_deque.append(data_hash) | ||||
|             self.mif_deque_times.append([data_hash, time.time()]) | ||||
|             self.rxb += len(data) | ||||
|             self.owner.inbound(data, self) | ||||
|             if not deque_hit: | ||||
|                 self.mif_deque.append(data_hash) | ||||
|                 self.mif_deque_times.append([data_hash, time.time()]) | ||||
|                 self.rxb += len(data) | ||||
|                 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+"]" | ||||
| 
 | ||||
|  |  | |||
|  | @ -67,12 +67,13 @@ class Interface: | |||
|     AUTOCONFIGURE_MTU = False | ||||
| 
 | ||||
|     def __init__(self): | ||||
|         self.rxb     = 0 | ||||
|         self.txb     = 0 | ||||
|         self.created = time.time() | ||||
|         self.online  = False | ||||
|         self.bitrate = 62500 | ||||
|         self.HW_MTU  = None | ||||
|         self.rxb      = 0 | ||||
|         self.txb      = 0 | ||||
|         self.created  = time.time() | ||||
|         self.detached = False | ||||
|         self.online   = False | ||||
|         self.bitrate  = 62500 | ||||
|         self.HW_MTU   = None | ||||
| 
 | ||||
|         self.ingress_control = True | ||||
|         self.ic_max_held_announces = Interface.MAX_HELD_ANNOUNCES | ||||
|  |  | |||
|  | @ -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,14 +288,15 @@ class TCPClientInterface(Interface): | |||
|             raise IOError("Attempt to reconnect on a non-initiator TCP interface") | ||||
| 
 | ||||
|     def process_incoming(self, data): | ||||
|         self.rxb += len(data) | ||||
|         if hasattr(self, "parent_interface") and self.parent_interface != None: | ||||
|             self.parent_interface.rxb += len(data) | ||||
|                      | ||||
|         self.owner.inbound(data, self) | ||||
|         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) | ||||
|                          | ||||
|             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) | ||||
| 
 | ||||
|  |  | |||
|  | @ -161,14 +161,16 @@ class Reticulum: | |||
|     interfacepath    = "" | ||||
| 
 | ||||
|     __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: | ||||
|                 interface.detach() | ||||
|                 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: | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Mark Qvist
						Mark Qvist