mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 21:50:18 +00:00
Implemented app_data recall from announces, better destination registration handling and link inactivity querying.
This commit is contained in:
parent
54206d9101
commit
51ab2d3488
@ -43,12 +43,24 @@ class Identity:
|
||||
identity_data = Identity.known_destinations[destination_hash]
|
||||
identity = Identity(public_only=True)
|
||||
identity.loadPublicKey(identity_data[2])
|
||||
identity.app_data = identity_data[3]
|
||||
RNS.log("Found "+RNS.prettyhexrep(destination_hash)+" in known destinations", RNS.LOG_EXTREME)
|
||||
return identity
|
||||
else:
|
||||
RNS.log("Could not find "+RNS.prettyhexrep(destination_hash)+" in known destinations", RNS.LOG_EXTREME)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def recall_app_data(destination_hash):
|
||||
RNS.log("Searching for app_data for "+RNS.prettyhexrep(destination_hash)+"...", RNS.LOG_EXTREME)
|
||||
if destination_hash in Identity.known_destinations:
|
||||
app_data = Identity.known_destinations[destination_hash][3]
|
||||
RNS.log("Found "+RNS.prettyhexrep(destination_hash)+" app_data in known destinations", RNS.LOG_EXTREME)
|
||||
return app_data
|
||||
else:
|
||||
RNS.log("Could not find "+RNS.prettyhexrep(destination_hash)+" app_data in known destinations", RNS.LOG_EXTREME)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def saveKnownDestinations():
|
||||
RNS.log("Saving known destinations to storage...", RNS.LOG_VERBOSE)
|
||||
@ -79,10 +91,6 @@ class Identity:
|
||||
|
||||
@staticmethod
|
||||
def truncatedHash(data):
|
||||
# TODO: Remove
|
||||
# digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
|
||||
# digest.update(data)
|
||||
|
||||
return Identity.fullHash(data)[:(Identity.TRUNCATED_HASHLENGTH//8)]
|
||||
|
||||
@staticmethod
|
||||
@ -103,11 +111,14 @@ class Identity:
|
||||
|
||||
signed_data = destination_hash+public_key+random_hash+app_data
|
||||
|
||||
if not len(packet.data) > Identity.DERKEYSIZE//8+20+Identity.KEYSIZE//8:
|
||||
app_data = None
|
||||
|
||||
announced_identity = Identity(public_only=True)
|
||||
announced_identity.loadPublicKey(public_key)
|
||||
|
||||
if announced_identity.pub != None and announced_identity.validate(signature, signed_data):
|
||||
RNS.Identity.remember(packet.getHash(), destination_hash, public_key)
|
||||
RNS.Identity.remember(packet.getHash(), destination_hash, public_key, app_data)
|
||||
RNS.log("Stored valid announce from "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
|
||||
del announced_identity
|
||||
return True
|
||||
|
@ -238,6 +238,9 @@ class Link:
|
||||
def getContext(self):
|
||||
return None
|
||||
|
||||
def inactive_for(self):
|
||||
return min(time.time() - self.last_inbound, time.time() - self.last_outbound)
|
||||
|
||||
def teardown(self):
|
||||
if self.status != Link.PENDING and self.status != Link.CLOSED:
|
||||
teardown_packet = RNS.Packet(self, self.link_id, context=RNS.Packet.LINKCLOSE)
|
||||
@ -331,6 +334,7 @@ class Link:
|
||||
if sleep_time == None or sleep_time < 0:
|
||||
RNS.log("Timing error! Tearing down link "+str(self)+" now.", RNS.LOG_ERROR)
|
||||
self.teardown()
|
||||
sleep_time = 0.1
|
||||
|
||||
sleep(sleep_time)
|
||||
|
||||
@ -454,7 +458,10 @@ class Link:
|
||||
return plaintext
|
||||
except Exception as e:
|
||||
RNS.log("Decryption failed on link "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
traceback.print_exc()
|
||||
RNS.log(traceback.format_exc(), RNS.LOG_ERROR)
|
||||
# TODO: Do we really need to do this? Or can we recover somehow?
|
||||
self.teardown()
|
||||
|
||||
|
||||
def sign(self, message):
|
||||
return self.prv.sign(message, ec.ECDSA(hashes.SHA256()))
|
||||
|
@ -111,8 +111,6 @@ class Resource:
|
||||
return resource
|
||||
except Exception as e:
|
||||
RNS.log("Could not decode resource advertisement, dropping resource", RNS.LOG_DEBUG)
|
||||
# TODO: Remove
|
||||
raise e
|
||||
return None
|
||||
|
||||
# Create a resource for transmission to a remote destination
|
||||
|
@ -446,6 +446,7 @@ class Transport:
|
||||
@staticmethod
|
||||
def inbound(raw, interface=None):
|
||||
while (Transport.jobs_running):
|
||||
# TODO: Decrease this for performance
|
||||
sleep(0.1)
|
||||
|
||||
Transport.jobs_locked = True
|
||||
@ -849,6 +850,9 @@ class Transport:
|
||||
def registerDestination(destination):
|
||||
destination.MTU = RNS.Reticulum.MTU
|
||||
if destination.direction == RNS.Destination.IN:
|
||||
for registered_destination in Transport.destinations:
|
||||
if destination.hash == registered_destination.hash:
|
||||
raise KeyError("Attempt to register an already registered destination.")
|
||||
Transport.destinations.append(destination)
|
||||
|
||||
@staticmethod
|
||||
|
Loading…
Reference in New Issue
Block a user