mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-05-20 06:44:48 -07:00
Implemented bootstrap interface handling
This commit is contained in:
@@ -472,9 +472,10 @@ class InterfaceDiscovery():
|
|||||||
if not interface in detached_interfaces: detached_interfaces.append(interface)
|
if not interface in detached_interfaces: detached_interfaces.append(interface)
|
||||||
|
|
||||||
if online_interfaces == 0:
|
if online_interfaces == 0:
|
||||||
|
if self.bootstrap_interface_count() == 0:
|
||||||
RNS.log(f"No auto-discovered interfaces connected, re-enabling bootstrap interfaces", RNS.LOG_NOTICE)
|
RNS.log(f"No auto-discovered interfaces connected, re-enabling bootstrap interfaces", RNS.LOG_NOTICE)
|
||||||
# TODO: Implement
|
for config in RNS.Reticulum.get_instance().bootstrap_configs:
|
||||||
RNS.log(f"Available bootstrap configs:\n{RNS.Reticulum.get_instance().bootstrap_configs}", RNS.LOG_DEBUG)
|
RNS.Reticulum.get_instance()._synthesize_interface(config, config["name"])
|
||||||
|
|
||||||
for interface in detached_interfaces:
|
for interface in detached_interfaces:
|
||||||
try: self.teardown_interface(interface)
|
try: self.teardown_interface(interface)
|
||||||
@@ -483,12 +484,15 @@ class InterfaceDiscovery():
|
|||||||
|
|
||||||
def teardown_interface(self, interface):
|
def teardown_interface(self, interface):
|
||||||
interface.detach()
|
interface.detach()
|
||||||
RNS.Transport.interfaces.remove(interface)
|
if interface in RNS.Transport.interfaces: RNS.Transport.interfaces.remove(interface)
|
||||||
self.monitored_interfaces.remove(interface)
|
if interface in self.monitored_interfaces: self.monitored_interfaces.remove(interface)
|
||||||
|
|
||||||
def autoconnect_count(self):
|
def autoconnect_count(self):
|
||||||
return len([i for i in RNS.Transport.interfaces if hasattr(i, "autoconnect_hash")])
|
return len([i for i in RNS.Transport.interfaces if hasattr(i, "autoconnect_hash")])
|
||||||
|
|
||||||
|
def bootstrap_interface_count(self):
|
||||||
|
return len([i for i in RNS.Transport.interfaces if hasattr(i, "bootstrap_only") and i.bootstrap_only == True])
|
||||||
|
|
||||||
def connect_discovered(self):
|
def connect_discovered(self):
|
||||||
if RNS.Reticulum.should_autoconnect_discovered_interfaces():
|
if RNS.Reticulum.should_autoconnect_discovered_interfaces():
|
||||||
try:
|
try:
|
||||||
@@ -509,11 +513,11 @@ class InterfaceDiscovery():
|
|||||||
if interface_type in self.AUTOCONNECT_TYPES:
|
if interface_type in self.AUTOCONNECT_TYPES:
|
||||||
endpoint_specifier = ""
|
endpoint_specifier = ""
|
||||||
if "reachable_on" in info: endpoint_specifier += str(info["reachable_on"])
|
if "reachable_on" in info: endpoint_specifier += str(info["reachable_on"])
|
||||||
if "port" in info: endpoint_specifier += str(info["port"])
|
if "port" in info: endpoint_specifier += ":"+str(info["port"])
|
||||||
endpoint_hash = RNS.Identity.full_hash(endpoint_specifier.encode("utf-8"))
|
endpoint_hash = RNS.Identity.full_hash(endpoint_specifier.encode("utf-8"))
|
||||||
exists = False
|
exists = False
|
||||||
for interface in RNS.Transport.interfaces:
|
for interface in RNS.Transport.interfaces:
|
||||||
if hasattr(interface, "autoconnect_hash") and interface.autoconnect_hash:
|
if hasattr(interface, "autoconnect_hash") and interface.autoconnect_hash == endpoint_hash:
|
||||||
exists = True
|
exists = True
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -539,10 +543,10 @@ class InterfaceDiscovery():
|
|||||||
RNS.log(f"You can obtain the configuration entry and add this interface manually instead using rnstatus -D", RNS.LOG_WARNING)
|
RNS.log(f"You can obtain the configuration entry and add this interface manually instead using rnstatus -D", RNS.LOG_WARNING)
|
||||||
return
|
return
|
||||||
|
|
||||||
RNS.log(f"Auto-connecting discovered {interface_type}")
|
interface_name = info["name"]
|
||||||
|
RNS.log(f"Auto-connecting discovered {interface_type} {interface_name}")
|
||||||
config_entry = info["config_entry"]
|
config_entry = info["config_entry"]
|
||||||
interface_config = {}
|
interface_config = {}
|
||||||
interface_name = info["name"]
|
|
||||||
interface_config["name"] = f"{interface_name}"
|
interface_config["name"] = f"{interface_name}"
|
||||||
ifac_netname = info["ifac_netname"] if "ifac_netname" in info else None
|
ifac_netname = info["ifac_netname"] if "ifac_netname" in info else None
|
||||||
ifac_netkey = info["ifac_netkey"] if "ifac_netkey" in info else None
|
ifac_netkey = info["ifac_netkey"] if "ifac_netkey" in info else None
|
||||||
|
|||||||
@@ -604,6 +604,16 @@ class Reticulum:
|
|||||||
for name in self.config["interfaces"]:
|
for name in self.config["interfaces"]:
|
||||||
if not name in interface_names:
|
if not name in interface_names:
|
||||||
c = self.config["interfaces"][name]
|
c = self.config["interfaces"][name]
|
||||||
|
self._synthesize_interface(c, name, instance_init=True)
|
||||||
|
|
||||||
|
else:
|
||||||
|
RNS.log("The interface name \""+name+"\" was already used. Check your configuration file for errors!", RNS.LOG_ERROR)
|
||||||
|
RNS.panic()
|
||||||
|
|
||||||
|
RNS.log("System interfaces are ready", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
|
def _synthesize_interface(self, config, name, instance_init=False):
|
||||||
|
c = config
|
||||||
interface_mode = Interface.Interface.MODE_FULL
|
interface_mode = Interface.Interface.MODE_FULL
|
||||||
|
|
||||||
if "interface_mode" in c:
|
if "interface_mode" in c:
|
||||||
@@ -897,7 +907,7 @@ class Reticulum:
|
|||||||
interface = WeaveInterface.WeaveInterface(RNS.Transport, interface_config)
|
interface = WeaveInterface.WeaveInterface(RNS.Transport, interface_config)
|
||||||
interface_post_init(interface)
|
interface_post_init(interface)
|
||||||
|
|
||||||
if bootstrap_only: self.bootstrap_configs.append(interface_config)
|
if bootstrap_only and instance_init: self.bootstrap_configs.append(interface_config)
|
||||||
|
|
||||||
if interface == None:
|
if interface == None:
|
||||||
# Interface was not handled by any internal interface types,
|
# Interface was not handled by any internal interface types,
|
||||||
@@ -935,11 +945,6 @@ class Reticulum:
|
|||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
RNS.trace_exception(e)
|
RNS.trace_exception(e)
|
||||||
RNS.panic()
|
RNS.panic()
|
||||||
else:
|
|
||||||
RNS.log("The interface name \""+name+"\" was already used. Check your configuration file for errors!", RNS.LOG_ERROR)
|
|
||||||
RNS.panic()
|
|
||||||
|
|
||||||
RNS.log("System interfaces are ready", RNS.LOG_VERBOSE)
|
|
||||||
|
|
||||||
def _add_interface(self, interface, mode = None, configured_bitrate=None, ifac_size=None, ifac_netname=None, ifac_netkey=None,
|
def _add_interface(self, interface, mode = None, configured_bitrate=None, ifac_size=None, ifac_netname=None, ifac_netkey=None,
|
||||||
announce_cap=None, announce_rate_target=None, announce_rate_grace=None, announce_rate_penalty=None, bootstrap_only=False):
|
announce_cap=None, announce_rate_target=None, announce_rate_grace=None, announce_rate_penalty=None, bootstrap_only=False):
|
||||||
@@ -948,6 +953,7 @@ class Reticulum:
|
|||||||
|
|
||||||
if mode == None: mode = Interface.Interface.MODE_FULL
|
if mode == None: mode = Interface.Interface.MODE_FULL
|
||||||
interface.mode = mode
|
interface.mode = mode
|
||||||
|
interface.OUT = True
|
||||||
|
|
||||||
if configured_bitrate: interface.bitrate = configured_bitrate
|
if configured_bitrate: interface.bitrate = configured_bitrate
|
||||||
if bootstrap_only == True: interface.bootstrap_only = True
|
if bootstrap_only == True: interface.bootstrap_only = True
|
||||||
|
|||||||
Reference in New Issue
Block a user