From 4fa98228f03c5d6138da8c70720852652afc5ac3 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 2 Jan 2023 17:47:01 +0100 Subject: [PATCH] fix(dcutr): Skip unparsable multiaddr (#3280) With this commit `libp2p-dcutr` no longer discards the whole remote payload in case an addr is unparsable, but instead logs the failure and skips the unparsable multiaddr. See https://github.com/libp2p/rust-libp2p/issues/3244 for details. --- protocols/dcutr/CHANGELOG.md | 6 ++++++ protocols/dcutr/Cargo.toml | 4 ++-- protocols/dcutr/src/protocol/inbound.rs | 22 ++++++++++++++++------ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/protocols/dcutr/CHANGELOG.md b/protocols/dcutr/CHANGELOG.md index ab4e266c305..d262b957d0b 100644 --- a/protocols/dcutr/CHANGELOG.md +++ b/protocols/dcutr/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.8.1 + +- Skip unparsable multiaddr in `InboundUpgrade::upgrade_inbound`. See [PR XXX]. + +[PR XXX]: https://github.com/libp2p/rust-libp2p/pull/XXX + # 0.8.0 - Update to `prost-codec` `v0.3.0`. diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index fa161f479fd..be76db51d39 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-dcutr" edition = "2021" rust-version = "1.62.0" description = "Direct connection upgrade through relay" -version = "0.8.0" +version = "0.8.1" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -34,7 +34,7 @@ libp2p = { path = "../..", features = ["full"] } rand = "0.8" clap = { version = "4.0.13", features = ["derive"] } -# Passing arguments to the docsrs builder in order to properly document cfg's. +# Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling [package.metadata.docs.rs] all-features = true diff --git a/protocols/dcutr/src/protocol/inbound.rs b/protocols/dcutr/src/protocol/inbound.rs index 3b964881f51..05037da34dd 100644 --- a/protocols/dcutr/src/protocol/inbound.rs +++ b/protocols/dcutr/src/protocol/inbound.rs @@ -58,14 +58,23 @@ impl upgrade::InboundUpgrade for Upgrade { } else { obs_addrs .into_iter() - .map(Multiaddr::try_from) + .filter_map(|a| match Multiaddr::try_from(a) { + Ok(a) => Some(a), + Err(e) => { + log::debug!("Unable to parse multiaddr: {e}"); + None + } + }) // Filter out relayed addresses. - .filter(|a| match a { - Ok(a) => !a.iter().any(|p| p == Protocol::P2pCircuit), - Err(_) => true, + .filter(|a| { + if a.iter().any(|p| p == Protocol::P2pCircuit) { + log::debug!("Dropping relayed address {a}"); + false + } else { + true + } }) - .collect::, _>>() - .map_err(|_| UpgradeError::InvalidAddrs)? + .collect::>() }; let r#type = hole_punch::Type::from_i32(r#type).ok_or(UpgradeError::ParseTypeField)?; @@ -124,6 +133,7 @@ pub enum UpgradeError { StreamClosed, #[error("Expected at least one address in reservation.")] NoAddresses, + #[deprecated(since = "0.8.1", note = "Error is no longer constructed.")] #[error("Invalid addresses.")] InvalidAddrs, #[error("Failed to parse response type field.")]