Implemented bootstrap interface handling

This commit is contained in:
Mark Qvist
2026-01-03 22:29:26 +01:00
parent 7cadb3af8b
commit 15a123875f
2 changed files with 349 additions and 339 deletions

View File

@@ -472,9 +472,10 @@ class InterfaceDiscovery():
if not interface in detached_interfaces: detached_interfaces.append(interface)
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)
# TODO: Implement
RNS.log(f"Available bootstrap configs:\n{RNS.Reticulum.get_instance().bootstrap_configs}", RNS.LOG_DEBUG)
for config in RNS.Reticulum.get_instance().bootstrap_configs:
RNS.Reticulum.get_instance()._synthesize_interface(config, config["name"])
for interface in detached_interfaces:
try: self.teardown_interface(interface)
@@ -483,12 +484,15 @@ class InterfaceDiscovery():
def teardown_interface(self, interface):
interface.detach()
RNS.Transport.interfaces.remove(interface)
self.monitored_interfaces.remove(interface)
if interface in RNS.Transport.interfaces: RNS.Transport.interfaces.remove(interface)
if interface in self.monitored_interfaces: self.monitored_interfaces.remove(interface)
def autoconnect_count(self):
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):
if RNS.Reticulum.should_autoconnect_discovered_interfaces():
try:
@@ -509,11 +513,11 @@ class InterfaceDiscovery():
if interface_type in self.AUTOCONNECT_TYPES:
endpoint_specifier = ""
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"))
exists = False
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
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)
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"]
interface_config = {}
interface_name = info["name"]
interface_config["name"] = f"{interface_name}"
ifac_netname = info["ifac_netname"] if "ifac_netname" in info else None
ifac_netkey = info["ifac_netkey"] if "ifac_netkey" in info else None

View File

@@ -604,6 +604,16 @@ class Reticulum:
for name in self.config["interfaces"]:
if not name in interface_names:
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
if "interface_mode" in c:
@@ -897,7 +907,7 @@ class Reticulum:
interface = WeaveInterface.WeaveInterface(RNS.Transport, interface_config)
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:
# 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.trace_exception(e)
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,
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
interface.mode = mode
interface.OUT = True
if configured_bitrate: interface.bitrate = configured_bitrate
if bootstrap_only == True: interface.bootstrap_only = True