libp2p_autonat/v2.rs
1//! The second version of the autonat protocol.
2//!
3//! The implementation follows the [libp2p spec](https://github.com/libp2p/specs/blob/03718ef0f2dea4a756a85ba716ee33f97e4a6d6c/autonat/autonat-v2.md).
4//!
5//! The new version fixes the issues of the first version:
6//! - The server now always dials back over a newly allocated port. This greatly reduces the risk of
7//! false positives that often occurred in the first version, when the clinet-server connection
8//! occurred over a hole-punched port.
9//! - The server protects against DoS attacks by requiring the client to send more data to the
10//! server then the dial back puts on the client, thus making the protocol unatractive for an
11//! attacker.
12//!
13//! The protocol is separated into two parts:
14//! - The client part, which is implemented in the `client` module. (The client is the party that
15//! wants to check if it is reachable from the outside.)
16//! - The server part, which is implemented in the `server` module. (The server is the party
17//! performing reachability checks on behalf of the client.)
18//!
19//! The two can be used together.
20
21use libp2p_swarm::StreamProtocol;
22
23pub mod client;
24pub(crate) mod protocol;
25pub mod server;
26
27pub(crate) mod generated {
28 #![allow(unreachable_pub)]
29 include!("v2/generated/mod.rs");
30}
31
32pub(crate) const DIAL_REQUEST_PROTOCOL: StreamProtocol =
33 StreamProtocol::new("/libp2p/autonat/2/dial-request");
34pub(crate) const DIAL_BACK_PROTOCOL: StreamProtocol =
35 StreamProtocol::new("/libp2p/autonat/2/dial-back");
36
37type Nonce = u64;