Skip to content

Commit

Permalink
fix(server): filter out /quic in favor of /quic-v1
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
mxinden committed Sep 7, 2023
1 parent b9028e8 commit c5d5505
Showing 1 changed file with 32 additions and 4 deletions.
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
// 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

0 comments on commit c5d5505

Please sign in to comment.