From 22a7acf25981198ace40379ee71a0a9ee4a354b5 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 13 Aug 2023 21:54:35 +0200 Subject: [PATCH] Added compact announce stream option --- nomadnet/Directory.py | 39 +++++++++++++++++++++++++++++++++++++ nomadnet/NomadNetworkApp.py | 11 +++++++++++ nomadnet/ui/textui/Guide.py | 6 ++++++ 3 files changed, 56 insertions(+) diff --git a/nomadnet/Directory.py b/nomadnet/Directory.py index 2cba01b..aee392c 100644 --- a/nomadnet/Directory.py +++ b/nomadnet/Directory.py @@ -118,6 +118,19 @@ class Directory: def lxmf_announce_received(self, source_hash, app_data): if app_data != None: + if self.app.compact_stream: + try: + remove_announces = [] + for announce in self.announce_stream: + if announce[1] == source_hash: + remove_announces.append(announce) + + for a in remove_announces: + self.announce_stream.remove(a) + + except Exception as e: + RNS.log("An error occurred while compacting the announce stream. The contained exception was:"+str(e), RNS.LOG_ERROR) + timestamp = time.time() self.announce_stream.insert(0, (timestamp, source_hash, app_data, "peer")) while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH: @@ -128,6 +141,19 @@ class Directory: def node_announce_received(self, source_hash, app_data, associated_peer): if app_data != None: + if self.app.compact_stream: + try: + remove_announces = [] + for announce in self.announce_stream: + if announce[1] == source_hash: + remove_announces.append(announce) + + for a in remove_announces: + self.announce_stream.remove(a) + + except Exception as e: + RNS.log("An error occurred while compacting the announce stream. The contained exception was:"+str(e), RNS.LOG_ERROR) + timestamp = time.time() self.announce_stream.insert(0, (timestamp, source_hash, app_data, "node")) while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH: @@ -155,6 +181,19 @@ class Directory: break if not found_node: + if self.app.compact_stream: + try: + remove_announces = [] + for announce in self.announce_stream: + if announce[1] == source_hash: + remove_announces.append(announce) + + for a in remove_announces: + self.announce_stream.remove(a) + + except Exception as e: + RNS.log("An error occurred while compacting the announce stream. The contained exception was:"+str(e), RNS.LOG_ERROR) + timestamp = time.time() self.announce_stream.insert(0, (timestamp, source_hash, app_data, "pn")) while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH: diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index cd11bfe..f17c31c 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -126,6 +126,7 @@ class NomadNetworkApp: self.periodic_lxmf_sync = True self.lxmf_sync_interval = 360*60 self.lxmf_sync_limit = 8 + self.compact_stream = False if not os.path.isdir(self.storagepath): os.makedirs(self.storagepath) @@ -698,6 +699,10 @@ class NomadNetworkApp: else: self.lxmf_sync_limit = None + if option == "compact_announce_stream": + value = self.config["client"].as_bool(option) + self.compact_stream = value + if option == "user_interface": value = value.lower() if value == "none": @@ -929,6 +934,12 @@ lxmf_sync_interval = 360 # the limit, and download everything every time. lxmf_sync_limit = 8 +# The announce stream will only show one entry +# per destination or node by default. You can +# change this to show as many announces as have +# been received, for every destination. +compact_announce_stream = yes + [textui] # Amount of time to show intro screen diff --git a/nomadnet/ui/textui/Guide.py b/nomadnet/ui/textui/Guide.py index c8c2cfc..954cbd2 100644 --- a/nomadnet/ui/textui/Guide.py +++ b/nomadnet/ui/textui/Guide.py @@ -506,6 +506,12 @@ The number of minutes between each automatic sync. The default is equal to 6 hou On low-bandwidth networks, it can be useful to limit the amount of messages downloaded in each sync. The default is 8. Set to 0 to download all available messages every time a sync occurs. < +>>> +`!compact_announce_stream = yes`! +>>>> +With this option enabled, Nomad Network will only display one entry in the announce stream per destination. Older announces are culled when a new one arrives. +< + >> Text UI Section This section hold configuration directives related to the look and feel of the text-based user interface of the program. It is delimited by the `![textui]`! header in the configuration file. Available directives, along with their default values, are as follows: