Skip to content

Commit 5b1f4b0

Browse files
authored
Merge pull request #431 from mattsains/packet-structure
minor changes and fixes to docs
2 parents 5b1c7fe + 1de5753 commit 5b1f4b0

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

docs/packet_structure.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ Note: see the [payloads doc](./payloads.md) for more information about the conte
1111

1212
## Header Breakdown
1313

14+
bit 0 means the lowest bit (1s place)
15+
1416
| Bits | Mask | Field | Description |
1517
|-------|--------|-----------------|-----------------------------------------------|
1618
| 0-1 | `0x03` | Route Type | Flood, Direct, Reserved - see below. |
17-
| 2-5 | `0x0F` | Payload Type | Request, Response, ACK, etc. - see below. |
18-
| 6-7 | `0x03` | Payload Version | Versioning of the payload format - see below. |
19+
| 2-5 | `0x3C` | Payload Type | Request, Response, ACK, etc. - see below. |
20+
| 6-7 | `0xC0` | Payload Version | Versioning of the payload format - see below. |
1921

2022
## Route Type Values
2123

22-
| Value | Name | Description |
23-
|--------|------------------------|--------------------------------------|
24-
| `0x00` | `ROUTE_TYPE_RESERVED1` | Reserved for future use. |
25-
| `0x01` | `ROUTE_TYPE_FLOOD` | Flood routing mode (builds up path). |
26-
| `0x02` | `ROUTE_TYPE_DIRECT` | Direct route (path is supplied). |
27-
| `0x03` | `ROUTE_TYPE_RESERVED2` | Reserved for future use. |
24+
| Value | Name | Description |
25+
|--------|-------------------------------|--------------------------------------|
26+
| `0x00` | `ROUTE_TYPE_TRANSPORT_FLOOD` | Flood routing mode + transport codes |
27+
| `0x01` | `ROUTE_TYPE_FLOOD` | Flood routing mode (builds up path). |
28+
| `0x02` | `ROUTE_TYPE_DIRECT` | Direct route (path is supplied). |
29+
| `0x03` | `ROUTE_TYPE_TRANSPORT_DIRECT` | direct route + transport codes |
2830

2931
## Payload Type Values
3032

@@ -39,6 +41,7 @@ Note: see the [payloads doc](./payloads.md) for more information about the conte
3941
| `0x06` | `PAYLOAD_TYPE_GRP_DATA` | Group datagram (unverified). |
4042
| `0x07` | `PAYLOAD_TYPE_ANON_REQ` | Anonymous request. |
4143
| `0x08` | `PAYLOAD_TYPE_PATH` | Returned path. |
44+
| `0x09` | `PAYLOAD_TYPE_TRACE` | trace a path, collecting SNI for each hop. |
4245
| `0x0F` | `PAYLOAD_TYPE_RAW_CUSTOM` | Custom packet (raw bytes, custom encryption). |
4346

4447
## Payload Version Values

docs/payloads.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
# Meshcore payloads
22
Inside of each [meshcore packet](./packet_structure.md) is a payload, identified by the payload type in the packet header. The types of payloads are:
33

4+
* Node advertisement.
5+
* Acknowledgment.
6+
* Returned path.
47
* Request (destination/source hashes + MAC).
58
* Response to REQ or ANON_REQ.
69
* Plain text message.
7-
* Acknowledgment.
8-
* Node advertisement.
10+
* Anonymous request.
911
* Group text message (unverified).
1012
* Group datagram (unverified).
11-
* Anonymous request.
12-
* Returned path.
1313
* Custom packet (raw bytes, custom encryption).
1414

1515
This document defines the structure of each of these payload types
1616

17+
## Important concepts:
18+
19+
* Node/channel hash: the first byte of the node or channel's public key
20+
1721
# Node advertisement
1822
This kind of payload notifies receivers that a node exists, and gives information about the node
1923

2024
| Field | Size (bytes) | Description |
2125
|---------------|-----------------|----------------------------------------------------------|
22-
| public key | 32 | Ed25519 public key |
26+
| public key | 32 | Ed25519 public key of the node |
2327
| timestamp | 4 | unix timestamp of advertisement |
2428
| signature | 64 | Ed25519 signature of public key, timestamp, and app data |
2529
| appdata | rest of payload | optional, see below |
@@ -37,20 +41,29 @@ Appdata
3741

