mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-10-01 03:15:44 -04:00
Improved request timeout calculation and handling.
This commit is contained in:
parent
425f0153d0
commit
ad9f548eeb
60
RNS/Link.py
60
RNS/Link.py
@ -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,42 +920,56 @@ class RequestReceipt():
|
||||
self.callbacks.failed(self)
|
||||
|
||||
def response_resource_progress(self, resource):
|
||||
self.progress = resource.get_progress()
|
||||
self.__resource_response_timeout = time.time()+self.timeout
|
||||
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)
|
||||
|
||||
if self.callbacks.progress != None:
|
||||
self.callbacks.progress(self)
|
||||
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):
|
||||
self.progress = 1.0
|
||||
self.response = response
|
||||
self.status = RequestReceipt.READY
|
||||
self.response_concluded_at = time.time()
|
||||
if not self.status == RequestReceipt.FAILED:
|
||||
self.progress = 1.0
|
||||
self.response = response
|
||||
self.status = RequestReceipt.READY
|
||||
self.response_concluded_at = time.time()
|
||||
|
||||
if len(response) <= Link.MDU:
|
||||
self.response_size = len(response)
|
||||
self.response_transfer_size = len(response)
|
||||
if len(response) <= Link.MDU:
|
||||
self.response_size = len(response)
|
||||
self.response_transfer_size = len(response)
|
||||
|
||||
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)
|
||||
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.callbacks.progress(self)
|
||||
if self.callbacks.progress != None:
|
||||
self.callbacks.progress(self)
|
||||
|
||||
if self.callbacks.response != None:
|
||||
self.callbacks.response(self)
|
||||
if self.callbacks.response != None:
|
||||
self.callbacks.response(self)
|
||||
|
||||
def get_request_id(self):
|
||||
"""
|
||||
|
@ -48,9 +48,10 @@ class Resource:
|
||||
|
||||
# TODO: Should be allocated more
|
||||
# intelligently
|
||||
MAX_RETRIES = 5
|
||||
SENDER_GRACE_TIME = 10
|
||||
RETRY_GRACE_TIME = 0.25
|
||||
PART_TIMEOUT_FACTOR = 3
|
||||
MAX_RETRIES = 5
|
||||
SENDER_GRACE_TIME = 10
|
||||
RETRY_GRACE_TIME = 0.25
|
||||
|
||||
HASHMAP_IS_NOT_EXHAUSTED = 0x00
|
||||
HASHMAP_IS_EXHAUSTED = 0xFF
|
||||
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user