Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions protocols/autonat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 0.16.0

- Close server dial-back connections once the probe completes instead of leaving them open.
See [PR 6528](https://github.com/libp2p/rust-libp2p/pull/6528).

- Use `futures-timer` instead of tokio's timer for stream timeouts so the bounded `Delay` works on
`wasm32`; tokio's timer has no driver in the browser and panics at runtime.
See [PR 6488](https://github.com/libp2p/rust-libp2p/pull/6488).
Expand Down Expand Up @@ -32,19 +35,20 @@
## 0.13.0

- Due to the refactor of `Transport` it's no longer required to create a separate transport for
AutoNAT where port reuse is disabled. This information is now passed by the behaviour.
AutoNAT where port reuse is disabled. This information is now passed by the behaviour.
See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568).
- Introduce the new AutoNATv2 protocol.
It's split into a client and a server part, represented in their respective modules
Features:
- The server now always dials back over a newly allocated port.
This more accurately reflects the reachability state for other peers and avoids accidental hole punching.
- The server can now test addresses different from the observed address (i.e., the connection to the server was made through a `p2p-circuit`). To mitigate against DDoS attacks, the client has to send more data to the server than the dial-back costs.
See [PR 5526](https://github.com/libp2p/rust-libp2p/pull/5526).
See [PR 5526](https://github.com/libp2p/rust-libp2p/pull/5526).

<!-- Update to libp2p-swarm v0.45.0 -->

## 0.12.1

- Use `web-time` instead of `instant`.
See [PR 5347](https://github.com/libp2p/rust-libp2p/pull/5347).

Expand Down Expand Up @@ -92,7 +96,6 @@ AutoNAT where port reuse is disabled. This information is now passed by the beha

[PR 3351]: https://github.com/libp2p/rust-libp2p/pull/3351


## 0.9.0

- Update to `libp2p-core` `v0.38.0`.
Expand Down Expand Up @@ -177,7 +180,7 @@ AutoNAT where port reuse is disabled. This information is now passed by the beha

- Update to `libp2p-request-response` `v0.16.0`.

- Merge NetworkBehaviour's inject_\* paired methods (see PR 2445).
- Merge NetworkBehaviour's inject\_\* paired methods (see PR 2445).

[PR 2445]: https://github.com/libp2p/rust-libp2p/pull/2445

Expand Down
10 changes: 8 additions & 2 deletions protocols/autonat/src/v1/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use libp2p_request_response::{
self as request_response, InboundRequestId, OutboundRequestId, ProtocolSupport, ResponseChannel,
};
use libp2p_swarm::{
ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, THandler, THandlerInEvent,
THandlerOutEvent, ToSwarm,
CloseConnection, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, THandler,
THandlerInEvent, THandlerOutEvent, ToSwarm,
behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm},
};
use web_time::Instant;
Expand Down Expand Up @@ -349,6 +349,12 @@ impl Behaviour {
if let Some(event) = self.as_server().on_outbound_connection(&peer, address) {
self.pending_actions
.push_back(ToSwarm::GenerateEvent(Event::InboundProbe(event)));
// The probe is resolved and the response is sent over the peer's own
// connection. Close the dial-back connection.
self.pending_actions.push_back(ToSwarm::CloseConnection {
peer_id: peer,
connection: CloseConnection::One(conn),
});
}
}
ConnectedPoint::Dialer {
Expand Down
19 changes: 13 additions & 6 deletions protocols/autonat/src/v2/server/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use either::Either;
use libp2p_core::{Endpoint, Multiaddr, transport::PortUse};
use libp2p_identity::PeerId;
use libp2p_swarm::{
ConnectionDenied, ConnectionHandler, ConnectionId, DialFailure, FromSwarm, NetworkBehaviour,
ToSwarm,
CloseConnection, ConnectionDenied, ConnectionHandler, ConnectionId, DialFailure, FromSwarm,
NetworkBehaviour, ToSwarm,
dial_opts::{DialOpts, PeerCondition},
dummy,
};
Expand Down Expand Up @@ -102,13 +102,20 @@ where
fn on_connection_handler_event(
&mut self,
peer_id: PeerId,
_connection_id: ConnectionId,
connection_id: ConnectionId,
event: <Handler<R> as ConnectionHandler>::ToBehaviour,
) {
match event {
Either::Left(Either::Left(Ok(_))) => {}
Either::Left(Either::Left(Err(e))) => {
tracing::debug!("dial back error: {e:?}");
Either::Left(Either::Left(result)) => {
if let Err(e) = result {
tracing::debug!("dial back error: {e:?}");
}
// The dial-back has completed and its outcome reaches the client over
// the client's own connection. Close the dial-back connection.
self.pending_events.push_back(ToSwarm::CloseConnection {
peer_id,
connection: CloseConnection::One(connection_id),
});
}
Either::Left(Either::Right(v)) => libp2p_core::util::unreachable(v),
Either::Right(Either::Left(cmd)) => {
Expand Down