Added option to specify shared instance type
Some checks are pending
Build Reticulum / test (push) Waiting to run
Build Reticulum / package (push) Blocked by required conditions
Build Reticulum / release (push) Blocked by required conditions

This commit is contained in:
Mark Qvist 2025-05-15 01:14:55 +02:00
parent c1673f39b6
commit 756029e5af
4 changed files with 88 additions and 29 deletions

View file

@ -70,7 +70,7 @@ class LocalClientInterface(Interface):
self.HW_MTU = 262144 self.HW_MTU = 262144
self.online = False self.online = False
if socket_path != None and RNS.vendor.platformutils.use_af_unix(): self.socket_path = f"\0rns/{socket_path}" if socket_path != None and RNS.Reticulum.get_instance().use_af_unix: self.socket_path = f"\0rns/{socket_path}"
else: self.socket_path = None else: self.socket_path = None
self.IN = True self.IN = True
@ -350,7 +350,7 @@ class LocalServerInterface(Interface):
self.online = False self.online = False
self.clients = 0 self.clients = 0
if socket_path != None and RNS.vendor.platformutils.use_af_unix(): self.socket_path = f"\0rns/{socket_path}" if socket_path != None and RNS.Reticulum.get_instance().use_af_unix: self.socket_path = f"\0rns/{socket_path}"
else: self.socket_path = None else: self.socket_path = None
self.IN = True self.IN = True

View file

@ -211,7 +211,8 @@ class Reticulum:
""" """
return Reticulum.__instance return Reticulum.__instance
def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None, require_shared_instance=False): def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None,
require_shared_instance=False, shared_instance_type=None):
""" """
Initialises and starts a Reticulum instance. This must be Initialises and starts a Reticulum instance. This must be
done before any other operations, and Reticulum will not done before any other operations, and Reticulum will not
@ -263,12 +264,11 @@ class Reticulum:
self.local_control_port = 37429 self.local_control_port = 37429
self.local_socket_path = None self.local_socket_path = None
self.share_instance = True self.share_instance = True
self.shared_instance_type = shared_instance_type
self.rpc_listener = None self.rpc_listener = None
self.rpc_key = None self.rpc_key = None
self.rpc_type = "AF_INET" self.rpc_type = "AF_INET"
self.use_af_unix = False
if RNS.vendor.platformutils.use_af_unix():
self.local_socket_path = "default"
self.ifac_salt = Reticulum.IFAC_SALT self.ifac_salt = Reticulum.IFAC_SALT
@ -327,10 +327,9 @@ class Reticulum:
RNS.log(f"Configuration loaded from {self.configpath}", RNS.LOG_VERBOSE) RNS.log(f"Configuration loaded from {self.configpath}", RNS.LOG_VERBOSE)
RNS.Identity.load_known_destinations() RNS.Identity.load_known_destinations()
RNS.Transport.start(self) RNS.Transport.start(self)
if RNS.vendor.platformutils.use_af_unix(): if self.use_af_unix:
self.rpc_addr = f"\0rns/{self.local_socket_path}/rpc" self.rpc_addr = f"\0rns/{self.local_socket_path}/rpc"
self.rpc_type = "AF_UNIX" self.rpc_type = "AF_UNIX"
else: else:
@ -458,6 +457,11 @@ class Reticulum:
if option == "instance_name": if option == "instance_name":
value = self.config["reticulum"][option] value = self.config["reticulum"][option]
self.local_socket_path = value self.local_socket_path = value
if option == "shared_instance_type":
if self.shared_instance_type == None:
value = self.config["reticulum"][option].lower()
if value in ["tcp", "unix"]:
self.shared_instance_type = value
if option == "shared_instance_port": if option == "shared_instance_port":
value = int(self.config["reticulum"][option]) value = int(self.config["reticulum"][option])
self.local_interface_port = value self.local_interface_port = value
@ -516,6 +520,17 @@ class Reticulum:
if RNS.compiled: RNS.log("Reticulum running in compiled mode", RNS.LOG_DEBUG) if RNS.compiled: RNS.log("Reticulum running in compiled mode", RNS.LOG_DEBUG)
else: RNS.log("Reticulum running in interpreted mode", RNS.LOG_DEBUG) else: RNS.log("Reticulum running in interpreted mode", RNS.LOG_DEBUG)
if RNS.vendor.platformutils.use_af_unix():
if self.shared_instance_type == "tcp": self.use_af_unix = False
else: self.use_af_unix = True
else:
self.shared_instance_type = "tcp"
self.use_af_unix = False
if self.local_socket_path == None and self.use_af_unix:
self.local_socket_path = "default"
self.__start_local_interface() self.__start_local_interface()
if self.is_shared_instance or self.is_standalone_instance: if self.is_shared_instance or self.is_standalone_instance:
@ -1379,8 +1394,16 @@ instance_name = default
# is the case, you can isolate different instances by # is the case, you can isolate different instances by
# specifying a unique set of ports for each: # specifying a unique set of ports for each:
shared_instance_port = 37428 # shared_instance_port = 37428
instance_control_port = 37429 # instance_control_port = 37429
# If you want to explicitly use TCP for shared instance
# communication, instead of domain sockets, this is also
# possible, by using the following option:
# shared_instance_type = tcp
# You can configure Reticulum to panic and forcibly close # You can configure Reticulum to panic and forcibly close
# if an unrecoverable interface error occurs, such as the # if an unrecoverable interface error occurs, such as the
@ -1388,7 +1411,7 @@ instance_control_port = 37429
# an optional directive, and can be left out for brevity. # an optional directive, and can be left out for brevity.
# This behaviour is disabled by default. # This behaviour is disabled by default.
panic_on_interface_error = No # panic_on_interface_error = No
[logging] [logging]

