mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-10-01 03:15:44 -04:00
Added signal handler and interface detachment oon exit.
This commit is contained in:
parent
81cdb0b7e6
commit
3d4ac0126b
@ -12,3 +12,6 @@ class Interface:
|
||||
|
||||
def get_hash(self):
|
||||
return RNS.Identity.full_hash(str(self).encode("utf-8"))
|
||||
|
||||
def detach(self):
|
||||
pass
|
@ -96,6 +96,15 @@ class TCPClientInterface(Interface):
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
sock.setsockopt(socket.IPPROTO_TCP, TCP_KEEPIDLE, int(TCPClientInterface.TCP_PROBE_AFTER))
|
||||
|
||||
def detach(self):
|
||||
if self.socket != None:
|
||||
if hasattr(self.socket, "close"):
|
||||
if callable(self.socket.close):
|
||||
RNS.log("Detaching "+str(self), RNS.LOG_DEBUG)
|
||||
self.socket.shutdown(socket.SHUT_RDWR)
|
||||
self.socket.close()
|
||||
self.socket = None
|
||||
|
||||
def connect(self, initial=False):
|
||||
try:
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@ -276,6 +285,7 @@ class TCPServerInterface(Interface):
|
||||
|
||||
self.owner = owner
|
||||
address = (self.bind_ip, self.bind_port)
|
||||
ThreadingTCPServer.allow_reuse_address = True
|
||||
self.server = ThreadingTCPServer(address, handlerFactory(self.incoming_connection))
|
||||
|
||||
thread = threading.Thread(target=self.server.serve_forever)
|
||||
|
@ -2,6 +2,7 @@ from .Interfaces import *
|
||||
import configparser
|
||||
from .vendor.configobj import ConfigObj
|
||||
import RNS
|
||||
import signal
|
||||
import atexit
|
||||
import struct
|
||||
import array
|
||||
@ -78,6 +79,12 @@ class Reticulum:
|
||||
RNS.Transport.exit_handler()
|
||||
RNS.Identity.exit_handler()
|
||||
|
||||
@staticmethod
|
||||
def sigint_handler(signal, frame):
|
||||
RNS.Transport.detach_interfaces()
|
||||
RNS.exit()
|
||||
|
||||
|
||||
def __init__(self,configdir=None, loglevel=None):
|
||||
"""
|
||||
Initialises and starts a Reticulum instance. This must be
|
||||
@ -147,6 +154,7 @@ class Reticulum:
|
||||
RNS.Transport.start(self)
|
||||
|
||||
atexit.register(Reticulum.exit_handler)
|
||||
signal.signal(signal.SIGINT, Reticulum.sigint_handler)
|
||||
|
||||
def __start_local_interface(self):
|
||||
if self.share_instance:
|
||||
|
@ -1422,6 +1422,12 @@ class Transport:
|
||||
else:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def detach_interfaces():
|
||||
for interface in Transport.interfaces:
|
||||
interface.detach()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
try:
|
||||
|
@ -109,3 +109,6 @@ def prettyhexrep(data):
|
||||
|
||||
def panic():
|
||||
os._exit(255)
|
||||
|
||||
def exit():
|
||||
sys.exit(0)
|
Loading…
Reference in New Issue
Block a user