-
Notifications
You must be signed in to change notification settings - Fork 291
add autonat v2 spec #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add autonat v2 spec #538
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d663611
add autonat v2 spec
sukunrt 1db8613
use priority ordered list in requests for autonat-v2
sukunrt 0ff8ac6
only send index of the dialed address
sukunrt f2a431c
accept a priority ordered list of addresses for dial requests
sukunrt 62123df
Improve naming for messages
sukunrt 0771bab
add interaction diagram
sukunrt 3e57202
address review comments
sukunrt f6def9a
allow autonat v2 to dial all ips (#542)
sukunrt b769d79
use oneof for messages
sukunrt e4efaae
use a single nonce in DialRequest
sukunrt f28511c
drop terms node and peer in favour of client and server
sukunrt d4da279
client should not reuse listen port while making dial request
sukunrt 5b8d37d
explicitly disallow probing for private addresses
sukunrt 05a0de2
add explanation for amplification attack prevention mechanism
sukunrt 8b52643
add recommendation for 30k - 100k bytes
sukunrt dd2750c
move DialStatus proto out of Response
sukunrt 4e6ecaa
wrap data sent for amplification attack prevention in a protobuf
sukunrt 2af3309
send only a single dial status
sukunrt 6b1604b
add comment regarding nonce
sukunrt f979fac
rename attempt to dial-back
sukunrt 209b215
fix ResponseStatus_OK
sukunrt 094089b
IPv4 only servers should refuse requests for IPv6 addresses
sukunrt b4a856b
fix dial-request protocol name
sukunrt 1c76613
add a response to the dialback stream
sukunrt 03718ef
allow the client to send slightly more dial data
sukunrt 0195203
add note that server should not dial any private address
sukunrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # NAT Discovery <!-- omit in toc --> | ||
| > How we detect if we're behind a NAT. | ||
|
|
||
|
|
||
| Specifications: | ||
| - [autonat v1](autonat-v1.md) | ||
| - [autonat v2](autonat-v2.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # AutonatV2: spec | ||
sukunrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| | Lifecycle Stage | Maturity | Status | Latest Revision | | ||
| |-----------------|--------------------------|--------|-----------------| | ||
| | 1A | Working Draft | Active | r1, 2023-04-12 | | ||
|
|
||
| Authors: [@sukunrt] | ||
|
|
||
| Interest Group: [@marten-seemann], [@marcopolo], [@mxinden] | ||
|
|
||
| [@sukunrt]: https://github.com/sukunrt | ||
| [@marten-seemann]: https://github.com/marten-seemann | ||
| [@mxinden]: https://github.com/mxinden | ||
| [@marcopolo]: https://github.com/marcopolo | ||
|
|
||
|
|
||
| ## Overview | ||
|
|
||
| A priori, a node cannot know if it is behind a NAT / firewall or if it is | ||
| publicly reachable. Knowing its NAT status is essential for the node to be | ||
| well-behaved in the network: A node that's behind a doesn't need to | ||
| advertise its (undialable) addresses to the rest of the network, preventing | ||
| superfluous dials from other peers. Furthermore, it might actively seek to | ||
| improve its connectivity by finding a relay server, which would allow other | ||
| peers to establish a relayed connection. | ||
|
|
||
| `autonat v2` allows nodes to determine reachability for individual addresses. | ||
| Using `autonat v2` nodes can build an address pipeline where they can test | ||
| individual addresses discovered by different sources like identify, upnp | ||
| mappings, circuit addresses etc for reachability. | ||
|
|
||
| Compared to `autonat v1` there are two major differences | ||
| 1. `autonat v1` allowed testing reachability for the node. `autonat v2` allows for testing reachability for an individual address | ||
| 2. `autonat v2` provides a mechanism for nodes to verify whether the peer | ||
| actually successfully dialled an address. | ||
|
|
||
|
|
||
| ## AutoNAT V2 Protocol | ||
sukunrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| A node wishing to determine reachability of a particular adddress sends a | ||
| `DialRequest` message to peer B on a stream with protocol ID | ||
| `/libp2p/autonat/2.0.0/dial-request`. This `DialRequest` message has the | ||
| address and a uint64 nonce. | ||
|
|
||
| Upon receiving this message the peer attempts to dial the address and opens a | ||
| stream with Protocol ID `/libp2p/autonat/2.0.0/dial-attempt` and sends a | ||
| `DialAttempt` message with the nonce received in the `DialRequest`. The peer | ||
| MUST NOT dial any address other than the address provided in the `DialRequest` | ||
| message. | ||
|
|
||
| Upon completion of the dial attempt, the peer sends a `DialResponse` to the | ||
| initiator node on the `/libp2p/autonat/2.0.0/dial-request` stream. | ||
|
|
||
| The initiator SHOULD check that the nonce received in the `Dial` message is the | ||
sukunrt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| same as the nonce the initiator sent in the `DialRequest` message. If the nonce | ||
| received in the `Dial` message is different the initiator MUST discard this | ||
| `DialResponse` | ||
|
|
||
| ### Requirements for ResponseStatus | ||
|
|
||
| The `ResponseStatus` sent by the peer in the `DialResponse` message MUST be set | ||
| according to the following requirements | ||
|
|
||
| `OK`: the peer was able to dial the address successfully. | ||
| `E_DIAL_ERROR`: the peer attempted a dial and was unable to connect. | ||
| `E_DIAL_REFUSED`: the peer could have dialed the address but didn't attempt a | ||
| dial because of rate limiting, resource limit reached or blacklisting. | ||
| `E_TRANSPORT_NOT_SUPPORTED`: the peer didn't dial because it didn't have the | ||
| ability to dial the requested transport. | ||
| `E_BAD_REQUEST`: the peer didn't dial because it was unable to decode the | ||
| message. This includes inability to decode the requested address to dial. | ||
| `E_INTERNAL_ERROR`: error not classified within the above error codes occured | ||
| on peer that prevented it from completing the request. | ||
|
|
||
| Implementations MUST count `OK` as a successful dial and MUST only count | ||
| `E_DIAL_ERROR` as an unsuccessful dial. Implementations MUST discard error codes | ||
| other than these two in calculating the reachability of the requested address. | ||
|
|
||
| ### Consideration for DDOS Prevention | ||
|
|
||
sukunrt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| In order to prevent attacks like the one described in [RFC 3489, Section | ||
| 12.1.1](https://www.rfc-editor.org/rfc/rfc3489#section-12.1.1) (see excerpt | ||
| below), implementations MUST NOT dial any multiaddress unless it is based on the | ||
| IP address the requesting node is observed as. This restriction as well implies | ||
| that implementations MUST NOT accept dial requests via relayed connections as | ||
| one can not validate the IP address of the requesting node. | ||
|
|
||
| > RFC 3489 12.1.1 Attack I: DDOS Against a Target | ||
| > | ||
| > In this case, the attacker provides a large number of clients with the same | ||
| > faked MAPPED-ADDRESS that points to the intended target. This will trick all | ||
| > the STUN clients into thinking that their addresses are equal to that of the | ||
| > target. The clients then hand out that address in order to receive traffic on | ||
| > it (for example, in SIP or H.323 messages). However, all of that traffic | ||
| > becomes focused at the intended target. The attack can provide substantial | ||
| > amplification, especially when used with clients that are using STUN to enable | ||
| > multimedia applications. | ||
sukunrt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Implementation Suggestions | ||
|
|
||
| For any given address, implementations SHOULD do the following | ||
| - periodically recheck reachability status | ||
| - query multiple peers to determine reachability | ||
sukunrt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The suggested heuristic for implementations is to consider an address | ||
| reachable if more than 3 peers report a successful dial and to consider an | ||
| address unreachable if more than 3 peers report unsuccessful dials. | ||
|
|
||
| Implementations are free to use different heuristics than this one | ||
|
|
||
|
|
||
| ## Protobufs | ||
|
|
||
| All RPC messages sent over a stream are prefixed with the message length in | ||
| bytes, encoded as an unsigned variable length integer as defined by the | ||
| [multiformats unsigned-varint spec][uvarint-spec]. | ||
|
|
||
| ```proto | ||
| syntax = "proto3"; | ||
|
|
||
| message Message { | ||
| enum MessageType { | ||
| DIAL_REQUEST = 0; | ||
| DIAL_RESPONSE = 1; | ||
| DIAL_ATTEMPT = 2; | ||
| } | ||
|
|
||
| enum ResponseStatus { | ||
| OK = 0; | ||
| E_DIAL_ERROR = 100; | ||
| E_DIAL_REFUSED = 101; | ||
| E_TRANSPORT_NOT_SUPPORTED = 102; | ||
| E_BAD_REQUEST = 200; | ||
| E_INTERNAL_ERROR = 300; | ||
| } | ||
|
|
||
| message DialRequest { | ||
| bytes addr = 1; | ||
| fixed64 nonce = 2; | ||
| } | ||
|
|
||
| message DialResponse { | ||
| ResponseStatus status = 1; | ||
| string statusText = 2; | ||
| } | ||
|
|
||
| message DialAttempt { | ||
| fixed64 nonce = 1; | ||
sukunrt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| MessageType type = 1; | ||
| DialRequest dialRequest = 2; | ||
| DialResponse dialResponse = 3; | ||
| DialAttempt dialAttempt = 4; | ||
| } | ||
| ``` | ||
|
|
||
| [uvarint-spec]: https://github.com/multiformats/unsigned-varint | ||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.