Repository navigation
Protocol
sputlab edited this page Nov 13, 2026
·
1 revision
The authoritative definitions are in app/src/main/java/com/nodewave/mesh/protocol/Packet.kt and the neighbouring files. This page summarises them (wire format v4).
[version u8][type u8][ttl u8][hops u8][senderId 8B][destId 8B][messageId i32][payload ...]
-
senderIdis the original author and never changes while relayed. -
ttl(default 5) is decremented andhopsincremented by each relay, so they are not authenticated. -
(senderId, messageId)identifies a packet network-wide (dedupe key). - Every other header field is bound into the AES-GCM tag as AAD.
| Code | Type | Content |
|---|---|---|
| 1 | MESSAGE |
sealed chat text (max 180 bytes of text) |
| 2 | PING |
sealed ping text |
| 3 | ACK |
sealed message id being acknowledged |
| 4 | HELLO |
one-hop neighbour announcement, sealed, never forwarded |
| 5 | KEY |
signed ephemeral key exchange (handshake), routed like a message |
| 6 | GROUP |
group message, invitation, member update or leave, sealed |
| 7 | POSITION |
sealed position (lat, lon, accuracy, time: 14 bytes) |
| 8 | DATA |
one sealed chunk of a bulk transfer (voice clip, photo) |
| 9 | DATA_ACK |
receiver's sealed bitmap of chunks held |
| 10 | DATA_REFUSE |
relay tells the author it cannot forward a transfer (unauthenticated) |
| 11 | LINK |
sealed fast-link (Wi-Fi Direct) negotiation |
payload = sid(4) | nonce(12) | ciphertext | tag(16), with a fresh random nonce per message. AAD: version, type, senderId, destId, messageId plus the session id. See Security.
Node ID = first 8 bytes of SHA-256 of the P-256 identity public key, shown as 16 lowercase hex characters (the UI groups them by four).
- Each node announces its neighbours in a sealed HELLO (every ~60 s plus jitter, and shortly after a change). HELLOs carry an increasing sequence number against replay.
-
RoutingTablelearns routes from neighbours' HELLOs; a route expires after 150 s. -
Routerchooses: direct link, else known route, else flood. A node already seen is not forwarded again (seen-cache, 1024 entries).
- A message awaiting an ACK is resent after 10 s, at most 2 times.
- ACKs are sent twice with a short delay.
- A handshake
KEYis attempted 3 times with a 5 s timeout, rate limited in the background. - A reply is sent back on the link the request arrived on when possible.
- A transfer is cut into
DATAchunks sized for the slowest link class on the path:SLOW240 B,MEDIUM(BLE) 244 B,FAST(Wi-Fi Direct) 1400 B. - The receiver periodically returns a sealed
DATA_ACKbitmap; the sender resends the missing chunks. A chunk whose send fails is retried at once (3 times, growing pause); the transfer gives up after six passes without progress. - The link class byte is sealed with the chunk. A relay refuses a transfer its next link cannot carry (
DATA_REFUSE). - The receiver caps the number, size and age of transfers it assembles (
TransferAssembler).
- Bluetooth finds the peer; a big transfer asks for a fast link.
- One phone creates a Wi-Fi Direct group (random name
DIRECT-NW-xxxxand passphrase) and sends the sealed offer (name, passphrase, port) in aLINKpacket. - The receiver, if its who may start a link setting allows the sender, joins and connects over TCP.
- The TCP stream carries the same sealed packets as any radio. The link class becomes
FAST. - It closes after 40 s without traffic.
nodewave://c/1/<public key>/<name>: the full P-256 public key and the display name.