From 18e0dbddfaf232958305875c543b424028436845 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 20 Nov 2024 20:20:40 +0100 Subject: [PATCH] Internal interface config handling for UDPInterface --- RNS/Interfaces/UDPInterface.py | 18 +++++++++++++++- RNS/Reticulum.py | 39 ++-------------------------------- 2 files changed, 19 insertions(+), 38 deletions(-) diff --git a/RNS/Interfaces/UDPInterface.py b/RNS/Interfaces/UDPInterface.py index f230af9..d2a3b9a 100644 --- a/RNS/Interfaces/UDPInterface.py +++ b/RNS/Interfaces/UDPInterface.py @@ -31,6 +31,7 @@ import RNS class UDPInterface(Interface): BITRATE_GUESS = 10*1000*1000 + DEFAULT_IFAC_SIZE = 16 @staticmethod def get_address_for_if(name): @@ -44,9 +45,24 @@ class UDPInterface(Interface): ifaddr = netinfo.ifaddresses(name) return ifaddr[netinfo.AF_INET][0]["broadcast"] - def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None): + def __init__(self, owner, configuration): super().__init__() + 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 + forwardip = c["forward_ip"] if "forward_ip" in c else None + forwardport = int(c["forward_port"]) if "forward_port" in c else None + + if port != None: + if bindport == None: + bindport = port + if forwardport == None: + forwardport = port + self.HW_MTU = 1064 self.IN = True diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 7d2a984..ac3217b 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -582,43 +582,8 @@ class Reticulum: interface_post_init(interface) if c["type"] == "UDPInterface": - 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 - forward_ip = c["forward_ip"] if "forward_ip" in c else None - forward_port = int(c["forward_port"]) if "forward_port" in c else None - - if port != None: - if listen_port == None: - listen_port = port - if forward_port == None: - forward_port = port - - interface = UDPInterface.UDPInterface( - RNS.Transport, - name, - device, - listen_ip, - listen_port, - forward_ip, - forward_port - ) - - if "outgoing" in c and c.as_bool("outgoing") == False: - interface.OUT = False - else: - interface.OUT = True - - 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 = UDPInterface.UDPInterface(RNS.Transport, interface_config) + interface_post_init(interface) if c["type"] == "TCPServerInterface": device = c["device"] if "device" in c else None