From c9d744f88a3d0977fce7cab869edfd0e88cfc801 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 20 Nov 2024 20:27:01 +0100 Subject: [PATCH] Internal interface config handling for TCPServerInterface --- RNS/Interfaces/TCPInterface.py | 16 ++++++++++++++- RNS/Reticulum.py | 36 ++-------------------------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 261d671..a715ffe 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -419,6 +419,7 @@ class TCPClientInterface(Interface): class TCPServerInterface(Interface): BITRATE_GUESS = 10*1000*1000 + DEFAULT_IFAC_SIZE = 16 @staticmethod def get_address_for_if(name, bind_port, prefer_ipv6=False): @@ -451,7 +452,20 @@ class TCPServerInterface(Interface): raise SystemError(f"No suitable kernel interface available for address \"{name}\" for TCPServerInterface to bind to") - def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False, prefer_ipv6=False): + # def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False, prefer_ipv6=False): + def __init__(self, owner, configuration): + c = configuration + name = c["name"] + device = c["device"] if "device" in c else None + port = int(c["port"]) if "port" in c else None + bindip = c["listen_ip"] if "listen_ip" in c else None + bindport = int(c["listen_port"]) if "listen_port" in c else None + i2p_tunneled = c.as_bool("i2p_tunneled") if "i2p_tunneled" in c else False + prefer_ipv6 = c.as_bool("prefer_ipv6") if "prefer_ipv6" in c else False + + if port != None: + bindport = port + super().__init__() self.HW_MTU = 1064 diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index ac3217b..9acfe97 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -586,44 +586,12 @@ class Reticulum: interface_post_init(interface) if c["type"] == "TCPServerInterface": - device = c["device"] if "device" in c else None - port = int(c["port"]) if "port" in c else None - listen_ip = c["listen_ip"] if "listen_ip" in c else None - listen_port = int(c["listen_port"]) if "listen_port" in c else None - i2p_tunneled = c.as_bool("i2p_tunneled") if "i2p_tunneled" in c else False - prefer_ipv6 = c.as_bool("prefer_ipv6") if "prefer_ipv6" in c else False - - if port != None: - listen_port = port - - interface = TCPInterface.TCPServerInterface( - RNS.Transport, - name, - device, - listen_ip, - listen_port, - i2p_tunneled, - prefer_ipv6, - ) - - if "outgoing" in c and c.as_bool("outgoing") == False: - interface.OUT = False - else: - interface.OUT = True - if interface_mode == Interface.Interface.MODE_ACCESS_POINT: RNS.log(str(interface)+" does not support Access Point mode, reverting to default mode: Full", RNS.LOG_WARNING) interface_mode = Interface.Interface.MODE_FULL - - interface.mode = interface_mode - interface.announce_cap = announce_cap - if configured_bitrate: - interface.bitrate = configured_bitrate - if ifac_size != None: - interface.ifac_size = ifac_size - else: - interface.ifac_size = 16 + interface = TCPInterface.TCPServerInterface(RNS.Transport, interface_config) + interface_post_init(interface) if c["type"] == "TCPClientInterface": kiss_framing = False