From a24a9623d335c80026802828a107047891574c02 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 4 Mar 2020 21:25:55 +0100 Subject: [PATCH] Fixed resource transfers timing out over fast links --- RNS/Identity.py | 4 +++- RNS/Resource.py | 3 ++- RNS/Transport.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/RNS/Identity.py b/RNS/Identity.py index 19e55da..0458d95 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -23,6 +23,8 @@ class Identity: HASHLENGTH = 256 # In bits SIGLENGTH = KEYSIZE + TRUNCATED_HASHLENGTH = 80 # In bits + # Storage known_destinations = {} @@ -78,7 +80,7 @@ class Identity: digest = hashes.Hash(hashes.SHA256(), backend=default_backend()) digest.update(data) - return digest.finalize()[:10] + return digest.finalize()[:(Identity.TRUNCATED_HASHLENGTH/8)] @staticmethod def getRandomHash(): diff --git a/RNS/Resource.py b/RNS/Resource.py index be02343..b16b67c 100644 --- a/RNS/Resource.py +++ b/RNS/Resource.py @@ -18,6 +18,7 @@ class Resource: # intelligently MAX_RETRIES = 5 SENDER_GRACE_TIME = 10 + RETRY_GRACE_TIME = 0.25 HASHMAP_IS_NOT_EXHAUSTED = 0x00 HASHMAP_IS_EXHAUSTED = 0xFF @@ -232,7 +233,7 @@ class Resource: elif self.status == Resource.TRANSFERRING: if not self.initiator: rtt = self.link.rtt if self.rtt == None else self.rtt - sleep_time = self.last_activity + (rtt*self.timeout_factor) - time.time() + sleep_time = self.last_activity + (rtt*self.timeout_factor) + Resource.RETRY_GRACE_TIME - time.time() if sleep_time < 0: if self.retries_left > 0: diff --git a/RNS/Transport.py b/RNS/Transport.py index b18def5..d306e8e 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -236,6 +236,7 @@ class Transport: if packet.packet_type == RNS.Packet.ANNOUNCE: return True + RNS.log("Filtered packet with hash "+RNS.prettyhexrep(packet.packet_hash), RNS.LOG_DEBUG) return False @staticmethod @@ -261,7 +262,6 @@ class Transport: RNS.log("Received packet in transport for "+RNS.prettyhexrep(packet.destination_hash)+" with matching transport ID, transporting it...", RNS.LOG_DEBUG) if packet.destination_hash in Transport.destination_table: next_hop = Transport.destination_table[packet.destination_hash][1] - RNS.log("Packet hops: "+str(packet.hops), RNS.LOG_DEBUG) RNS.log("Next hop to destination is "+RNS.prettyhexrep(next_hop)+", transporting it.", RNS.LOG_DEBUG) new_raw = packet.raw[0:1] new_raw += struct.pack("!B", packet.hops)