-
Notifications
You must be signed in to change notification settings - Fork 395
Open
Description
Currently, path entries use a fixed 1-byte hash size. This can be extended to support 2-byte hashes by encoding the segment size in the upper 2 bits of path_len.
Proposal
You have 1 byte (8 bits = 256 possible states) for path_len. Encode:
- Lower 6 bits (0-63): Number of path entries (hops)
- Upper 2 bits: Path segment size selector
| Upper 2 bits | Segment Size | Max Hops | Total Path Bytes |
|---|---|---|---|
0b00 (0) |
1 byte | 64 | 64 |
0b01 (1) |
2 bytes | 32 | 64 |
0b10 (2) |
reserved/future | varies | varies |
0b11 (3) |
extension | - | - |
Extension Mechanism
To achieve full 64-byte path capacity, 0b11 indicates extension mode:
Extension Encoding:
0b11000001→ 1-byte segments, 64 hops (63 base + 1 extension)0b11010001→ 2-byte segments, 32 hops (31 base + 1 extension)
When upper bits = 0b11:
- Bits 5-4: Segment type (00=1byte, 01=2byte, 10=reserved)
- Bits 3-0: Extension amount (add to max base value)
Implementation
1. Encoding (Packet.cpp)
uint8_t seg_code = ...; // 0=1byte, 1=2byte
uint8_t hop_count = ...;
uint8_t max_base = (seg_code == 0) ? 63 : 31;
if (hop_count <= max_base) {
// Standard encoding
path_len = (seg_code << 6) | hop_count;
} else {
// Extension encoding for max hops
uint8_t extension = hop_count - max_base;
path_len = (0b11 << 6) | (seg_code << 4) | extension;
}2. Decoding - Extract both values:
uint8_t path_byte = src[i++];
uint8_t upper = (path_byte >> 6) & 0x03;
if (upper != 0b11) {
// Standard encoding
seg_code = upper;
hop_count = path_byte & 0x3F;
} else {
// Extension mode
seg_code = (path_byte >> 4) & 0x03;
uint8_t extension = path_byte & 0x0F;
uint8_t max_base = (seg_code == 0) ? 63 : 31;
hop_count = max_base + extension;
}
seg_size = (1 << seg_code); // 1 or 2 bytes
path_len = hop_count * seg_size;3. Update PATH_HASH_SIZE
Make it variable based on packet version.
4. Update Path Operations
All path operations in Mesh.cpp that use PATH_HASH_SIZE need to be segment-size-aware.
Benefits
- Better collision resistance: 2-byte hashes reduce collisions significantly
- Privacy vs. traceability controls: Each packet can be sent at any size, offering either maximum privacy or maximum traceability
- Future-proof: Can support larger node networks
Challenges
- Backward compatibility: Old firmware won't understand the new encoding - requires a new packet version and a phased rollout strategy
- Code complexity: Every place that manipulates paths needs to understand variable segment sizes
446564, nonononoodle, entr0p1 and andrew-dsevenbitbyte and mepholicnonononoodle and IoTThinks
Metadata
Metadata
Assignees
Labels
No labels