From c343ac170a9f4d1d745e7a7272d0a00ce03e28f4 Mon Sep 17 00:00:00 2001 From: chengtripp <124098378+chengtripp@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:06:14 +0000 Subject: [PATCH] Update: announcements, get directory, reduce log output * Created announce_check function which will check if need to rebroadcast announcement (hard coded to every 30 minutes) * Using os.getcwd now can get current directory so doesn't need hardcoded dir for storage/identity * Reduced RNS.log printout * Adjustable redis database --- messageboard.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/messageboard.py b/messageboard.py index 9ab97c6..c1dcb2f 100644 --- a/messageboard.py +++ b/messageboard.py @@ -6,10 +6,11 @@ import shortuuid import time display_name = "SolarExpress Message Board" -configdir = "~/retic/" -identitypath = configdir+"storage/identity" +configdir = os.getcwd() +identitypath = configdir+"/storage/identity" +redis_db = 2 -r = redis.Redis(db=2, decode_responses=True) +r = redis.Redis(db=redis_db, decode_responses=True) def setup_lxmf(): @@ -94,10 +95,18 @@ def send_message(destination_hash, message_content): # Send it message_router.handle_outbound(lxm) +def announce_check(): + if r.exists('announce'): + RNS.log('Recent announcement', RNS.LOG_DEBUG) + else: + r.set('announce', 1) + r.expire('announce', 1800) + announce_now(local_lxmf_destination) + RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO) # Start Reticulum and print out all the debug messages -reticulum = RNS.Reticulum(loglevel=RNS.LOG_EXTREME) +reticulum = RNS.Reticulum(loglevel=RNS.LOG_VERBOSE) # Create a Identity. current_identity = setup_lxmf() @@ -117,17 +126,11 @@ message_router.register_delivery_callback(lxmf_delivery) # Announce node properties RNS.log('LXMF Router ready to receive on: {}'.format(RNS.prettyhexrep(local_lxmf_destination.hash)), RNS.LOG_INFO) - -if r.exists('announce'): - RNS.log('Recent announcement', RNS.LOG_INFO) -else: - r.set('announce', 1) - r.expire('announce', 1800) - announce_now(local_lxmf_destination) - RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO) +announce_check() while True: + # Work through redis message queue for i in range(0, r.llen('message_queue')): message_id = r.lpop('message_queue') message = r.get(message_id) @@ -135,4 +138,9 @@ while True: destination_hash = message_id.split('_')[0] RNS.log('{} {}'.format(destination_hash, message), RNS.LOG_INFO) send_message(destination_hash, message) + + # Check whether we need to make another announcement + announce_check() + + #Sleep time.sleep(10)