Update libp2p breaking dep (#470)

* update deprecated api
This commit is contained in:
Al Liu 2023-10-20 14:08:15 +08:00 committed by GitHub
parent a3d9799121
commit 64a3436331
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 16 deletions

View File

@ -7,7 +7,7 @@ edition = "2021"
multiaddr = "0.18"
tokio = { version = "1", features = ["sync", "macros"] }
futures = "0.3"
libp2p = { version = "0.52.1", features = [
libp2p = { version = "0.52.4", features = [
"dns",
"yamux",
"plaintext",

View File

@ -57,8 +57,6 @@ struct GossipsubConfigDef {
fanout_ttl: Duration,
#[serde(getter = "gossipsub::Config::check_explicit_peers_ticks")]
check_explicit_peers_ticks: u64,
#[serde(getter = "gossipsub::Config::idle_timeout")]
idle_timeout: Duration,
#[serde(getter = "gossipsub::Config::duplicate_cache_time")]
duplicate_cache_time: Duration,
#[serde(getter = "gossipsub::Config::validate_messages")]
@ -115,7 +113,6 @@ impl From<GossipsubConfigDef> for gossipsub::Config {
.heartbeat_interval(def.heartbeat_interval)
.fanout_ttl(def.fanout_ttl)
.check_explicit_peers_ticks(def.check_explicit_peers_ticks)
.idle_timeout(def.idle_timeout)
.duplicate_cache_time(def.duplicate_cache_time)
.allow_self_origin(def.allow_self_origin)
.prune_peers(def.prune_peers)

View File

@ -18,11 +18,9 @@ pub use libp2p::{
dns,
gossipsub::{self, PublishError, SubscriptionError},
identity::{self, secp256k1},
plaintext::PlainText2Config,
swarm::{
dial_opts::DialOpts, DialError, NetworkBehaviour, SwarmBuilder, SwarmEvent, THandlerErr,
},
tcp, yamux, PeerId, Transport,
plaintext::Config as PlainText2Config,
swarm::{dial_opts::DialOpts, DialError, NetworkBehaviour, SwarmEvent, THandlerErr},
tcp, yamux, PeerId, SwarmBuilder, Transport,
};
use libp2p::{swarm::ConnectionId, tcp::tokio::Tcp};
pub use multiaddr::{multiaddr, Multiaddr, Protocol};
@ -59,15 +57,13 @@ impl Swarm {
// TODO: consider using noise authentication
let tcp_transport = tcp::Transport::<Tcp>::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1Lazy)
.authenticate(PlainText2Config {
local_public_key: id_keys.public(),
})
.authenticate(PlainText2Config::new(&id_keys))
.multiplex(yamux::Config::default())
.timeout(TRANSPORT_TIMEOUT)
.boxed();
// Wrapping TCP transport into DNS transport to resolve hostnames.
let tcp_transport = dns::TokioDnsConfig::system(tcp_transport)?.boxed();
let tcp_transport = dns::tokio::Transport::system(tcp_transport)?.boxed();
// TODO: consider using Signed or Anonymous.
// For Anonymous, a custom `message_id` function need to be set
@ -80,12 +76,12 @@ impl Swarm {
.build()?,
)?;
let mut swarm = SwarmBuilder::with_tokio_executor(
let mut swarm = libp2p::Swarm::new(
tcp_transport,
Behaviour { gossipsub },
local_peer_id,
)
.build();
libp2p::swarm::Config::with_tokio_executor(),
);
swarm.listen_on(multiaddr!(Ip4(config.host), Tcp(config.port)))?;