Add transport key to packet and utilities for mesh packet calcs#16
Add transport key to packet and utilities for mesh packet calcs#16
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds transport key functionality to the mesh packet system, enabling packet authentication using region-based transport codes. The implementation matches the C++ MeshCore firmware protocol, ensuring cross-platform compatibility.
Key Changes:
- Introduced transport key generation and transport code calculation utilities
- Extended packet structure to support optional 4-byte transport code fields for TRANSPORT_FLOOD and TRANSPORT_DIRECT route types
- Added helper methods to identify packet routing characteristics
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/pymc_core/protocol/transport_keys.py | New module providing get_auto_key_for() to generate 128-bit keys from region names and calc_transport_code() to compute HMAC-based transport codes for packet authentication |
| src/pymc_core/protocol/packet.py | Extended Packet class with transport_codes attribute, updated serialization/deserialization to conditionally include 4-byte transport codes, added routing helper methods (has_transport_codes(), is_route_flood(), is_route_direct()), and updated documentation to reflect transport code support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return key_hash[:16] # First 16 bytes (128 bits) | ||
|
|
||
|
|
||
| def calc_transport_code(key: bytes, packet) -> int: |
There was a problem hiding this comment.
The packet parameter is missing a type annotation. Based on usage in the function body (calling packet.get_payload_type() and packet.get_payload()), it should be typed as Packet from the .packet module. This would improve type safety and IDE support.
Suggestion: Add type annotation like packet: "Packet" or import Packet and use packet: Packet.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Add transport codes to the packet class and new functions to work out transport code with packet data.