From c5d5505c3a8464d07cc30513bfaae60d0f091956 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 7 Sep 2023 13:04:14 +0200 Subject: [PATCH 1/5] fix(server): filter out `/quic` in favor of `/quic-v1` Configuration files generated by Kubo <= v0.22 list both `/quic` and `/quic-v1` listen addresses with the same UDP port. Given that we enable draft-29, the two addresses are treated the same by rust-libp2p's QUIC implementation. Though calling `listen_on` with both results in an "Address already in use" error by the OS on the second call. To prevent this from happening filter out `/quic` addresses in favor of `/quic-v1`. --- misc/server/src/main.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 67abb5b2549..97533645aa7 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -12,11 +12,13 @@ use libp2p::identity; use libp2p::identity::PeerId; use libp2p::kad; use libp2p::metrics::{Metrics, Recorder}; +use libp2p::multiaddr::Protocol; use libp2p::noise; use libp2p::quic; use libp2p::swarm::{SwarmBuilder, SwarmEvent}; use libp2p::tcp; use libp2p::yamux; +use libp2p::Multiaddr; use libp2p::Transport; use log::{debug, info, warn}; use prometheus_client::metrics::info::Info; @@ -114,10 +116,35 @@ async fn main() -> Result<(), Box> { ); let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build(); - if config.addresses.swarm.is_empty() { - warn!("No listen addresses configured."); - } - for address in &config.addresses.swarm { + let listen_addresses = { + let addresses = config.addresses.swarm.clone(); + if addresses.is_empty() { + warn!("No listen addresses configured."); + } + // Configuration files generated by Kubo <= v0.22 list both `/quic` and `/quic-v1` listen + // addresses with the same UDP port. Given that we enable draft-29, the two addresses are + // treated the same by rust-libp2p's QUIC implementation. Though calling `listen_on` with + // both results in an "Address already in use" error by the OS on the second call. To + // prevent this from happening filter out `/quic` addresses in favor of `/quic-v1`. + let mut addresses = addresses + .into_iter() + .map(|a| { + a.into_iter() + .map(|p| { + if p == Protocol::Quic { + Protocol::QuicV1 + } else { + p + } + }) + .collect() + }) + .collect::>(); + addresses.sort(); + addresses.dedup(); + addresses + }; + for address in listen_addresses { match swarm.listen_on(address.clone()) { Ok(_) => {} Err(e @ libp2p::TransportError::MultiaddrNotSupported(_)) => { @@ -126,6 +153,7 @@ async fn main() -> Result<(), Box> { Err(e) => return Err(e.into()), } } + if config.addresses.append_announce.is_empty() { warn!("No external addresses configured."); } From 40f7935df470985614d36b188c7a971056ad016d Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 7 Sep 2023 13:09:36 +0200 Subject: [PATCH 2/5] Bump versions and add changelog entries --- Cargo.lock | 2 +- misc/server/CHANGELOG.md | 7 +++++++ misc/server/Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89a4289cb1a..e5ba223f1eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3165,7 +3165,7 @@ dependencies = [ [[package]] name = "libp2p-server" -version = "0.12.2" +version = "0.12.3" dependencies = [ "base64 0.21.2", "clap", diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index 8bb5768822c..f81687e9c47 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.3] - unreleased +### Fixed +- Filter out otherwise identical `/quic` listen addresses in favor of `/quic-v1` listen addresses to prevent "Address already in use" error by OS. + See [PR 4467]. + +[PR 4467]: https://github.com/libp2p/rust-libp2p/pull/4467 + ## [0.12.2] ### Fixed - Adhere to `--metrics-path` flag and listen on `0.0.0.0:8888` (default IPFS metrics port). diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index 32b815c407a..aa259ce8214 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-server" -version = "0.12.2" +version = "0.12.3" authors = ["Max Inden "] edition = "2021" repository = "https://github.com/libp2p/rust-libp2p" From 93564ba8bc52f98d4c95496e38a1b4759b469be9 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 11 Sep 2023 12:50:05 +1000 Subject: [PATCH 3/5] Disable `draft-29` support --- misc/server/CHANGELOG.md | 4 +++- misc/server/src/main.rs | 41 +++++----------------------------------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index f81687e9c47..a07c5f974ce 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.12.3] - unreleased ### Fixed -- Filter out otherwise identical `/quic` listen addresses in favor of `/quic-v1` listen addresses to prevent "Address already in use" error by OS. + +- Disable QUIC `draft-29` support. + Listening on `/quic` and `/quic-v1` addresses with the same port would otherwise result in an "Address already in use" error by the OS. See [PR 4467]. [PR 4467]: https://github.com/libp2p/rust-libp2p/pull/4467 diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 97533645aa7..e5c74a81ecb 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -12,13 +12,11 @@ use libp2p::identity; use libp2p::identity::PeerId; use libp2p::kad; use libp2p::metrics::{Metrics, Recorder}; -use libp2p::multiaddr::Protocol; use libp2p::noise; use libp2p::quic; use libp2p::swarm::{SwarmBuilder, SwarmEvent}; use libp2p::tcp; use libp2p::yamux; -use libp2p::Multiaddr; use libp2p::Transport; use log::{debug, info, warn}; use prometheus_client::metrics::info::Info; @@ -91,11 +89,7 @@ async fn main() -> Result<(), Box> { .multiplex(yamux::Config::default()) .timeout(Duration::from_secs(20)); - let quic_transport = { - let mut config = quic::Config::new(&local_keypair); - config.support_draft_29 = true; - quic::tokio::Transport::new(config) - }; + let quic_transport = quic::tokio::Transport::new(quic::Config::new(&local_keypair)); dns::TokioDnsConfig::system(libp2p::core::transport::OrTransport::new( quic_transport, @@ -116,35 +110,10 @@ async fn main() -> Result<(), Box> { ); let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build(); - let listen_addresses = { - let addresses = config.addresses.swarm.clone(); - if addresses.is_empty() { - warn!("No listen addresses configured."); - } - // Configuration files generated by Kubo <= v0.22 list both `/quic` and `/quic-v1` listen - // addresses with the same UDP port. Given that we enable draft-29, the two addresses are - // treated the same by rust-libp2p's QUIC implementation. Though calling `listen_on` with - // both results in an "Address already in use" error by the OS on the second call. To - // prevent this from happening filter out `/quic` addresses in favor of `/quic-v1`. - let mut addresses = addresses - .into_iter() - .map(|a| { - a.into_iter() - .map(|p| { - if p == Protocol::Quic { - Protocol::QuicV1 - } else { - p - } - }) - .collect() - }) - .collect::>(); - addresses.sort(); - addresses.dedup(); - addresses - }; - for address in listen_addresses { + if config.addresses.swarm.is_empty() { + warn!("No listen addresses configured."); + } + for address in &config.addresses.swarm { match swarm.listen_on(address.clone()) { Ok(_) => {} Err(e @ libp2p::TransportError::MultiaddrNotSupported(_)) => { From 41991d9d758571bbd7ee409a7ea1d944f64aad75 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 11 Sep 2023 21:47:38 +1000 Subject: [PATCH 4/5] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 97c8c10adfa..17d34c07e2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ libp2p-quic = { version = "0.9.2", path = "transports/quic" } libp2p-relay = { version = "0.16.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } -libp2p-server = { version = "0.12.2", path = "misc/server" } +libp2p-server = { version = "0.12.3", path = "misc/server" } libp2p-swarm = { version = "0.43.3", path = "swarm" } libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" } From ba0065785548c4efe68d4616544748f170979e12 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 11 Sep 2023 21:50:45 +1000 Subject: [PATCH 5/5] Fix bad merge --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c4bf0b8606b..55258267fec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,7 +85,7 @@ libp2p-muxer-test-harness = { path = "muxers/test-harness" } libp2p-noise = { version = "0.43.1", path = "transports/noise" } libp2p-perf = { version = "0.2.0", path = "protocols/perf" } libp2p-ping = { version = "0.43.1", path = "protocols/ping" } -libp2p-plaintext = { version = , path = "transports/plaintext" } +libp2p-plaintext = { version = "0.40.0", path = "transports/plaintext" } libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } libp2p-quic = { version = "0.9.2", path = "transports/quic" } libp2p-relay = { version = "0.16.1", path = "protocols/relay" }