mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 15:30:18 +00:00
Added config options for UDP interface binding to network interface instead of IP.
This commit is contained in:
parent
4fd3d26714
commit
6382409194
@ -1,18 +1,34 @@
|
|||||||
from .Interface import Interface
|
from .Interface import Interface
|
||||||
import socketserver
|
import socketserver
|
||||||
import threading
|
import threading
|
||||||
|
import netifaces
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
|
|
||||||
class UDPInterface(Interface):
|
class UDPInterface(Interface):
|
||||||
|
|
||||||
def __init__(self, owner, name, bindip=None, bindport=None, forwardip=None, forwardport=None):
|
@staticmethod
|
||||||
|
def get_address_for_if(name):
|
||||||
|
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr']
|
||||||
|
|
||||||
|
def get_broadcast_for_if(name):
|
||||||
|
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast']
|
||||||
|
|
||||||
|
def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None):
|
||||||
self.IN = True
|
self.IN = True
|
||||||
self.OUT = False
|
self.OUT = False
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
if device != None:
|
||||||
|
if bindip == None:
|
||||||
|
bindip = UDPInterface.get_broadcast_for_if(device)
|
||||||
|
if forwardip == None:
|
||||||
|
forwardip = UDPInterface.get_broadcast_for_if(device)
|
||||||
|
|
||||||
|
|
||||||
if (bindip != None and bindport != None):
|
if (bindip != None and bindport != None):
|
||||||
self.receives = True
|
self.receives = True
|
||||||
self.bind_ip = bindip
|
self.bind_ip = bindip
|
||||||
|
@ -217,13 +217,27 @@ class Reticulum:
|
|||||||
try:
|
try:
|
||||||
if ("interface_enabled" in c) and c.as_bool("interface_enabled") == True:
|
if ("interface_enabled" in c) and c.as_bool("interface_enabled") == True:
|
||||||
if c["type"] == "UDPInterface":
|
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(
|
interface = UDPInterface.UDPInterface(
|
||||||
RNS.Transport,
|
RNS.Transport,
|
||||||
name,
|
name,
|
||||||
c["listen_ip"],
|
device,
|
||||||
int(c["listen_port"]),
|
listen_ip,
|
||||||
c["forward_ip"],
|
listen_port,
|
||||||
int(c["forward_port"])
|
forward_ip,
|
||||||
|
forward_port
|
||||||
)
|
)
|
||||||
|
|
||||||
if "outgoing" in c and c.as_bool("outgoing") == True:
|
if "outgoing" in c and c.as_bool("outgoing") == True:
|
||||||
|
2
setup.py
2
setup.py
@ -20,6 +20,6 @@ setuptools.setup(
|
|||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
],
|
],
|
||||||
install_requires=['cryptography>=3.4.7', 'pyserial'],
|
install_requires=['cryptography>=3.4.7', 'pyserial', 'netifaces>=0.10.4'],
|
||||||
python_requires='>=3.5',
|
python_requires='>=3.5',
|
||||||
)
|
)
|
Loading…
Reference in New Issue
Block a user