Don't forward unparseable packets to community endpoints. Closes #255.

This commit is contained in:
Jack Kingsman
2026-05-13 16:43:33 -07:00
parent baca8b5234
commit 79c8b45d89
3 changed files with 31 additions and 20 deletions
+9 -2
View File
@@ -167,13 +167,20 @@ def _decode_packet_fields(raw_bytes: bytes) -> tuple[str, str, str, list[str], i
return route, packet_type, payload_len, path_values, payload_type
def _format_raw_packet(data: dict[str, Any], device_name: str, public_key_hex: str) -> dict:
"""Convert a RawPacketBroadcast dict to meshcore-packet-capture format."""
def _format_raw_packet(data: dict[str, Any], device_name: str, public_key_hex: str) -> dict | None:
"""Convert a RawPacketBroadcast dict to meshcore-packet-capture format.
Returns ``None`` when the packet cannot be decoded — callers should skip
publishing rather than forwarding malformed data.
"""
raw_hex = data.get("data", "")
raw_bytes = bytes.fromhex(raw_hex) if raw_hex else b""
route, packet_type, payload_len, path_values, _payload_type = _decode_packet_fields(raw_bytes)
if route == "U":
return None
# Reference format uses local "now" timestamp and derived time/date fields.
current_time = datetime.now()
ts_str = current_time.isoformat()
+2
View File
@@ -130,6 +130,8 @@ async def _publish_community_packet(
device_name = radio_manager.meshcore.self_info.get("name", "")
packet = _format_raw_packet(data, device_name, pubkey_hex)
if packet is None:
return
iata = config.get("iata", "").upper().strip()
if not _IATA_RE.fullmatch(iata):
logger.debug("Community MQTT: skipping publish — no valid IATA code configured")