diff --git a/nomadnet/Node.py b/nomadnet/Node.py index 31d4a26..44a9978 100644 --- a/nomadnet/Node.py +++ b/nomadnet/Node.py @@ -21,6 +21,8 @@ class Node: self.app = app self.identity = self.app.identity self.destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, "nomadnetwork", "node") + self.destination.set_link_cost(self.app.node_link_cost) + if self.app.node_stamp_value: self.destination.set_value(self.app.node_stamp_value) self.last_announce = time.time() self.last_file_refresh = time.time() self.last_page_refresh = time.time() diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index b32a4e2..cb379da 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -36,6 +36,9 @@ class NomadNetworkApp: START_ANNOUNCE_DELAY = 3 + REQUIRED_DESTINATION_TYPES = ["nomadnetwork.node", "rrc.hub"] + DEFAULT_LINK_COST = 17.8 + def exit_handler(self): self.should_run_jobs = False @@ -103,6 +106,9 @@ class NomadNetworkApp: NomadNetworkApp._shared_instance = self self.rns = RNS.Reticulum(configdir = rnsconfigdir) + # self.rns.required_announces_only(True) + for full_name in self.REQUIRED_DESTINATION_TYPES: + self.rns.wants_destination_type(full_name) self.configpath = self.configdir+"/config" self.ignoredpath = self.configdir+"/ignored" @@ -144,10 +150,13 @@ class NomadNetworkApp: self.notify_on_new_message = True self.compose_markdown = True + self.lxmf_stamp_value = None self.lxmf_max_propagation_size = None self.lxmf_max_sync_size = None self.lxmf_max_incoming_size = None self.node_propagation_cost = LXMF.LXMRouter.PROPAGATION_COST + self.node_link_cost = self.DEFAULT_LINK_COST + self.node_stamp_value = None self.periodic_lxmf_sync = True self.lxmf_sync_interval = 360*60 @@ -381,7 +390,7 @@ class NomadNetworkApp: for destination_hash in self.ignored_list: self.message_router.ignore_destination(destination_hash) - self.lxmf_destination = self.message_router.register_delivery_identity(self.identity, display_name=self.peer_settings["display_name"], stamp_cost=self.required_stamp_cost) + self.lxmf_destination = self.message_router.register_delivery_identity(self.identity, display_name=self.peer_settings["display_name"], stamp_cost=self.required_stamp_cost, stamp_value=self.lxmf_stamp_value) if not self.accept_invalid_stamps: self.message_router.enforce_stamps() @@ -862,6 +871,11 @@ class NomadNetworkApp: value = self.config["client"].as_bool(option) self.enable_client = value + if option == "stamp_value": + value = self.config["client"].as_float("stamp_value") + if value < 1: value = 1 + self.lxmf_stamp_value = RNS.Stamps.quantize_cost(value) + if option == "downloads_path": value = self.config["client"]["downloads_path"] self.downloads_path = os.path.expanduser(value) @@ -1140,6 +1154,16 @@ class NomadNetworkApp: else: self.node_name = self.config["node"]["node_name"] + if "link_cost" in self.config["node"]: + value = self.config["node"].as_float("link_cost") + if value < 1: value = 1 + self.node_link_cost = RNS.Stamps.quantize_cost(value) + + if "stamp_value" in self.config["node"]: + value = self.config["node"].as_float("stamp_value") + if value < 1: value = 1 + self.node_stamp_value = RNS.Stamps.quantize_cost(value) + if not "disable_propagation" in self.config["node"]: self.disable_propagation = True else: diff --git a/nomadnet/RRC.py b/nomadnet/RRC.py index f5cde89..3fefcca 100644 --- a/nomadnet/RRC.py +++ b/nomadnet/RRC.py @@ -223,6 +223,9 @@ class RRCHub: self.dest_name = dest_name or DEFAULT_DEST_NAME self.name = name or RNS.prettyhexrep(hub_hash) + if not self.dest_name == DEFAULT_DEST_NAME: + RNS.Reticulum.get_instance().wants_destination_type(self.dest_name) + self.link = None self.status = RRCHub.STATUS_DISCONNECTED self.status_text = "Disconnected" diff --git a/nomadnet/_version.py b/nomadnet/_version.py index c0f285b..0f228f2 100644 --- a/nomadnet/_version.py +++ b/nomadnet/_version.py @@ -1 +1 @@ -__version__ = "1.4.4" +__version__ = "1.5.1" diff --git a/nomadnet/ui/textui/Guide.py b/nomadnet/ui/textui/Guide.py index a204272..3dc0a56 100644 --- a/nomadnet/ui/textui/Guide.py +++ b/nomadnet/ui/textui/Guide.py @@ -1018,6 +1018,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. < +>>> +`!stamp_value = 25.0`! +>>>> +The target stamp value for your LXMF destination can be configured with this option. Defaults to 25.0. Each increase of 1.0 doubles the generation difficulty. Destination stamps are one-time generations, so it can be worth targeting a high value here, to ensure that other transport nodes will accept your announces. The default should be sufficient for most cases, though. +< + >>> `!required_stamp_cost = None`! >>>> @@ -1215,6 +1221,18 @@ Determines whether the node server should be started on launch. Must be a boolea Defines what the announced name of the node should be. < +>>> +`!stamp_value = 25.0`! +>>>> +The target stamp value for your node destination can be configured with this option. Defaults to 25.0. Each increase of 1.0 doubles the generation difficulty. Destination stamps are one-time generations, so it can be worth targeting a high value here, to ensure that other transport nodes will accept your announces. The default should be sufficient for most cases, though. +< + +>>> +`!link_cost = 17.8`! +>>>> +The link stamp cost required for other peers to connect to your node. The default is a relatively high value, that should deter most automated scraping and misuse, but you can set it even higher, if you wish, or lower it to allow connecting more easily. +< + >>> `!announce_at_start = yes`! >>>> diff --git a/nomadnet/ui/textui/Network.py b/nomadnet/ui/textui/Network.py index 11c4e54..39852a3 100644 --- a/nomadnet/ui/textui/Network.py +++ b/nomadnet/ui/textui/Network.py @@ -8,6 +8,7 @@ from nomadnet.Directory import DirectoryEntry from nomadnet.vendor.additional_urwid_widgets import IndicativeListBox, MODIFIER_KEY from nomadnet.util import strip_modifiers from nomadnet.util import sanitize_name +from LXMF import pn_stamp_cost_from_app_data from .Browser import Browser from .ReadlineEdit import ReadlineEdit @@ -241,13 +242,25 @@ class AnnounceInfo(urwid.WidgetWrap): type_button, ]) - pile_widgets = [] + dst_value = RNS.Identity.recall_stamp_value(source_hash) + link_cost = RNS.Identity.recall_link_cost(source_hash) + dst_val_str = f"{RNS.prettycost(dst_value)}" if dst_value else "None" + link_cost_str = f"{RNS.prettycost(link_cost)}" if link_cost else "None" + + pile_widgets = [] if is_pn: + pn_app_data = RNS.Identity.recall_app_data(source_hash) + prop_cost = pn_stamp_cost_from_app_data(pn_app_data) + + prop_cost_str = f"{RNS.prettycost(prop_cost)}" if prop_cost else "None" pile_widgets = [ urwid.Text("Time : "+ts_string, align=urwid.LEFT), urwid.Text("Addr : "+addr_str, align=urwid.LEFT), urwid.Text("Type : "+type_string, align=urwid.LEFT), + urwid.Text("D.Val : "+dst_val_str, align=urwid.LEFT), + urwid.Text("L.Cst : "+link_cost_str, align=urwid.LEFT), + urwid.Text("P.Cst : "+prop_cost_str, align=urwid.LEFT), urwid.Divider(g["divider1"]), button_columns ] @@ -258,6 +271,8 @@ class AnnounceInfo(urwid.WidgetWrap): urwid.Text("Addr : "+addr_str, align=urwid.LEFT), urwid.Text("Type : "+type_string, align=urwid.LEFT), urwid.Text("Name : "+display_str, align=urwid.LEFT), + urwid.Text("D.Val : "+dst_val_str, align=urwid.LEFT), + urwid.Text("L.Cst : "+link_cost_str, align=urwid.LEFT), urwid.Text(["Trust : ", (style, trust_str)], align=urwid.LEFT), urwid.Divider(g["divider1"]), urwid.Text(["Announce Data: \n", (data_style, data_str)], align=urwid.LEFT), @@ -626,6 +641,8 @@ class KnownNodeInfo(urwid.WidgetWrap): source_hash = node_hash node_ident = RNS.Identity.recall(node_hash) + dst_value = RNS.Identity.recall_stamp_value(node_hash) + link_cost = RNS.Identity.recall_link_cost(node_hash) time_format = self.app.time_format trust_level = self.app.directory.trust_level(source_hash) trust_str = "" @@ -641,7 +658,9 @@ class KnownNodeInfo(urwid.WidgetWrap): else: display_str = strip_modifiers(node_entry.display_name) - addr_str = "<"+RNS.hexrep(source_hash, delimit=False)+">" + addr_str = "<"+RNS.hexrep(source_hash, delimit=False)+">" + dst_val_str = f"{RNS.prettycost(dst_value)}" if dst_value else "None" + link_cost_str = f"{RNS.prettycost(link_cost)}" if link_cost else "None" if display_str == None: display_str = addr_str @@ -791,6 +810,8 @@ class KnownNodeInfo(urwid.WidgetWrap): urwid.Text("Type : "+type_string, align=urwid.LEFT), e_name, urwid.Text("Node Addr : "+addr_str, align=urwid.LEFT), + urwid.Text("Dst Value : "+dst_val_str, align=urwid.LEFT), + urwid.Text("Link Cost : "+link_cost_str, align=urwid.LEFT), e_sort, urwid.Divider(g["divider1"]), urwid.Text(lxmf_addr_str, align=urwid.CENTER), diff --git a/setup.py b/setup.py index 45721bd..d06c3e5 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,6 @@ setuptools.setup( entry_points= { 'console_scripts': ['nomadnet=nomadnet.nomadnet:main'] }, - install_requires=["rns>=1.5.5", "lxmf>=1.2.0", "urwid>=3.0.5", "qrcode"], + install_requires=["rns>=1.6.1", "lxmf>=1.3.1", "urwid>=3.0.5", "qrcode"], python_requires=">=3.8", )