Skip to content

Commit

Permalink
AutoNAT: reject inbound dial request from peer if it is not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligioo committed Sep 13, 2024
1 parent 3837e33 commit e749ffe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions protocols/autonat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.13.1
- Verify that an incoming AutoNAT dial comes from a connected peer. See [PR 5597](https://github.com/libp2p/rust-libp2p/pull/5597).

## 0.13.0

- Due to the refactor of `Transport` it's no longer required to create a seperate transport for
Expand Down
2 changes: 1 addition & 1 deletion protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-autonat"
edition = "2021"
rust-version = { workspace = true }
description = "NAT and firewall detection for libp2p"
version = "0.13.0"
version = "0.13.1"
authors = ["David Craven <david@craven.ch>", "Elena Frank <elena.frank@protonmail.com>", "Hannes Furmans <hannes@umgefahren.xyz>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
15 changes: 15 additions & 0 deletions protocols/autonat/src/v1/behaviour/as_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ impl<'a> HandleInnerEvent for AsServer<'a> {
},
} => {
let probe_id = self.probe_id.next();
if !self.connected.contains_key(&peer) {
tracing::debug!(
%peer,
"Reject inbound dial request from peer since it is not connected"
);

return VecDeque::from([ToSwarm::GenerateEvent(Event::InboundProbe(
InboundProbeEvent::Error {
probe_id,
peer,
error: InboundProbeError::Response(ResponseError::DialRefused),
},
))]);
}

match self.resolve_inbound_request(peer, request) {
Ok(addrs) => {
tracing::debug!(
Expand Down

0 comments on commit e749ffe

Please sign in to comment.