Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): filter out /quic in favor of /quic-v1 #4467

Merged
merged 8 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

7 changes: 7 additions & 0 deletions misc/server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion misc/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libp2p-server"
version = "0.12.2"
version = "0.12.3"
authors = ["Max Inden <mail@max-inden.de>"]
edition = "2021"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
36 changes: 32 additions & 4 deletions misc/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,10 +116,35 @@ async fn main() -> Result<(), Box<dyn Error>> {
);
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
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
// 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::<Vec<Multiaddr>>();
addresses.sort();
addresses.dedup();
addresses
};
for address in listen_addresses {
match swarm.listen_on(address.clone()) {
Ok(_) => {}
Err(e @ libp2p::TransportError::MultiaddrNotSupported(_)) => {
Expand All @@ -126,6 +153,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
Err(e) => return Err(e.into()),
}
}

if config.addresses.append_announce.is_empty() {
warn!("No external addresses configured.");
}
Expand Down
Loading