From 92cd0cfacacf036b93e48c59da5e4af2dd9e50a0 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 11 Sep 2024 17:40:03 +0200 Subject: [PATCH] AutoNAT V1: reject inbound dial request from peer if it is not connected --- .../autonat/src/v1/behaviour/as_server.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/protocols/autonat/src/v1/behaviour/as_server.rs b/protocols/autonat/src/v1/behaviour/as_server.rs index 3ecdd3ac26e8..6163c1017af8 100644 --- a/protocols/autonat/src/v1/behaviour/as_server.rs +++ b/protocols/autonat/src/v1/behaviour/as_server.rs @@ -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!(