mirror of https://github.com/craigerl/aprsd.git
Cleaned out all references to messaging
The messaging.py now is nothing but a shell that contains a link to packets.NULL_MESSAGE to help maintain some backwards compatibility with plugins. Packets dataclass has fully replaced messaging objects.
This commit is contained in:
parent
59e5af8ee5
commit
bfc0a5a1e9
|
@ -4,7 +4,7 @@ import aprslib
|
||||||
from ax253 import Frame
|
from ax253 import Frame
|
||||||
import kiss
|
import kiss
|
||||||
|
|
||||||
from aprsd import messaging
|
from aprsd.packets import core
|
||||||
from aprsd.utils import trace
|
from aprsd.utils import trace
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class KISS3Client:
|
||||||
self.kiss.read(callback=self.parse_frame, min_frames=None)
|
self.kiss.read(callback=self.parse_frame, min_frames=None)
|
||||||
LOG.debug("END blocking KISS consumer")
|
LOG.debug("END blocking KISS consumer")
|
||||||
|
|
||||||
def send(self, msg):
|
def send(self, packet):
|
||||||
"""Send an APRS Message object."""
|
"""Send an APRS Message object."""
|
||||||
|
|
||||||
# payload = (':%-9s:%s' % (
|
# payload = (':%-9s:%s' % (
|
||||||
|
@ -93,26 +93,26 @@ class KISS3Client:
|
||||||
# payload = str(msg).encode('US-ASCII')
|
# payload = str(msg).encode('US-ASCII')
|
||||||
payload = None
|
payload = None
|
||||||
path = ["WIDE1-1", "WIDE2-1"]
|
path = ["WIDE1-1", "WIDE2-1"]
|
||||||
if isinstance(msg, messaging.AckMessage):
|
if isinstance(packet, core.AckPacket):
|
||||||
msg_payload = f"ack{msg.id}"
|
msg_payload = f"ack{packet.msgNo}"
|
||||||
elif isinstance(msg, messaging.RawMessage):
|
elif isinstance(packet, core.Packet):
|
||||||
payload = msg.message.encode("US-ASCII")
|
payload = packet.raw.encode("US-ASCII")
|
||||||
path = ["WIDE2-1"]
|
path = ["WIDE2-1"]
|
||||||
else:
|
else:
|
||||||
msg_payload = f"{msg.message}{{{str(msg.id)}"
|
msg_payload = f"{packet.raw}{{{str(packet.msgNo)}"
|
||||||
|
|
||||||
if not payload:
|
if not payload:
|
||||||
payload = (
|
payload = (
|
||||||
":{:<9}:{}".format(
|
":{:<9}:{}".format(
|
||||||
msg.tocall,
|
packet.to_call,
|
||||||
msg_payload,
|
msg_payload,
|
||||||
)
|
)
|
||||||
).encode("US-ASCII")
|
).encode("US-ASCII")
|
||||||
|
|
||||||
LOG.debug(f"Send '{payload}' TO KISS")
|
LOG.debug(f"Send '{payload}' TO KISS")
|
||||||
frame = Frame.ui(
|
frame = Frame.ui(
|
||||||
destination=msg.tocall,
|
destination=packet.to_call,
|
||||||
source=msg.fromcall,
|
source=packet.from_call,
|
||||||
path=path,
|
path=path,
|
||||||
info=payload,
|
info=payload,
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import logging
|
||||||
import click
|
import click
|
||||||
|
|
||||||
# local imports here
|
# local imports here
|
||||||
from aprsd import cli_helper, client, messaging, packets, plugin, stats, utils
|
from aprsd import cli_helper, client, packets, plugin, stats, utils
|
||||||
from aprsd.aprsd import cli
|
from aprsd.aprsd import cli
|
||||||
from aprsd.utils import trace
|
from aprsd.utils import trace
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ def test_plugin(
|
||||||
|
|
||||||
client.Client(config)
|
client.Client(config)
|
||||||
stats.APRSDStats(config)
|
stats.APRSDStats(config)
|
||||||
messaging.MsgTrack(config=config)
|
packets.PacketTrack(config=config)
|
||||||
packets.WatchList(config=config)
|
packets.WatchList(config=config)
|
||||||
packets.SeenList(config=config)
|
packets.SeenList(config=config)
|
||||||
|
|
||||||
|
|
|
@ -80,14 +80,12 @@ def server(ctx, flush):
|
||||||
packets.PacketList(config=config)
|
packets.PacketList(config=config)
|
||||||
if flush:
|
if flush:
|
||||||
LOG.debug("Deleting saved MsgTrack.")
|
LOG.debug("Deleting saved MsgTrack.")
|
||||||
#messaging.MsgTrack(config=config).flush()
|
|
||||||
packets.PacketTrack(config=config).flush()
|
packets.PacketTrack(config=config).flush()
|
||||||
packets.WatchList(config=config)
|
packets.WatchList(config=config)
|
||||||
packets.SeenList(config=config)
|
packets.SeenList(config=config)
|
||||||
else:
|
else:
|
||||||
# Try and load saved MsgTrack list
|
# Try and load saved MsgTrack list
|
||||||
LOG.debug("Loading saved MsgTrack object.")
|
LOG.debug("Loading saved MsgTrack object.")
|
||||||
#messaging.MsgTrack(config=config).load()
|
|
||||||
packets.PacketTrack(config=config).load()
|
packets.PacketTrack(config=config).load()
|
||||||
packets.WatchList(config=config).load()
|
packets.WatchList(config=config).load()
|
||||||
packets.SeenList(config=config).load()
|
packets.SeenList(config=config).load()
|
||||||
|
@ -103,7 +101,6 @@ def server(ctx, flush):
|
||||||
)
|
)
|
||||||
rx_thread.start()
|
rx_thread.start()
|
||||||
|
|
||||||
#messaging.MsgTrack().restart()
|
|
||||||
packets.PacketTrack().restart()
|
packets.PacketTrack().restart()
|
||||||
|
|
||||||
keepalive = threads.KeepAliveThread(config=config)
|
keepalive = threads.KeepAliveThread(config=config)
|
||||||
|
|
194
aprsd/flask.py
194
aprsd/flask.py
|
@ -14,11 +14,12 @@ import flask_classful
|
||||||
from flask_httpauth import HTTPBasicAuth
|
from flask_httpauth import HTTPBasicAuth
|
||||||
from flask_socketio import Namespace, SocketIO
|
from flask_socketio import Namespace, SocketIO
|
||||||
from werkzeug.security import check_password_hash, generate_password_hash
|
from werkzeug.security import check_password_hash, generate_password_hash
|
||||||
|
import wrapt
|
||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import client
|
from aprsd import client
|
||||||
from aprsd import config as aprsd_config
|
from aprsd import config as aprsd_config
|
||||||
from aprsd import messaging, packets, plugin, stats, threads, utils
|
from aprsd import packets, plugin, stats, threads, utils
|
||||||
from aprsd.clients import aprsis
|
from aprsd.clients import aprsis
|
||||||
from aprsd.logging import log
|
from aprsd.logging import log
|
||||||
from aprsd.logging import rich as aprsd_logging
|
from aprsd.logging import rich as aprsd_logging
|
||||||
|
@ -32,7 +33,7 @@ users = None
|
||||||
|
|
||||||
class SentMessages:
|
class SentMessages:
|
||||||
_instance = None
|
_instance = None
|
||||||
lock = None
|
lock = threading.Lock()
|
||||||
|
|
||||||
msgs = {}
|
msgs = {}
|
||||||
|
|
||||||
|
@ -41,16 +42,16 @@ class SentMessages:
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super().__new__(cls)
|
cls._instance = super().__new__(cls)
|
||||||
# Put any initialization here.
|
# Put any initialization here.
|
||||||
cls.lock = threading.Lock()
|
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
def add(self, msg):
|
@wrapt.synchronized(lock)
|
||||||
with self.lock:
|
def add(self, packet):
|
||||||
self.msgs[msg.id] = self._create(msg.id)
|
self.msgs[packet.msgNo] = self._create(packet.msgNo)
|
||||||
self.msgs[msg.id]["from"] = msg.fromcall
|
self.msgs[packet.msgNo]["from"] = packet.from_call
|
||||||
self.msgs[msg.id]["to"] = msg.tocall
|
self.msgs[packet.msgNo]["to"] = packet.to_call
|
||||||
self.msgs[msg.id]["message"] = msg.message.rstrip("\n")
|
self.msgs[packet.msgNo]["message"] = packet.message_text.rstrip("\n")
|
||||||
self.msgs[msg.id]["raw"] = str(msg).rstrip("\n")
|
packet._build_raw()
|
||||||
|
self.msgs[packet.msgNo]["raw"] = packet.raw.rstrip("\n")
|
||||||
|
|
||||||
def _create(self, id):
|
def _create(self, id):
|
||||||
return {
|
return {
|
||||||
|
@ -66,34 +67,34 @@ class SentMessages:
|
||||||
"reply": None,
|
"reply": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
with self.lock:
|
return len(self.msgs.keys())
|
||||||
return len(self.msgs.keys())
|
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def get(self, id):
|
def get(self, id):
|
||||||
with self.lock:
|
if id in self.msgs:
|
||||||
if id in self.msgs:
|
return self.msgs[id]
|
||||||
return self.msgs[id]
|
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
with self.lock:
|
return self.msgs
|
||||||
return self.msgs
|
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def set_status(self, id, status):
|
def set_status(self, id, status):
|
||||||
with self.lock:
|
self.msgs[id]["last_update"] = str(datetime.datetime.now())
|
||||||
self.msgs[id]["last_update"] = str(datetime.datetime.now())
|
self.msgs[id]["status"] = status
|
||||||
self.msgs[id]["status"] = status
|
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def ack(self, id):
|
def ack(self, id):
|
||||||
"""The message got an ack!"""
|
"""The message got an ack!"""
|
||||||
with self.lock:
|
self.msgs[id]["last_update"] = str(datetime.datetime.now())
|
||||||
self.msgs[id]["last_update"] = str(datetime.datetime.now())
|
self.msgs[id]["ack"] = True
|
||||||
self.msgs[id]["ack"] = True
|
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def reply(self, id, packet):
|
def reply(self, id, packet):
|
||||||
"""We got a packet back from the sent message."""
|
"""We got a packet back from the sent message."""
|
||||||
with self.lock:
|
self.msgs[id]["reply"] = packet
|
||||||
self.msgs[id]["reply"] = packet
|
|
||||||
|
|
||||||
|
|
||||||
# HTTPBasicAuth doesn't work on a class method.
|
# HTTPBasicAuth doesn't work on a class method.
|
||||||
|
@ -107,7 +108,7 @@ def verify_password(username, password):
|
||||||
return username
|
return username
|
||||||
|
|
||||||
|
|
||||||
class SendMessageThread(threads.APRSDThread):
|
class SendMessageThread(threads.APRSDRXThread):
|
||||||
"""Thread for sending a message from web."""
|
"""Thread for sending a message from web."""
|
||||||
|
|
||||||
aprsis_client = None
|
aprsis_client = None
|
||||||
|
@ -115,10 +116,10 @@ class SendMessageThread(threads.APRSDThread):
|
||||||
got_ack = False
|
got_ack = False
|
||||||
got_reply = False
|
got_reply = False
|
||||||
|
|
||||||
def __init__(self, config, info, msg, namespace):
|
def __init__(self, config, info, packet, namespace):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.request = info
|
self.request = info
|
||||||
self.msg = msg
|
self.packet = packet
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
self.start_time = datetime.datetime.now()
|
self.start_time = datetime.datetime.now()
|
||||||
msg = "({} -> {}) : {}".format(
|
msg = "({} -> {}) : {}".format(
|
||||||
|
@ -180,8 +181,8 @@ class SendMessageThread(threads.APRSDThread):
|
||||||
except LoginError as e:
|
except LoginError as e:
|
||||||
f"Failed to setup Connection {e}"
|
f"Failed to setup Connection {e}"
|
||||||
|
|
||||||
self.msg.send_direct(aprsis_client=self.aprs_client)
|
self.packet.send_direct(aprsis_client=self.aprs_client)
|
||||||
SentMessages().set_status(self.msg.id, "Sent")
|
SentMessages().set_status(self.packet.msgNo, "Sent")
|
||||||
|
|
||||||
while not self.thread_stop:
|
while not self.thread_stop:
|
||||||
can_loop = self.loop()
|
can_loop = self.loop()
|
||||||
|
@ -190,59 +191,55 @@ class SendMessageThread(threads.APRSDThread):
|
||||||
threads.APRSDThreadList().remove(self)
|
threads.APRSDThreadList().remove(self)
|
||||||
LOG.debug("Exiting")
|
LOG.debug("Exiting")
|
||||||
|
|
||||||
def rx_packet(self, packet):
|
def process_ack_packet(self, packet):
|
||||||
global socketio
|
global socketio
|
||||||
# LOG.debug("Got packet back {}".format(packet))
|
ack_num = packet.msgNo
|
||||||
resp = packet.get("response", None)
|
LOG.info(f"We got ack for our sent message {ack_num}")
|
||||||
if resp == "ack":
|
packet.log("RXACK")
|
||||||
ack_num = packet.get("msgNo")
|
SentMessages().ack(self.packet.msgNo)
|
||||||
LOG.info(f"We got ack for our sent message {ack_num}")
|
stats.APRSDStats().ack_rx_inc()
|
||||||
messaging.log_packet(packet)
|
socketio.emit(
|
||||||
SentMessages().ack(self.msg.id)
|
"ack", SentMessages().get(self.packet.msgNo),
|
||||||
socketio.emit(
|
namespace="/sendmsg",
|
||||||
"ack", SentMessages().get(self.msg.id),
|
)
|
||||||
namespace="/sendmsg",
|
if self.request["wait_reply"] == "0" or self.got_reply:
|
||||||
)
|
# We aren't waiting for a reply, so we can bail
|
||||||
stats.APRSDStats().ack_rx_inc()
|
self.stop()
|
||||||
self.got_ack = True
|
self.thread_stop = self.aprs_client.thread_stop = True
|
||||||
if self.request["wait_reply"] == "0" or self.got_reply:
|
|
||||||
# We aren't waiting for a reply, so we can bail
|
def process_our_message_packet(self, packet):
|
||||||
self.stop()
|
global socketio
|
||||||
self.thread_stop = self.aprs_client.thread_stop = True
|
packets.PacketList().add(packet)
|
||||||
|
stats.APRSDStats().msgs_rx_inc()
|
||||||
|
msg_number = packet.msgNo
|
||||||
|
SentMessages().reply(self.packet.msgNo, packet)
|
||||||
|
SentMessages().set_status(self.packet.msgNo, "Got Reply")
|
||||||
|
socketio.emit(
|
||||||
|
"reply", SentMessages().get(self.packet.msgNo),
|
||||||
|
namespace="/sendmsg",
|
||||||
|
)
|
||||||
|
ack_pkt = packets.AckPacket(
|
||||||
|
from_call=self.request["from"],
|
||||||
|
to_call=packet.from_call,
|
||||||
|
msgNo=msg_number,
|
||||||
|
)
|
||||||
|
ack_pkt.send_direct(aprsis_client=self.aprsis_client)
|
||||||
|
SentMessages().set_status(self.packet.msgNo, "Ack Sent")
|
||||||
|
|
||||||
|
# Now we can exit, since we are done.
|
||||||
|
self.got_reply = True
|
||||||
|
if self.got_ack:
|
||||||
|
self.stop()
|
||||||
|
self.thread_stop = self.aprs_client.thread_stop = True
|
||||||
|
|
||||||
|
def process_packet(self, *args, **kwargs):
|
||||||
|
packet = self._client.decode_packet(*args, **kwargs)
|
||||||
|
packet.log(header="RX Packet")
|
||||||
|
|
||||||
|
if isinstance(packet, packets.AckPacket):
|
||||||
|
self.process_ack_packet(packet)
|
||||||
else:
|
else:
|
||||||
packets.PacketList().add(packet)
|
self.process_our_message_packet(packet)
|
||||||
stats.APRSDStats().msgs_rx_inc()
|
|
||||||
message = packet.get("message_text", None)
|
|
||||||
fromcall = packet["from"]
|
|
||||||
msg_number = packet.get("msgNo", "0")
|
|
||||||
messaging.log_message(
|
|
||||||
"Received Message",
|
|
||||||
packet["raw"],
|
|
||||||
message,
|
|
||||||
fromcall=fromcall,
|
|
||||||
ack=msg_number,
|
|
||||||
)
|
|
||||||
SentMessages().reply(self.msg.id, packet)
|
|
||||||
SentMessages().set_status(self.msg.id, "Got Reply")
|
|
||||||
socketio.emit(
|
|
||||||
"reply", SentMessages().get(self.msg.id),
|
|
||||||
namespace="/sendmsg",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Send the ack back?
|
|
||||||
ack = messaging.AckMessage(
|
|
||||||
self.request["from"],
|
|
||||||
fromcall,
|
|
||||||
msg_id=msg_number,
|
|
||||||
)
|
|
||||||
ack.send_direct()
|
|
||||||
SentMessages().set_status(self.msg.id, "Ack Sent")
|
|
||||||
|
|
||||||
# Now we can exit, since we are done.
|
|
||||||
self.got_reply = True
|
|
||||||
if self.got_ack:
|
|
||||||
self.stop()
|
|
||||||
self.thread_stop = self.aprs_client.thread_stop = True
|
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
# we have a general time limit expecting results of
|
# we have a general time limit expecting results of
|
||||||
|
@ -265,7 +262,9 @@ class SendMessageThread(threads.APRSDThread):
|
||||||
# This will register a packet consumer with aprslib
|
# This will register a packet consumer with aprslib
|
||||||
# When new packets come in the consumer will process
|
# When new packets come in the consumer will process
|
||||||
# the packet
|
# the packet
|
||||||
self.aprs_client.consumer(self.rx_packet, raw=False, blocking=False)
|
self.aprs_client.consumer(
|
||||||
|
self.process_packet, raw=False, blocking=False,
|
||||||
|
)
|
||||||
except aprslib.exceptions.ConnectionDrop:
|
except aprslib.exceptions.ConnectionDrop:
|
||||||
LOG.error("Connection dropped.")
|
LOG.error("Connection dropped.")
|
||||||
return False
|
return False
|
||||||
|
@ -353,7 +352,7 @@ class APRSDFlask(flask_classful.FlaskView):
|
||||||
|
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def messages(self):
|
def messages(self):
|
||||||
track = messaging.MsgTrack()
|
track = packets.PacketTrack()
|
||||||
msgs = []
|
msgs = []
|
||||||
for id in track:
|
for id in track:
|
||||||
LOG.info(track[id].dict())
|
LOG.info(track[id].dict())
|
||||||
|
@ -393,13 +392,13 @@ class APRSDFlask(flask_classful.FlaskView):
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Save the existing queue to disk."""
|
"""Save the existing queue to disk."""
|
||||||
track = messaging.MsgTrack()
|
track = packets.PacketTrack()
|
||||||
track.save()
|
track.save()
|
||||||
return json.dumps({"messages": "saved"})
|
return json.dumps({"messages": "saved"})
|
||||||
|
|
||||||
def _stats(self):
|
def _stats(self):
|
||||||
stats_obj = stats.APRSDStats()
|
stats_obj = stats.APRSDStats()
|
||||||
track = messaging.MsgTrack()
|
track = packets.PacketTrack()
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
time_format = "%m-%d-%Y %H:%M:%S"
|
time_format = "%m-%d-%Y %H:%M:%S"
|
||||||
|
@ -444,7 +443,7 @@ class SendMessageNamespace(Namespace):
|
||||||
_config = None
|
_config = None
|
||||||
got_ack = False
|
got_ack = False
|
||||||
reply_sent = False
|
reply_sent = False
|
||||||
msg = None
|
packet = None
|
||||||
request = None
|
request = None
|
||||||
|
|
||||||
def __init__(self, namespace=None, config=None):
|
def __init__(self, namespace=None, config=None):
|
||||||
|
@ -466,24 +465,27 @@ class SendMessageNamespace(Namespace):
|
||||||
global socketio
|
global socketio
|
||||||
LOG.debug(f"WS: on_send {data}")
|
LOG.debug(f"WS: on_send {data}")
|
||||||
self.request = data
|
self.request = data
|
||||||
msg = messaging.TextMessage(
|
self.packet = packets.MessagePacket(
|
||||||
data["from"], data["to"],
|
from_call=data["from"],
|
||||||
data["message"],
|
to_call=data["to"],
|
||||||
|
message_text=data["message"],
|
||||||
)
|
)
|
||||||
self.msg = msg
|
|
||||||
msgs = SentMessages()
|
msgs = SentMessages()
|
||||||
msgs.add(msg)
|
msgs.add(self.packet)
|
||||||
msgs.set_status(msg.id, "Sending")
|
msgs.set_status(self.packet.msgNo, "Sending")
|
||||||
socketio.emit(
|
socketio.emit(
|
||||||
"sent", SentMessages().get(self.msg.id),
|
"sent", SentMessages().get(self.packet.msgNo),
|
||||||
namespace="/sendmsg",
|
namespace="/sendmsg",
|
||||||
)
|
)
|
||||||
|
|
||||||
socketio.start_background_task(self._start, self._config, data, msg, self)
|
socketio.start_background_task(
|
||||||
|
self._start, self._config, data,
|
||||||
|
self.packet, self,
|
||||||
|
)
|
||||||
LOG.warning("WS: on_send: exit")
|
LOG.warning("WS: on_send: exit")
|
||||||
|
|
||||||
def _start(self, config, data, msg, namespace):
|
def _start(self, config, data, packet, namespace):
|
||||||
msg_thread = SendMessageThread(self._config, data, msg, self)
|
msg_thread = SendMessageThread(self._config, data, packet, self)
|
||||||
msg_thread.start()
|
msg_thread.start()
|
||||||
|
|
||||||
def handle_message(self, data):
|
def handle_message(self, data):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
# What to return from a plugin if we have processed the message
|
# What to return from a plugin if we have processed the message
|
||||||
# and it's ok, but don't send a usage string back
|
# and it's ok, but don't send a usage string back
|
||||||
NULL_MESSAGE = -1
|
|
||||||
|
# REMOVE THIS FILE
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
from aprsd.packets.core import (
|
from aprsd.packets.core import ( # noqa: F401
|
||||||
AckPacket, GPSPacket, MessagePacket, MicEPacket, Packet, PathPacket,
|
AckPacket, GPSPacket, MessagePacket, MicEPacket, Packet, PathPacket,
|
||||||
StatusPacket, WeatherPacket,
|
StatusPacket, WeatherPacket,
|
||||||
)
|
)
|
||||||
from aprsd.packets.packet_list import PacketList
|
from aprsd.packets.packet_list import PacketList # noqa: F401
|
||||||
from aprsd.packets.seen_list import SeenList
|
from aprsd.packets.seen_list import SeenList # noqa: F401
|
||||||
from aprsd.packets.tracker import PacketTrack
|
from aprsd.packets.tracker import PacketTrack # noqa: F401
|
||||||
from aprsd.packets.watch_list import WatchList
|
from aprsd.packets.watch_list import WatchList # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
|
NULL_MESSAGE = -1
|
||||||
|
|
|
@ -46,6 +46,12 @@ class Packet(metaclass=abc.ABCMeta):
|
||||||
_transport = None
|
_transport = None
|
||||||
_raw_message = None
|
_raw_message = None
|
||||||
|
|
||||||
|
def __post__init(self):
|
||||||
|
if not self.msgNo:
|
||||||
|
c = counter.PacketCounter()
|
||||||
|
c.increment()
|
||||||
|
self.msgNo = c.value
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
"""Emulate a getter on a dict."""
|
"""Emulate a getter on a dict."""
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
|
@ -55,11 +61,6 @@ class Packet(metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
def _init_for_send(self):
|
def _init_for_send(self):
|
||||||
"""Do stuff here that is needed prior to sending over the air."""
|
"""Do stuff here that is needed prior to sending over the air."""
|
||||||
if not self.msgNo:
|
|
||||||
c = counter.PacketCounter()
|
|
||||||
c.increment()
|
|
||||||
self.msgNo = c.value
|
|
||||||
|
|
||||||
# now build the raw message for sending
|
# now build the raw message for sending
|
||||||
self._build_raw()
|
self._build_raw()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import pluggy
|
||||||
from thesmuggler import smuggle
|
from thesmuggler import smuggle
|
||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import client, messaging, threads
|
from aprsd import client, packets, threads
|
||||||
from aprsd.packets import watch_list
|
from aprsd.packets import watch_list
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
@hookimpl
|
@hookimpl
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
result = messaging.NULL_MESSAGE
|
result = packets.NULL_MESSAGE
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
wl = watch_list.WatchList()
|
wl = watch_list.WatchList()
|
||||||
if wl.callsign_in_watchlist(packet.from_call):
|
if wl.callsign_in_watchlist(packet.from_call):
|
||||||
|
|
|
@ -10,7 +10,7 @@ import time
|
||||||
|
|
||||||
import imapclient
|
import imapclient
|
||||||
|
|
||||||
from aprsd import messaging, packets, plugin, stats, threads
|
from aprsd import packets, plugin, stats, threads
|
||||||
from aprsd.utils import trace
|
from aprsd.utils import trace
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,10 +90,10 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
# Email has not been enabled
|
# Email has not been enabled
|
||||||
# so the plugin will just NOOP
|
# so the plugin will just NOOP
|
||||||
return messaging.NULL_MESSAGE
|
return packets.NULL_MESSAGE
|
||||||
|
|
||||||
fromcall = packet.from_call
|
fromcall = packet.from_call
|
||||||
message = packet.get("message_text", None)
|
message = packet.message_text
|
||||||
ack = packet.get("msgNo", "0")
|
ack = packet.get("msgNo", "0")
|
||||||
|
|
||||||
reply = None
|
reply = None
|
||||||
|
@ -109,7 +109,7 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
if r is not None:
|
if r is not None:
|
||||||
LOG.debug("RESEND EMAIL")
|
LOG.debug("RESEND EMAIL")
|
||||||
resend_email(self.config, r.group(1), fromcall)
|
resend_email(self.config, r.group(1), fromcall)
|
||||||
reply = messaging.NULL_MESSAGE
|
reply = packets.NULL_MESSAGE
|
||||||
# -user@address.com body of email
|
# -user@address.com body of email
|
||||||
elif re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message):
|
elif re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message):
|
||||||
# (same search again)
|
# (same search again)
|
||||||
|
@ -142,7 +142,7 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
if not too_soon or ack == 0:
|
if not too_soon or ack == 0:
|
||||||
LOG.info(f"Send email '{content}'")
|
LOG.info(f"Send email '{content}'")
|
||||||
send_result = send_email(self.config, to_addr, content)
|
send_result = send_email(self.config, to_addr, content)
|
||||||
reply = messaging.NULL_MESSAGE
|
reply = packets.NULL_MESSAGE
|
||||||
if send_result != 0:
|
if send_result != 0:
|
||||||
reply = f"-{to_addr} failed"
|
reply = f"-{to_addr} failed"
|
||||||
else:
|
else:
|
||||||
|
@ -157,7 +157,7 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
self.email_sent_dict.clear()
|
self.email_sent_dict.clear()
|
||||||
self.email_sent_dict[ack] = now
|
self.email_sent_dict[ack] = now
|
||||||
else:
|
else:
|
||||||
reply = messaging.NULL_MESSAGE
|
reply = packets.NULL_MESSAGE
|
||||||
LOG.info(
|
LOG.info(
|
||||||
"Email for message number "
|
"Email for message number "
|
||||||
+ ack
|
+ ack
|
||||||
|
@ -165,7 +165,6 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
reply = "Bad email address"
|
reply = "Bad email address"
|
||||||
# messaging.send_message(fromcall, "Bad email address")
|
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
@ -466,13 +465,12 @@ def resend_email(config, count, fromcall):
|
||||||
from_addr = shortcuts_inverted[from_addr]
|
from_addr = shortcuts_inverted[from_addr]
|
||||||
# asterisk indicates a resend
|
# asterisk indicates a resend
|
||||||
reply = "-" + from_addr + " * " + body.decode(errors="ignore")
|
reply = "-" + from_addr + " * " + body.decode(errors="ignore")
|
||||||
# messaging.send_message(fromcall, reply)
|
pkt = packets.MessagePacket(
|
||||||
msg = messaging.TextMessage(
|
from_call=config["aprsd"]["callsign"],
|
||||||
config["aprs"]["login"],
|
to_call=fromcall,
|
||||||
fromcall,
|
message_text=reply,
|
||||||
reply,
|
|
||||||
)
|
)
|
||||||
msg.send()
|
pkt.send()
|
||||||
msgexists = True
|
msgexists = True
|
||||||
|
|
||||||
if msgexists is not True:
|
if msgexists is not True:
|
||||||
|
@ -489,9 +487,12 @@ def resend_email(config, count, fromcall):
|
||||||
str(m).zfill(2),
|
str(m).zfill(2),
|
||||||
str(s).zfill(2),
|
str(s).zfill(2),
|
||||||
)
|
)
|
||||||
# messaging.send_message(fromcall, reply)
|
pkt = packets.MessagePacket(
|
||||||
msg = messaging.TextMessage(config["aprs"]["login"], fromcall, reply)
|
from_call=config["aprsd"]["callsign"],
|
||||||
msg.send()
|
to_call=fromcall,
|
||||||
|
message_text=reply,
|
||||||
|
)
|
||||||
|
pkt.send()
|
||||||
|
|
||||||
# check email more often since we're resending one now
|
# check email more often since we're resending one now
|
||||||
EmailInfo().delay = 60
|
EmailInfo().delay = 60
|
||||||
|
@ -605,12 +606,14 @@ class APRSDEmailThread(threads.APRSDThread):
|
||||||
from_addr = shortcuts_inverted[from_addr]
|
from_addr = shortcuts_inverted[from_addr]
|
||||||
|
|
||||||
reply = "-" + from_addr + " " + body.decode(errors="ignore")
|
reply = "-" + from_addr + " " + body.decode(errors="ignore")
|
||||||
msg = messaging.TextMessage(
|
# Send the message to the registered user in the
|
||||||
self.config["aprs"]["login"],
|
# config ham.callsign
|
||||||
self.config["ham"]["callsign"],
|
pkt = packets.MessagePacket(
|
||||||
reply,
|
from_call=self.config["aprsd"]["callsign"],
|
||||||
|
to_call=self.config["ham"]["callsign"],
|
||||||
|
message_text=reply,
|
||||||
)
|
)
|
||||||
msg.send()
|
pkt.send()
|
||||||
# flag message as sent via aprs
|
# flag message as sent via aprs
|
||||||
try:
|
try:
|
||||||
server.add_flags(msgid, ["APRS"])
|
server.add_flags(msgid, ["APRS"])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aprsd import messaging, packets, plugin
|
from aprsd import packets, plugin
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
@ -34,20 +34,21 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
|
||||||
wl.max_delta(),
|
wl.max_delta(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
packet_type = packet.packet_type
|
packet_type = packet.__class__.__name__
|
||||||
# we shouldn't notify the alert user that they are online.
|
# we shouldn't notify the alert user that they are online.
|
||||||
if fromcall != notify_callsign:
|
if fromcall != notify_callsign:
|
||||||
msg = messaging.TextMessage(
|
pkt = packets.MessagePacket(
|
||||||
self.config["aprs"]["login"],
|
from_call=self.config["aprsd"]["callsign"],
|
||||||
notify_callsign,
|
to_call=notify_callsign,
|
||||||
f"{fromcall} was just seen by type:'{packet_type}'",
|
message_text=(
|
||||||
# We don't need to keep this around if it doesn't go thru
|
f"{fromcall} was just seen by type:'{packet_type}'"
|
||||||
allow_delay=False,
|
),
|
||||||
|
_allow_delay=False,
|
||||||
)
|
)
|
||||||
return msg
|
return pkt
|
||||||
else:
|
else:
|
||||||
LOG.debug("fromcall and notify_callsign are the same, not notifying")
|
LOG.debug("fromcall and notify_callsign are the same, not notifying")
|
||||||
return messaging.NULL_MESSAGE
|
return packets.NULL_MESSAGE
|
||||||
else:
|
else:
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
"Not old enough to notify on callsign '{}' : {} < {}".format(
|
"Not old enough to notify on callsign '{}' : {} < {}".format(
|
||||||
|
@ -56,4 +57,4 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
|
||||||
wl.max_delta(),
|
wl.max_delta(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return messaging.NULL_MESSAGE
|
return packets.NULL_MESSAGE
|
||||||
|
|
|
@ -2,7 +2,8 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from aprsd import messaging, packets, plugin
|
from aprsd import packets, plugin
|
||||||
|
from aprsd.packets import tracker
|
||||||
from aprsd.utils import trace
|
from aprsd.utils import trace
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,10 +25,10 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
message = packet.get("message_text", None)
|
message = packet.get("message_text", None)
|
||||||
# ack = packet.get("msgNo", "0")
|
# ack = packet.get("msgNo", "0")
|
||||||
|
|
||||||
tracker = messaging.MsgTrack()
|
pkt_tracker = tracker.PacketTrack()
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
reply = "Pending messages ({}) {}".format(
|
reply = "Pending messages ({}) {}".format(
|
||||||
len(tracker),
|
len(pkt_tracker),
|
||||||
now.strftime("%H:%M:%S"),
|
now.strftime("%H:%M:%S"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,11 +39,11 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
# resend last N most recent: "!3"
|
# resend last N most recent: "!3"
|
||||||
r = re.search(r"^\!([0-9]).*", message)
|
r = re.search(r"^\!([0-9]).*", message)
|
||||||
if r is not None:
|
if r is not None:
|
||||||
if len(tracker) > 0:
|
if len(pkt_tracker) > 0:
|
||||||
last_n = r.group(1)
|
last_n = r.group(1)
|
||||||
reply = messaging.NULL_MESSAGE
|
reply = packets.NULL_MESSAGE
|
||||||
LOG.debug(reply)
|
LOG.debug(reply)
|
||||||
tracker.restart_delayed(count=int(last_n))
|
pkt_tracker.restart_delayed(count=int(last_n))
|
||||||
else:
|
else:
|
||||||
reply = "No pending msgs to resend"
|
reply = "No pending msgs to resend"
|
||||||
LOG.debug(reply)
|
LOG.debug(reply)
|
||||||
|
@ -51,10 +52,10 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
# resend all: "!a"
|
# resend all: "!a"
|
||||||
r = re.search(r"^\![aA].*", message)
|
r = re.search(r"^\![aA].*", message)
|
||||||
if r is not None:
|
if r is not None:
|
||||||
if len(tracker) > 0:
|
if len(pkt_tracker) > 0:
|
||||||
reply = messaging.NULL_MESSAGE
|
reply = packets.NULL_MESSAGE
|
||||||
LOG.debug(reply)
|
LOG.debug(reply)
|
||||||
tracker.restart_delayed()
|
pkt_tracker.restart_delayed()
|
||||||
else:
|
else:
|
||||||
reply = "No pending msgs"
|
reply = "No pending msgs"
|
||||||
LOG.debug(reply)
|
LOG.debug(reply)
|
||||||
|
@ -65,7 +66,7 @@ class QueryPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
if r is not None:
|
if r is not None:
|
||||||
reply = "Deleted ALL pending msgs."
|
reply = "Deleted ALL pending msgs."
|
||||||
LOG.debug(reply)
|
LOG.debug(reply)
|
||||||
tracker.flush()
|
pkt_tracker.flush()
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
|
|
|
@ -4,7 +4,7 @@ import time
|
||||||
|
|
||||||
import aprslib
|
import aprslib
|
||||||
|
|
||||||
from aprsd import client, messaging, packets, plugin, stats
|
from aprsd import client, packets, plugin, stats
|
||||||
from aprsd.threads import APRSDThread
|
from aprsd.threads import APRSDThread
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,6 @@ class APRSDPluginRXThread(APRSDRXThread):
|
||||||
def process_packet(self, *args, **kwargs):
|
def process_packet(self, *args, **kwargs):
|
||||||
packet = self._client.decode_packet(*args, **kwargs)
|
packet = self._client.decode_packet(*args, **kwargs)
|
||||||
# LOG.debug(raw)
|
# LOG.debug(raw)
|
||||||
#packet = packets.Packet.factory(raw.copy())
|
|
||||||
packet.log(header="RX Packet")
|
packet.log(header="RX Packet")
|
||||||
thread = APRSDPluginProcessPacketThread(
|
thread = APRSDPluginProcessPacketThread(
|
||||||
config=self.config,
|
config=self.config,
|
||||||
|
@ -186,7 +185,7 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread):
|
||||||
replied = True
|
replied = True
|
||||||
for subreply in reply:
|
for subreply in reply:
|
||||||
LOG.debug(f"Sending '{subreply}'")
|
LOG.debug(f"Sending '{subreply}'")
|
||||||
if isinstance(subreply, messaging.Message):
|
if isinstance(subreply, packets.Packet):
|
||||||
subreply.send()
|
subreply.send()
|
||||||
else:
|
else:
|
||||||
msg_pkt = packets.MessagePacket(
|
msg_pkt = packets.MessagePacket(
|
||||||
|
@ -195,23 +194,9 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread):
|
||||||
message_text=subreply,
|
message_text=subreply,
|
||||||
)
|
)
|
||||||
msg_pkt.send()
|
msg_pkt.send()
|
||||||
#msg = messaging.TextMessage(
|
elif isinstance(reply, packets.Packet):
|
||||||
# self.config["aprsd"]["callsign"],
|
|
||||||
# from_call,
|
|
||||||
# subreply,
|
|
||||||
#)
|
|
||||||
#msg.send()
|
|
||||||
elif isinstance(reply, messaging.Message):
|
|
||||||
# We have a message based object.
|
# We have a message based object.
|
||||||
LOG.debug(f"Sending '{reply}'")
|
reply.send()
|
||||||
# Convert this to the new packet
|
|
||||||
msg_pkt = packets.MessagePacket(
|
|
||||||
from_call=reply.fromcall,
|
|
||||||
to_call=reply.tocall,
|
|
||||||
message_text=reply._raw_message,
|
|
||||||
)
|
|
||||||
#reply.send()
|
|
||||||
msg_pkt.send()
|
|
||||||
replied = True
|
replied = True
|
||||||
else:
|
else:
|
||||||
replied = True
|
replied = True
|
||||||
|
@ -219,7 +204,7 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread):
|
||||||
# us that they processed the message correctly, but have
|
# us that they processed the message correctly, but have
|
||||||
# nothing to reply with, so we avoid replying with a
|
# nothing to reply with, so we avoid replying with a
|
||||||
# usage string
|
# usage string
|
||||||
if reply is not messaging.NULL_MESSAGE:
|
if reply is not packets.NULL_MESSAGE:
|
||||||
LOG.debug(f"Sending '{reply}'")
|
LOG.debug(f"Sending '{reply}'")
|
||||||
msg_pkt = packets.MessagePacket(
|
msg_pkt = packets.MessagePacket(
|
||||||
from_call=self.config["aprsd"]["callsign"],
|
from_call=self.config["aprsd"]["callsign"],
|
||||||
|
@ -230,13 +215,6 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread):
|
||||||
msg_pkt.send()
|
msg_pkt.send()
|
||||||
LOG.warning("Calling msg_pkg.send() --- DONE")
|
LOG.warning("Calling msg_pkg.send() --- DONE")
|
||||||
|
|
||||||
#msg = messaging.TextMessage(
|
|
||||||
# self.config["aprsd"]["callsign"],
|
|
||||||
# from_call,
|
|
||||||
# reply,
|
|
||||||
#)
|
|
||||||
#msg.send()
|
|
||||||
|
|
||||||
# If the message was for us and we didn't have a
|
# If the message was for us and we didn't have a
|
||||||
# response, then we send a usage statement.
|
# response, then we send a usage statement.
|
||||||
if to_call == self.config["aprsd"]["callsign"] and not replied:
|
if to_call == self.config["aprsd"]["callsign"] and not replied:
|
||||||
|
@ -247,12 +225,6 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread):
|
||||||
message_text="Unknown command! Send 'help' message for help",
|
message_text="Unknown command! Send 'help' message for help",
|
||||||
)
|
)
|
||||||
msg_pkt.send()
|
msg_pkt.send()
|
||||||
#msg = messaging.TextMessage(
|
|
||||||
# self.config["aprsd"]["callsign"],
|
|
||||||
# from_call,
|
|
||||||
# "Unknown command! Send 'help' message for help",
|
|
||||||
#)
|
|
||||||
#msg.send()
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error("Plugin failed!!!")
|
LOG.error("Plugin failed!!!")
|
||||||
LOG.exception(ex)
|
LOG.exception(ex)
|
||||||
|
@ -265,11 +237,5 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread):
|
||||||
message_text=reply,
|
message_text=reply,
|
||||||
)
|
)
|
||||||
msg_pkt.send()
|
msg_pkt.send()
|
||||||
#msg = messaging.TextMessage(
|
|
||||||
# self.config["aprsd"]["callsign"],
|
|
||||||
# from_call,
|
|
||||||
# reply,
|
|
||||||
#)
|
|
||||||
#msg.send()
|
|
||||||
|
|
||||||
LOG.debug("Completed process_our_message_packet")
|
LOG.debug("Completed process_our_message_packet")
|
||||||
|
|
Loading…
Reference in New Issue