Improved peer sync sequence

This commit is contained in:
Mark Qvist 2021-10-08 17:05:11 +02:00
parent 2a6c602e9b
commit 831e91a87a

View File

@ -627,10 +627,12 @@ class LXMPeer:
def sync(self, initiator=True):
RNS.log("Attempting sync to peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
if RNS.Transport.has_path(self.destination_hash):
RNS.log("Path to peer "+RNS.prettyhexrep(self.destination_hash)+" exist over "+str(RNS.Transport.hops_to(self.destination_hash))+" via "+str(RNS.Transport.next_hop_interface(self.destination_hash)), RNS.LOG_DEBUG)
if not RNS.Transport.has_path(self.destination_hash):
RNS.log("No path to peer "+RNS.prettyhexrep(self.destination_hash)+" exists, requesting...", RNS.LOG_DEBUG)
RNS.Transport.request_path(self.destination_hash)
RNS.log("Path requested, retrying sync later", RNS.LOG_DEBUG)
else:
RNS.log("Attempting sync to peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
RNS.log("Path to peer "+RNS.prettyhexrep(self.destination_hash)+" exist over "+str(RNS.Transport.hops_to(self.destination_hash))+" hops via "+str(RNS.Transport.next_hop_interface(self.destination_hash)), RNS.LOG_DEBUG)
if self.identity == None:
RNS.log("Attempting to recall identity for peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
@ -643,6 +645,9 @@ class LXMPeer:
RNS.log("Establishing link for sync to peer "+RNS.prettyhexrep(self.destination_hash)+"...", RNS.LOG_DEBUG)
self.link = RNS.Link(self.destination, established_callback = self.link_established, closed_callback = self.link_closed)
self.state = LXMPeer.LINK_ESTABLISHING
# TODO: Remove
RNS.log("Establishment timeout is "+str(self.link.establishment_timeout))
else:
if self.state == LXMPeer.LINK_READY:
RNS.log("Sync link to peer "+RNS.prettyhexrep(self.destination_hash)+" established, preparing request...", RNS.LOG_DEBUG)
@ -744,6 +749,8 @@ class LXMPeer:
message = self.unhandled_messages.pop(transient_id)
self.handled_messages[transient_id] = message
self.state = LXMPeer.IDLE
self.link.teardown()
RNS.log("Sync to peer "+RNS.prettyhexrep(self.destination_hash)+" completed", RNS.LOG_DEBUG)
else:
RNS.log("Resource transfer for LXMF peer sync failed to "+str(self.destination), RNS.LOG_DEBUG)
if self.link != None:
@ -759,6 +766,9 @@ class LXMPeer:
self.sync()
def link_closed(self, link):
# TODO: Remove
RNS.log("The sync link to peer "+RNS.prettyhexrep(self.destination_hash)+" was closed: "+str(link.teardown_reason), RNS.LOG_DEBUG)
self.link = None
self.state = LXMPeer.IDLE
@ -1169,7 +1179,10 @@ class LXMRouter:
if os.path.isfile(self.storagepath+"/peers"):
peers_file = open(self.storagepath+"/peers", "rb")
serialised_peers = msgpack.unpackb(peers_file.read())
peers_data = peers_file.read()
if len(peers_data) > 0:
serialised_peers = msgpack.unpackb(peers_data)
for serialised_peer in serialised_peers:
peer = LXMPeer.from_bytes(serialised_peer, self)
@ -1191,6 +1204,7 @@ class LXMRouter:
except Exception as e:
RNS.log("Could not enable propagation node. The contained exception was: "+str(e), RNS.LOG_ERROR)
raise e
RNS.panic()
def disable_propagation(self):