Skip to content

Commit

Permalink
feat: add more transports to peer swarm in relay
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Apr 17, 2024
1 parent bda5998 commit 28910f2
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 14 deletions.
92 changes: 91 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions mithril-relay/Cargo.toml
Expand Up @@ -24,7 +24,11 @@ libp2p = { version = "0.53.2", features = [
"noise",
"ping",
"pnet",
"quic",
"tcp",
"tls",
"websocket-websys",
"websocket",
"yamux",
] }
mithril-common = { path = "../mithril-common", features = ["full"] }
Expand Down
28 changes: 15 additions & 13 deletions mithril-relay/src/p2p/peer.rs
@@ -1,12 +1,12 @@
#![allow(missing_docs)]
use anyhow::{anyhow, Context};
use libp2p::{
core::upgrade::Version,
core::{muxing::StreamMuxerBox, transport::dummy::DummyTransport},
futures::StreamExt,
gossipsub::{self, ValidationMode},
noise, ping,
swarm::{self, DialError, NetworkBehaviour},
tcp, yamux, Multiaddr, PeerId, Swarm, Transport,
tls, yamux, Multiaddr, PeerId, Swarm, SwarmBuilder,
};
use mithril_common::{
messages::{RegisterSignatureMessage, RegisterSignerMessage},
Expand Down Expand Up @@ -104,19 +104,21 @@ impl Peer {
/// Start the peer
pub async fn start(mut self) -> StdResult<Self> {
debug!("Peer: starting...");
let mut swarm = libp2p::SwarmBuilder::with_new_identity()
let mut swarm = SwarmBuilder::with_new_identity()
.with_tokio()
.with_other_transport(|key| {
let noise_config = noise::Config::new(key).unwrap();
let yamux_config = yamux::Config::default();
let base_transport =
tcp::tokio::Transport::new(tcp::Config::default().nodelay(true));
base_transport
.upgrade(Version::V1Lazy)
.authenticate(noise_config)
.multiplex(yamux_config)
})?
.with_tcp(
Default::default(),
(tls::Config::new, noise::Config::new),
yamux::Config::default,
)?
.with_quic()
.with_other_transport(|_key| DummyTransport::<(PeerId, StreamMuxerBox)>::new())?
.with_dns()?
.with_websocket(
(tls::Config::new, noise::Config::new),
yamux::Config::default,
)
.await?
.with_behaviour(|key| {
let gossipsub_config = gossipsub::ConfigBuilder::default()
.max_transmit_size(262144)
Expand Down

0 comments on commit 28910f2

Please sign in to comment.