3842
Appdata Flags
3943

40-
| Value | Name | Description |
41-
|--------|-----------|---------------------------------------|
42-
| `0x10` | location | appdata contains lat/long information |
43-
| `0x20` | feature 1 | Reserved for future use. |
44-
| `0x40` | feature 2 | Reserved for future use. |
45-
| `0x80` | name | appdata contains a node name |
44+
| Value | Name | Description |
45+
|--------|----------------|---------------------------------------|
46+
| `0x01` | is chat node | advert is for a chat node |
47+
| `0x02` | is repeater | advert is for a repeater |
48+
| `0x03` | is room server | advert is for a room server |
49+
| `0x10` | has location | appdata contains lat/long information |
50+
| `0x20` | has feature 1 | Reserved for future use. |
51+
| `0x40` | has feature 2 | Reserved for future use. |
52+
| `0x80` | has name | appdata contains a node name |
4653

4754
# Acknowledgement
55+
56+
An acknowledgement that a message was received. Note that for returned path messages, an acknowledgement will be sent in the "extra" payload (see [Returned Path](#returned-path)) and not as a discrete ackowledgement. CLI commands do not require an acknowledgement, neither discrete nor extra.
57+
4858
| Field | Size (bytes) | Description |
4959
|----------|--------------|------------------------------------------------------------|
5060
| checksum | 4 | CRC checksum of message timestamp, text, and sender pubkey |
5161

5262

5363
# Returned path, request, response, and plain text message
64+
65+
Returned path, request, response, and plain text messages are all formatted in the same way. See the subsection for more details about the ciphertext's associated plaintext representation.
66+
5467
| Field | Size (bytes) | Description |
5568
|------------------|-----------------|------------------------------------------------------|
5669
| destination hash | 1 | first byte of destination node public key |
@@ -60,11 +73,13 @@ Appdata Flags
6073

6174
## Returned path
6275

76+
Returned path messages provide a description of the route a packet took from the original author. Receivers will send returned path messages to the author of the original message.
77+
6378
| Field | Size (bytes) | Description |
6479
|-------------|--------------|----------------------------------------------------------------------------------------------|
6580
| path length | 1 | length of next field |
66-
| path | see above | a list of node hashes (one byte each) describing the route from us to the packet author |
67-
| extra type | 1 | extra, bundled payload type, eg., acknowledgement or response. See packet structure spec |
81+
| path | see above | a list of node hashes (one byte each) |
82+
| extra type | 1 | extra, bundled payload type, eg., acknowledgement or response. Same values as in [packet structure](./packet_structure.md) |
6883
| extra | rest of data | extra, bundled payload content, follows same format as main content defined by this document |
6984

7085
## Request
@@ -156,18 +171,14 @@ Plaintext message
156171

157172
# Group text message / datagram
158173

159-
| Field | Size (bytes) | Description |
160-
|--------------|-----------------|------------------------------------------|
161-
| channel hash | 1 | TODO |
162-
| cipher MAC | 2 | MAC for encrypted data in next field |
163-
| ciphertext | rest of payload | encrypted message, see below for details |
174+
| Field | Size (bytes) | Description |
175+
|--------------|-----------------|--------------------------------------------|
176+
| channel hash | 1 | the first byte of the channel's public key |
177+
| cipher MAC | 2 | MAC for encrypted data in next field |
178+
| ciphertext | rest of payload | encrypted message, see below for details |
164179

165-
Plaintext for text message
180+
The plaintext contained in the ciphertext matches the format described in [plain text message](#plain-text-message). Specifically, it consists of a four byte timestamp, a flags byte, and the message. The flags byte will generally be `0x00` because it is a "plain text message". The message will be of the form `<sender name>: <message body>` (eg., `user123: I'm on my way`).
166181

167-
| Field | Size (bytes) | Description |
168-
|-----------|-----------------|----------------------------------|
169-
| timestamp | 4 | send time (unix timestamp) |
170-
| content | rest of message | plain group text message content |
171182

172183
TODO: describe what datagram looks like
173184

0 commit comments

Comments
 (0)