Skip to content

Commit

Permalink
Internal interface config handling for UDPInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Nov 20, 2024
1 parent 52c816c commit 18e0dbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
18 changes: 17 additions & 1 deletion RNS/Interfaces/UDPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

class UDPInterface(Interface):
BITRATE_GUESS = 10*1000*1000
DEFAULT_IFAC_SIZE = 16

@staticmethod
def get_address_for_if(name):
Expand All @@ -44,9 +45,24 @@ def get_broadcast_for_if(name):
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
Expand Down
39 changes: 2 additions & 37 deletions RNS/Reticulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,43 +582,8 @@ def interface_post_init(interface):
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
Expand Down

0 comments on commit 18e0dbd

Please sign in to comment.