From 7ceb2d2078c1b8bd443f65c4f2b06ec23a99461c Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 7 May 2026 18:40:28 +0200 Subject: [PATCH] Added ability to retain identity data based on identity hash --- RNS/Identity.py | 12 ++++++++++++ RNS/Reticulum.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/RNS/Identity.py b/RNS/Identity.py index aae60807..e2d1b6bb 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -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(): diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 957382de..6f90ea0b 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -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()