mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-12-14 10:24:29 -05:00
Added prefer_ipv6 option to TCPServerInterface
This commit is contained in:
parent
9373819234
commit
ebec63487f
@ -415,15 +415,14 @@ class TCPServerInterface(Interface):
|
||||
BITRATE_GUESS = 10*1000*1000
|
||||
|
||||
@staticmethod
|
||||
def get_address_for_if(name, bind_port):
|
||||
def get_address_for_if(name, bind_port, prefer_ipv6=False):
|
||||
import RNS.vendor.ifaddr.niwrapper as netinfo
|
||||
ifaddr = netinfo.ifaddresses(name)
|
||||
|
||||
if len(ifaddr) < 1:
|
||||
raise SystemError(f"No addresses available on specified kernel interface \"{name}\" for TCPServerInterface to bind to")
|
||||
|
||||
# TODO: Add IPv6 prefer option
|
||||
if False and netinfo.AF_INET6 in ifaddr:
|
||||
if prefer_ipv6 and netinfo.AF_INET6 in ifaddr:
|
||||
bind_ip = ifaddr[netinfo.AF_INET6][0]["addr"]
|
||||
return TCPServerInterface.get_address_for_host(f"{bind_ip}%{name}", bind_port)
|
||||
|
||||
@ -448,7 +447,7 @@ 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):
|
||||
def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False, prefer_ipv6=False):
|
||||
super().__init__()
|
||||
|
||||
self.HW_MTU = 1064
|
||||
@ -471,7 +470,7 @@ class TCPServerInterface(Interface):
|
||||
|
||||
bind_address = None
|
||||
if device != None:
|
||||
bind_address = TCPServerInterface.get_address_for_if(device, self.bind_port)
|
||||
bind_address = TCPServerInterface.get_address_for_if(device, self.bind_port, prefer_ipv6)
|
||||
else:
|
||||
if bindip == None:
|
||||
raise SystemError(f"No TCP bind IP configured for interface \"{name}\"")
|
||||
|
@ -640,6 +640,7 @@ class Reticulum:
|
||||
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
|
||||
@ -650,7 +651,8 @@ class Reticulum:
|
||||
device,
|
||||
listen_ip,
|
||||
listen_port,
|
||||
i2p_tunneled
|
||||
i2p_tunneled,
|
||||
prefer_ipv6,
|
||||
)
|
||||
|
||||
if "outgoing" in c and c.as_bool("outgoing") == False:
|
||||
|
Loading…
Reference in New Issue
Block a user