Skip to content

Commit

Permalink
Internal interface config handling for TCPServerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Nov 20, 2024
1 parent 18e0dbd commit c9d744f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
16 changes: 15 additions & 1 deletion RNS/Interfaces/TCPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def __str__(self):

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

@staticmethod
def get_address_for_if(name, bind_port, prefer_ipv6=False):
Expand Down Expand Up @@ -451,7 +452,20 @@ def get_address_for_host(name, bind_port):
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
Expand Down
36 changes: 2 additions & 34 deletions RNS/Reticulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,44 +586,12 @@ def interface_post_init(interface):
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
Expand Down

0 comments on commit c9d744f

Please sign in to comment.