mirror of
https://github.com/markqvist/Reticulum.git
synced 2025-07-25 15:55:24 -04:00
Cleanup
This commit is contained in:
parent
9a7e517c73
commit
5913f61e7d
2 changed files with 24 additions and 41 deletions
|
@ -225,7 +225,7 @@ class BackboneInterface(Interface):
|
||||||
if client_socket and fileno == client_socket.fileno() and (event & select.EPOLLIN):
|
if client_socket and fileno == client_socket.fileno() and (event & select.EPOLLIN):
|
||||||
try: received_bytes = client_socket.recv(4096)
|
try: received_bytes = client_socket.recv(4096)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log(f"Error while reading from {spawned_interface}: {e}", RNS.LOG_ERROR)
|
RNS.log(f"Error while reading from {spawned_interface}: {e}", RNS.LOG_DEBUG)
|
||||||
received_bytes = b""
|
received_bytes = b""
|
||||||
|
|
||||||
if len(received_bytes): spawned_interface.receive(received_bytes)
|
if len(received_bytes): spawned_interface.receive(received_bytes)
|
||||||
|
@ -238,7 +238,7 @@ class BackboneInterface(Interface):
|
||||||
written = client_socket.send(spawned_interface.transmit_buffer)
|
written = client_socket.send(spawned_interface.transmit_buffer)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
written = 0
|
written = 0
|
||||||
if not spawned_interface.detached: RNS.log(f"Error while writing to {spawned_interface}: {e}", RNS.LOG_ERROR)
|
if not spawned_interface.detached: RNS.log(f"Error while writing to {spawned_interface}: {e}", RNS.LOG_DEBUG)
|
||||||
BackboneInterface.deregister_fileno(fileno)
|
BackboneInterface.deregister_fileno(fileno)
|
||||||
try: client_socket.close()
|
try: client_socket.close()
|
||||||
except Exception as e: RNS.log(f"Error while closing socket for {spawned_interface}: {e}", RNS.LOG_ERROR)
|
except Exception as e: RNS.log(f"Error while closing socket for {spawned_interface}: {e}", RNS.LOG_ERROR)
|
||||||
|
@ -343,7 +343,7 @@ class BackboneInterface(Interface):
|
||||||
if hasattr(listener_socket, "shutdown"):
|
if hasattr(listener_socket, "shutdown"):
|
||||||
if callable(listener_socket.shutdown):
|
if callable(listener_socket.shutdown):
|
||||||
try: listener_socket.shutdown(socket.SHUT_RDWR)
|
try: listener_socket.shutdown(socket.SHUT_RDWR)
|
||||||
except Exception as e: RNS.log("Error while shutting down socket for "+str(self)+": "+str(e))
|
except Exception as e: RNS.log("Error while shutting down socket for "+str(self)+": "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if ":" in self.bind_ip:
|
if ":" in self.bind_ip:
|
||||||
|
@ -455,16 +455,12 @@ class BackboneClientInterface(Interface):
|
||||||
self.detached = True
|
self.detached = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.socket != None:
|
if self.socket != None: self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
except Exception as e: RNS.log("Error while shutting down socket for "+str(self)+": "+str(e), RNS.LOG_ERROR)
|
||||||
except Exception as e:
|
|
||||||
RNS.log("Error while shutting down socket for "+str(self)+": "+str(e))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.socket != None:
|
if self.socket != None: self.socket.close()
|
||||||
self.socket.close()
|
except Exception as e: RNS.log("Error while closing socket for "+str(self)+": "+str(e), RNS.LOG_ERROR)
|
||||||
except Exception as e:
|
|
||||||
RNS.log("Error while closing socket for "+str(self)+": "+str(e))
|
|
||||||
|
|
||||||
self.socket = None
|
self.socket = None
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import gc
|
||||||
import RNS
|
import RNS
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
@ -620,8 +621,7 @@ class Transport:
|
||||||
RNS.log("Waiting path request for "+RNS.prettyhexrep(destination_hash)+" timed out and was removed", RNS.LOG_DEBUG)
|
RNS.log("Waiting path request for "+RNS.prettyhexrep(destination_hash)+" timed out and was removed", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
# Cull the tunnel table
|
# Cull the tunnel table
|
||||||
stale_tunnels = []
|
stale_tunnels = []; ti = 0
|
||||||
ti = 0
|
|
||||||
for tunnel_id in Transport.tunnels:
|
for tunnel_id in Transport.tunnels:
|
||||||
tunnel_entry = Transport.tunnels[tunnel_id]
|
tunnel_entry = Transport.tunnels[tunnel_id]
|
||||||
|
|
||||||
|
@ -645,10 +645,8 @@ class Transport:
|
||||||
|
|
||||||
|
|
||||||
if ti > 0:
|
if ti > 0:
|
||||||
if ti == 1:
|
if ti == 1: RNS.log("Removed "+str(ti)+" tunnel path", RNS.LOG_EXTREME)
|
||||||
RNS.log("Removed "+str(ti)+" tunnel path", RNS.LOG_EXTREME)
|
else: RNS.log("Removed "+str(ti)+" tunnel paths", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Removed "+str(ti)+" tunnel paths", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for truncated_packet_hash in stale_reverse_entries:
|
for truncated_packet_hash in stale_reverse_entries:
|
||||||
|
@ -656,10 +654,8 @@ class Transport:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i == 1:
|
if i == 1: RNS.log("Released "+str(i)+" reverse table entry", RNS.LOG_EXTREME)
|
||||||
RNS.log("Released "+str(i)+" reverse table entry", RNS.LOG_EXTREME)
|
else: RNS.log("Released "+str(i)+" reverse table entries", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Released "+str(i)+" reverse table entries", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for link_id in stale_links:
|
for link_id in stale_links:
|
||||||
|
@ -667,10 +663,8 @@ class Transport:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i == 1:
|
if i == 1: RNS.log("Released "+str(i)+" link", RNS.LOG_EXTREME)
|
||||||
RNS.log("Released "+str(i)+" link", RNS.LOG_EXTREME)
|
else: RNS.log("Released "+str(i)+" links", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Released "+str(i)+" links", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for destination_hash in stale_paths:
|
for destination_hash in stale_paths:
|
||||||
|
@ -678,10 +672,8 @@ class Transport:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i == 1:
|
if i == 1: RNS.log("Removed "+str(i)+" path", RNS.LOG_EXTREME)
|
||||||
RNS.log("Removed "+str(i)+" path", RNS.LOG_EXTREME)
|
else: RNS.log("Removed "+str(i)+" paths", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Removed "+str(i)+" paths", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for destination_hash in stale_discovery_path_requests:
|
for destination_hash in stale_discovery_path_requests:
|
||||||
|
@ -689,10 +681,8 @@ class Transport:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i == 1:
|
if i == 1: RNS.log("Removed "+str(i)+" waiting path request", RNS.LOG_EXTREME)
|
||||||
RNS.log("Removed "+str(i)+" waiting path request", RNS.LOG_EXTREME)
|
else: RNS.log("Removed "+str(i)+" waiting path requests", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Removed "+str(i)+" waiting path requests", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for tunnel_id in stale_tunnels:
|
for tunnel_id in stale_tunnels:
|
||||||
|
@ -700,10 +690,8 @@ class Transport:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i == 1:
|
if i == 1: RNS.log("Removed "+str(i)+" tunnel", RNS.LOG_EXTREME)
|
||||||
RNS.log("Removed "+str(i)+" tunnel", RNS.LOG_EXTREME)
|
else: RNS.log("Removed "+str(i)+" tunnels", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Removed "+str(i)+" tunnels", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for destination_hash in stale_path_states:
|
for destination_hash in stale_path_states:
|
||||||
|
@ -711,10 +699,8 @@ class Transport:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i == 1:
|
if i == 1: RNS.log("Removed "+str(i)+" path state entry", RNS.LOG_EXTREME)
|
||||||
RNS.log("Removed "+str(i)+" path state entry", RNS.LOG_EXTREME)
|
else: RNS.log("Removed "+str(i)+" path state entries", RNS.LOG_EXTREME)
|
||||||
else:
|
|
||||||
RNS.log("Removed "+str(i)+" path state entries", RNS.LOG_EXTREME)
|
|
||||||
|
|
||||||
Transport.tables_last_culled = time.time()
|
Transport.tables_last_culled = time.time()
|
||||||
|
|
||||||
|
@ -732,6 +718,7 @@ class Transport:
|
||||||
RNS.log("An exception occurred while running Transport jobs.", RNS.LOG_ERROR)
|
RNS.log("An exception occurred while running Transport jobs.", RNS.LOG_ERROR)
|
||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
finally: gc.collect()
|
||||||
Transport.jobs_running = False
|
Transport.jobs_running = False
|
||||||
|
|
||||||
for packet in outgoing:
|
for packet in outgoing:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue