@@ -49,9 +49,11 @@ the request.
49
49
50
50
## Packet Encoding
51
51
52
- The protocol deals with three distinct kinds of packets:
52
+ The protocol deals with four distinct kinds of packets:
53
53
54
54
- Ordinary message packets, which carry an encrypted/authenticated message.
55
+ - Session message packets. These are identical to an ordinary message packets, but cannot
56
+ trigger a handshake.
55
57
- WHOAREYOU packets, which are sent when the recipient of an ordinary message packet
56
58
cannot decrypt/authenticate the packet's message.
57
59
- Handshake message packets, which are sent following WHOAREYOU. These packets establish a
@@ -115,6 +117,15 @@ For message packets, the `authdata` section is just the source node ID.
115
117
116
118
![ message packet layout] ( ./img/message-packet-layout.png )
117
119
120
+ ### Session Message Packet (` flag = 3 ` )
121
+
122
+ The structure of this type is identical to an [ ordinary message packet] , apart from the
123
+ different ` flag ` value.
124
+
125
+ Session packets are used to send a message that assumes an existing session. When a packet
126
+ with this flag value is received and cannot be decrypted, the packet should be dropped,
127
+ and not trigger a WHOAREYOU response.
128
+
118
129
### WHOAREYOU Packet (` flag = 1 ` )
119
130
120
131
In WHOAREYOU packets, the ` authdata ` section contains information for the identity
@@ -153,15 +164,25 @@ handshake packet.
153
164
154
165
![ handshake packet layout] ( ./img/handshake-packet-layout.png )
155
166
156
- ## Protocol Messages
167
+ ## Messages
168
+
169
+ Messages are the payloads of packets. A message is identified by its ` message-type ` and
170
+ contain ` message-data ` specific to each type.
157
171
158
- This section lists all defined messages which can be sent and received. The hexadecimal
159
- value in parentheses is the ` message-type ` .
172
+ There are three classes of messages:
160
173
161
- The first element of every ` message-data ` list is the request ID. ` request-id ` is an RLP
162
- byte array of length <= 8 bytes. For requests, this value is assigned by the requester.
163
- The recipient of a message must mirror the value in the ` request-id ` element of the
164
- response. The selection of appropriate values for request IDs is left to the implementation.
174
+ - * Request* messages are sent as a [ message packet] or [ handshake message packet] .
175
+ - * Responses* are the answers to requests, and are sent using a [ session message packet] .
176
+ - * Notifications* do not require a response, They are also sent as a [ session message packet] .
177
+
178
+ For request and response messages, the first element of every ` message-data ` list is the
179
+ request ID. ` request-id ` is an RLP byte array of length <= 8 bytes. For requests, this
180
+ value is assigned by the requester. The recipient of a message must mirror the value in
181
+ the ` request-id ` element of the response. The selection of appropriate values for request
182
+ IDs is left to the implementation.
183
+
184
+ All defined protocol messages are listed below. The hexadecimal value in parentheses is
185
+ the ` message-type ` .
165
186
166
187
### PING Request (0x01)
167
188
@@ -231,11 +252,39 @@ containing empty `response` data.
231
252
TALKRESP is the response to TALKREQ. The ` response ` is a RLP byte array containing the
232
253
response data.
233
254
255
+ ### RELAYINIT Notification (0x07)
256
+
257
+ message-data = [initiator-enr, target-id, nonce]
258
+ notification-type = 0x07
259
+ target-id = 256-bit node ID of target
260
+ nonce = uint96 -- nonce of timed out request
261
+
262
+ RELAYINIT is a notification sent from the initiator of a hole punch attempt to a relay.
263
+ The sender sets the ` initiator-enr ` to its own ENR.
264
+
265
+ The relay looks up the ENR of ` target-id ` in its node table, and if it exists relays the
266
+ ` initiator-enr ` and ` nonce ` to the target in a RELAYMSG notification.
267
+
268
+ ### RELAYMSG Notification (0x08)
269
+
270
+ message-data = [initiator-enr, nonce]
271
+ notification-type = 0x08
272
+ nonce = uint96 -- nonce of timed out request
273
+
274
+ RELAYMSG is a notification from the relay in a hole punch attempt to the target. The
275
+ receiver sends the ` nonce ` back to the initiator in a [ WHOAREYOU packet] using the
276
+ ` initiator-enr ` to address it.
277
+
234
278
## Test Vectors
235
279
236
280
A collection of test vectors for this specification can be found at
237
281
[ discv5 wire test vectors] .
238
282
283
+ [ ordinary message packet ] : #ordinary-message-packet-flag--0
284
+ [ message packet ] : #ordinary-message-packet-flag--0
285
+ [ WHOAREYOU packet ] : #whoareyou-packet-flag--1
286
+ [ handshake message packet ] : #handshake-message-packet-flag--2
287
+ [ session message packet ] : #session-message-packet-flag--3
239
288
[ handshake section ] : ./discv5-theory.md#handshake-steps
240
289
[ EIP-778 ] : ../enr.md
241
290
[ discv5 wire test vectors ] : ./discv5-wire-test-vectors.md
0 commit comments