mirror of
https://github.com/markqvist/LXMF
synced 2026-11-27 23:00:33 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd3ace0885 | ||
|
|
ed4effdab7 | ||
|
|
2d1828513f | ||
|
|
505176b6ee | ||
|
|
853e70dcbe | ||
|
|
38cc471eaf | ||
|
|
704930f91a | ||
|
|
137db1e6a3 | ||
|
|
5e8b2d87af | ||
|
|
38b6f7651c | ||
|
|
6aa793252f | ||
|
|
1ca2493c36 | ||
|
|
38bbf19421 | ||
|
|
776e72d0ba | ||
|
|
29f6089967 | ||
|
|
512a34e2c3 | ||
|
|
934a208965 |
No files matched your search
+79
-28
@@ -228,7 +228,7 @@ class LXMessage:
|
|||||||
# If no desired delivery method has been defined,
|
# If no desired delivery method has been defined,
|
||||||
# one will be chosen according to these rules:
|
# one will be chosen according to these rules:
|
||||||
if self.desired_method == None:
|
if self.desired_method == None:
|
||||||
self.desired_method == LXMessage.DIRECT
|
self.desired_method = LXMessage.DIRECT
|
||||||
# TODO: Expand rules to something more intelligent
|
# TODO: Expand rules to something more intelligent
|
||||||
|
|
||||||
if self.desired_method == LXMessage.OPPORTUNISTIC:
|
if self.desired_method == LXMessage.OPPORTUNISTIC:
|
||||||
@@ -308,7 +308,7 @@ class LXMessage:
|
|||||||
if self.__destination.type == RNS.Destination.SINGLE:
|
if self.__destination.type == RNS.Destination.SINGLE:
|
||||||
self.transport_encrypted = True
|
self.transport_encrypted = True
|
||||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC
|
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC
|
||||||
elif destination_type == RNS.Destination.GROUP:
|
elif self.__destination.type == RNS.Destination.GROUP:
|
||||||
self.transport_encrypted = True
|
self.transport_encrypted = True
|
||||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_AES
|
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_AES
|
||||||
else:
|
else:
|
||||||
@@ -405,26 +405,28 @@ class LXMessage:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def packed_container(self):
|
||||||
|
if not self.packed:
|
||||||
|
self.pack()
|
||||||
|
|
||||||
|
container = {
|
||||||
|
"state": self.state,
|
||||||
|
"lxmf_bytes": self.packed,
|
||||||
|
"transport_encrypted": self.transport_encrypted,
|
||||||
|
"transport_encryption": self.transport_encryption,
|
||||||
|
"method": self.method
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgpack.packb(container)
|
||||||
|
|
||||||
|
|
||||||
def write_to_directory(self, directory_path):
|
def write_to_directory(self, directory_path):
|
||||||
file_name = RNS.hexrep(self.hash, delimit=False)
|
file_name = RNS.hexrep(self.hash, delimit=False)
|
||||||
file_path = directory_path+"/"+file_name
|
file_path = directory_path+"/"+file_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self.packed:
|
|
||||||
self.pack()
|
|
||||||
|
|
||||||
container = {
|
|
||||||
"state": self.state,
|
|
||||||
"lxmf_bytes": self.packed,
|
|
||||||
"transport_encrypted": self.transport_encrypted,
|
|
||||||
"transport_encryption": self.transport_encryption,
|
|
||||||
"method": self.method
|
|
||||||
}
|
|
||||||
|
|
||||||
packed_container = msgpack.packb(container)
|
|
||||||
|
|
||||||
file = open(file_path, "wb")
|
file = open(file_path, "wb")
|
||||||
file.write(packed_container)
|
file.write(self.packed_container())
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
return file_path
|
return file_path
|
||||||
@@ -569,6 +571,10 @@ class LXMPeer:
|
|||||||
|
|
||||||
ERROR_NO_IDENTITY = 0xf0
|
ERROR_NO_IDENTITY = 0xf0
|
||||||
|
|
||||||
|
# Maximum amount of time a peer can
|
||||||
|
# be unreachable before it is removed
|
||||||
|
MAX_UNREACHABLE = 4*24*60*60
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_bytes(peer_bytes, router):
|
def from_bytes(peer_bytes, router):
|
||||||
dictionary = msgpack.unpackb(peer_bytes)
|
dictionary = msgpack.unpackb(peer_bytes)
|
||||||
@@ -610,7 +616,7 @@ class LXMPeer:
|
|||||||
|
|
||||||
def __init__(self, router, destination_hash):
|
def __init__(self, router, destination_hash):
|
||||||
self.alive = False
|
self.alive = False
|
||||||
self.last_heard = None
|
self.last_heard = 0
|
||||||
self.peering_timebase = 0
|
self.peering_timebase = 0
|
||||||
|
|
||||||
self.link = None
|
self.link = None
|
||||||
@@ -648,6 +654,9 @@ class LXMPeer:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if self.state == LXMPeer.LINK_READY:
|
if self.state == LXMPeer.LINK_READY:
|
||||||
|
self.alive = True
|
||||||
|
self.last_heard = time.time()
|
||||||
|
|
||||||
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)
|
||||||
unhandled_ids = []
|
unhandled_ids = []
|
||||||
purged_ids = []
|
purged_ids = []
|
||||||
@@ -756,6 +765,8 @@ class LXMPeer:
|
|||||||
self.state = LXMPeer.IDLE
|
self.state = LXMPeer.IDLE
|
||||||
self.link.teardown()
|
self.link.teardown()
|
||||||
RNS.log("Sync to peer "+RNS.prettyhexrep(self.destination_hash)+" completed", RNS.LOG_DEBUG)
|
RNS.log("Sync to peer "+RNS.prettyhexrep(self.destination_hash)+" completed", RNS.LOG_DEBUG)
|
||||||
|
self.alive = True
|
||||||
|
self.last_heard = time.time()
|
||||||
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:
|
||||||
@@ -780,15 +791,23 @@ class LXMPeer:
|
|||||||
RNS.log("The message "+RNS.prettyhexrep(transient_id)+" was added to distribution queue for "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_EXTREME)
|
RNS.log("The message "+RNS.prettyhexrep(transient_id)+" was added to distribution queue for "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_EXTREME)
|
||||||
self.unhandled_messages[transient_id] = self.router.propagation_entries[transient_id]
|
self.unhandled_messages[transient_id] = self.router.propagation_entries[transient_id]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
if self.destination_hash:
|
||||||
|
return RNS.prettyhexrep(self.destination_hash)
|
||||||
|
else:
|
||||||
|
return "<Unknown>"
|
||||||
|
|
||||||
class LXMRouter:
|
class LXMRouter:
|
||||||
MAX_DELIVERY_ATTEMPTS = 3
|
MAX_DELIVERY_ATTEMPTS = 4
|
||||||
PROCESSING_INTERVAL = 5
|
PROCESSING_INTERVAL = 5
|
||||||
DELIVERY_RETRY_WAIT = 15
|
DELIVERY_RETRY_WAIT = 12
|
||||||
PATH_REQUEST_WAIT = 5
|
PATH_REQUEST_WAIT = 5
|
||||||
LINK_MAX_INACTIVITY = 10*60
|
LINK_MAX_INACTIVITY = 10*60
|
||||||
|
|
||||||
MESSAGE_EXPIRY = 30*24*60*60
|
MESSAGE_EXPIRY = 30*24*60*60
|
||||||
|
|
||||||
|
NODE_ANNOUNCE_DELAY = 20
|
||||||
|
|
||||||
AUTOPEER = True
|
AUTOPEER = True
|
||||||
AUTOPEER_MAXDEPTH = 4
|
AUTOPEER_MAXDEPTH = 4
|
||||||
|
|
||||||
@@ -799,8 +818,9 @@ class LXMRouter:
|
|||||||
PR_LINK_ESTABLISHING = 0x02
|
PR_LINK_ESTABLISHING = 0x02
|
||||||
PR_LINK_ESTABLISHED = 0x03
|
PR_LINK_ESTABLISHED = 0x03
|
||||||
PR_REQUEST_SENT = 0x04
|
PR_REQUEST_SENT = 0x04
|
||||||
PR_RESPONSE_RECEIVED = 0x05
|
PR_RECEIVING = 0x05
|
||||||
PR_COMPLETE = 0x06
|
PR_RESPONSE_RECEIVED = 0x06
|
||||||
|
PR_COMPLETE = 0x07
|
||||||
|
|
||||||
PR_ALL_MESSAGES = 0x00
|
PR_ALL_MESSAGES = 0x00
|
||||||
|
|
||||||
@@ -958,6 +978,7 @@ class LXMRouter:
|
|||||||
response_callback=self.message_list_response,
|
response_callback=self.message_list_response,
|
||||||
failed_callback=self.message_get_failed
|
failed_callback=self.message_get_failed
|
||||||
)
|
)
|
||||||
|
self.propagation_transfer_state = LXMRouter.PR_REQUEST_SENT
|
||||||
else:
|
else:
|
||||||
if self.outbound_propagation_link == None:
|
if self.outbound_propagation_link == None:
|
||||||
if RNS.Transport.has_path(self.outbound_propagation_node):
|
if RNS.Transport.has_path(self.outbound_propagation_node):
|
||||||
@@ -1042,6 +1063,7 @@ class LXMRouter:
|
|||||||
self.propagation_transfer_last_result = 0
|
self.propagation_transfer_last_result = 0
|
||||||
|
|
||||||
def message_get_progress(self, request_receipt):
|
def message_get_progress(self, request_receipt):
|
||||||
|
self.propagation_transfer_state = LXMRouter.PR_RECEIVING
|
||||||
self.propagation_transfer_progress = request_receipt.get_progress()
|
self.propagation_transfer_progress = request_receipt.get_progress()
|
||||||
|
|
||||||
def message_get_response(self, request_receipt):
|
def message_get_response(self, request_receipt):
|
||||||
@@ -1210,8 +1232,14 @@ class LXMRouter:
|
|||||||
self.announce_propagation_node()
|
self.announce_propagation_node()
|
||||||
|
|
||||||
def announce_propagation_node(self):
|
def announce_propagation_node(self):
|
||||||
data = msgpack.packb([self.propagation_node, int(time.time())])
|
def delayed_announce():
|
||||||
self.propagation_destination.announce(app_data=data)
|
time.sleep(LXMRouter.NODE_ANNOUNCE_DELAY)
|
||||||
|
data = msgpack.packb([self.propagation_node, int(time.time())])
|
||||||
|
self.propagation_destination.announce(app_data=data)
|
||||||
|
|
||||||
|
da_thread = threading.Thread(target=delayed_announce)
|
||||||
|
da_thread.setDaemon(True)
|
||||||
|
da_thread.start()
|
||||||
|
|
||||||
def offer_request(self, path, data, request_id, remote_identity, requested_at):
|
def offer_request(self, path, data, request_id, remote_identity, requested_at):
|
||||||
if remote_identity == None:
|
if remote_identity == None:
|
||||||
@@ -1429,7 +1457,7 @@ class LXMRouter:
|
|||||||
|
|
||||||
if timestamp >= peer.peering_timebase:
|
if timestamp >= peer.peering_timebase:
|
||||||
self.peers.pop(destination_hash)
|
self.peers.pop(destination_hash)
|
||||||
RNS.log(str(self.propagation_destination)+" broke peering with "+str(peer.destination))
|
RNS.log("Broke peering with "+str(peer.destination))
|
||||||
|
|
||||||
|
|
||||||
def jobloop(self):
|
def jobloop(self):
|
||||||
@@ -1528,11 +1556,15 @@ class LXMRouter:
|
|||||||
|
|
||||||
|
|
||||||
def sync_peers(self):
|
def sync_peers(self):
|
||||||
|
culled_peers = []
|
||||||
waiting_peers = []
|
waiting_peers = []
|
||||||
for peer_id in self.peers:
|
for peer_id in self.peers:
|
||||||
peer = self.peers[peer_id]
|
peer = self.peers[peer_id]
|
||||||
if peer.state == LXMPeer.IDLE and len(peer.unhandled_messages) > 0:
|
if time.time() > peer.last_heard + LXMPeer.MAX_UNREACHABLE:
|
||||||
waiting_peers.append(peer)
|
culled_peers.append(peer_id)
|
||||||
|
else:
|
||||||
|
if peer.state == LXMPeer.IDLE and len(peer.unhandled_messages) > 0:
|
||||||
|
waiting_peers.append(peer)
|
||||||
|
|
||||||
if len(waiting_peers) > 0:
|
if len(waiting_peers) > 0:
|
||||||
RNS.log("Randomly selecting peer to sync from "+str(len(waiting_peers))+" waiting peers.", RNS.LOG_DEBUG)
|
RNS.log("Randomly selecting peer to sync from "+str(len(waiting_peers))+" waiting peers.", RNS.LOG_DEBUG)
|
||||||
@@ -1541,6 +1573,14 @@ class LXMRouter:
|
|||||||
RNS.log("Selected waiting peer "+str(selected_index)+": "+RNS.prettyhexrep(selected_peer.destination.hash), RNS.LOG_DEBUG)
|
RNS.log("Selected waiting peer "+str(selected_index)+": "+RNS.prettyhexrep(selected_peer.destination.hash), RNS.LOG_DEBUG)
|
||||||
selected_peer.sync()
|
selected_peer.sync()
|
||||||
|
|
||||||
|
for peer_id in culled_peers:
|
||||||
|
RNS.log("Removing peer "+RNS.prettyhexrep(peer_id)+" due to excessive unreachability", RNS.LOG_WARNING)
|
||||||
|
try:
|
||||||
|
if peer_id in self.peers:
|
||||||
|
self.peers.pop(peer_id)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while removing peer "+RNS.prettyhexrep(peer_id)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
|
||||||
def fail_message(self, lxmessage):
|
def fail_message(self, lxmessage):
|
||||||
RNS.log(str(lxmessage)+" failed to send", RNS.LOG_DEBUG)
|
RNS.log(str(lxmessage)+" failed to send", RNS.LOG_DEBUG)
|
||||||
@@ -1598,7 +1638,18 @@ class LXMRouter:
|
|||||||
else:
|
else:
|
||||||
RNS.log("Waiting for proof for "+str(lxmessage)+" sent as link packet", RNS.LOG_DEBUG)
|
RNS.log("Waiting for proof for "+str(lxmessage)+" sent as link packet", RNS.LOG_DEBUG)
|
||||||
elif direct_link.status == RNS.Link.CLOSED:
|
elif direct_link.status == RNS.Link.CLOSED:
|
||||||
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was closed", RNS.LOG_DEBUG)
|
if direct_link.activated_at != None:
|
||||||
|
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was closed", RNS.LOG_DEBUG)
|
||||||
|
else:
|
||||||
|
if not hasattr(lxmessage, "path_request_retried"):
|
||||||
|
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was never activated, retrying path request...", RNS.LOG_DEBUG)
|
||||||
|
RNS.Transport.request_path(lxmessage.get_destination().hash)
|
||||||
|
lxmessage.path_request_retried = True
|
||||||
|
else:
|
||||||
|
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was never activated", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
|
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT
|
||||||
|
|
||||||
lxmessage.set_delivery_destination(None)
|
lxmessage.set_delivery_destination(None)
|
||||||
self.direct_links.pop(delivery_destination_hash)
|
self.direct_links.pop(delivery_destination_hash)
|
||||||
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT
|
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT
|
||||||
@@ -1681,4 +1732,4 @@ class LXMRouter:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
RNS.log("Max delivery attempts reached for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
RNS.log("Max delivery attempts reached for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
||||||
self.fail_message(lxmessage)
|
self.fail_message(lxmessage)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
all: release
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo Cleaning...
|
||||||
|
-rm -r ./build
|
||||||
|
-rm -r ./dist
|
||||||
|
|
||||||
|
remove_symlinks:
|
||||||
|
@echo Removing symlinks for build...
|
||||||
|
-rm ./RNS
|
||||||
|
|
||||||
|
create_symlinks:
|
||||||
|
@echo Creating symlinks...
|
||||||
|
-ln -s ../Reticulum/RNS ./
|
||||||
|
|
||||||
|
build_wheel:
|
||||||
|
python3 setup.py sdist bdist_wheel
|
||||||
|
|
||||||
|
release: remove_symlinks build_wheel create_symlinks
|
||||||
|
|
||||||
|
upload:
|
||||||
|
@echo Uploading to PyPi...
|
||||||
|
twine upload dist/*
|
||||||
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="lxmf",
|
name="lxmf",
|
||||||
version="0.1.0",
|
version="0.1.5",
|
||||||
author="Mark Qvist",
|
author="Mark Qvist",
|
||||||
author_email="mark@unsigned.io",
|
author_email="mark@unsigned.io",
|
||||||
description="Lightweight Extensible Message Format for Reticulum",
|
description="Lightweight Extensible Message Format for Reticulum",
|
||||||
@@ -18,6 +18,6 @@ setuptools.setup(
|
|||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
],
|
],
|
||||||
install_requires=['rns>=0.2.4'],
|
install_requires=['rns>=0.3.4'],
|
||||||
python_requires='>=3.6',
|
python_requires='>=3.6',
|
||||||
)
|
)
|
||||||
Reference in new issue
Block a user