Fixed resource transfers timing out over fast links

This commit is contained in:
Mark Qvist 2020-03-04 21:25:55 +01:00
parent 7867d7ded9
commit a24a9623d3
3 changed files with 6 additions and 3 deletions

View File

@ -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():

View File

@ -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:

View File

@ -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)