fix: Dedup packets across sources, translate numeric port numbers to names

Packet dedup: track seen packet IDs across all sources. Same packet from
Meshview + MeshMonitor counted once, not twice. Fixes inflated counts.
Portnum: numeric values (3, 4, 71) mapped to names (Position, NodeInfo, Neighbors).
LLM prompt: guidance on normal vs abnormal packet rates per type.
This commit is contained in:
K7ZVX 2026-05-07 03:07:56 +00:00
commit a80ed6cc7c
3 changed files with 39 additions and 2 deletions

View file

@ -458,12 +458,20 @@ class MeshDataStore:
- Deliverability (source overlap)
Does NOT rebuild the full node model.
"""
# Recount packets per node from all sources
# Recount packets per node from all sources (deduped by packet ID)
packet_counts: dict[int, int] = {}
packets_by_type: dict[int, dict[str, int]] = {}
seen_packet_ids: set = set()
for name, source in self._sources.items():
for pkt in (source.packets if hasattr(source, 'packets') else []):
# Dedup: skip packets already seen from another source
pkt_id = pkt.get("packet_id") or pkt.get("id")
if pkt_id is not None:
if pkt_id in seen_packet_ids:
continue
seen_packet_ids.add(pkt_id)
from_node = pkt.get("from_node") or pkt.get("from_node_id") or pkt.get("from")
if from_node is None:
continue
@ -478,7 +486,7 @@ class MeshDataStore:
packet_counts[from_node] = packet_counts.get(from_node, 0) + 1
portnum = pkt.get("portnum") or pkt.get("portnum_name") or pkt.get("type") or "UNKNOWN"
portnum = str(pkt.get("portnum") or pkt.get("portnum_name") or pkt.get("type") or "UNKNOWN")
if from_node not in packets_by_type:
packets_by_type[from_node] = {}
packets_by_type[from_node][portnum] = packets_by_type[from_node].get(portnum, 0) + 1