mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-12-18 18:10:17 +00:00
Allow announce handler to receive announce packet hash
This commit is contained in:
parent
0984f92fa2
commit
7e52c37580
@ -501,6 +501,10 @@ class PacketReceipt:
|
|||||||
return False
|
return False
|
||||||
elif len(proof) == PacketReceipt.IMPL_LENGTH:
|
elif len(proof) == PacketReceipt.IMPL_LENGTH:
|
||||||
# This is an implicit proof
|
# This is an implicit proof
|
||||||
|
|
||||||
|
if not hasattr(self.destination, "identity"):
|
||||||
|
return False
|
||||||
|
|
||||||
if self.destination.identity == None:
|
if self.destination.identity == None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import RNS
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import struct
|
import struct
|
||||||
|
import inspect
|
||||||
import threading
|
import threading
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from .vendor import umsgpack as umsgpack
|
from .vendor import umsgpack as umsgpack
|
||||||
@ -1149,27 +1150,21 @@ class Transport:
|
|||||||
if hasattr(interface, "r_stat_rssi"):
|
if hasattr(interface, "r_stat_rssi"):
|
||||||
if interface.r_stat_rssi != None:
|
if interface.r_stat_rssi != None:
|
||||||
packet.rssi = interface.r_stat_rssi
|
packet.rssi = interface.r_stat_rssi
|
||||||
if len(Transport.local_client_interfaces) > 0:
|
|
||||||
Transport.local_client_rssi_cache.append([packet.packet_hash, packet.rssi])
|
Transport.local_client_rssi_cache.append([packet.packet_hash, packet.rssi])
|
||||||
|
|
||||||
while len(Transport.local_client_rssi_cache) > Transport.LOCAL_CLIENT_CACHE_MAXSIZE:
|
while len(Transport.local_client_rssi_cache) > Transport.LOCAL_CLIENT_CACHE_MAXSIZE:
|
||||||
Transport.local_client_rssi_cache.pop(0)
|
Transport.local_client_rssi_cache.pop(0)
|
||||||
|
|
||||||
if hasattr(interface, "r_stat_snr"):
|
if hasattr(interface, "r_stat_snr"):
|
||||||
if interface.r_stat_rssi != None:
|
if interface.r_stat_rssi != None:
|
||||||
packet.snr = interface.r_stat_snr
|
packet.snr = interface.r_stat_snr
|
||||||
if len(Transport.local_client_interfaces) > 0:
|
|
||||||
Transport.local_client_snr_cache.append([packet.packet_hash, packet.snr])
|
Transport.local_client_snr_cache.append([packet.packet_hash, packet.snr])
|
||||||
|
|
||||||
while len(Transport.local_client_snr_cache) > Transport.LOCAL_CLIENT_CACHE_MAXSIZE:
|
while len(Transport.local_client_snr_cache) > Transport.LOCAL_CLIENT_CACHE_MAXSIZE:
|
||||||
Transport.local_client_snr_cache.pop(0)
|
Transport.local_client_snr_cache.pop(0)
|
||||||
|
|
||||||
if hasattr(interface, "r_stat_q"):
|
if hasattr(interface, "r_stat_q"):
|
||||||
if interface.r_stat_q != None:
|
if interface.r_stat_q != None:
|
||||||
packet.q = interface.r_stat_q
|
packet.q = interface.r_stat_q
|
||||||
if len(Transport.local_client_interfaces) > 0:
|
|
||||||
Transport.local_client_q_cache.append([packet.packet_hash, packet.q])
|
Transport.local_client_q_cache.append([packet.packet_hash, packet.q])
|
||||||
|
|
||||||
while len(Transport.local_client_q_cache) > Transport.LOCAL_CLIENT_CACHE_MAXSIZE:
|
while len(Transport.local_client_q_cache) > Transport.LOCAL_CLIENT_CACHE_MAXSIZE:
|
||||||
Transport.local_client_q_cache.pop(0)
|
Transport.local_client_q_cache.pop(0)
|
||||||
|
|
||||||
@ -1713,11 +1708,20 @@ class Transport:
|
|||||||
execute_callback = False
|
execute_callback = False
|
||||||
|
|
||||||
if execute_callback:
|
if execute_callback:
|
||||||
handler.received_announce(
|
|
||||||
destination_hash=packet.destination_hash,
|
if len(inspect.signature(handler.received_announce).parameters) == 3:
|
||||||
|
handler.received_announce(destination_hash=packet.destination_hash,
|
||||||
announced_identity=announce_identity,
|
announced_identity=announce_identity,
|
||||||
app_data=RNS.Identity.recall_app_data(packet.destination_hash)
|
app_data=RNS.Identity.recall_app_data(packet.destination_hash))
|
||||||
)
|
|
||||||
|
elif len(inspect.signature(handler.received_announce).parameters) == 4:
|
||||||
|
handler.received_announce(destination_hash=packet.destination_hash,
|
||||||
|
announced_identity=announce_identity,
|
||||||
|
app_data=RNS.Identity.recall_app_data(packet.destination_hash),
|
||||||
|
announce_packet_hash = packet.packet_hash)
|
||||||
|
else:
|
||||||
|
raise TypeError("Invalid signature for announce handler callback")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR)
|
RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR)
|
||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
@ -2021,8 +2025,9 @@ class Transport:
|
|||||||
Registers an announce handler.
|
Registers an announce handler.
|
||||||
|
|
||||||
:param handler: Must be an object with an *aspect_filter* attribute and a *received_announce(destination_hash, announced_identity, app_data)*
|
:param handler: Must be an object with an *aspect_filter* attribute and a *received_announce(destination_hash, announced_identity, app_data)*
|
||||||
callable. Can optionally have a *receive_path_responses* attribute set to ``True``, to also receive all path responses, in addition to live
|
or *received_announce(destination_hash, announced_identity, app_data, announce_packet_hash)* callable. Can optionally have a
|
||||||
announces. See the :ref:`Announce Example<example-announce>` for more info.
|
*receive_path_responses* attribute set to ``True``, to also receive all path responses, in addition to live announces. See
|
||||||
|
the :ref:`Announce Example<example-announce>` for more info.
|
||||||
"""
|
"""
|
||||||
if hasattr(handler, "received_announce") and callable(handler.received_announce):
|
if hasattr(handler, "received_announce") and callable(handler.received_announce):
|
||||||
if hasattr(handler, "aspect_filter"):
|
if hasattr(handler, "aspect_filter"):
|
||||||
|
Loading…
Reference in New Issue
Block a user