channels list as json; announce interval
This commit is contained in:
@@ -9,6 +9,8 @@ with ``/create_channel <name>``. Each channel is its own
|
||||
Reticulum node with a unique identity.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import RNS
|
||||
import LXMF
|
||||
import os
|
||||
@@ -467,11 +469,13 @@ class LXSTRelay(SignallingReceiver):
|
||||
rnsconfigdir=None,
|
||||
channel_name="default",
|
||||
verbosity=0,
|
||||
announce_interval=0,
|
||||
):
|
||||
super().__init__()
|
||||
self.configdir = configdir
|
||||
self.channel_name = channel_name
|
||||
self.should_run = False
|
||||
self.announce_interval = announce_interval
|
||||
|
||||
if self.configdir is None:
|
||||
if os.path.isdir("/etc/lxst-relay"):
|
||||
@@ -626,6 +630,8 @@ class LXSTRelay(SignallingReceiver):
|
||||
|
||||
if content.startswith("/create_channel"):
|
||||
self._cmd_create_channel(message, content, sender_hash)
|
||||
elif content.startswith("/channels_json"):
|
||||
self._cmd_list_channels_as_json(message)
|
||||
elif content.startswith("/channels"):
|
||||
self._cmd_list_channels(message)
|
||||
else:
|
||||
@@ -675,6 +681,15 @@ class LXSTRelay(SignallingReceiver):
|
||||
lines.append(f" {name} → {hash_hex}")
|
||||
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 ----------------------------------------------------
|
||||
|
||||
def _bot_reply(self, incoming_msg, text):
|
||||
@@ -734,6 +749,11 @@ class LXSTRelay(SignallingReceiver):
|
||||
self.channel_manager.announce_all()
|
||||
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):
|
||||
if self.should_run:
|
||||
return
|
||||
@@ -761,6 +781,12 @@ class LXSTRelay(SignallingReceiver):
|
||||
)
|
||||
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:
|
||||
time.sleep(1)
|
||||
|
||||
@@ -820,6 +846,12 @@ def main():
|
||||
parser.add_argument(
|
||||
"-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()
|
||||
|
||||
@@ -828,6 +860,7 @@ def main():
|
||||
rnsconfigdir=args.rnsconfig,
|
||||
channel_name=args.channel,
|
||||
verbosity=args.verbose,
|
||||
announce_interval=args.announce_interval,
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user