Improved request timeout calculation and handling.

This commit is contained in:
Mark Qvist 2021-09-03 14:22:53 +02:00
parent 425f0153d0
commit ad9f548eeb
2 changed files with 43 additions and 27 deletions

View File

@ -52,7 +52,7 @@ class Link:
Default timeout for link establishment in seconds per hop to destination.
"""
TRAFFIC_TIMEOUT_FACTOR = 20
TRAFFIC_TIMEOUT_FACTOR = 6
KEEPALIVE_TIMEOUT_FACTOR = 4
STALE_GRACE = 2
KEEPALIVE = 360
@ -920,21 +920,35 @@ class RequestReceipt():
self.callbacks.failed(self)
def response_resource_progress(self, resource):
if not self.status == RequestReceipt.FAILED:
self.status = RequestReceipt.DELIVERED
if self.packet_receipt != None:
self.packet_receipt.status = RNS.PacketReceipt.DELIVERED
self.packet_receipt.proved = True
self.packet_receipt.concluded_at = time.time()
if self.packet_receipt.callbacks.delivery != None:
self.packet_receipt.callbacks.delivery(self.packet_receipt)
self.progress = resource.get_progress()
now = time.time()
self.__resource_response_timeout = time.time()+self.timeout
if self.callbacks.progress != None:
self.callbacks.progress(self)
else:
resource.cancel()
def __resource_response_timeout_job(self):
while self.status == RequestReceipt.DELIVERED:
if time.time() > self.__resource_response_timeout:
now = time.time()
if now > self.__resource_response_timeout:
self.request_timed_out(None)
time.sleep(0.1)
def response_received(self, response):
if not self.status == RequestReceipt.FAILED:
self.progress = 1.0
self.response = response
self.status = RequestReceipt.READY
@ -949,7 +963,7 @@ class RequestReceipt():
self.packet_receipt.proved = True
self.packet_receipt.concluded_at = time.time()
if self.packet_receipt.callbacks.delivery != None:
self.packet_receipt.callbacks.delivery(self)
self.packet_receipt.callbacks.delivery(self.packet_receipt)
if self.callbacks.progress != None:
self.callbacks.progress(self)

View File

@ -48,6 +48,7 @@ class Resource:
# TODO: Should be allocated more
# intelligently
PART_TIMEOUT_FACTOR = 3
MAX_RETRIES = 5
SENDER_GRACE_TIME = 10
RETRY_GRACE_TIME = 0.25
@ -179,6 +180,7 @@ class Resource:
self.max_retries = Resource.MAX_RETRIES
self.retries_left = self.max_retries
self.timeout_factor = self.link.traffic_timeout_factor
self.part_timeout_factor = Resource.PART_TIMEOUT_FACTOR
self.sender_grace_time = Resource.SENDER_GRACE_TIME
self.hmu_retry_ok = False
self.watchdog_lock = False
@ -389,7 +391,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) + Resource.RETRY_GRACE_TIME - time.time()
sleep_time = self.last_activity + (rtt*self.part_timeout_factor) + Resource.RETRY_GRACE_TIME - time.time()
if sleep_time < 0:
if self.retries_left > 0: