Added ability to retain identity data based on identity hash

This commit is contained in:
Mark Qvist
2026-05-07 18:40:28 +02:00
parent 304acdd0c1
commit 7ceb2d2078
2 changed files with 29 additions and 0 deletions
+12
View File
@@ -280,6 +280,18 @@ class Identity:
return True
return False
@staticmethod
def _retain_identity(identity_hash):
try:
retained = False
for destination_hash in Identity.known_destinations:
if identity_hash == Identity.truncated_hash(Identity.known_destinations[destination_hash][2]):
if Identity._retain_destination_data(destination_hash): retained = True
return retained
except Exception as e: RNS.log(f"Error while retaining identity {RNS.prettyhexrep(identity_hash)}: {e}", RNS.LOG_ERROR)
@staticmethod
def clean_known_destinations():
+17
View File
@@ -1119,6 +1119,11 @@ class Reticulum:
elif operation == "retain": rpc_connection.send(self._retain_destination_data(destination_hash))
elif operation == "unretain": rpc_connection.send(self._unretain_destination_data(destination_hash))
if "identity_data" in call:
operation = call["identity_data"]
identity_hash = call["identity_hash"]
if operation == "retain": rpc_connection.send(self._retain_identity(identity_hash))
rpc_connection.close()
except Exception as e:
@@ -1153,6 +1158,18 @@ class Reticulum:
else: return RNS.Identity._unretain_destination_data(destination_hash)
def _retain_identity(self, identity_hash):
if type(identity_hash) != bytes or len(identity_hash) != RNS.Reticulum.TRUNCATED_HASHLENGTH//8:
raise TypeError("Cannot retain identity, not a valid identity hash")
if self.is_connected_to_shared_instance:
rpc_connection = self.get_rpc_client()
rpc_connection.send({"identity_data": "retain", "identity_hash": identity_hash})
response = rpc_connection.recv()
return response
else: return RNS.Identity._retain_identity(identity_hash)
def get_interface_stats(self):
if self.is_connected_to_shared_instance:
rpc_connection = self.get_rpc_client()