Skip to content

Commit

Permalink
Added compact announce stream option
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Aug 13, 2023
1 parent 919a146 commit 22a7acf
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
39 changes: 39 additions & 0 deletions nomadnet/Directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ def load_from_disk(self):

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:
Expand All @@ -128,6 +141,19 @@ def lxmf_announce_received(self, source_hash, app_data):

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:
Expand Down Expand Up @@ -155,6 +181,19 @@ def pn_announce_received(self, source_hash, app_data, associated_peer, associate
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:
Expand Down
11 changes: 11 additions & 0 deletions nomadnet/NomadNetworkApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __init__(self, configdir = None, rnsconfigdir = None, daemon = False, force_
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)
Expand Down Expand Up @@ -698,6 +699,10 @@ def applyConfig(self):
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":
Expand Down Expand Up @@ -929,6 +934,12 @@ def quit(self):
# 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
Expand Down
6 changes: 6 additions & 0 deletions nomadnet/ui/textui/Guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ def focus_reader(self):
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:
Expand Down

0 comments on commit 22a7acf

Please sign in to comment.