Skip to content

Commit 3060cd0

Browse files
committed
add some canonical error codes
1 parent 070f090 commit 3060cd0

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

error-codes/README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ Interest Group: [@marcopolo], [@achingbrain]
1313

1414
## Introduction
1515

16-
When closing a connection or resetting a stream, it's useful to provide the peer with a code that explains the reason for the closure. This enables the peer to better respond to the abrupt closures. For instance, it can implement a backoff strategy to retry _only_ when it receives a `RATE_LIMITED` error code. An error code doesn't always indicate an error condition. For example, a connection may be closed because a connection to the same peer over a better transport is available.
16+
When closing a connection or resetting a stream, it's useful to provide the peer
17+
with a code that explains the reason for the closure. This enables the peer to
18+
better respond to the abrupt closures. For instance, it can implement a backoff
19+
strategy to retry _only_ when it receives a `RATE_LIMITED` error code. An error
20+
code doesn't always indicate an error condition. For example, a connection may
21+
be closed because a connection to the same peer over a better transport is
22+
available.
1723

1824
## Semantics
1925
Error codes are unsigned 32-bit integers. The range 0 to 10000 is reserved for
@@ -42,10 +48,12 @@ Close error code on streams that are reset as a result of remote closing the
4248
connection.
4349

4450
For stream resets, when the underlying transport supports it, implementations
45-
SHOULD allow sending an error code on both closing the read side of the stream, and resetting the write side of the stream.
51+
SHOULD allow sending an error code on both closing the read side of the stream,
52+
and resetting the write side of the stream.
4653

47-
## Libp2p Error Codes
48-
TODO!
54+
## Libp2p Reserved Error Codes
55+
see [Libp2p error codes](./libp2p-error-codes.md) for the libp2p reserved error
56+
codes.
4957

5058
## Wire Encoding
5159
Different transports will encode the 32-bit error code differently.
@@ -67,18 +75,22 @@ using the Error Code field as defined in the
6775
Yamux has no `STOP_SENDING` frame, so there's no way to signal an error on
6876
closing the read side of the stream.
6977

70-
For Connection Close, the 32-bit Length field is interpreted as the error
71-
code.
78+
For Connection Close, the 32-bit Length field is interpreted as the error code.
7279

73-
For Stream Resets, the error code is sent in the `Window Update` frame, with the 32-bit Length field interpreted as the error code. See [yamux spec
80+
For Stream Resets, the error code is sent in the `Window Update` frame, with the
81+
32-bit Length field interpreted as the error code. See [yamux spec
7482
extension](https://github.com/libp2p/specs/pull/622).
7583

76-
Note: On TCP connections with `SO_LINGER` set to 0, the Connection Close error code may not be delivered.
84+
Note: On TCP connections with `SO_LINGER` set to 0, the Connection Close error
85+
code may not be delivered.
7786

7887
### WebRTC
79-
There is no way to provide any information on closing a peer connection in WebRTC. Providing error codes on Connection Close will be taken up in the future.
88+
There is no way to provide any information on closing a peer connection in
89+
WebRTC. Providing error codes on Connection Close will be taken up in the
90+
future.
8091

81-
For Stream Resets, the error code can be sent in the `errorCode` field of the WebRTC message with `flag` set to `RESET_STREAM` .
92+
For Stream Resets, the error code can be sent in the `errorCode` field of the
93+
WebRTC message with `flag` set to `RESET_STREAM` .
8294

8395
### WebTransport
8496
Error codes for WebTransport will be introduced when browsers upgrade to draft-9

error-codes/libp2p-error-codes.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Libp2p error codes
2+
3+
## TODO!
4+
make this a CSV
5+
6+
## Connection Error Codes
7+
8+
| Name | Code | Description |
9+
| --- | --- | --- |
10+
| NO_ERROR | 0 | No reason provided for disconnection. This is equivalent to closing a connection or resetting a stream without any error code. |
11+
| Reserved For Transport | 0x1 - 0x1000 | Reserved for transport level error codes. |
12+
| GATED | 0x1001 | The connection was gated. Most likely the IP / node is blacklisted. |
13+
| RESOURCE_LIMIT_EXCEEDED | 0x1002 | Rejected because we ran into a resource limit. Implementations MAY retry with a backoff |
14+
| RATE_LIMITED | 0x1003 | Rejected because the connection was rate limited. Implementations MAY retry with a backoff |
15+
| PROTOCOL_VIOLATION | 0x1004 | Peer violated the protocol |
16+
| SUPPLANTED | 0x1005 | Connection closed because a connection over a better tranpsort was available |
17+
| GARBAGE_COLLECTED | 0x1006 | Connection was garbage collected |
18+
| SHUTDOWN | 0x1007 | The node is going down |
19+
| PROTOCOL_NEGOTIATION_FAILED | 0x1008 | Rejected because we couldn't negotiate a protocol |
20+
21+
22+
## Stream Error Codes
23+
24+
| Name | Code | Description |
25+
| --- | --- | --- |
26+
| NO_ERROR | 0 | No reason provided for disconnection. This is equivalent to resetting a stream without any error code. |
27+
| Reserved For Transport | 0x1 - 0x1000 | Reserved for transport level error codes. |
28+
| PROTOCOL_NEGOTIATION_FAILED | 0x1001 | Rejected because we couldn't negotiate a protocol |
29+
| RESOURCE_LIMIT_EXCEEDED | 0x1002 | Connection rejected because we ran into a resource limit. Implementations MAY retry with a backoff |
30+
| RATE_LIMITED | 0x1003 | Rejected because the connection was rate limited. Implementations MAY retry with a backoff |
31+
| BAD_REQUEST | 0x1004 | Rejected because the request was invalid |
32+
| PROTOCOL_VIOLATION | 0x1005 | Rejected because the stream protocol was violated. MAY be used interchangably with `BAD_REQUEST` |

0 commit comments

Comments
 (0)