From 136713eec1c959ba4353ba94a91cbfea4d38a5e5 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 30 Sep 2023 19:13:58 +0200 Subject: [PATCH] Added announce frequency stats --- RNS/Identity.py | 6 +++++- RNS/Reticulum.py | 2 ++ RNS/Transport.py | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/RNS/Identity.py b/RNS/Identity.py index d202afc..601af2e 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -217,7 +217,7 @@ class Identity: return Identity.truncated_hash(os.urandom(Identity.TRUNCATED_HASHLENGTH//8)) @staticmethod - def validate_announce(packet): + def validate_announce(packet, only_validate_signature=False): try: if packet.packet_type == RNS.Packet.ANNOUNCE: destination_hash = packet.destination_hash @@ -238,6 +238,10 @@ class Identity: announced_identity.load_public_key(public_key) if announced_identity.pub != None and announced_identity.validate(signature, signed_data): + if only_validate_signature: + del announced_identity + return True + hash_material = name_hash+announced_identity.hash expected_hash = RNS.Identity.full_hash(hash_material)[:RNS.Reticulum.TRUNCATED_HASHLENGTH//8] diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index a40ecf4..234612a 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -1143,6 +1143,8 @@ class Reticulum: ifstats["name"] = str(interface) ifstats["rxb"] = interface.rxb ifstats["txb"] = interface.txb + ifstats["incoming_announce_frequency"] = interface.incoming_announce_frequency() + ifstats["outgoing_announce_frequency"] = interface.outgoing_announce_frequency() ifstats["status"] = interface.online ifstats["mode"] = interface.mode diff --git a/RNS/Transport.py b/RNS/Transport.py index 8099f4d..1166641 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -887,6 +887,8 @@ class Transport: # thread.start() Transport.transmit(interface, packet.raw) + if packet.packet_type == RNS.Packet.ANNOUNCE: + interface.sent_announce() sent = True if sent: @@ -1227,8 +1229,11 @@ class Transport: # announces, queueing rebroadcasts of these, and removal # of queued announce rebroadcasts once handed to the next node. if packet.packet_type == RNS.Packet.ANNOUNCE: + if interface != None and RNS.Identity.validate_announce(packet, only_validate_signature=True): + interface.received_announce() + local_destination = next((d for d in Transport.destinations if d.hash == packet.destination_hash), None) - if local_destination == None and RNS.Identity.validate_announce(packet): + if local_destination == None and RNS.Identity.validate_announce(packet): if packet.transport_id != None: received_from = packet.transport_id