parent
a3d9799121
commit
64a3436331
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||||
multiaddr = "0.18"
|
multiaddr = "0.18"
|
||||||
tokio = { version = "1", features = ["sync", "macros"] }
|
tokio = { version = "1", features = ["sync", "macros"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
libp2p = { version = "0.52.1", features = [
|
libp2p = { version = "0.52.4", features = [
|
||||||
"dns",
|
"dns",
|
||||||
"yamux",
|
"yamux",
|
||||||
"plaintext",
|
"plaintext",
|
||||||
|
|
|
@ -57,8 +57,6 @@ struct GossipsubConfigDef {
|
||||||
fanout_ttl: Duration,
|
fanout_ttl: Duration,
|
||||||
#[serde(getter = "gossipsub::Config::check_explicit_peers_ticks")]
|
#[serde(getter = "gossipsub::Config::check_explicit_peers_ticks")]
|
||||||
check_explicit_peers_ticks: u64,
|
check_explicit_peers_ticks: u64,
|
||||||
#[serde(getter = "gossipsub::Config::idle_timeout")]
|
|
||||||
idle_timeout: Duration,
|
|
||||||
#[serde(getter = "gossipsub::Config::duplicate_cache_time")]
|
#[serde(getter = "gossipsub::Config::duplicate_cache_time")]
|
||||||
duplicate_cache_time: Duration,
|
duplicate_cache_time: Duration,
|
||||||
#[serde(getter = "gossipsub::Config::validate_messages")]
|
#[serde(getter = "gossipsub::Config::validate_messages")]
|
||||||
|
@ -115,7 +113,6 @@ impl From<GossipsubConfigDef> for gossipsub::Config {
|
||||||
.heartbeat_interval(def.heartbeat_interval)
|
.heartbeat_interval(def.heartbeat_interval)
|
||||||
.fanout_ttl(def.fanout_ttl)
|
.fanout_ttl(def.fanout_ttl)
|
||||||
.check_explicit_peers_ticks(def.check_explicit_peers_ticks)
|
.check_explicit_peers_ticks(def.check_explicit_peers_ticks)
|
||||||
.idle_timeout(def.idle_timeout)
|
|
||||||
.duplicate_cache_time(def.duplicate_cache_time)
|
.duplicate_cache_time(def.duplicate_cache_time)
|
||||||
.allow_self_origin(def.allow_self_origin)
|
.allow_self_origin(def.allow_self_origin)
|
||||||
.prune_peers(def.prune_peers)
|
.prune_peers(def.prune_peers)
|
||||||
|
|
|
@ -18,11 +18,9 @@ pub use libp2p::{
|
||||||
dns,
|
dns,
|
||||||
gossipsub::{self, PublishError, SubscriptionError},
|
gossipsub::{self, PublishError, SubscriptionError},
|
||||||
identity::{self, secp256k1},
|
identity::{self, secp256k1},
|
||||||
plaintext::PlainText2Config,
|
plaintext::Config as PlainText2Config,
|
||||||
swarm::{
|
swarm::{dial_opts::DialOpts, DialError, NetworkBehaviour, SwarmEvent, THandlerErr},
|
||||||
dial_opts::DialOpts, DialError, NetworkBehaviour, SwarmBuilder, SwarmEvent, THandlerErr,
|
tcp, yamux, PeerId, SwarmBuilder, Transport,
|
||||||
},
|
|
||||||
tcp, yamux, PeerId, Transport,
|
|
||||||
};
|
};
|
||||||
use libp2p::{swarm::ConnectionId, tcp::tokio::Tcp};
|
use libp2p::{swarm::ConnectionId, tcp::tokio::Tcp};
|
||||||
pub use multiaddr::{multiaddr, Multiaddr, Protocol};
|
pub use multiaddr::{multiaddr, Multiaddr, Protocol};
|
||||||
|
@ -59,15 +57,13 @@ impl Swarm {
|
||||||
// TODO: consider using noise authentication
|
// TODO: consider using noise authentication
|
||||||
let tcp_transport = tcp::Transport::<Tcp>::new(tcp::Config::default().nodelay(true))
|
let tcp_transport = tcp::Transport::<Tcp>::new(tcp::Config::default().nodelay(true))
|
||||||
.upgrade(upgrade::Version::V1Lazy)
|
.upgrade(upgrade::Version::V1Lazy)
|
||||||
.authenticate(PlainText2Config {
|
.authenticate(PlainText2Config::new(&id_keys))
|
||||||
local_public_key: id_keys.public(),
|
|
||||||
})
|
|
||||||
.multiplex(yamux::Config::default())
|
.multiplex(yamux::Config::default())
|
||||||
.timeout(TRANSPORT_TIMEOUT)
|
.timeout(TRANSPORT_TIMEOUT)
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
// Wrapping TCP transport into DNS transport to resolve hostnames.
|
// 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.
|
// TODO: consider using Signed or Anonymous.
|
||||||
// For Anonymous, a custom `message_id` function need to be set
|
// For Anonymous, a custom `message_id` function need to be set
|
||||||
|
@ -80,12 +76,12 @@ impl Swarm {
|
||||||
.build()?,
|
.build()?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut swarm = SwarmBuilder::with_tokio_executor(
|
let mut swarm = libp2p::Swarm::new(
|
||||||
tcp_transport,
|
tcp_transport,
|
||||||
Behaviour { gossipsub },
|
Behaviour { gossipsub },
|
||||||
local_peer_id,
|
local_peer_id,
|
||||||
)
|
libp2p::swarm::Config::with_tokio_executor(),
|
||||||
.build();
|
);
|
||||||
|
|
||||||
swarm.listen_on(multiaddr!(Ip4(config.host), Tcp(config.port)))?;
|
swarm.listen_on(multiaddr!(Ip4(config.host), Tcp(config.port)))?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue