Track filtered announce count per interface

This commit is contained in:
Mark Qvist 2026-11-13 21:51:00 +01:00
parent d183791956
commit 819076c378
No known key found for this signature in database
4 changed files with 28 additions and 16 deletions

View file

@ -104,6 +104,7 @@ class Interface:
self.atxb = 0
self.arxc = 0
self.atxc = 0
self.afrxc = 0
self.prxb = 0
self.ptxb = 0
self.prxc = 0
@ -277,11 +278,14 @@ class Interface:
def hold_announce(self, announce_packet):
if announce_packet.hops >= RNS.Transport.PATHFINDER_M-1:
return
return self.filtered_announce()
elif announce_packet.destination_hash in self.held_announces:
self.held_announces[announce_packet.destination_hash] = announce_packet
return self.filtered_announce()
elif not len(self.held_announces) >= self.ic_max_held_announces:
self.held_announces[announce_packet.destination_hash] = announce_packet
return True
else: return self.filtered_announce()
def process_held_announces(self):
try:
@ -311,25 +315,31 @@ class Interface:
def received_announce(self, size=0, from_spawned=False):
self.arxc += 1; self.arxb += size
self.ia_freq_deque.append(time.time())
if hasattr(self, "parent_interface") and self.parent_interface != None:
if self.parent_interface != None:
self.parent_interface.received_announce(size=size, from_spawned=True)
def sent_announce(self, size=0, from_spawned=False):
self.atxc += 1; self.atxb += size
self.oa_freq_deque.append(time.time())
if hasattr(self, "parent_interface") and self.parent_interface != None:
if self.parent_interface != None:
self.parent_interface.sent_announce(size=size, from_spawned=True)
def filtered_announce(self, size=0, from_spawned=False):
self.afrxc += 1
RNS.Transport.filtered_arxc += 1
if self.parent_interface != None: self.parent_interface.afrxc += 1
return None
def received_path_request(self, size=0, from_spawned=False):
self.prxc += 1; self.prxb += size
self.ip_freq_deque.append(time.time())
if hasattr(self, "parent_interface") and self.parent_interface != None:
if self.parent_interface != None:
self.parent_interface.received_path_request(size=size, from_spawned=True)
def sent_path_request(self, size=0, from_spawned=False):
self.ptxc += 1; self.ptxb += size
self.op_freq_deque.append(time.time())
if hasattr(self, "parent_interface") and self.parent_interface != None:
if self.parent_interface != None:
self.parent_interface.sent_path_request(size=size, from_spawned=True)
def protocol_violation(self, description=None, level=None):

View file

@ -1797,6 +1797,7 @@ class Reticulum:
ifstats["atxb"] = interface.atxb
ifstats["arxc"] = interface.arxc
ifstats["atxc"] = interface.atxc
ifstats["afrxc"] = interface.afrxc
ifstats["prxb"] = interface.prxb
ifstats["ptxb"] = interface.ptxb
ifstats["prxc"] = interface.prxc

View file

@ -381,6 +381,7 @@ class Transport:
traffic_txb = 0
filtered_rxb = 0
filtered_txb = 0
filtered_arxc = 0
announce_rxc = 0
announce_txc = 0
announce_rxb = 0
@ -2041,7 +2042,7 @@ class Transport:
time.sleep(0.25)
if time.time() > wait_start + Transport.READY_WAIT:
RNS.log("Inbound packet timed out waiting for transport startup, dropping", RNS.LOG_WARNING)
return
return None
# If interface access codes are enabled,
# we must authenticate each packet.
@ -2052,7 +2053,7 @@ class Transport:
if raw[0] & 0x80 == 0x80:
if len(raw) > 2+interface.ifac_size:
ifac_valid, raw = Transport.handle_ifac(raw, interface)
if not ifac_valid: return
if not ifac_valid: return None
else: return interface.ifac_violation("Insufficient packet size for IFAC packet")
@ -2088,7 +2089,6 @@ class Transport:
name_hash = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8]
if len(name_hash) != RNS.Identity.NAME_HASH_LENGTH//8: return packet.receiving_interface.protocol_violation(f"Malformed announce packet with size {len(packet.data)}")
if len(raw) > RNS.Reticulum.MTU: return packet.receiving_interface.protocol_violation(f"Excessive announce packet frame size of {len(raw)} bytes")
if len(packet.receiving_interface.held_announces) >= packet.receiving_interface.ic_max_held_announces: return None
if Transport.blocked_destination_types and name_hash in Transport.blocked_destination_types: return
if Transport.required_destinations_only:
@ -2097,13 +2097,13 @@ class Transport:
elif Transport.is_local_client_interface(packet.receiving_interface): allowed = True if packet.hops == 1 else False # 1 == 0 really, yes it's weird ~. . .~
elif Transport.interface_to_shared_instance(packet.receiving_interface): allowed = True if packet.hops == 1 else False # 1 == 0 really, yes it's weird `-`
else: allowed = False
if not allowed: return
if not allowed: return packet.receiving_interface.filtered_announce()
if traffic_class < Transport.TC_ANNOUNCE: traffic_class = Transport.TC_ANNOUNCE
announce_signature_valid = RNS.Identity.validate_announce(packet, only_validate_signature=True, signal_blackholed=True, signal_stamp=True)
if announce_signature_valid == "blackholed": return None
elif announce_signature_valid == "no_stamp": return None
elif announce_signature_valid == "invalid_stamp": return None
if announce_signature_valid == "blackholed": return packet.receiving_interface.filtered_announce()
elif announce_signature_valid == "no_stamp": return packet.receiving_interface.filtered_announce()
elif announce_signature_valid == "invalid_stamp": return packet.receiving_interface.filtered_announce()
elif not announce_signature_valid:
return packet.receiving_interface.protocol_violation(f"Invalid announce signature for {RNS.prettyhexrep(packet.destination_hash)}")
@ -2121,8 +2121,7 @@ class Transport:
pass
elif packet.receiving_interface.should_ingress_limit():
packet.receiving_interface.hold_announce(packet)
return
return packet.receiving_interface.hold_announce(packet)
# Ingress limit path requests early
elif packet.destination_hash == Transport.pr_destination_hash:

View file

@ -444,6 +444,7 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
if sorting == "atx": interfaces.sort(key=lambda i: i["outgoing_announce_frequency"], reverse=not sort_reverse)
if sorting == "arxc": interfaces.sort(key=lambda i: i["arxc"], reverse=not sort_reverse)
if sorting == "atxc": interfaces.sort(key=lambda i: i["atxc"], reverse=not sort_reverse)
if sorting == "afrxc": interfaces.sort(key=lambda i: i["afrxc"], reverse=not sort_reverse)
if sorting == "prx": interfaces.sort(key=lambda i: i["incoming_pr_frequency"], reverse=not sort_reverse)
if sorting == "ptx": interfaces.sort(key=lambda i: i["outgoing_pr_frequency"], reverse=not sort_reverse)
if sorting == "prxc": interfaces.sort(key=lambda i: i["prxc"], reverse=not sort_reverse)
@ -745,7 +746,8 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
if asr:
if ifstat["arxc"] and ifstat["atxc"]:
print(f" Announces : {ifstat['arxc']}↓ {ifstat['atxc']}↑ total")
f_str = f", {ifstat['afrxc']} filtered" if ifstat["afrxc"] else ""
print(f" Announces : {ifstat['arxc']}↓ {ifstat['atxc']}↑ total{f_str}")
print(f" {oaf} {pc_str}")
else:
print(f" Announces : {oaf} {pc_str}")
@ -928,7 +930,7 @@ def main(must_exit=True, rns_instance=None):
parser.add_argument("-p", "--pps", action="store_true", help="display packets per second in totals", default=False)
parser.add_argument("-q", "--queues", action="store_true", help="display queue stats", default=False)
parser.add_argument("-z", "--profiling", action="store_true", help="display live profiling results", default=False)
parser.add_argument("-s", "--sort", action="store", help="sort interfaces by [rate, traffic, rx, tx, rxs, txs, anns, arx, atx, arxc, atxc, held, prx, ptx, prxc, ptxc, pvs, ivs, flt, txdrp, txdrb, txbuf]", default=None, type=str)
parser.add_argument("-s", "--sort", action="store", help="sort interfaces by [rate, traffic, rx, tx, rxs, txs, frx, ftx, anns, arx, atx, arxc, atxc, afrxc, held, prx, ptx, prxc, ptxc, pvs, ivs, flt, txdrp, txdrb, txbuf]", default=None, type=str)
parser.add_argument("-r", "--reverse", action="store_true", help="reverse sorting", default=False)
parser.add_argument("-j", "--json", action="store_true", help="output in JSON format", default=False)
parser.add_argument("-R", action="store", metavar="hash", help="transport identity hash of remote instance to get status from", default=None, type=str)