diff --git a/RNS/Link.py b/RNS/Link.py index 4b624623..407fe3cc 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -308,7 +308,7 @@ class Link: self.expected_hops = RNS.Transport.hops_to(self.destination.hash) self.establishment_timeout = RNS.Reticulum.get_instance().get_first_hop_timeout(self.destination.hash) self.establishment_timeout += Link.ESTABLISHMENT_TIMEOUT_PER_HOP * max(1, RNS.Transport.hops_to(self.destination.hash)) - self.stamp_cost = RNS.Identity.recall_link_cost(self.destination.hash) + self.stamp_cost = RNS.Identity.recall_link_cost(self.destination.hash) or RNS.Transport.LR_COST if RNS.Transport.ALWAYS_STAMP_LRS else None if self.stamp_cost and RNS.Transport.STAMP_LRS: self.__defer_keys = True else: @@ -350,7 +350,9 @@ class Link: def stamp_watchdog(): deadline = time.time() + RNS.Transport.LINK_STAMP_TIMEOUT while self.stamp_status == None and time.time() <= deadline: time.sleep(1) - if time.time() > deadline and self.stamp_job_id and not self.stamp_status: cancel_work(self.stamp_job_id) + if time.time() > deadline and self.stamp_job_id and not self.stamp_status: + cancel_work(self.stamp_job_id) + RNS.log(f"Stamp generation timed out for link request to {RNS.prettyhexrep(self.destination.hash)}", RNS.LOG_NOTICE) self.sig_prv = Ed25519PrivateKey.generate() self.sig_pub = self.sig_prv.public_key() diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 631e3c76..929d8dd6 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -487,9 +487,9 @@ class Reticulum: value = self.config["stamps"].as_bool(option) if value == True: RNS.Transport.STAMP_PRS = True - if option == "stamp_lrs": + if option == "always_stamp_lrs": value = self.config["stamps"].as_bool(option) - if value == True: RNS.Transport.STAMP_LRS = True + if value == True: RNS.Transport.ALWAYS_STAMP_LRS = True if option == "destination_cost": v = self.config["stamps"].as_int(option) diff --git a/RNS/Stamps.py b/RNS/Stamps.py index b873eb69..d5190e6b 100644 --- a/RNS/Stamps.py +++ b/RNS/Stamps.py @@ -259,9 +259,9 @@ def generate_stamp(message_id, stamp_cost, expand_rounds=WORKBLOCK_EXPAND_ROUNDS stamp_cost = cost_to_fp(stamp_cost) start_time = time.time() - stamp = None - rounds = 0 - value = 0 + stamp = None + value = None + rounds = 0 if RNS.vendor.platformutils.is_windows() or RNS.vendor.platformutils.is_darwin(): RNS.log(f"Multi-core stamp generation on this platform is not supported, work limited to single CPU core.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None @@ -276,7 +276,8 @@ def generate_stamp(message_id, stamp_cost, expand_rounds=WORKBLOCK_EXPAND_ROUNDS speed = rounds/duration if stamp != None: value = stamp_value(workblock, stamp) - RNS.log(f"Stamp with value {value} generated in {RNS.prettytime(duration)}, {rounds} rounds, {RNS.prettysize(speed, suffix='rps')}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None + if value != None: RNS.log(f"Stamp with value {value} generated in {RNS.prettytime(duration)}, {rounds} rounds, {RNS.prettysize(speed, suffix='rps')}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None + else: RNS.log(f"Stamp generation aborted or failed after {RNS.prettytime(duration)}, {rounds} rounds", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None return stamp, value @@ -322,8 +323,8 @@ def generate_stamped_key(material, stamp_cost): stamp_cost = cost_to_fp(stamp_cost) start_time = time.time() keypair = None + value = None rounds = 0 - value = 0 if RNS.vendor.platformutils.is_windows() or RNS.vendor.platformutils.is_darwin(): RNS.log(f"Multi-core stamp generation on this platform is not supported, work limited to single CPU core.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None @@ -338,7 +339,8 @@ def generate_stamped_key(material, stamp_cost): speed = rounds/duration if keypair != None: value = stamp_value(material, keypair[1]) - RNS.log(f"Stamped key with value {value} generated in {RNS.prettyshorttime(duration)}, {rounds} rounds, {RNS.prettysize(speed, suffix='rps')}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None + if value != None: RNS.log(f"Stamped key with value {value} generated in {RNS.prettyshorttime(duration)}, {rounds} rounds, {RNS.prettysize(speed, suffix='rps')}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None + else: RNS.log(f"Stamp generation aborted or failed after {RNS.prettytime(duration)}, {rounds} rounds", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None return keypair, value diff --git a/RNS/Transport.py b/RNS/Transport.py index 1e0cf2c0..0fe9e376 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -193,14 +193,15 @@ class Transport: LR_STAMPS_ENFORCED = False # Whether to enforce link request stamp requirements STAMP_DESTINATIONS = False # Whether to stamp destination announces emitted from this instance STAMP_PRS = False # Whether to stamp path requests emitted from this instance - STAMP_LRS = False # Whether to stamp link requests emitted from this instance - STAMP_COST_CAP = 100 # Global hard cap on stamp cost to ensure search-space viability at 14-byte stamp sizes - LINK_COST_CAP = 40 # Global hard cap on link request cost, separate from detached stamps - DESTINATION_COST = 23 # Default required announce cost if no specifics configured or determined - DESTINATION_VALUE = 25 # Default target stamp value for emitted announces - PR_COST = 19 # Default required path request cost if no specifics configured or determined - PR_VALUE = 19 # Default target stamp value for emitted path requests - LR_COST = 11 # Default required link request cost if not explicitly announced or configured + STAMP_LRS = True # Whether to stamp link requests emitted from this instance + ALWAYS_STAMP_LRS = False # Whether to stamp link requests even when no link cost is announced + STAMP_COST_CAP = 100.0 # Global hard cap on stamp cost to ensure search-space viability at 14-byte stamp sizes + LINK_COST_CAP = 40.0 # Global hard cap on link request cost, separate from detached stamps + DESTINATION_COST = 23.5 # Default required announce cost if no specifics configured or determined + DESTINATION_VALUE = 25.0 # Default target stamp value for emitted announces + PR_COST = 19.8 # Default required path request cost if no specifics configured or determined + PR_VALUE = 19.8 # Default target stamp value for emitted path requests + LR_COST = 19.2 # Default required link request cost if not explicitly announced or configured LINK_STAMP_TIMEOUT = 15 # Default link request stamp generation timeout PR_STAMP_TIMEOUT = 15 # Default path request stamp generation timeout HOP_LIMITER = PATHFINDER_M diff --git a/RNS/Utilities/rnsd.py b/RNS/Utilities/rnsd.py index a24ab076..e59f7ba7 100755 --- a/RNS/Utilities/rnsd.py +++ b/RNS/Utilities/rnsd.py @@ -314,14 +314,15 @@ instance_name = default # and enforcement. RNS 1.6.0 includes all the required stamp # generation and verification functionality, and actively # validates stamps, while leaving generation, emission and -# enforcement disabled by default. Version 1.6.1 will enable -# generation and emission by default, and version 1.6.2 will -# finally activate enforcement. Any option can be enabled -# early by configuration. +# enforcement disabled by default for destinations and PRs. +# Link requests will be stamped already from 1.6.0 if a cost +# has been announced by the destination. Version 1.6.1 will +# enable generation and emission by default, and version +# 1.6.2 will finally activate enforcement. Any of these +# options can be enabled early by configuration: # stamp_destinations = yes # stamp_prs = yes -# stamp_lrs = yes # enforce_stamps = yes