From 582d2b91f58aa8d4ea6ce22ff22e007a36d6c1c0 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 20 Nov 2024 20:14:02 +0100 Subject: [PATCH] Internal interface config handling for AutoInterface --- RNS/Interfaces/AutoInterface.py | 15 ++++++++- RNS/Reticulum.py | 56 +++++++++++++-------------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/RNS/Interfaces/AutoInterface.py b/RNS/Interfaces/AutoInterface.py index 75c52d2..46eb683 100644 --- a/RNS/Interfaces/AutoInterface.py +++ b/RNS/Interfaces/AutoInterface.py @@ -36,6 +36,7 @@ class AutoInterface(Interface): DEFAULT_DISCOVERY_PORT = 29716 DEFAULT_DATA_PORT = 42671 DEFAULT_GROUP_ID = "reticulum".encode("utf-8") + DEFAULT_IFAC_SIZE = 16 SCOPE_LINK = "2" SCOPE_ADMIN = "4" @@ -86,7 +87,19 @@ class AutoInterface(Interface): return socket.if_nametoindex(ifname) - def __init__(self, owner, name, group_id=None, discovery_scope=None, discovery_port=None, multicast_address_type=None, data_port=None, allowed_interfaces=None, ignored_interfaces=None, configured_bitrate=None): + # def __init__(self, owner, name, group_id=None, discovery_scope=None, discovery_port=None, multicast_address_type=None, data_port=None, allowed_interfaces=None, ignored_interfaces=None, configured_bitrate=None): + def __init__(self, owner, configuration): + c = configuration + name = c["name"] + group_id = c["group_id"] if "group_id" in c else None + discovery_scope = c["discovery_scope"] if "discovery_scope" in c else None + discovery_port = int(c["discovery_port"]) if "discovery_port" in c else None + multicast_address_type = c["multicast_address_type"] if "multicast_address_type" in c else None + data_port = int(c["data_port"]) if "data_port" in c else None + allowed_interfaces = c.as_list("devices") if "devices" in c else None + ignored_interfaces = c.as_list("ignored_devices") if "ignored_devices" in c else None + configured_bitrate = c["configured_bitrate"] + from RNS.vendor.ifaddr import niwrapper super().__init__() self.netinfo = niwrapper diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 55483de..7d2a984 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -556,44 +556,30 @@ class Reticulum: announce_cap = c.as_float("announce_cap")/100.0 try: + def interface_post_init(interface): + 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 = interface.DEFAULT_IFAC_SIZE + interface = None - if (("interface_enabled" in c) and c.as_bool("interface_enabled") == True) or (("enabled" in c) and c.as_bool("enabled") == True): + interface_config = c + interface_config["name"] = name + interface_config["configured_bitrate"] = configured_bitrate + if c["type"] == "AutoInterface": - group_id = c["group_id"] if "group_id" in c else None - discovery_scope = c["discovery_scope"] if "discovery_scope" in c else None - discovery_port = int(c["discovery_port"]) if "discovery_port" in c else None - multicast_address_type = c["multicast_address_type"] if "multicast_address_type" in c else None - data_port = int(c["data_port"]) if "data_port" in c else None - allowed_interfaces = c.as_list("devices") if "devices" in c else None - ignored_interfaces = c.as_list("ignored_devices") if "ignored_devices" in c else None - - interface = AutoInterface.AutoInterface( - RNS.Transport, - name, - group_id, - discovery_scope, - discovery_port, - multicast_address_type, - data_port, - allowed_interfaces, - ignored_interfaces - ) - - 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 = AutoInterface.AutoInterface(RNS.Transport, interface_config) + interface_post_init(interface) if c["type"] == "UDPInterface": device = c["device"] if "device" in c else None