From 8392d6b8efec4aeb3c87edf381c672440ee2cf07 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sun, 14 Apr 2024 12:48:09 -0400 Subject: [PATCH] Added new config optons for PacketList This allows the admin to set the number of packets to store in the PacketList object for tracking. For apps like IRC, we need to store lots more packets to detect dupes. --- aprsd/conf/common.py | 10 ++++++++++ aprsd/packets/packet_list.py | 15 +++++++++++++-- aprsd/threads/rx.py | 7 ++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/aprsd/conf/common.py b/aprsd/conf/common.py index 24a4022..2bd64c3 100644 --- a/aprsd/conf/common.py +++ b/aprsd/conf/common.py @@ -110,6 +110,16 @@ aprsd_opts = [ default=3, help="The number of times to send an ack packet in response to recieving a packet.", ), + cfg.IntOpt( + "packet_list_maxlen", + default=100, + help="The maximum number of packets to store in the packet list.", + ), + cfg.IntOpt( + "packet_list_stats_maxlen", + default=20, + help="The maximum number of packets to send in the stats dict for admin ui.", + ), ] watch_list_opts = [ diff --git a/aprsd/packets/packet_list.py b/aprsd/packets/packet_list.py index 109c7c4..87f89fd 100644 --- a/aprsd/packets/packet_list.py +++ b/aprsd/packets/packet_list.py @@ -22,7 +22,7 @@ class PacketList(objectstore.ObjectStoreMixin): def __new__(cls, *args, **kwargs): if cls._instance is None: cls._instance = super().__new__(cls) - cls._maxlen = 100 + cls._maxlen = CONF.packet_list_maxlen cls.data = { "types": {}, "packets": OrderedDict(), @@ -88,11 +88,22 @@ class PacketList(objectstore.ObjectStoreMixin): @wrapt.synchronized(lock) def stats(self, serializable=False) -> dict: + # limit the number of packets to return to 50 + LOG.info(f"PacketList stats called len={len(self.data['packets'])}") + tmp = OrderedDict(reversed(list(self.data["packets"].items()))) + pkts = [] + count = 1 + for packet in tmp: + pkts.append(tmp[packet]) + count += 1 + if count > CONF.packet_list_stats_maxlen: + break + stats = { "total_tracked": self._total_rx + self._total_rx, "rx": self._total_rx, "tx": self._total_tx, "types": self.data["types"], - "packets": self.data["packets"], + "packets": pkts, } return stats diff --git a/aprsd/threads/rx.py b/aprsd/threads/rx.py index f4b9186..3f0842a 100644 --- a/aprsd/threads/rx.py +++ b/aprsd/threads/rx.py @@ -115,14 +115,11 @@ class APRSDDupeRXThread(APRSDRXThread): found = False if not found: - # If we are in the process of already ack'ing - # a packet, we should drop the packet - # because it's a dupe within the time that - # we send the 3 acks for the packet. + # We haven't seen this packet before, so we process it. pkt_list.rx(packet) self.packet_queue.put(packet) elif packet.timestamp - found.timestamp < CONF.packet_dupe_timeout: - # If the packet came in within 60 seconds of the + # If the packet came in within N seconds of the # Last time seeing the packet, then we drop it as a dupe. LOG.warning(f"Packet {packet.from_call}:{packet.msgNo} already tracked, dropping.") else: