mirror of
https://github.com/markqvist/LXMF.git
synced 2025-03-31 19:18:22 -04:00
Added announce handler for faster initial link establishment.
This commit is contained in:
parent
1e8ef437b9
commit
1ac9c3ad72
22
LXMF/LXMF.py
22
LXMF/LXMF.py
@ -463,10 +463,28 @@ class LXMessage:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class LXMFDeliveryAnnounceHandler:
|
||||||
|
def __init__(self, lxmrouter):
|
||||||
|
self.aspect_filter = APP_NAME+".delivery"
|
||||||
|
self.lxmrouter = lxmrouter
|
||||||
|
|
||||||
|
def received_announce(self, destination_hash, announced_identity, app_data):
|
||||||
|
for lxmessage in self.lxmrouter.pending_outbound:
|
||||||
|
if destination_hash == lxmessage.destination_hash:
|
||||||
|
if lxmessage.method == LXMessage.DIRECT:
|
||||||
|
lxmessage.next_delivery_attempt = time.time()
|
||||||
|
|
||||||
|
while self.lxmrouter.processing_outbound:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
self.lxmrouter.process_outbound()
|
||||||
|
|
||||||
|
|
||||||
class LXMRouter:
|
class LXMRouter:
|
||||||
MAX_DELIVERY_ATTEMPTS = 3
|
MAX_DELIVERY_ATTEMPTS = 3
|
||||||
PROCESSING_INTERVAL = 5
|
PROCESSING_INTERVAL = 5
|
||||||
DELIVERY_RETRY_WAIT = 15
|
DELIVERY_RETRY_WAIT = 15
|
||||||
|
PATH_REQUEST_WAIT = 5
|
||||||
LINK_MAX_INACTIVITY = 10*60
|
LINK_MAX_INACTIVITY = 10*60
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -483,6 +501,8 @@ class LXMRouter:
|
|||||||
self.lxmf_query_destination = RNS.Destination(None, RNS.Destination.IN, RNS.Destination.PLAIN, APP_NAME, "query")
|
self.lxmf_query_destination = RNS.Destination(None, RNS.Destination.IN, RNS.Destination.PLAIN, APP_NAME, "query")
|
||||||
self.propagation_destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, "propagation")
|
self.propagation_destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, "propagation")
|
||||||
|
|
||||||
|
RNS.Transport.register_announce_handler(LXMFDeliveryAnnounceHandler(self))
|
||||||
|
|
||||||
self.__delivery_callback = None
|
self.__delivery_callback = None
|
||||||
|
|
||||||
job_thread = threading.Thread(target=self.jobloop)
|
job_thread = threading.Thread(target=self.jobloop)
|
||||||
@ -680,6 +700,7 @@ class LXMRouter:
|
|||||||
if not hasattr(lxmessage, "next_delivery_attempt") or time.time() > lxmessage.next_delivery_attempt:
|
if not hasattr(lxmessage, "next_delivery_attempt") or time.time() > lxmessage.next_delivery_attempt:
|
||||||
lxmessage.delivery_attempts += 1
|
lxmessage.delivery_attempts += 1
|
||||||
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT
|
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT
|
||||||
|
|
||||||
if lxmessage.delivery_attempts < LXMRouter.MAX_DELIVERY_ATTEMPTS:
|
if lxmessage.delivery_attempts < LXMRouter.MAX_DELIVERY_ATTEMPTS:
|
||||||
if RNS.Transport.has_path(lxmessage.get_destination().hash):
|
if RNS.Transport.has_path(lxmessage.get_destination().hash):
|
||||||
RNS.log("Establishing link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
RNS.log("Establishing link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
||||||
@ -689,6 +710,7 @@ class LXMRouter:
|
|||||||
else:
|
else:
|
||||||
RNS.log("No path known for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+". Requesting path...", RNS.LOG_DEBUG)
|
RNS.log("No path known for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+". Requesting path...", RNS.LOG_DEBUG)
|
||||||
RNS.Transport.request_path(lxmessage.get_destination().hash)
|
RNS.Transport.request_path(lxmessage.get_destination().hash)
|
||||||
|
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT
|
||||||
else:
|
else:
|
||||||
RNS.log("Max delivery attempts reached for direct "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
RNS.log("Max delivery attempts reached for direct "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
||||||
self.fail_message(lxmessage)
|
self.fail_message(lxmessage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user