QUIC-based LibP2p Swarm (replacing TCP)

This commit is contained in:
Luke Parker 2023-11-21 02:05:48 -05:00
parent c6c74684c9
commit 0ad8ac9520
No known key found for this signature in database
2 changed files with 2 additions and 13 deletions

View file

@ -48,7 +48,7 @@ env_logger = { version = "0.10", default-features = false, features = ["humantim
futures = { version = "0.3", default-features = false, features = ["std"] } futures = { version = "0.3", default-features = false, features = ["std"] }
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "sync", "time", "macros"] } tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "sync", "time", "macros"] }
libp2p = { version = "0.52", default-features = false, features = ["tokio", "tcp", "noise", "yamux", "gossipsub", "mdns", "macros"] } libp2p = { version = "0.52", default-features = false, features = ["tokio", "quic", "gossipsub", "mdns", "macros"] }
[dev-dependencies] [dev-dependencies]
futures = { version = "0.3", default-features = false, features = ["std"] } futures = { version = "0.3", default-features = false, features = ["std"] }

View file

@ -22,8 +22,6 @@ use libp2p::{
futures::StreamExt, futures::StreamExt,
identity::Keypair, identity::Keypair,
PeerId, PeerId,
tcp::Config as TcpConfig,
noise, yamux,
gossipsub::{ gossipsub::{
IdentTopic, FastMessageId, MessageId, MessageAuthenticity, ValidationMode, ConfigBuilder, IdentTopic, FastMessageId, MessageId, MessageAuthenticity, ValidationMode, ConfigBuilder,
IdentityTransform, AllowAllSubscriptionFilter, Event as GsEvent, PublishError, IdentityTransform, AllowAllSubscriptionFilter, Event as GsEvent, PublishError,
@ -276,16 +274,7 @@ impl LibP2p {
// TODO: Relay client? // TODO: Relay client?
let mut swarm = SwarmBuilder::with_existing_identity(throwaway_key_pair) let mut swarm = SwarmBuilder::with_existing_identity(throwaway_key_pair)
.with_tokio() .with_tokio()
.with_tcp(TcpConfig::default().nodelay(true), noise::Config::new, || { .with_quic()
let mut config = yamux::Config::default();
// 1 MiB default + max message size
config.set_max_buffer_size((1024 * 1024) + MAX_LIBP2P_MESSAGE_SIZE);
// 256 KiB default + max message size
config
.set_receive_window_size(((256 * 1024) + MAX_LIBP2P_MESSAGE_SIZE).try_into().unwrap());
config
})
.unwrap()
.with_behaviour(|_| behavior) .with_behaviour(|_| behavior)
.unwrap() .unwrap()
.build(); .build();