Skip to content

Commit

Permalink
Disable draft-29 support
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Sep 11, 2023
1 parent 40f7935 commit 93564ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
4 changes: 3 additions & 1 deletion misc/server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 5 additions & 36 deletions misc/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,11 +89,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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,
Expand All @@ -116,35 +110,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
);
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::<Vec<Multiaddr>>();
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(_)) => {
Expand Down

0 comments on commit 93564ba

Please sign in to comment.