From bef32059f4e5443cec80dbcf4d63fe7b3c89afe8 Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 19 Apr 2024 12:53:12 -0400 Subject: [PATCH] Call packet collecter after prepare during tx. We have to call the packet collector.tx() only after a packet has been prepared for tx, because that's when the new msgNo is assigned. --- aprsd/packets/tracker.py | 4 +++- aprsd/threads/tx.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/aprsd/packets/tracker.py b/aprsd/packets/tracker.py index 52b6fc6..09ed0ca 100644 --- a/aprsd/packets/tracker.py +++ b/aprsd/packets/tracker.py @@ -1,4 +1,5 @@ import datetime +import logging import threading from oslo_config import cfg @@ -9,6 +10,7 @@ from aprsd.utils import objectstore CONF = cfg.CONF +LOG = logging.getLogger("APRSD") class PacketTrack(objectstore.ObjectStoreMixin): @@ -100,7 +102,7 @@ class PacketTrack(objectstore.ObjectStoreMixin): @wrapt.synchronized(lock) def get(self, key): - return self.data.get(key, None) + return self.data.get(key) @wrapt.synchronized(lock) def remove(self, key): diff --git a/aprsd/threads/tx.py b/aprsd/threads/tx.py index 634f486..9b6c75a 100644 --- a/aprsd/threads/tx.py +++ b/aprsd/threads/tx.py @@ -1,4 +1,5 @@ import logging +import threading import time from oslo_config import cfg @@ -6,6 +7,7 @@ from rush import quota, throttle from rush.contrib import decorator from rush.limiters import periodic from rush.stores import dictionary +import wrapt from aprsd import client from aprsd import conf # noqa @@ -37,15 +39,19 @@ ack_t = throttle.Throttle( msg_throttle_decorator = decorator.ThrottleDecorator(throttle=msg_t) ack_throttle_decorator = decorator.ThrottleDecorator(throttle=ack_t) +s_lock = threading.Lock() +@wrapt.synchronized(s_lock) @msg_throttle_decorator.sleep_and_retry def send(packet: core.Packet, direct=False, aprs_client=None): """Send a packet either in a thread or directly to the client.""" # prepare the packet for sending. # This constructs the packet.raw - collector.PacketCollector().tx(packet) packet.prepare() + # Have to call the collector to track the packet + # After prepare, as prepare assigns the msgNo + collector.PacketCollector().tx(packet) if isinstance(packet, core.AckPacket): _send_ack(packet, direct=direct, aprs_client=aprs_client) else: