1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-08-03 05:52:26 -04:00

Fixed a bug with multiple notify plugins enabled

This patch fixes an issue with the processing of packets
and updateing the watchlist.  Previously after the
notify plugin processed the packet it would update the watchlist.
This doesn't work when there are more than 1 notify plugins
enabled, only the first notify plugin seeing the packet will
recognize that the callsign is old.
This commit is contained in:
Hemna 2021-12-10 14:20:57 -05:00
parent 6a1cea63e4
commit e57a2e2ffc
6 changed files with 22 additions and 12 deletions

View File

@ -25,7 +25,7 @@ def setup_logging(config, loglevel, quiet):
log_format = "%(message)s" log_format = "%(message)s"
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format) log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
rh = aprsd_logging.APRSDRichHandler( rh = aprsd_logging.APRSDRichHandler(
show_thread=True, thread_width=15, show_thread=True, thread_width=20,
rich_tracebacks=True, omit_repeated_times=False, rich_tracebacks=True, omit_repeated_times=False,
) )
rh.setFormatter(log_formatter) rh.setFormatter(log_formatter)

View File

@ -190,6 +190,7 @@ class Message(metaclass=abc.ABCMeta):
fromcall, fromcall,
tocall, tocall,
msg_id=None, msg_id=None,
allow_delay=True,
): ):
self.fromcall = fromcall self.fromcall = fromcall
self.tocall = tocall self.tocall = tocall
@ -199,6 +200,10 @@ class Message(metaclass=abc.ABCMeta):
msg_id = c.value msg_id = c.value
self.id = msg_id self.id = msg_id
# do we try and save this message for later if we don't get
# an ack? Some messages we don't want to do this ever.
self.allow_delay = allow_delay
@abc.abstractmethod @abc.abstractmethod
def send(self): def send(self):
"""Child class must declare.""" """Child class must declare."""
@ -214,8 +219,8 @@ class RawMessage(Message):
message = None message = None
def __init__(self, message): def __init__(self, message, allow_delay=True):
super().__init__(None, None, msg_id=None) super().__init__(fromcall=None, tocall=None, msg_id=None, allow_delay=allow_delay)
self.message = message self.message = message
def dict(self): def dict(self):
@ -269,11 +274,11 @@ class TextMessage(Message):
msg_id=None, msg_id=None,
allow_delay=True, allow_delay=True,
): ):
super().__init__(fromcall, tocall, msg_id) super().__init__(
fromcall=fromcall, tocall=tocall,
msg_id=msg_id, allow_delay=allow_delay,
)
self.message = message self.message = message
# do we try and save this message for later if we don't get
# an ack? Some messages we don't want to do this ever.
self.allow_delay = allow_delay
def dict(self): def dict(self):
now = datetime.datetime.now() now = datetime.datetime.now()
@ -369,6 +374,8 @@ class SendMessageThread(threads.APRSDThread):
# we reached the send limit, don't send again # we reached the send limit, don't send again
# TODO(hemna) - Need to put this in a delayed queue? # TODO(hemna) - Need to put this in a delayed queue?
LOG.info("Message Send Complete. Max attempts reached.") LOG.info("Message Send Complete. Max attempts reached.")
if not msg.allow_delay:
tracker.remove(msg.id)
return False return False
# Message is still outstanding and needs to be acked. # Message is still outstanding and needs to be acked.

View File

@ -86,7 +86,7 @@ class WatchList(objectstore.ObjectStoreMixin):
if config: if config:
self.config = config self.config = config
ring_size = config["aprsd"]["watch_list"]["packet_keep_count"] ring_size = config["aprsd"]["watch_list"].get("packet_keep_count", 10)
for callsign in config["aprsd"]["watch_list"].get("callsigns", []): for callsign in config["aprsd"]["watch_list"].get("callsigns", []):
call = callsign.replace("*", "") call = callsign.replace("*", "")

View File

@ -177,7 +177,6 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
) )
if result: if result:
self.tx_inc() self.tx_inc()
wl.update_seen(packet)
else: else:
LOG.warning(f"{self.__class__} plugin is not enabled") LOG.warning(f"{self.__class__} plugin is not enabled")

View File

@ -1,6 +1,6 @@
import logging import logging
from aprsd import messaging, packets, plugin from aprsd import messaging, packets, plugin, trace
LOG = logging.getLogger("APRSD") LOG = logging.getLogger("APRSD")
@ -17,6 +17,7 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
short_description = "Notify me when a CALLSIGN is recently seen on APRS-IS" short_description = "Notify me when a CALLSIGN is recently seen on APRS-IS"
@trace.trace
def process(self, packet): def process(self, packet):
LOG.info("NotifySeenPlugin") LOG.info("NotifySeenPlugin")
@ -46,10 +47,11 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
) )
return msg return msg
else: else:
LOG.debug("fromcall and notify_callsign are the same, not notifying")
return messaging.NULL_MESSAGE return messaging.NULL_MESSAGE
else: else:
LOG.debug( LOG.debug(
"Not old enough to notify callsign '{}' : {} < {}".format( "Not old enough to notify on callsign '{}' : {} < {}".format(
fromcall, fromcall,
age, age,
wl.max_delta(), wl.max_delta(),

View File

@ -202,7 +202,7 @@ class APRSDProcessPacketThread(APRSDThread):
self.packet = packet self.packet = packet
self.config = config self.config = config
name = self.packet["raw"][:10] name = self.packet["raw"][:10]
super().__init__(f"RX_PACKET-{name}") super().__init__(f"RXPKT-{name}")
def process_ack_packet(self, packet): def process_ack_packet(self, packet):
ack_num = packet.get("msgNo") ack_num = packet.get("msgNo")
@ -261,6 +261,8 @@ class APRSDProcessPacketThread(APRSDThread):
pm = plugin.PluginManager() pm = plugin.PluginManager()
try: try:
results = pm.run(packet) results = pm.run(packet)
wl = packets.WatchList()
wl.update_seen(packet)
replied = False replied = False
for reply in results: for reply in results:
if isinstance(reply, list): if isinstance(reply, list):