RNS Logo

rns.recipes

◈ 9ce92808be498e9e05590ff27cbfdfe4
Upcoming RNS 1.6.0 https://rns.recipes/forum/general/upcoming-rns-160-help-testing

Can we get configurable ANNOUNCE_STREAM_MAXLENGTH?

Started by flok 941b29d0ffe891b8... ·

flok 3139c1fa6446992c...
#1

Heyo, I see that my NomadNet is clearing old announces and maxes out at 256. I'd love to be able to increase this. I'm unsure if this is the right place to make feature requests, please direct me somewhere else if not :)

f24bcd7d 1f616ced081d70ff...
#2

FYI I suck at programming, someone should probably fix this up a bit and maybe contribute it

 

that being said, here's a patch I wrote

 

(if anyone wants to use this, dedicated to the public domain under CC0. I prefer to remain anonymous)

 

diff --git a/nomadnet/Directory.py b/nomadnet/Directory.py
index 8727b7d..828788a 100644
--- a/nomadnet/Directory.py
+++ b/nomadnet/Directory.py
@@ -37,8 +37,6 @@ class PNAnnounceHandler:
             RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
 
 class Directory:
-    ANNOUNCE_STREAM_MAXLENGTH = 256
-
     aspect_filter = "nomadnetwork.node"
     @staticmethod
     def received_announce(destination_hash, announced_identity, app_data):
@@ -64,15 +62,20 @@ class Directory:
         return self._node_announces+self._peer_announces+self._pn_announces
 
     def _clean_node_announces(self):
-        while len(self._node_announces) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
+        RNS.log(
+            f"Directory cleanup: count={len(self._node_announces)}, "
+            f"limit={self.app.announce_stream_maxlength}",
+            RNS.LOG_NOTICE
+        )
+        while len(self._node_announces) > self.app.announce_stream_maxlength:
             self._node_announces.pop()
 
     def _clean_peer_announces(self):
-        while len(self._peer_announces) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
+        while len(self._peer_announces) > self.app.announce_stream_maxlength:
             self._peer_announces.pop()
 
     def _clean_pn_announces(self):
-        while len(self._pn_announces) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
+        while len(self._pn_announces) > self.app.announce_stream_maxlength:
             self._pn_announces.pop()
 
     def __init__(self, app):
diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py
index b32a4e2..5a8d091 100644
--- a/nomadnet/NomadNetworkApp.py
+++ b/nomadnet/NomadNetworkApp.py
@@ -1033,6 +1033,10 @@ class NomadNetworkApp:
                     if value == "web":
                         self.uimode = nomadnet.ui.UI_WEB
 
+                if option == "announce_stream_maxlength":
+                    value = self.config["client"].as_int(option)
+                    self.announce_stream_maxlength = value
+
         if not "utilities" in self.config:
             self.config["utilities"] = {}
         if not "enable_utilities" in self.config["utilities"]:
f24bcd7d 1f616ced081d70ff...
#3

PS: I tested it and it seems to work, but it might have gaping holes I haven't noticed. quadruple check this before applying it to your nomadnet

f24bcd7d 1f616ced081d70ff...
#4

here's a slightly better version of that patch:

 

diff --git a/nomadnet/Directory.py b/nomadnet/Directory.py
index 8727b7d..a3f94e4 100644
--- a/nomadnet/Directory.py
+++ b/nomadnet/Directory.py
@@ -37,8 +37,6 @@ class PNAnnounceHandler:
             RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
 
 class Directory:
-    ANNOUNCE_STREAM_MAXLENGTH = 256
-
     aspect_filter = "nomadnetwork.node"
     @staticmethod
     def received_announce(destination_hash, announced_identity, app_data):
@@ -64,15 +62,15 @@ class Directory:
         return self._node_announces+self._peer_announces+self._pn_announces
 
     def _clean_node_announces(self):
-        while len(self._node_announces) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
+        while len(self._node_announces) > self.app.announce_stream_maxlength:
             self._node_announces.pop()
 
     def _clean_peer_announces(self):
-        while len(self._peer_announces) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
+        while len(self._peer_announces) > self.app.announce_stream_maxlength:
             self._peer_announces.pop()
 
     def _clean_pn_announces(self):
-        while len(self._pn_announces) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
+        while len(self._pn_announces) > self.app.announce_stream_maxlength:
             self._pn_announces.pop()
 
     def __init__(self, app):
diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py
index b32a4e2..810ad70 100644
--- a/nomadnet/NomadNetworkApp.py
+++ b/nomadnet/NomadNetworkApp.py
@@ -1033,6 +1033,10 @@ class NomadNetworkApp:
                     if value == "web":
                         self.uimode = nomadnet.ui.UI_WEB
 
+                if option == "announce_stream_maxlength":
+                    value = self.config["client"].as_int(option)
+                    self.announce_stream_maxlength = max(1, value)
+
         if not "utilities" in self.config:
             self.config["utilities"] = {}
         if not "enable_utilities" in self.config["utilities"]:

 

I removed that debug log I added and ensured the announce length is at least positive

flok 3139c1fa6446992c...
#5

sweet thx! Would be great to have this implemented upstream but I can't find information on how to make contributions :/

Zenith Admin
#6

flok wrote:

sweet thx! Would be great to have this implemented upstream but I can't find information on how to make contributions :/

 

I have this planned already in the codebase for my Web UI fork so if that gets accepted upstream it will be in base NomadNet

Post a Reply

Supports Markdown: **bold**, *italic*, `code`, ```code blocks```, [links](url)

Log in to upload images

Quote
Copied to clipboard