mirror of
https://github.com/markqvist/Reticulum.git
synced 2025-08-13 00:35:50 -04:00
add handler endpoints for tx and rx recording
This commit is contained in:
parent
51e3983bf8
commit
7f5e39fece
1 changed files with 48 additions and 0 deletions
|
@ -113,6 +113,9 @@ class Transport:
|
||||||
path_requests = {} # A table for storing path request timestamps
|
path_requests = {} # A table for storing path request timestamps
|
||||||
path_states = {} # A table for keeping track of path states
|
path_states = {} # A table for keeping track of path states
|
||||||
|
|
||||||
|
transmission_handlers = []
|
||||||
|
receive_handlers = []
|
||||||
|
|
||||||
discovery_path_requests = {} # A table for keeping track of path requests on behalf of other nodes
|
discovery_path_requests = {} # A table for keeping track of path requests on behalf of other nodes
|
||||||
discovery_pr_tags = [] # A table for keeping track of tagged path requests
|
discovery_pr_tags = [] # A table for keeping track of tagged path requests
|
||||||
max_pr_tags = 32000 # Maximum amount of unique path request tags to remember
|
max_pr_tags = 32000 # Maximum amount of unique path request tags to remember
|
||||||
|
@ -833,6 +836,23 @@ class Transport:
|
||||||
else:
|
else:
|
||||||
interface.process_outgoing(raw)
|
interface.process_outgoing(raw)
|
||||||
|
|
||||||
|
# send transmission to handlers
|
||||||
|
# TODO: this won't capture things left in the queue
|
||||||
|
for handler in Transport.transmission_handlers:
|
||||||
|
try:
|
||||||
|
# grab parameters from interface
|
||||||
|
params = dict(
|
||||||
|
frequency=getattr(interface, "frequency", None),
|
||||||
|
bandwidth=getattr(interface, "bandwidth", None),
|
||||||
|
txpower=getattr(interface, "tx_power", None),
|
||||||
|
sf=getattr(interface, "sf", None),
|
||||||
|
state=getattr(interface, "state", None),
|
||||||
|
)
|
||||||
|
handler(interface, raw, params)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Handler {handler} encountered exception {e}")
|
||||||
|
pass
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while transmitting on "+str(interface)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error while transmitting on "+str(interface)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
@ -1257,6 +1277,14 @@ class Transport:
|
||||||
elif Transport.interface_to_shared_instance(interface):
|
elif Transport.interface_to_shared_instance(interface):
|
||||||
packet.hops -= 1
|
packet.hops -= 1
|
||||||
|
|
||||||
|
# NOTE - placing handlers here means we don't capture anything if IFAC is enabled
|
||||||
|
for handler in Transport.receive_handlers:
|
||||||
|
try:
|
||||||
|
handler(packet)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Encountered exception {e}, passing")
|
||||||
|
pass
|
||||||
|
|
||||||
if Transport.packet_filter(packet):
|
if Transport.packet_filter(packet):
|
||||||
# By default, remember packet hashes to avoid routing
|
# By default, remember packet hashes to avoid routing
|
||||||
# loops in the network, using the packet filter.
|
# loops in the network, using the packet filter.
|
||||||
|
@ -2169,6 +2197,26 @@ class Transport:
|
||||||
while handler in Transport.announce_handlers: Transport.announce_handlers.remove(handler)
|
while handler in Transport.announce_handlers: Transport.announce_handlers.remove(handler)
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def register_transmission_handler(handler):
|
||||||
|
if callable(handler):
|
||||||
|
Transport.transmission_handlers.append(handler)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def deregister_transmission_handler(handler):
|
||||||
|
while handler in Transport.transmission_handlers: Transport.transmission_handlers.remove(handler)
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def register_receive_handler(handler):
|
||||||
|
if callable(handler):
|
||||||
|
Transport.receive_handlers.append(handler)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def deregister_receive_handler(handler):
|
||||||
|
while handler in Transport.receive_handlers: Transport.receive_handlers.remove(handler)
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_interface_from_hash(interface_hash):
|
def find_interface_from_hash(interface_hash):
|
||||||
for interface in Transport.interfaces:
|
for interface in Transport.interfaces:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue