mirror of
https://github.com/markqvist/LXMF.git
synced 2024-12-17 19:54:19 -05:00
Improved peer sync sequence
This commit is contained in:
parent
2a6c602e9b
commit
831e91a87a
22
LXMF/LXMF.py
22
LXMF/LXMF.py
@ -627,10 +627,12 @@ class LXMPeer:
|
|||||||
def sync(self, initiator=True):
|
def sync(self, initiator=True):
|
||||||
RNS.log("Attempting sync to peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
|
RNS.log("Attempting sync to peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
if RNS.Transport.has_path(self.destination_hash):
|
if not 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)
|
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:
|
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:
|
if self.identity == None:
|
||||||
RNS.log("Attempting to recall identity for peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
|
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)
|
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.link = RNS.Link(self.destination, established_callback = self.link_established, closed_callback = self.link_closed)
|
||||||
self.state = LXMPeer.LINK_ESTABLISHING
|
self.state = LXMPeer.LINK_ESTABLISHING
|
||||||
|
|
||||||
|
# TODO: Remove
|
||||||
|
RNS.log("Establishment timeout is "+str(self.link.establishment_timeout))
|
||||||
else:
|
else:
|
||||||
if self.state == LXMPeer.LINK_READY:
|
if self.state == LXMPeer.LINK_READY:
|
||||||
RNS.log("Sync link to peer "+RNS.prettyhexrep(self.destination_hash)+" established, preparing request...", RNS.LOG_DEBUG)
|
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)
|
message = self.unhandled_messages.pop(transient_id)
|
||||||
self.handled_messages[transient_id] = message
|
self.handled_messages[transient_id] = message
|
||||||
self.state = LXMPeer.IDLE
|
self.state = LXMPeer.IDLE
|
||||||
|
self.link.teardown()
|
||||||
|
RNS.log("Sync to peer "+RNS.prettyhexrep(self.destination_hash)+" completed", RNS.LOG_DEBUG)
|
||||||
else:
|
else:
|
||||||
RNS.log("Resource transfer for LXMF peer sync failed to "+str(self.destination), RNS.LOG_DEBUG)
|
RNS.log("Resource transfer for LXMF peer sync failed to "+str(self.destination), RNS.LOG_DEBUG)
|
||||||
if self.link != None:
|
if self.link != None:
|
||||||
@ -759,6 +766,9 @@ class LXMPeer:
|
|||||||
self.sync()
|
self.sync()
|
||||||
|
|
||||||
def link_closed(self, link):
|
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.link = None
|
||||||
self.state = LXMPeer.IDLE
|
self.state = LXMPeer.IDLE
|
||||||
|
|
||||||
@ -1169,7 +1179,10 @@ class LXMRouter:
|
|||||||
|
|
||||||
if os.path.isfile(self.storagepath+"/peers"):
|
if os.path.isfile(self.storagepath+"/peers"):
|
||||||
peers_file = open(self.storagepath+"/peers", "rb")
|
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:
|
for serialised_peer in serialised_peers:
|
||||||
peer = LXMPeer.from_bytes(serialised_peer, self)
|
peer = LXMPeer.from_bytes(serialised_peer, self)
|
||||||
@ -1191,6 +1204,7 @@ class LXMRouter:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Could not enable propagation node. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Could not enable propagation node. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
raise e
|
||||||
RNS.panic()
|
RNS.panic()
|
||||||
|
|
||||||
def disable_propagation(self):
|
def disable_propagation(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user