channels list as json; announce interval

This commit is contained in:
Gabby Morgan
2026-05-29 20:01:42 -05:00
parent 5fc9cdf79d
commit 205697a6f8
2 changed files with 33 additions and 0 deletions
Executable → Regular
View File
+33
View File
@@ -9,6 +9,8 @@ with ``/create_channel <name>``. Each channel is its own
Reticulum node with a unique identity. Reticulum node with a unique identity.
""" """
import json
import RNS import RNS
import LXMF import LXMF
import os import os
@@ -467,11 +469,13 @@ class LXSTRelay(SignallingReceiver):
rnsconfigdir=None, rnsconfigdir=None,
channel_name="default", channel_name="default",
verbosity=0, verbosity=0,
announce_interval=0,
): ):
super().__init__() super().__init__()
self.configdir = configdir self.configdir = configdir
self.channel_name = channel_name self.channel_name = channel_name
self.should_run = False self.should_run = False
self.announce_interval = announce_interval
if self.configdir is None: if self.configdir is None:
if os.path.isdir("/etc/lxst-relay"): if os.path.isdir("/etc/lxst-relay"):
@@ -626,6 +630,8 @@ class LXSTRelay(SignallingReceiver):
if content.startswith("/create_channel"): if content.startswith("/create_channel"):
self._cmd_create_channel(message, content, sender_hash) self._cmd_create_channel(message, content, sender_hash)
elif content.startswith("/channels_json"):
self._cmd_list_channels_as_json(message)
elif content.startswith("/channels"): elif content.startswith("/channels"):
self._cmd_list_channels(message) self._cmd_list_channels(message)
else: else:
@@ -675,6 +681,15 @@ class LXSTRelay(SignallingReceiver):
lines.append(f" {name}{hash_hex}") lines.append(f" {name}{hash_hex}")
self._bot_reply(message, "\n".join(lines)) self._bot_reply(message, "\n".join(lines))
def _cmd_list_channels_as_json(self, message):
if not self.channel_manager.channels:
self._bot_reply(message, "No channels created yet.")
return
channels = [RNS.hexrep(node.destination.hash, delimit=False) for node in self.channel_manager.channels.values()]
self._bot_reply(message, json.dumps(channels))
# -- Send reply ---------------------------------------------------- # -- Send reply ----------------------------------------------------
def _bot_reply(self, incoming_msg, text): def _bot_reply(self, incoming_msg, text):
@@ -734,6 +749,11 @@ class LXSTRelay(SignallingReceiver):
self.channel_manager.announce_all() self.channel_manager.announce_all()
RNS.log("Relay announced on network", RNS.LOG_NOTICE) RNS.log("Relay announced on network", RNS.LOG_NOTICE)
def _announce_loop(self):
while self.should_run:
time.sleep(self.announce_interval)
self.announce()
def start(self): def start(self):
if self.should_run: if self.should_run:
return return
@@ -761,6 +781,12 @@ class LXSTRelay(SignallingReceiver):
) )
RNS.log("Waiting for calls and messages...", RNS.LOG_NOTICE) RNS.log("Waiting for calls and messages...", RNS.LOG_NOTICE)
if self.announce_interval > 0:
threading.Thread(
target=self._announce_loop,
daemon=True,
).start()
while self.should_run: while self.should_run:
time.sleep(1) time.sleep(1)
@@ -820,6 +846,12 @@ def main():
parser.add_argument( parser.add_argument(
"-v", "--verbose", action="count", default=0 "-v", "--verbose", action="count", default=0
) )
parser.add_argument(
"--announce_interval",
default=0,
help="seconds between announces (0 = announce once at startup, default)",
type=int,
)
args = parser.parse_args() args = parser.parse_args()
@@ -828,6 +860,7 @@ def main():
rnsconfigdir=args.rnsconfig, rnsconfigdir=args.rnsconfig,
channel_name=args.channel, channel_name=args.channel,
verbosity=args.verbose, verbosity=args.verbose,
announce_interval=args.announce_interval,
) )
try: try: