Skip to content

Commit

Permalink
Added option to disable propagation node for pageserving-only nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Oct 15, 2023
1 parent 0fb9e18 commit 8d72a83
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 13 deletions.
42 changes: 34 additions & 8 deletions nomadnet/NomadNetworkApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, configdir = None, rnsconfigdir = None, daemon = False, force_

self.peer_announce_at_start = True
self.try_propagation_on_fail = True
self.disable_propagation = False

self.periodic_lxmf_sync = True
self.lxmf_sync_interval = 360*60
Expand Down Expand Up @@ -308,15 +309,27 @@ def __init__(self, configdir = None, rnsconfigdir = None, daemon = False, force_
except Exception as e:
RNS.log("Cannot prioritise "+str(dest_str)+", it is not a valid destination hash", RNS.LOG_ERROR)

self.message_router.enable_propagation()
try:
with open(self.pnannouncedpath, "wb") as pnf:
pnf.write(msgpack.packb(time.time()))
pnf.close()
except Exception as e:
RNS.log("An error ocurred while writing Propagation Node announce timestamp. The contained exception was: "+str(e), RNS.LOG_ERROR)
if self.disable_propagation:
if os.path.isfile(self.pnannouncedpath):
try:
RNS.log("Sending indication to peered LXMF Propagation Node that this node is no longer participating", RNS.LOG_DEBUG)
self.message_router.disable_propagation()
os.unlink(self.pnannouncedpath)
except Exception as e:
RNS.log("An error ocurred while indicating that this LXMF Propagation Node is no longer participating. The contained exception was: "+str(e), RNS.LOG_ERROR)
else:
self.message_router.enable_propagation()
try:
with open(self.pnannouncedpath, "wb") as pnf:
pnf.write(msgpack.packb(time.time()))
pnf.close()

except Exception as e:
RNS.log("An error ocurred while writing Propagation Node announce timestamp. The contained exception was: "+str(e), RNS.LOG_ERROR)

RNS.log("LXMF Propagation Node started on: "+RNS.prettyhexrep(self.message_router.propagation_destination.hash))
if not self.disable_propagation:
RNS.log("LXMF Propagation Node started on: "+RNS.prettyhexrep(self.message_router.propagation_destination.hash))

self.node = nomadnet.Node(self)
else:
self.node = None
Expand Down Expand Up @@ -788,6 +801,11 @@ def applyConfig(self):
else:
self.node_name = self.config["node"]["node_name"]

if not "disable_propagation" in self.config["node"]:
self.disable_propagation = False
else:
self.disable_propagation = self.config["node"].as_bool("disable_propagation")

if not "announce_at_start" in self.config["node"]:
self.node_announce_at_start = False
else:
Expand Down Expand Up @@ -1003,6 +1021,14 @@ def quit(self):
# Whether to announce when the node starts.
announce_at_start = Yes
# By default, when Nomad Network is hosting a
# node, it will also act as an LXMF propagation
# node. If there is already a large amount of
# propagation nodes on the network, or you
# simply want to run a pageserving-only node,
# you can disable running a propagation node.
# disable_propagation = False
# The maximum amount of storage to use for
# the LXMF Propagation Node message store,
# specified in megabytes. When this limit
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 @@ -620,6 +620,12 @@ def focus_reader(self):
Determines where the node server will look for downloadable files. Must be a readable filesystem path.
<
>>>
`!disable_propagation = no`!
>>>>
By default, when Nomad Network is hosting a node, it will also run an LXMF propagation node. If there is already a large amount of propagation nodes on the network, or you simply want to run a pageserving-only node, you can disable running a propagation node.
<
>>>
`!message_storage_limit = 2000`!
>>>>
Expand Down
33 changes: 28 additions & 5 deletions nomadnet/ui/textui/Network.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,12 +977,12 @@ def __init__(self, app):

def update_stat(self):
self.stat_string = "None"
if self.app.node != None:
if self.app.node != None and not self.app.disable_propagation:

limit = self.app.message_router.message_storage_limit
used = self.app.message_router.message_storage_size()

if limit != None:
if limit != None and used != None:
pct = round((used/limit)*100, 1)
pct_str = str(pct)+"%, "
limit_str = " of "+RNS.prettysize(limit)
Expand Down Expand Up @@ -1313,12 +1313,35 @@ def connect_query(sender):
connect_button = urwid.Button("Browse", on_press=connect_query)
reset_button = urwid.Button("Rst Stats", on_press=stats_query)

pile = urwid.Pile([
if not self.app.disable_propagation:
pile = urwid.Pile([
t_id,
e_name,
urwid.Divider(g["divider1"]),
e_lxmf,
urwid.Divider(g["divider1"]),
self.t_last_announce,
self.t_storage_stats,
self.t_active_links,
self.t_total_connections,
self.t_total_pages,
self.t_total_files,
urwid.Divider(g["divider1"]),
urwid.Columns([
("weight", 5, urwid.Button("Back", on_press=show_peer_info)),
("weight", 0.5, urwid.Text("")),
("weight", 6, connect_button),
("weight", 0.5, urwid.Text("")),
("weight", 8, reset_button),
("weight", 0.5, urwid.Text("")),
("weight", 7, announce_button),
])
])
else:
pile = urwid.Pile([
t_id,
e_name,
urwid.Divider(g["divider1"]),
e_lxmf,
urwid.Divider(g["divider1"]),
self.t_last_announce,
self.t_storage_stats,
self.t_active_links,
Expand Down

0 comments on commit 8d72a83

Please sign in to comment.