mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-10-23 14:22:22 +00:00
Enhance TRACE payload handling and path extraction in message processing
- Updated `update_mesh_graph_from_trace_data` to clarify the format of `path_hashes` as per-hop hash strings from the trace payload. - Modified `MessageHandler` to differentiate between TRACE packets and regular transmissions, preventing incorrect extraction of repeater prefixes from RF path bytes. - Introduced `parse_trace_payload_route_hashes` utility to extract TRACE route hash segments from payloads, ensuring accurate handling of path data. - Enhanced `PacketCaptureService` to correctly populate packet information for TRACE packets, including SNR path and route hashes. - Expanded test coverage for TRACE payload decoding and path extraction to validate functionality and correctness. These changes improve the accuracy and reliability of TRACE data processing in the application.
This commit is contained in:
1 parent
6a7a79af3c
commit
f3e667e64f
7 files changed
+247
-76
No files matched your search
@@ -416,6 +416,39 @@ def decode_path_len_byte(path_len_byte: int, max_path_size: int = 64) -> tuple:
|
||||
return (path_byte_length, bytes_per_hop)
|
||||
|
||||
|
||||
def parse_trace_payload_route_hashes(payload: bytes) -> list[str]:
|
||||
"""Extract TRACE route hash segments from mesh payload (after tag, auth, flags).
|
||||
|
||||
Matches MeshCore: ``bytes_per_hash = 1 << (flags & 3)`` for bytes at ``payload[9:]``.
|
||||
If the tail length is not a multiple of ``bytes_per_hash``, falls back to 1-byte
|
||||
segments (same as MessageHandler._process_packet_path).
|
||||
|
||||
Args:
|
||||
payload: Full mesh payload bytes (not including header/path).
|
||||
|
||||
Returns:
|
||||
List of uppercase hex strings, one per hop hash.
|
||||
"""
|
||||
if len(payload) < 9:
|
||||
return []
|
||||
flags = payload[8]
|
||||
path_hash_len = 1 << (flags & 3)
|
||||
if path_hash_len <= 0:
|
||||
path_hash_len = 1
|
||||
path_hashes_bytes = payload[9:]
|
||||
if not path_hashes_bytes:
|
||||
return []
|
||||
try:
|
||||
if len(path_hashes_bytes) % path_hash_len == 0:
|
||||
return [
|
||||
path_hashes_bytes[i : i + path_hash_len].hex().upper()
|
||||
for i in range(0, len(path_hashes_bytes), path_hash_len)
|
||||
]
|
||||
except Exception:
|
||||
pass
|
||||
return [f"{b:02X}" for b in path_hashes_bytes]
|
||||
|
||||
|
||||
def encode_path_len_byte(hop_count: int, bytes_per_hop: int) -> int:
|
||||
"""Pack hop count and hash size into the single path_len wire byte (inverse of decode_path_len_byte).
|
||||
|
||||
|
||||
Reference in new issue
Block a user