View file

@ -117,12 +117,24 @@ share_instance = Yes
# If you want to run multiple *different* shared instances # If you want to run multiple *different* shared instances
# on the same system, you will need to specify different # on the same system, you will need to specify different
# shared instance ports for each. The defaults are given # instance names for each. On platforms supporting domain
# below, and again, these options can be left out if you # sockets, this can be done with the instance_name option:
# don't need them.
shared_instance_port = 37428 instance_name = default
instance_control_port = 37429
# Some platforms don't support domain sockets, and if that
# is the case, you can isolate different instances by
# specifying a unique set of ports for each:
# shared_instance_port = 37428
# instance_control_port = 37429
# If you want to explicitly use TCP for shared instance
# communication, instead of domain sockets, this is also
# possible, by using the following option:
# shared_instance_type = tcp
# On systems where running instances may not have access # On systems where running instances may not have access
@ -154,7 +166,7 @@ instance_control_port = 37429
# an optional directive, and can be left out for brevity. # an optional directive, and can be left out for brevity.
# This behaviour is disabled by default. # This behaviour is disabled by default.
panic_on_interface_error = No # panic_on_interface_error = No
# When Transport is enabled, it is possible to allow the # When Transport is enabled, it is possible to allow the
@ -165,7 +177,7 @@ panic_on_interface_error = No
# Transport Instance, and printed to the log at startup. # Transport Instance, and printed to the log at startup.
# Optional, and disabled by default. # Optional, and disabled by default.
respond_to_probes = No # respond_to_probes = No
[logging] [logging]

View file

@ -69,12 +69,12 @@ configuration file is created. The default configuration looks like this:
# If you enable Transport, your system will route traffic # If you enable Transport, your system will route traffic
# for other peers, pass announces and serve path requests. # for other peers, pass announces and serve path requests.
# This should only be done for systems that are suited to # This should be done for systems that are suited to act
# act as transport nodes, ie. if they are stationary and # as transport nodes, ie. if they are stationary and
# always-on. This directive is optional and can be removed # always-on. This directive is optional and can be removed
# for brevity. # for brevity.
enable_transport = False enable_transport = No
# By default, the first program to launch the Reticulum # By default, the first program to launch the Reticulum
@ -91,12 +91,24 @@ configuration file is created. The default configuration looks like this:
# If you want to run multiple *different* shared instances # If you want to run multiple *different* shared instances
# on the same system, you will need to specify different # on the same system, you will need to specify different
# shared instance ports for each. The defaults are given # instance names for each. On platforms supporting domain
# below, and again, these options can be left out if you # sockets, this can be done with the instance_name option:
# don't need them.
shared_instance_port = 37428 instance_name = default
instance_control_port = 37429
# Some platforms don't support domain sockets, and if that
# is the case, you can isolate different instances by
# specifying a unique set of ports for each:
# shared_instance_port = 37428
# instance_control_port = 37429
# If you want to explicitly use TCP for shared instance
# communication, instead of domain sockets, this is also
# possible, by using the following option:
# shared_instance_type = tcp
# On systems where running instances may not have access # On systems where running instances may not have access
@ -110,13 +122,25 @@ configuration file is created. The default configuration looks like this:
# rpc_key = e5c032d3ec4e64a6aca9927ba8ab73336780f6d71790 # rpc_key = e5c032d3ec4e64a6aca9927ba8ab73336780f6d71790
# It is possible to allow remote management of Reticulum
# systems using the various built-in utilities, such as
# rnstatus and rnpath. You will need to specify one or
# more Reticulum Identity hashes for authenticating the
# queries from client programs. For this purpose, you can
# use existing identity files, or generate new ones with
# the rnid utility.
# enable_remote_management = yes
# remote_management_allowed = 9fb6d773498fb3feda407ed8ef2c3229, 2d882c5586e548d79b5af27bca1776dc
# You can configure Reticulum to panic and forcibly close # You can configure Reticulum to panic and forcibly close
# if an unrecoverable interface error occurs, such as the # if an unrecoverable interface error occurs, such as the
# hardware device for an interface disappearing. This is # hardware device for an interface disappearing. This is
# an optional directive, and can be left out for brevity. # an optional directive, and can be left out for brevity.
# This behaviour is disabled by default. # This behaviour is disabled by default.
panic_on_interface_error = No # panic_on_interface_error = No
# When Transport is enabled, it is possible to allow the # When Transport is enabled, it is possible to allow the
@ -127,7 +151,7 @@ configuration file is created. The default configuration looks like this:
# Transport Instance, and printed to the log at startup. # Transport Instance, and printed to the log at startup.
# Optional, and disabled by default. # Optional, and disabled by default.
respond_to_probes = No # respond_to_probes = No
[logging] [logging]