You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: datagrams/datagrams.md
+50-22Lines changed: 50 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,46 +22,74 @@ and spec status.
22
22
23
23
-[Introduction](#introduction)
24
24
-[Native support at the transport level](#native-support-at-the-transport-level)
25
-
-[Encoding Datagrams](#encoding-datagrams)
25
+
-[Datagrams on QUIC](#datagrams-on-quic)
26
+
-[Encoding](#encoding)
27
+
-[Datagrams on WebTransport](#datagrams-on-webtransport)
26
28
-[Datagrams on top of a multiplexed stream on top of TCP](#datagrams-on-top-of-a-multiplexed-stream-on-top-of-tcp)
27
29
-[Datagrams with WebRTC](#datagrams-with-webrtc)
28
30
29
31
## Introduction
30
32
31
-
This specification defines the datagrams on libp2p, which enable the
32
-
transmission of MTU-sized, unreliable, and low latency messages between peers.
33
+
This specification defines libp2p datagrams, which enable the transmission of
34
+
MTU-sized, unreliable, and low latency messages between peers.
33
35
34
36
TODO write more about the tradeoffs here as well as the kinds of applications that would benefit from using datagrams.
35
37
36
38
## Native support at the transport level
37
39
38
-
Some libp2p transports natively support datagrams, such as QUIC and WebTransport. libp2p implementations MUST use the native datagram support to send datagrams.
40
+
Some libp2p transports natively support datagrams, such as QUIC and
41
+
WebTransport. libp2p implementations MUST use the native datagram support to
42
+
send datagrams.
39
43
40
-
QUIC has an Unreliable Datagram Extension [RFC 9221]
41
-
WebTransport supports Datagrams though HTTP Datagrams [WebTransport draft RFC](https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-12.html#name-datagrams)
44
+
-QUIC has an Unreliable Datagram Extension [RFC 9221].
45
+
-WebTransport supports Datagrams though HTTP Datagrams [WebTransport draft RFC](https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-12.html#name-datagrams)
42
46
43
-
## Encoding Datagrams
47
+
## Datagrams on QUIC
44
48
45
-
The libp2p datagram encoding introduces minimal framing overhead to application payloads. Each datagram MUST be encoded with the following structure to ensure proper protocol identification and version compatibility.
49
+
Each datagram flow MUST be associated with a control stream. A datagram flow is
50
+
defined as a logical flow of datagrams for a specific application protocol. A
51
+
control stream is a QUIC bidirectional stream that has negotiated the application
52
+
protocol ID. The control stream MUST stay open for the duration of the datagram
53
+
flow. Implementation MAY create the control stream and start sending datagrams
54
+
at once.
46
55
47
-
The datagram frame consists of the following components:
56
+
There is currently no other use for the control stream besides negotiating the
57
+
application protocol ID.
48
58
49
-
| Field Name | Data Type | Length (bits) | Description |
Receipt of a QUIC DATAGRAM frame whose payload is too short to allow parsing the
60
+
Control Stream ID field MUST be treated as a connection error of type
61
+
PROTOCOL_VIOLATION (0x1003).
55
62
56
-
The complete datagram frame is constructed as follows:
63
+
libp2p datagrams MUST NOT be sent unless the control stream's send side is
64
+
open. If a datagram is received after the corresponding stream's receive side is
65
+
closed, the received datagrams MUST be silently dropped.
57
66
58
-
```
59
-
version || protocol id length || protocol id || application data
60
-
```
67
+
If a libp2p datagram is received and its Control Stream ID field maps to a
68
+
stream that has not yet been created, the receiver SHALL either drop that
69
+
datagram silently or buffer it temporarily (on the order of a round trip) while
70
+
awaiting the creation of the corresponding stream.
61
71
62
-
Where "||" denotes byte concatenation.
72
+
If a libp2p datagram is received and its Control Stream ID field maps to a
73
+
stream that cannot be created due to client-initiated bidirectional stream
74
+
limits, it MUST be treated as a connection error of type PROTOCOL_VIOLATION
75
+
(0x1003).
63
76
64
-
The version field provides extensibility for future encoding modifications while maintaining backward compatibility. Implementations MUST verify the version field before processing the remainder of the datagram.
77
+
### Encoding
78
+
79
+
Each libp2p datagram SHALL be encoded with the following structure.
80
+
81
+
| Field Name | Data Type | Length (bits) | Description |
0 commit comments