Skip to main content

Module relay

Module relay 

Source
Expand description

Multi-hop relay support for Peat BLE mesh

This module provides message deduplication and hop tracking for multi-hop relay scenarios. Without deduplication, messages would bounce infinitely between mesh nodes.

§Wire Format

Relay envelope wraps documents for multi-hop transmission:

[1 byte:  marker (0xB1)]
[1 byte:  flags]
  - bit 0: requires_ack
  - bit 1: is_broadcast
  - bits 2-7: reserved
[16 bytes: message_id (UUID)]
[1 byte:  hop_count (current)]
[1 byte:  max_hops (TTL)]
[4 bytes: origin_node_id]
[4 bytes: payload_len]
[N bytes: payload (encrypted document)]

§Deduplication

The SeenMessageCache tracks message IDs with TTL expiration to prevent infinite relay loops while allowing legitimate re-transmissions after the TTL expires.

Structs§

MessageId
A 128-bit message identifier for deduplication
RelayEnvelope
A relay envelope wrapping a document for multi-hop transmission
RelayFlags
Relay envelope flags
SeenMessageCache
Cache of seen message IDs for deduplication

Constants§

DEFAULT_MAX_HOPS
Default max hops for relay messages
DEFAULT_SEEN_TTL_MS
Default TTL for seen messages (5 minutes in ms)
MAX_CACHE_SIZE
Maximum cache size before cleanup is forced
RELAY_ENVELOPE_MARKER
Marker byte indicating relay envelope