Skip to content

Commit

Permalink
AutoNAT V1: 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 11, 2024
1 parent 3837e33 commit 40b55f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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
21 changes: 21 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,27 @@ impl<'a> HandleInnerEvent for AsServer<'a> {
},
} => {
let probe_id = self.probe_id.next();
if self.connected.get(&peer).is_none() {
tracing::debug!(
%peer,
"Reject inbound dial request from peer since it is not connected"
);

let response = DialResponse {
result: Err(ResponseError::DialRefused),
status_text: Some("dial from non-connected peer".to_string()),
};
let _ = self.inner.send_response(channel, response);

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 40b55f4

Please sign in to comment.