From 9bdfd166fd213983ddd55e57b726bb8fc7eba8b7 Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 29 Sep 2023 10:04:15 -0400 Subject: [PATCH] Fixed issue with packet tracker and msgNO Counter The packet msgNo field is a string, but is typically is an integer counter to keep track of a specific packet id. The counter was returning an int, but the packet.msgNo is a string. So, when trying to delete a packet from the packet tracker, the key for accessing the packet is the msgNo, which has to be a string. Passing an int, will cause the packet tracker to not find the packet, and hence silently fail. This patch forces the msgNo counter to be a string. --- aprsd/packets/tracker.py | 15 ++++----------- aprsd/utils/counter.py | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/aprsd/packets/tracker.py b/aprsd/packets/tracker.py index ac5d4b4..b512320 100644 --- a/aprsd/packets/tracker.py +++ b/aprsd/packets/tracker.py @@ -62,14 +62,6 @@ class PacketTrack(objectstore.ObjectStoreMixin): def __len__(self): return len(self.data) - @wrapt.synchronized(lock) - def __str__(self): - result = "{" - for key in self.data.keys(): - result += f"{key}: {str(self.data[key])}, " - result += "}" - return result - @wrapt.synchronized(lock) def add(self, packet): key = packet.msgNo @@ -78,13 +70,14 @@ class PacketTrack(objectstore.ObjectStoreMixin): @wrapt.synchronized(lock) def get(self, key): - if key in self.data: - return self.data[key] + return self.data.get(key, None) @wrapt.synchronized(lock) def remove(self, key): - if key in self.data.keys(): + try: del self.data[key] + except KeyError: + pass def restart(self): """Walk the list of messages and restart them if any.""" diff --git a/aprsd/utils/counter.py b/aprsd/utils/counter.py index e423bfb..5f569f4 100644 --- a/aprsd/utils/counter.py +++ b/aprsd/utils/counter.py @@ -37,7 +37,7 @@ class PacketCounter: @property @wrapt.synchronized(lock) def value(self): - return self.val.value + return str(self.val.value) @wrapt.synchronized(lock) def __repr__(self):