mirror of
https://github.com/craigerl/aprsd.git
synced 2025-07-25 18:12:28 -04:00
Fixed issue with packet object and prepare()
If any part of the code had a packet object and called prepare() on it, it would create a msgNo if it wasn't set. Sometimes we get packets on the wire/RF that don't have a msgNo, so adding one locally is wrong. We should ONLY create a msgNo on a packet that is destined for transmission. This patch ensures that even if prepare() is called, that only packets that are created locally for TX get a msgNo unless it already exists from RX'd packets.
This commit is contained in:
parent
3a8b8f26dd
commit
f66b96288f
@ -12,7 +12,7 @@ from dataclasses_json import (
|
|||||||
)
|
)
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from aprsd.utils import counter
|
from aprsd.utils import counter, trace
|
||||||
|
|
||||||
|
|
||||||
# For mypy to be happy
|
# For mypy to be happy
|
||||||
@ -127,10 +127,11 @@ class Packet:
|
|||||||
msg = self._filter_for_send(self.raw).rstrip("\n")
|
msg = self._filter_for_send(self.raw).rstrip("\n")
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def prepare(self) -> None:
|
@trace.trace
|
||||||
|
def prepare(self, create_msg_number=False) -> None:
|
||||||
"""Do stuff here that is needed prior to sending over the air."""
|
"""Do stuff here that is needed prior to sending over the air."""
|
||||||
# now build the raw message for sending
|
# now build the raw message for sending
|
||||||
if not self.msgNo:
|
if not self.msgNo and create_msg_number:
|
||||||
self.msgNo = _init_msgNo()
|
self.msgNo = _init_msgNo()
|
||||||
self._build_payload()
|
self._build_payload()
|
||||||
self._build_raw()
|
self._build_raw()
|
||||||
@ -244,11 +245,17 @@ class MessagePacket(Packet):
|
|||||||
return self._filter_for_send(self.message_text).rstrip("\n")
|
return self._filter_for_send(self.message_text).rstrip("\n")
|
||||||
|
|
||||||
def _build_payload(self):
|
def _build_payload(self):
|
||||||
self.payload = ":{}:{}{{{}".format(
|
if self.msgNo:
|
||||||
self.to_call.ljust(9),
|
self.payload = ":{}:{}{{{}".format(
|
||||||
self._filter_for_send(self.message_text).rstrip("\n"),
|
self.to_call.ljust(9),
|
||||||
str(self.msgNo),
|
self._filter_for_send(self.message_text).rstrip("\n"),
|
||||||
)
|
str(self.msgNo),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.payload = ":{}:{}".format(
|
||||||
|
self.to_call.ljust(9),
|
||||||
|
self._filter_for_send(self.message_text).rstrip("\n"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
|
@ -48,7 +48,7 @@ def send(packet: core.Packet, direct=False, aprs_client=None):
|
|||||||
"""Send a packet either in a thread or directly to the client."""
|
"""Send a packet either in a thread or directly to the client."""
|
||||||
# prepare the packet for sending.
|
# prepare the packet for sending.
|
||||||
# This constructs the packet.raw
|
# This constructs the packet.raw
|
||||||
packet.prepare()
|
packet.prepare(create_msg_number=True)
|
||||||
# Have to call the collector to track the packet
|
# Have to call the collector to track the packet
|
||||||
# After prepare, as prepare assigns the msgNo
|
# After prepare, as prepare assigns the msgNo
|
||||||
collector.PacketCollector().tx(packet)
|
collector.PacketCollector().tx(packet)
|
||||||
|
@ -61,7 +61,7 @@ class TestAPRSISClient(unittest.TestCase):
|
|||||||
"connected": True,
|
"connected": True,
|
||||||
"filter": "m/50",
|
"filter": "m/50",
|
||||||
"login_status": {"message": mock.ANY, "success": True},
|
"login_status": {"message": mock.ANY, "success": True},
|
||||||
"server_keepalive": mock_client.aprsd_keepalive,
|
"connection_keepalive": mock_client.aprsd_keepalive,
|
||||||
"server_string": mock_client.server_string,
|
"server_string": mock_client.server_string,
|
||||||
"transport": "aprsis",
|
"transport": "aprsis",
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,7 @@ import flask_socketio
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import conf # noqa: F401
|
from aprsd import conf # noqa: F401
|
||||||
|
from aprsd.client import fake as fake_client
|
||||||
from aprsd.cmds import webchat # noqa
|
from aprsd.cmds import webchat # noqa
|
||||||
from aprsd.packets import core
|
from aprsd.packets import core
|
||||||
|
|
||||||
@ -64,11 +65,13 @@ class TestSendMessageCommand(unittest.TestCase):
|
|||||||
@mock.patch("aprsd.threads.tx.send")
|
@mock.patch("aprsd.threads.tx.send")
|
||||||
@mock.patch("aprsd.packets.PacketList.rx")
|
@mock.patch("aprsd.packets.PacketList.rx")
|
||||||
@mock.patch("aprsd.cmds.webchat.socketio")
|
@mock.patch("aprsd.cmds.webchat.socketio")
|
||||||
|
@mock.patch("aprsd.client.factory.ClientFactory.create")
|
||||||
def test_process_our_message_packet(
|
def test_process_our_message_packet(
|
||||||
self,
|
self,
|
||||||
mock_tx_send,
|
mock_tx_send,
|
||||||
mock_packet_add,
|
mock_packet_add,
|
||||||
mock_socketio,
|
mock_socketio,
|
||||||
|
mock_factory,
|
||||||
):
|
):
|
||||||
self.config_and_init()
|
self.config_and_init()
|
||||||
mock_socketio.emit = mock.MagicMock()
|
mock_socketio.emit = mock.MagicMock()
|
||||||
@ -77,6 +80,7 @@ class TestSendMessageCommand(unittest.TestCase):
|
|||||||
msg_number=1,
|
msg_number=1,
|
||||||
message_format=core.PACKET_TYPE_MESSAGE,
|
message_format=core.PACKET_TYPE_MESSAGE,
|
||||||
)
|
)
|
||||||
|
mock_factory.return_value = fake_client.APRSDFakeClient()
|
||||||
mock_queue = mock.MagicMock()
|
mock_queue = mock.MagicMock()
|
||||||
socketio = mock.MagicMock()
|
socketio = mock.MagicMock()
|
||||||
wcp = webchat.WebChatProcessPacketThread(mock_queue, socketio)
|
wcp = webchat.WebChatProcessPacketThread(mock_queue, socketio)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user