Skip to content

Commit

Permalink
enable Quic transport on libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Aug 2, 2023
1 parent 61d4ae1 commit 3eb4937
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions beacon_node/lighthouse_network/src/service/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::types::{
error, EnrAttestationBitfield, EnrSyncCommitteeBitfield, GossipEncoding, GossipKind,
};
use crate::{GossipTopic, NetworkConfig};
use futures::future::Either;
use libp2p::bandwidth::BandwidthSinks;
use libp2p::core::{multiaddr::Multiaddr, muxing::StreamMuxerBox, transport::Boxed};
use libp2p::gossipsub;
Expand Down Expand Up @@ -51,25 +52,24 @@ pub fn build_transport(
// yamux config
let mut yamux_config = yamux::Config::default();
yamux_config.set_window_update_mode(yamux::WindowUpdateMode::on_read());
let (transport, bandwidth) = transport
let transport = transport
.upgrade(core::upgrade::Version::V1)
.authenticate(generate_noise_config(&local_private_key))
.multiplex(yamux_config)
.timeout(Duration::from_secs(10))
.with_bandwidth_logging();
.timeout(Duration::from_secs(10));

// Enables Quic
/*
// The default quic configuration suits us for now.
let quic_config = libp2p_quic::Config::new(&local_private_key);
let transport = transport.or_transport(libp2p_quic::tokio::Transport::new(quic_config));
// TODO: Get quick to support bandwidth measurements.
*/

let transport = transport.boxed();
let (transport, bandwidth) = transport
.or_transport(libp2p_quic::tokio::Transport::new(quic_config))
.map(|either_output, _| match either_output {
Either::Left((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
Either::Right((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
})
.with_bandwidth_logging();

Ok((transport, bandwidth))
Ok((transport.boxed(), bandwidth))
}

// Useful helper functions for debugging. Currently not used in the client.
Expand Down Expand Up @@ -274,4 +274,4 @@ pub(crate) fn save_metadata_to_disk<E: EthSpec>(
);
}
}
}
}

0 comments on commit 3eb4937

Please sign in to comment.