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. Default timeout for link establishment in seconds per hop to destination.
""" """
TRAFFIC_TIMEOUT_FACTOR = 20 TRAFFIC_TIMEOUT_FACTOR = 6
KEEPALIVE_TIMEOUT_FACTOR = 4 KEEPALIVE_TIMEOUT_FACTOR = 4
STALE_GRACE = 2 STALE_GRACE = 2
KEEPALIVE = 360 KEEPALIVE = 360
@ -920,42 +920,56 @@ class RequestReceipt():
self.callbacks.failed(self) self.callbacks.failed(self)
def response_resource_progress(self, resource): def response_resource_progress(self, resource):
self.progress = resource.get_progress() if not self.status == RequestReceipt.FAILED:
self.__resource_response_timeout = time.time()+self.timeout 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)
if self.callbacks.progress != None: self.progress = resource.get_progress()
self.callbacks.progress(self) 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): def __resource_response_timeout_job(self):
while self.status == RequestReceipt.DELIVERED: 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) self.request_timed_out(None)
time.sleep(0.1) time.sleep(0.1)
def response_received(self, response): def response_received(self, response):
self.progress = 1.0 if not self.status == RequestReceipt.FAILED:
self.response = response self.progress = 1.0
self.status = RequestReceipt.READY self.response = response
self.response_concluded_at = time.time() self.status = RequestReceipt.READY
self.response_concluded_at = time.time()
if len(response) <= Link.MDU: if len(response) <= Link.MDU:
self.response_size = len(response) self.response_size = len(response)
self.response_transfer_size = len(response) self.response_transfer_size = len(response)
if self.packet_receipt != None: if self.packet_receipt != None:
self.packet_receipt.status = RNS.PacketReceipt.DELIVERED self.packet_receipt.status = RNS.PacketReceipt.DELIVERED
self.packet_receipt.proved = True self.packet_receipt.proved = True
self.packet_receipt.concluded_at = time.time() self.packet_receipt.concluded_at = time.time()
if self.packet_receipt.callbacks.delivery != None: 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: if self.callbacks.progress != None:
self.callbacks.progress(self) self.callbacks.progress(self)
if self.callbacks.response != None: if self.callbacks.response != None:
self.callbacks.response(self) self.callbacks.response(self)
def get_request_id(self): def get_request_id(self):
""" """

View File

@ -48,9 +48,10 @@ class Resource:
# TODO: Should be allocated more # TODO: Should be allocated more
# intelligently # intelligently
MAX_RETRIES = 5 PART_TIMEOUT_FACTOR = 3
SENDER_GRACE_TIME = 10 MAX_RETRIES = 5
RETRY_GRACE_TIME = 0.25 SENDER_GRACE_TIME = 10
RETRY_GRACE_TIME = 0.25
HASHMAP_IS_NOT_EXHAUSTED = 0x00 HASHMAP_IS_NOT_EXHAUSTED = 0x00
HASHMAP_IS_EXHAUSTED = 0xFF HASHMAP_IS_EXHAUSTED = 0xFF
@ -179,6 +180,7 @@ class Resource:
self.max_retries = Resource.MAX_RETRIES self.max_retries = Resource.MAX_RETRIES
self.retries_left = self.max_retries self.retries_left = self.max_retries
self.timeout_factor = self.link.traffic_timeout_factor 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.sender_grace_time = Resource.SENDER_GRACE_TIME
self.hmu_retry_ok = False self.hmu_retry_ok = False
self.watchdog_lock = False self.watchdog_lock = False
@ -389,7 +391,7 @@ class Resource:
elif self.status == Resource.TRANSFERRING: elif self.status == Resource.TRANSFERRING:
if not self.initiator: if not self.initiator:
rtt = self.link.rtt if self.rtt == None else self.rtt 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 sleep_time < 0:
if self.retries_left > 0: if self.retries_left > 0: