mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-25 00:51:18 +00:00
fix: Remove circular dependencies across workspace (#3023)
Circular dependencies are problematic in several ways: - They result in cognitive overhead for developers, in trying to figure out what depends on what. - They present `cargo` with limits in what order the crates can be compiled in. - They invalidate build caches unnecessarily thus forcing `cargo` to rebuild certain crates. - They cause problems with tooling such as `release-please`. To actually break the circular dependencies, this patch inlines the uses of `development_transport` in the examples and tests for all sub-crates. This is only meant to be a short-term fix until https://github.com/libp2p/rust-libp2p/issues/3111 and https://github.com/libp2p/rust-libp2p/pull/2888 are fixed. To ensure we don't accidentally reintroduce this dependency, we add a basic CI that queries `cargo metadata` using `jq`. Resolves https://github.com/libp2p/rust-libp2p/issues/3053. Fixes https://github.com/libp2p/rust-libp2p/issues/3223. Related: https://github.com/libp2p/rust-libp2p/pull/2918#discussion_r976514245 Related: https://github.com/googleapis/release-please/issues/1662
This commit is contained in:
parent
f8f19baad0
commit
d7363a53d3
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -75,6 +75,11 @@ jobs:
|
|||||||
cargo install cargo-semver-checks --locked
|
cargo install cargo-semver-checks --locked
|
||||||
cargo semver-checks check-release -p ${{ matrix.crate }}
|
cargo semver-checks check-release -p ${{ matrix.crate }}
|
||||||
|
|
||||||
|
- name: Enforce no dependency on meta crate
|
||||||
|
run: |
|
||||||
|
cargo metadata --format-version=1 --no-deps | \
|
||||||
|
jq -e -r '.packages[] | select(.name == "${{ matrix.crate }}") | .dependencies | all(.name != "libp2p")'
|
||||||
|
|
||||||
cross:
|
cross:
|
||||||
name: Compile on ${{ matrix.target }}
|
name: Compile on ${{ matrix.target }}
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -61,7 +61,6 @@ identify = ["dep:libp2p-identify", "libp2p-metrics?/identify"]
|
|||||||
kad = ["dep:libp2p-kad", "libp2p-metrics?/kad"]
|
kad = ["dep:libp2p-kad", "libp2p-metrics?/kad"]
|
||||||
macros = ["libp2p-swarm/macros"]
|
macros = ["libp2p-swarm/macros"]
|
||||||
mdns = ["dep:libp2p-mdns"]
|
mdns = ["dep:libp2p-mdns"]
|
||||||
tls = ["dep:libp2p-tls"]
|
|
||||||
metrics = ["dep:libp2p-metrics"]
|
metrics = ["dep:libp2p-metrics"]
|
||||||
mplex = ["dep:libp2p-mplex"]
|
mplex = ["dep:libp2p-mplex"]
|
||||||
noise = ["dep:libp2p-noise"]
|
noise = ["dep:libp2p-noise"]
|
||||||
@ -76,6 +75,7 @@ rsa = ["libp2p-core/rsa"]
|
|||||||
secp256k1 = ["libp2p-core/secp256k1"]
|
secp256k1 = ["libp2p-core/secp256k1"]
|
||||||
serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"]
|
serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"]
|
||||||
tcp = ["dep:libp2p-tcp"]
|
tcp = ["dep:libp2p-tcp"]
|
||||||
|
tls = ["dep:libp2p-tls"]
|
||||||
tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-webrtc?/tokio"]
|
tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-webrtc?/tokio"]
|
||||||
uds = ["dep:libp2p-uds"]
|
uds = ["dep:libp2p-uds"]
|
||||||
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen"]
|
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen"]
|
||||||
|
@ -47,7 +47,8 @@ ring = { version = "0.16.9", features = ["alloc", "std"], default-features = fal
|
|||||||
async-std = { version = "1.6.2", features = ["attributes"] }
|
async-std = { version = "1.6.2", features = ["attributes"] }
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
criterion = "0.4"
|
criterion = "0.4"
|
||||||
libp2p = { path = "..", features = ["full"] }
|
libp2p-mplex = { path = "../muxers/mplex" }
|
||||||
|
libp2p-noise = { path = "../transports/noise" }
|
||||||
multihash = { version = "0.16", default-features = false, features = ["arb"] }
|
multihash = { version = "0.16", default-features = false, features = ["arb"] }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" }
|
quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" }
|
||||||
rmp-serde = "1.0"
|
rmp-serde = "1.0"
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::core::identity;
|
use libp2p_core::identity;
|
||||||
use libp2p::core::transport::{MemoryTransport, Transport};
|
use libp2p_core::transport::{MemoryTransport, Transport};
|
||||||
use libp2p::core::upgrade::{self, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
use libp2p_core::upgrade::{self, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||||
use libp2p::mplex::MplexConfig;
|
use libp2p_mplex::MplexConfig;
|
||||||
use libp2p::noise;
|
use libp2p_noise as noise;
|
||||||
use multiaddr::{Multiaddr, Protocol};
|
use multiaddr::{Multiaddr, Protocol};
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use std::{io, pin::Pin};
|
use std::{io, pin::Pin};
|
||||||
|
@ -32,11 +32,15 @@ prometheus-client = "0.18.0"
|
|||||||
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }
|
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
log = "0.4.0"
|
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
|
||||||
hyper = { version="0.14", features = ["server", "tcp", "http1"] }
|
hyper = { version="0.14", features = ["server", "tcp", "http1"] }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-ping = { path = "../../protocols/ping" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["macros"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
log = "0.4.0"
|
||||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
@ -45,3 +49,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] }
|
|||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
rustc-args = ["--cfg", "docsrs"]
|
rustc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "metrics"
|
||||||
|
required-features = ["ping"]
|
||||||
|
@ -51,11 +51,17 @@
|
|||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use libp2p::core::Multiaddr;
|
use libp2p_core::{identity, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::metrics::{Metrics, Recorder};
|
use libp2p_identify as identify;
|
||||||
use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
|
use libp2p_metrics::{Metrics, Recorder};
|
||||||
use libp2p::{identify, identity, ping, PeerId, Swarm};
|
use libp2p_noise as noise;
|
||||||
|
use libp2p_ping as ping;
|
||||||
use libp2p_swarm::keep_alive;
|
use libp2p_swarm::keep_alive;
|
||||||
|
use libp2p_swarm::NetworkBehaviour;
|
||||||
|
use libp2p_swarm::Swarm;
|
||||||
|
use libp2p_swarm::SwarmEvent;
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use log::info;
|
use log::info;
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@ -69,10 +75,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let local_key = identity::Keypair::generate_ed25519();
|
let local_key = identity::Keypair::generate_ed25519();
|
||||||
let local_peer_id = PeerId::from(local_key.public());
|
let local_peer_id = PeerId::from(local_key.public());
|
||||||
let local_pub_key = local_key.public();
|
let local_pub_key = local_key.public();
|
||||||
info!("Local peer id: {:?}", local_peer_id);
|
info!("Local peer id: {local_peer_id:?}");
|
||||||
|
|
||||||
let mut swarm = Swarm::without_executor(
|
let mut swarm = Swarm::without_executor(
|
||||||
block_on(libp2p::development_transport(local_key))?,
|
tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
|
||||||
|
.multiplex(yamux::YamuxConfig::default())
|
||||||
|
.boxed(),
|
||||||
Behaviour::new(local_pub_key),
|
Behaviour::new(local_pub_key),
|
||||||
local_peer_id,
|
local_peer_id,
|
||||||
);
|
);
|
||||||
@ -115,6 +125,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
/// For illustrative purposes, this includes the [`keep_alive::Behaviour`]) behaviour so the ping actually happen
|
/// For illustrative purposes, this includes the [`keep_alive::Behaviour`]) behaviour so the ping actually happen
|
||||||
/// and can be observed via the metrics.
|
/// and can be observed via the metrics.
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
|
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
identify: identify::Behaviour,
|
identify: identify::Behaviour,
|
||||||
keep_alive: keep_alive::Behaviour,
|
keep_alive: keep_alive::Behaviour,
|
||||||
@ -122,7 +133,7 @@ struct Behaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Behaviour {
|
impl Behaviour {
|
||||||
fn new(local_pub_key: libp2p::identity::PublicKey) -> Self {
|
fn new(local_pub_key: identity::PublicKey) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ping: ping::Behaviour::default(),
|
ping: ping::Behaviour::default(),
|
||||||
identify: identify::Behaviour::new(identify::Config::new(
|
identify: identify::Behaviour::new(identify::Config::new(
|
||||||
|
@ -21,7 +21,10 @@ unsigned-varint = "0.7"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-core = { path = "../../core" }
|
||||||
|
libp2p-mplex = { path = "../../muxers/mplex" }
|
||||||
|
libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["async-std"] }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
rw-stream-sink = { version = "0.3.0", path = "../../misc/rw-stream-sink" }
|
rw-stream-sink = { version = "0.3.0", path = "../../misc/rw-stream-sink" }
|
||||||
|
@ -19,16 +19,16 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::{channel::oneshot, prelude::*, ready};
|
use futures::{channel::oneshot, prelude::*, ready};
|
||||||
use libp2p::core::{
|
use libp2p_core::{
|
||||||
identity,
|
identity,
|
||||||
multiaddr::Protocol,
|
multiaddr::Protocol,
|
||||||
muxing::StreamMuxerBox,
|
muxing::StreamMuxerBox,
|
||||||
transport::{self, MemoryTransport},
|
transport::{self, MemoryTransport},
|
||||||
upgrade, Multiaddr, PeerId, Transport,
|
upgrade, Multiaddr, PeerId, Transport,
|
||||||
};
|
};
|
||||||
use libp2p::mplex::MplexConfig;
|
use libp2p_mplex::MplexConfig;
|
||||||
use libp2p::plaintext::PlainText2Config;
|
use libp2p_plaintext::PlainText2Config;
|
||||||
use libp2p::swarm::{dummy, Swarm, SwarmEvent};
|
use libp2p_swarm::{dummy, Swarm, SwarmEvent};
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|
||||||
|
@ -27,8 +27,9 @@ async-std = { version = "1.7.0", features = ["attributes"] }
|
|||||||
criterion = "0.4"
|
criterion = "0.4"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
|
||||||
libp2p-muxer-test-harness = { path = "../test-harness" }
|
libp2p-muxer-test-harness = { path = "../test-harness" }
|
||||||
|
libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
|
@ -26,12 +26,12 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughpu
|
|||||||
use futures::future::poll_fn;
|
use futures::future::poll_fn;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use futures::{channel::oneshot, future::join};
|
use futures::{channel::oneshot, future::join};
|
||||||
use libp2p::core::muxing::StreamMuxerExt;
|
use libp2p_core::muxing::StreamMuxerExt;
|
||||||
use libp2p::core::{
|
use libp2p_core::{
|
||||||
identity, multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, PeerId, Transport,
|
identity, multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, PeerId, Transport,
|
||||||
};
|
};
|
||||||
use libp2p::plaintext::PlainText2Config;
|
use libp2p_mplex as mplex;
|
||||||
use libp2p::{mplex, tcp};
|
use libp2p_plaintext::PlainText2Config;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ fn tcp_transport(split_send_size: usize) -> BenchTransport {
|
|||||||
let mut mplex = mplex::MplexConfig::default();
|
let mut mplex = mplex::MplexConfig::default();
|
||||||
mplex.set_split_send_size(split_send_size);
|
mplex.set_split_send_size(split_send_size);
|
||||||
|
|
||||||
tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
|
libp2p_tcp::async_io::Transport::new(libp2p_tcp::Config::default().nodelay(true))
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(PlainText2Config { local_public_key })
|
.authenticate(PlainText2Config { local_public_key })
|
||||||
.multiplex(mplex)
|
.multiplex(mplex)
|
||||||
|
@ -27,9 +27,13 @@ prost = "0.11"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = { version = "1.10", features = ["attributes"] }
|
async-std = { version = "1.10", features = ["attributes"] }
|
||||||
env_logger = "0.10"
|
|
||||||
clap = { version = "4.0.13", features = ["derive"] }
|
clap = { version = "4.0.13", features = ["derive"] }
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
env_logger = "0.10"
|
||||||
|
libp2p-identify = { path = "../identify" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["async-std", "macros"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
# More information: https://docs.rs/about/builds#cross-compiling
|
# More information: https://docs.rs/about/builds#cross-compiling
|
||||||
|
@ -31,11 +31,14 @@
|
|||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::autonat;
|
use libp2p_autonat as autonat;
|
||||||
use libp2p::identify;
|
use libp2p_core::multiaddr::Protocol;
|
||||||
use libp2p::multiaddr::Protocol;
|
use libp2p_core::{identity, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_identify as identify;
|
||||||
use libp2p::{identity, Multiaddr, PeerId};
|
use libp2p_noise as noise;
|
||||||
|
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -63,7 +66,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let local_peer_id = PeerId::from(local_key.public());
|
let local_peer_id = PeerId::from(local_key.public());
|
||||||
println!("Local peer id: {:?}", local_peer_id);
|
println!("Local peer id: {:?}", local_peer_id);
|
||||||
|
|
||||||
let transport = libp2p::development_transport(local_key.clone()).await?;
|
let transport = tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
|
||||||
|
.multiplex(yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
|
|
||||||
let behaviour = Behaviour::new(local_key.public());
|
let behaviour = Behaviour::new(local_key.public());
|
||||||
|
|
||||||
@ -89,7 +96,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "Event")]
|
#[behaviour(out_event = "Event", prelude = "libp2p_swarm::derive_prelude")]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
identify: identify::Behaviour,
|
identify: identify::Behaviour,
|
||||||
auto_nat: autonat::Behaviour,
|
auto_nat: autonat::Behaviour,
|
||||||
|
@ -28,11 +28,13 @@
|
|||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::autonat;
|
use libp2p_autonat as autonat;
|
||||||
use libp2p::identify;
|
use libp2p_core::{identity, multiaddr::Protocol, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::multiaddr::Protocol;
|
use libp2p_identify as identify;
|
||||||
use libp2p::swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_noise as noise;
|
||||||
use libp2p::{identity, Multiaddr, PeerId};
|
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
|
|
||||||
@ -53,7 +55,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let local_peer_id = PeerId::from(local_key.public());
|
let local_peer_id = PeerId::from(local_key.public());
|
||||||
println!("Local peer id: {:?}", local_peer_id);
|
println!("Local peer id: {:?}", local_peer_id);
|
||||||
|
|
||||||
let transport = libp2p::development_transport(local_key.clone()).await?;
|
let transport = tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
|
||||||
|
.multiplex(yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
|
|
||||||
let behaviour = Behaviour::new(local_key.public());
|
let behaviour = Behaviour::new(local_key.public());
|
||||||
|
|
||||||
@ -74,7 +80,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "Event")]
|
#[behaviour(out_event = "Event", prelude = "libp2p_swarm::derive_prelude")]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
identify: identify::Behaviour,
|
identify: identify::Behaviour,
|
||||||
auto_nat: autonat::Behaviour,
|
auto_nat: autonat::Behaviour,
|
||||||
|
@ -20,15 +20,14 @@
|
|||||||
|
|
||||||
use futures::{channel::oneshot, Future, FutureExt, StreamExt};
|
use futures::{channel::oneshot, Future, FutureExt, StreamExt};
|
||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use libp2p::{
|
|
||||||
development_transport,
|
|
||||||
identity::Keypair,
|
|
||||||
swarm::{AddressScore, Swarm, SwarmEvent},
|
|
||||||
Multiaddr, PeerId,
|
|
||||||
};
|
|
||||||
use libp2p_autonat::{
|
use libp2p_autonat::{
|
||||||
Behaviour, Config, Event, NatStatus, OutboundProbeError, OutboundProbeEvent, ResponseError,
|
Behaviour, Config, Event, NatStatus, OutboundProbeError, OutboundProbeEvent, ResponseError,
|
||||||
};
|
};
|
||||||
|
use libp2p_core::{identity::Keypair, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
|
use libp2p_noise as noise;
|
||||||
|
use libp2p_swarm::{AddressScore, Swarm, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
const MAX_CONFIDENCE: usize = 3;
|
const MAX_CONFIDENCE: usize = 3;
|
||||||
@ -38,7 +37,11 @@ const TEST_REFRESH_INTERVAL: Duration = Duration::from_secs(2);
|
|||||||
async fn init_swarm(config: Config) -> Swarm<Behaviour> {
|
async fn init_swarm(config: Config) -> Swarm<Behaviour> {
|
||||||
let keypair = Keypair::generate_ed25519();
|
let keypair = Keypair::generate_ed25519();
|
||||||
let local_id = PeerId::from_public_key(&keypair.public());
|
let local_id = PeerId::from_public_key(&keypair.public());
|
||||||
let transport = development_transport(keypair).await.unwrap();
|
let transport = tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap())
|
||||||
|
.multiplex(yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
let behaviour = Behaviour::new(local_id, config);
|
let behaviour = Behaviour::new(local_id, config);
|
||||||
Swarm::with_async_std_executor(transport, behaviour, local_id)
|
Swarm::with_async_std_executor(transport, behaviour, local_id)
|
||||||
}
|
}
|
||||||
|
@ -20,24 +20,28 @@
|
|||||||
|
|
||||||
use futures::{channel::oneshot, Future, FutureExt, StreamExt};
|
use futures::{channel::oneshot, Future, FutureExt, StreamExt};
|
||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use libp2p::core::{ConnectedPoint, Endpoint};
|
|
||||||
use libp2p::swarm::DialError;
|
|
||||||
use libp2p::{
|
|
||||||
development_transport,
|
|
||||||
identity::Keypair,
|
|
||||||
multiaddr::Protocol,
|
|
||||||
swarm::{AddressScore, Swarm, SwarmEvent},
|
|
||||||
Multiaddr, PeerId,
|
|
||||||
};
|
|
||||||
use libp2p_autonat::{
|
use libp2p_autonat::{
|
||||||
Behaviour, Config, Event, InboundProbeError, InboundProbeEvent, ResponseError,
|
Behaviour, Config, Event, InboundProbeError, InboundProbeEvent, ResponseError,
|
||||||
};
|
};
|
||||||
|
use libp2p_core::{
|
||||||
|
identity::Keypair, multiaddr::Protocol, upgrade::Version, ConnectedPoint, Endpoint, Multiaddr,
|
||||||
|
PeerId, Transport,
|
||||||
|
};
|
||||||
|
use libp2p_noise as noise;
|
||||||
|
use libp2p_swarm::DialError;
|
||||||
|
use libp2p_swarm::{AddressScore, Swarm, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use std::{num::NonZeroU32, time::Duration};
|
use std::{num::NonZeroU32, time::Duration};
|
||||||
|
|
||||||
async fn init_swarm(config: Config) -> Swarm<Behaviour> {
|
async fn init_swarm(config: Config) -> Swarm<Behaviour> {
|
||||||
let keypair = Keypair::generate_ed25519();
|
let keypair = Keypair::generate_ed25519();
|
||||||
let local_id = PeerId::from_public_key(&keypair.public());
|
let local_id = PeerId::from_public_key(&keypair.public());
|
||||||
let transport = development_transport(keypair).await.unwrap();
|
let transport = tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap())
|
||||||
|
.multiplex(yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
let behaviour = Behaviour::new(local_id, config);
|
let behaviour = Behaviour::new(local_id, config);
|
||||||
Swarm::with_async_std_executor(transport, behaviour, local_id)
|
Swarm::with_async_std_executor(transport, behaviour, local_id)
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,18 @@ void = "1"
|
|||||||
prost-build = "0.11"
|
prost-build = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.10.0"
|
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
|
||||||
rand = "0.8"
|
|
||||||
clap = { version = "4.0.13", features = ["derive"] }
|
clap = { version = "4.0.13", features = ["derive"] }
|
||||||
|
env_logger = "0.10.0"
|
||||||
|
libp2p-dns = { path = "../../transports/dns", features = ["async-std"] }
|
||||||
|
libp2p-identify = { path = "../../protocols/identify" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-ping = { path = "../../protocols/ping" }
|
||||||
|
libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||||
|
libp2p-relay = { path = "../relay" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["macros"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
rand = "0.8"
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
# More information: https://docs.rs/about/builds#cross-compiling
|
# More information: https://docs.rs/about/builds#cross-compiling
|
||||||
|
@ -22,18 +22,19 @@ use clap::Parser;
|
|||||||
use futures::executor::{block_on, ThreadPool};
|
use futures::executor::{block_on, ThreadPool};
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use libp2p::core::multiaddr::{Multiaddr, Protocol};
|
use libp2p_core::multiaddr::{Multiaddr, Protocol};
|
||||||
use libp2p::core::transport::OrTransport;
|
use libp2p_core::transport::OrTransport;
|
||||||
use libp2p::core::upgrade;
|
use libp2p_core::upgrade;
|
||||||
use libp2p::dns::DnsConfig;
|
use libp2p_core::Transport;
|
||||||
use libp2p::identify;
|
use libp2p_core::{identity, PeerId};
|
||||||
use libp2p::noise;
|
use libp2p_dcutr as dcutr;
|
||||||
use libp2p::relay::v2::client::{self, Client};
|
use libp2p_dns::DnsConfig;
|
||||||
use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
|
use libp2p_identify as identify;
|
||||||
use libp2p::tcp;
|
use libp2p_noise as noise;
|
||||||
use libp2p::Transport;
|
use libp2p_ping as ping;
|
||||||
use libp2p::{dcutr, ping};
|
use libp2p_relay::v2::client::{self, Client};
|
||||||
use libp2p::{identity, PeerId};
|
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@ -100,11 +101,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
noise::NoiseAuthenticated::xx(&local_key)
|
noise::NoiseAuthenticated::xx(&local_key)
|
||||||
.expect("Signing libp2p-noise static DH keypair failed."),
|
.expect("Signing libp2p-noise static DH keypair failed."),
|
||||||
)
|
)
|
||||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "Event", event_process = false)]
|
#[behaviour(
|
||||||
|
out_event = "Event",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
relay_client: Client,
|
relay_client: Client,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
|
@ -23,17 +23,17 @@ use futures::future::FutureExt;
|
|||||||
use futures::io::{AsyncRead, AsyncWrite};
|
use futures::io::{AsyncRead, AsyncWrite};
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use futures::task::Spawn;
|
use futures::task::Spawn;
|
||||||
use libp2p::core::multiaddr::{Multiaddr, Protocol};
|
use libp2p_core::multiaddr::{Multiaddr, Protocol};
|
||||||
use libp2p::core::muxing::StreamMuxerBox;
|
use libp2p_core::muxing::StreamMuxerBox;
|
||||||
use libp2p::core::transport::upgrade::Version;
|
use libp2p_core::transport::upgrade::Version;
|
||||||
use libp2p::core::transport::{Boxed, MemoryTransport, OrTransport, Transport};
|
use libp2p_core::transport::{Boxed, MemoryTransport, OrTransport, Transport};
|
||||||
use libp2p::core::PublicKey;
|
use libp2p_core::PublicKey;
|
||||||
use libp2p::core::{identity, PeerId};
|
use libp2p_core::{identity, PeerId};
|
||||||
use libp2p::dcutr;
|
use libp2p_dcutr as dcutr;
|
||||||
use libp2p::plaintext::PlainText2Config;
|
use libp2p_plaintext::PlainText2Config;
|
||||||
use libp2p::relay::v2::client;
|
use libp2p_relay::v2::client;
|
||||||
use libp2p::relay::v2::relay;
|
use libp2p_relay::v2::relay;
|
||||||
use libp2p::swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -142,12 +142,16 @@ where
|
|||||||
transport
|
transport
|
||||||
.upgrade(Version::V1)
|
.upgrade(Version::V1)
|
||||||
.authenticate(PlainText2Config { local_public_key })
|
.authenticate(PlainText2Config { local_public_key })
|
||||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "ClientEvent", event_process = false)]
|
#[behaviour(
|
||||||
|
out_event = "ClientEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct Client {
|
struct Client {
|
||||||
relay: client::Client,
|
relay: client::Client,
|
||||||
dcutr: dcutr::behaviour::Behaviour,
|
dcutr: dcutr::behaviour::Behaviour,
|
||||||
|
@ -37,11 +37,15 @@ prometheus-client = "0.18.0"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.3"
|
async-std = "1.6.3"
|
||||||
env_logger = "0.10.0"
|
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
|
||||||
hex = "0.4.2"
|
|
||||||
derive_builder = "0.11.1"
|
derive_builder = "0.11.1"
|
||||||
|
env_logger = "0.10.0"
|
||||||
|
hex = "0.4.2"
|
||||||
|
libp2p-mplex = { path = "../../muxers/mplex" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||||
|
libp2p-swarm = { path = "../../swarm" }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = "0.11"
|
prost-build = "0.11"
|
||||||
|
@ -101,8 +101,8 @@
|
|||||||
//! // This is test transport (memory).
|
//! // This is test transport (memory).
|
||||||
//! let transport = MemoryTransport::default()
|
//! let transport = MemoryTransport::default()
|
||||||
//! .upgrade(libp2p_core::upgrade::Version::V1)
|
//! .upgrade(libp2p_core::upgrade::Version::V1)
|
||||||
//! .authenticate(libp2p::noise::NoiseAuthenticated::xx(&local_key).unwrap())
|
//! .authenticate(libp2p_noise::NoiseAuthenticated::xx(&local_key).unwrap())
|
||||||
//! .multiplex(libp2p::mplex::MplexConfig::new())
|
//! .multiplex(libp2p_mplex::MplexConfig::new())
|
||||||
//! .boxed();
|
//! .boxed();
|
||||||
//!
|
//!
|
||||||
//! // Create a Gossipsub topic
|
//! // Create a Gossipsub topic
|
||||||
|
@ -29,16 +29,16 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::{
|
use libp2p_core::{
|
||||||
identity, multiaddr::Protocol, transport::MemoryTransport, upgrade, Multiaddr, Transport,
|
identity, multiaddr::Protocol, transport::MemoryTransport, upgrade, Multiaddr, Transport,
|
||||||
};
|
};
|
||||||
use libp2p::gossipsub::{
|
use libp2p_gossipsub::{
|
||||||
Gossipsub, GossipsubConfigBuilder, GossipsubEvent, IdentTopic as Topic, MessageAuthenticity,
|
Gossipsub, GossipsubConfigBuilder, GossipsubEvent, IdentTopic as Topic, MessageAuthenticity,
|
||||||
ValidationMode,
|
ValidationMode,
|
||||||
};
|
};
|
||||||
use libp2p::plaintext::PlainText2Config;
|
use libp2p_plaintext::PlainText2Config;
|
||||||
use libp2p::swarm::{Swarm, SwarmEvent};
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
use libp2p::yamux;
|
use libp2p_yamux as yamux;
|
||||||
|
|
||||||
struct Graph {
|
struct Graph {
|
||||||
pub nodes: Vec<(Multiaddr, Swarm<Gossipsub>)>,
|
pub nodes: Vec<(Multiaddr, Swarm<Gossipsub>)>,
|
||||||
|
@ -27,7 +27,11 @@ void = "1.0"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = { version = "1.6.2", features = ["attributes"] }
|
async-std = { version = "1.6.2", features = ["attributes"] }
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-mplex = { path = "../../muxers/mplex" }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["async-std"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = "0.11"
|
prost-build = "0.11"
|
||||||
|
@ -37,7 +37,9 @@
|
|||||||
//! and will send each other identify info which is then printed to the console.
|
//! and will send each other identify info which is then printed to the console.
|
||||||
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::{identify, identity, Multiaddr, PeerId};
|
use libp2p_core::upgrade::Version;
|
||||||
|
use libp2p_core::{identity, Multiaddr, PeerId, Transport};
|
||||||
|
use libp2p_identify as identify;
|
||||||
use libp2p_swarm::{Swarm, SwarmEvent};
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
@ -47,7 +49,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let local_peer_id = PeerId::from(local_key.public());
|
let local_peer_id = PeerId::from(local_key.public());
|
||||||
println!("Local peer id: {:?}", local_peer_id);
|
println!("Local peer id: {:?}", local_peer_id);
|
||||||
|
|
||||||
let transport = libp2p::development_transport(local_key.clone()).await?;
|
let transport = libp2p_tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&local_key).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
|
|
||||||
// Create a identify network behaviour.
|
// Create a identify network behaviour.
|
||||||
let behaviour = identify::Behaviour::new(identify::Config::new(
|
let behaviour = identify::Behaviour::new(identify::Config::new(
|
||||||
|
@ -557,11 +557,11 @@ impl PeerCache {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use libp2p::mplex::MplexConfig;
|
|
||||||
use libp2p::noise;
|
|
||||||
use libp2p::tcp;
|
|
||||||
use libp2p_core::{identity, muxing::StreamMuxerBox, transport, upgrade, PeerId, Transport};
|
use libp2p_core::{identity, muxing::StreamMuxerBox, transport, upgrade, PeerId, Transport};
|
||||||
|
use libp2p_mplex::MplexConfig;
|
||||||
|
use libp2p_noise as noise;
|
||||||
use libp2p_swarm::{Swarm, SwarmEvent};
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
fn transport() -> (
|
fn transport() -> (
|
||||||
|
@ -46,22 +46,22 @@ pub use self::protocol::{Info, UpgradeError, PROTOCOL_NAME, PUSH_PROTOCOL_NAME};
|
|||||||
|
|
||||||
#[deprecated(
|
#[deprecated(
|
||||||
since = "0.40.0",
|
since = "0.40.0",
|
||||||
note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p::identify::Config`"
|
note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p_identify::Config`"
|
||||||
)]
|
)]
|
||||||
pub type IdentifyConfig = Config;
|
pub type IdentifyConfig = Config;
|
||||||
|
|
||||||
#[deprecated(
|
#[deprecated(
|
||||||
since = "0.40.0",
|
since = "0.40.0",
|
||||||
note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p::identify::Event`"
|
note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p_identify::Event`"
|
||||||
)]
|
)]
|
||||||
pub type IdentifyEvent = Event;
|
pub type IdentifyEvent = Event;
|
||||||
|
|
||||||
#[deprecated(since = "0.40.0", note = "Use libp2p::identify::Behaviour instead.")]
|
#[deprecated(since = "0.40.0", note = "Use libp2p_identify::Behaviour instead.")]
|
||||||
pub type Identify = Behaviour;
|
pub type Identify = Behaviour;
|
||||||
|
|
||||||
#[deprecated(
|
#[deprecated(
|
||||||
since = "0.40.0",
|
since = "0.40.0",
|
||||||
note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p::identify::Info`"
|
note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p_identify::Info`"
|
||||||
)]
|
)]
|
||||||
pub type IdentifyInfo = Info;
|
pub type IdentifyInfo = Info;
|
||||||
|
|
||||||
|
@ -275,12 +275,12 @@ pub enum UpgradeError {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::channel::oneshot;
|
use futures::channel::oneshot;
|
||||||
use libp2p::tcp;
|
|
||||||
use libp2p_core::{
|
use libp2p_core::{
|
||||||
identity,
|
identity,
|
||||||
upgrade::{self, apply_inbound, apply_outbound},
|
upgrade::{self, apply_inbound, apply_outbound},
|
||||||
Transport,
|
Transport,
|
||||||
};
|
};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn correct_transfer() {
|
fn correct_transfer() {
|
||||||
|
@ -35,7 +35,8 @@ thiserror = "1"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
futures-timer = "3.0"
|
futures-timer = "3.0"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -27,9 +27,6 @@ use crate::record::{store::MemoryStore, Key};
|
|||||||
use crate::K_VALUE;
|
use crate::K_VALUE;
|
||||||
use futures::{executor::block_on, future::poll_fn, prelude::*};
|
use futures::{executor::block_on, future::poll_fn, prelude::*};
|
||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use libp2p::noise;
|
|
||||||
use libp2p::swarm::{Swarm, SwarmEvent};
|
|
||||||
use libp2p::yamux;
|
|
||||||
use libp2p_core::{
|
use libp2p_core::{
|
||||||
connection::{ConnectedPoint, ConnectionId},
|
connection::{ConnectedPoint, ConnectionId},
|
||||||
identity,
|
identity,
|
||||||
@ -38,6 +35,9 @@ use libp2p_core::{
|
|||||||
transport::MemoryTransport,
|
transport::MemoryTransport,
|
||||||
upgrade, Endpoint, PeerId, Transport,
|
upgrade, Endpoint, PeerId, Transport,
|
||||||
};
|
};
|
||||||
|
use libp2p_noise as noise;
|
||||||
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use quickcheck::*;
|
use quickcheck::*;
|
||||||
use rand::{random, rngs::StdRng, thread_rng, Rng, SeedableRng};
|
use rand::{random, rngs::StdRng, thread_rng, Rng, SeedableRng};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -32,10 +32,12 @@ async-io = ["dep:async-io", "if-watch/smol"]
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = { version = "1.9.0", features = ["attributes"] }
|
async-std = { version = "1.9.0", features = ["attributes"] }
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["tokio", "async-std"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["tokio", "async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
tokio = { version = "1.19", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] }
|
tokio = { version = "1.19", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] }
|
||||||
|
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "use-async-std"
|
name = "use-async-std"
|
||||||
required-features = ["async-io"]
|
required-features = ["async-io"]
|
||||||
|
@ -20,18 +20,17 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
marker::Unpin,
|
marker::Unpin,
|
||||||
pin::Pin,
|
|
||||||
task::{Context, Poll},
|
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Simple wrapper for the differents type of timers
|
/// Simple wrapper for the different type of timers
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg(any(feature = "async-io", feature = "tokio"))]
|
||||||
pub struct Timer<T> {
|
pub struct Timer<T> {
|
||||||
inner: T,
|
inner: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builder interface to homogenize the differents implementations
|
/// Builder interface to homogenize the different implementations
|
||||||
pub trait Builder: Send + Unpin + 'static {
|
pub trait Builder: Send + Unpin + 'static {
|
||||||
/// Creates a timer that emits an event once at the given time instant.
|
/// Creates a timer that emits an event once at the given time instant.
|
||||||
fn at(instant: Instant) -> Self;
|
fn at(instant: Instant) -> Self;
|
||||||
@ -48,6 +47,10 @@ pub mod asio {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use async_io::Timer as AsioTimer;
|
use async_io::Timer as AsioTimer;
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
|
use std::{
|
||||||
|
pin::Pin,
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
|
||||||
/// Async Timer
|
/// Async Timer
|
||||||
pub type AsyncTimer = Timer<AsioTimer>;
|
pub type AsyncTimer = Timer<AsioTimer>;
|
||||||
@ -86,6 +89,10 @@ pub mod tokio {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use ::tokio::time::{self, Instant as TokioInstant, Interval, MissedTickBehavior};
|
use ::tokio::time::{self, Instant as TokioInstant, Interval, MissedTickBehavior};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
|
use std::{
|
||||||
|
pin::Pin,
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
|
||||||
/// Tokio wrapper
|
/// Tokio wrapper
|
||||||
pub type TokioTimer = Timer<Interval>;
|
pub type TokioTimer = Timer<Interval>;
|
||||||
|
@ -19,12 +19,10 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.use futures::StreamExt;
|
// DEALINGS IN THE SOFTWARE.use futures::StreamExt;
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::{
|
use libp2p_core::{identity, upgrade::Version, PeerId, Transport};
|
||||||
identity,
|
use libp2p_mdns::Event;
|
||||||
mdns::{async_io::Behaviour, Config, Event},
|
use libp2p_mdns::{async_io::Behaviour, Config};
|
||||||
swarm::{Swarm, SwarmEvent},
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
PeerId,
|
|
||||||
};
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -60,7 +58,11 @@ async fn test_expired_async_std() -> Result<(), Box<dyn Error>> {
|
|||||||
async fn create_swarm(config: Config) -> Result<Swarm<Behaviour>, Box<dyn Error>> {
|
async fn create_swarm(config: Config) -> Result<Swarm<Behaviour>, Box<dyn Error>> {
|
||||||
let id_keys = identity::Keypair::generate_ed25519();
|
let id_keys = identity::Keypair::generate_ed25519();
|
||||||
let peer_id = PeerId::from(id_keys.public());
|
let peer_id = PeerId::from(id_keys.public());
|
||||||
let transport = libp2p::development_transport(id_keys).await?;
|
let transport = libp2p_tcp::async_io::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&id_keys).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
let behaviour = Behaviour::new(config)?;
|
let behaviour = Behaviour::new(config)?;
|
||||||
let mut swarm = Swarm::with_async_std_executor(transport, behaviour, peer_id);
|
let mut swarm = Swarm::with_async_std_executor(transport, behaviour, peer_id);
|
||||||
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
||||||
|
@ -18,12 +18,10 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.use futures::StreamExt;
|
// DEALINGS IN THE SOFTWARE.use futures::StreamExt;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::{
|
use libp2p_core::{identity, upgrade::Version, PeerId, Transport};
|
||||||
identity,
|
use libp2p_mdns::{tokio::Behaviour, Config, Event};
|
||||||
mdns::{tokio::Behaviour, Config, Event},
|
use libp2p_swarm::Swarm;
|
||||||
swarm::{Swarm, SwarmEvent},
|
use libp2p_swarm::SwarmEvent;
|
||||||
PeerId,
|
|
||||||
};
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -56,7 +54,11 @@ async fn test_expired_tokio() -> Result<(), Box<dyn Error>> {
|
|||||||
async fn create_swarm(config: Config) -> Result<Swarm<Behaviour>, Box<dyn Error>> {
|
async fn create_swarm(config: Config) -> Result<Swarm<Behaviour>, Box<dyn Error>> {
|
||||||
let id_keys = identity::Keypair::generate_ed25519();
|
let id_keys = identity::Keypair::generate_ed25519();
|
||||||
let peer_id = PeerId::from(id_keys.public());
|
let peer_id = PeerId::from(id_keys.public());
|
||||||
let transport = libp2p::tokio_development_transport(id_keys)?;
|
let transport = libp2p_tcp::tokio::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&id_keys).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed();
|
||||||
let behaviour = Behaviour::new(config)?;
|
let behaviour = Behaviour::new(config)?;
|
||||||
let mut swarm = Swarm::with_tokio_executor(transport, behaviour, peer_id);
|
let mut swarm = Swarm::with_tokio_executor(transport, behaviour, peer_id);
|
||||||
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
||||||
|
@ -22,7 +22,11 @@ void = "1.0"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-mplex = { path = "../../muxers/mplex" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["async-std", "macros"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
|
@ -21,19 +21,19 @@
|
|||||||
//! Integration tests for the `Ping` network behaviour.
|
//! Integration tests for the `Ping` network behaviour.
|
||||||
|
|
||||||
use futures::{channel::mpsc, prelude::*};
|
use futures::{channel::mpsc, prelude::*};
|
||||||
use libp2p::core::{
|
use libp2p_core::{
|
||||||
identity,
|
identity,
|
||||||
muxing::StreamMuxerBox,
|
muxing::StreamMuxerBox,
|
||||||
transport::{self, Transport},
|
transport::{self, Transport},
|
||||||
upgrade, Multiaddr, PeerId,
|
upgrade, Multiaddr, PeerId,
|
||||||
};
|
};
|
||||||
use libp2p::mplex;
|
use libp2p_mplex as mplex;
|
||||||
use libp2p::noise;
|
use libp2p_noise as noise;
|
||||||
use libp2p::ping;
|
use libp2p_ping as ping;
|
||||||
use libp2p::swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
|
||||||
use libp2p::tcp;
|
|
||||||
use libp2p::yamux;
|
|
||||||
use libp2p_swarm::keep_alive;
|
use libp2p_swarm::keep_alive;
|
||||||
|
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use quickcheck::*;
|
use quickcheck::*;
|
||||||
use std::{num::NonZeroU8, time::Duration};
|
use std::{num::NonZeroU8, time::Duration};
|
||||||
|
|
||||||
@ -271,6 +271,7 @@ impl Arbitrary for MuxerChoice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour, Default)]
|
#[derive(NetworkBehaviour, Default)]
|
||||||
|
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
keep_alive: keep_alive::Behaviour,
|
keep_alive: keep_alive::Behaviour,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
|
@ -33,10 +33,16 @@ void = "1"
|
|||||||
prost-build = "0.11"
|
prost-build = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.10.0"
|
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
|
||||||
clap = { version = "4.0.13", features = ["derive"] }
|
clap = { version = "4.0.13", features = ["derive"] }
|
||||||
|
env_logger = "0.10.0"
|
||||||
|
libp2p-identify = { path = "../../protocols/identify" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-ping = { path = "../../protocols/ping" }
|
||||||
|
libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||||
|
libp2p-swarm = { path = "../../swarm", features = ["macros"] }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
# More information: https://docs.rs/about/builds#cross-compiling
|
# More information: https://docs.rs/about/builds#cross-compiling
|
||||||
|
@ -22,16 +22,15 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use libp2p::core::upgrade;
|
use libp2p_core::multiaddr::Protocol;
|
||||||
use libp2p::identify;
|
use libp2p_core::upgrade;
|
||||||
use libp2p::multiaddr::Protocol;
|
use libp2p_core::{identity, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::ping;
|
use libp2p_identify as identify;
|
||||||
use libp2p::relay::v2::relay::{self, Relay};
|
use libp2p_noise as noise;
|
||||||
use libp2p::swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_ping as ping;
|
||||||
use libp2p::tcp;
|
use libp2p_relay::v2::relay::{self, Relay};
|
||||||
use libp2p::Transport;
|
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use libp2p::{identity, PeerId};
|
use libp2p_tcp as tcp;
|
||||||
use libp2p::{noise, Multiaddr};
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
noise::NoiseAuthenticated::xx(&local_key)
|
noise::NoiseAuthenticated::xx(&local_key)
|
||||||
.expect("Signing libp2p-noise static DH keypair failed."),
|
.expect("Signing libp2p-noise static DH keypair failed."),
|
||||||
)
|
)
|
||||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
let behaviour = Behaviour {
|
let behaviour = Behaviour {
|
||||||
@ -93,7 +92,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "Event", event_process = false)]
|
#[behaviour(
|
||||||
|
out_event = "Event",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
relay: Relay,
|
relay: Relay,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
|
@ -23,17 +23,17 @@ use futures::future::FutureExt;
|
|||||||
use futures::io::{AsyncRead, AsyncWrite};
|
use futures::io::{AsyncRead, AsyncWrite};
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use futures::task::Spawn;
|
use futures::task::Spawn;
|
||||||
use libp2p::core::multiaddr::{Multiaddr, Protocol};
|
use libp2p_core::multiaddr::{Multiaddr, Protocol};
|
||||||
use libp2p::core::muxing::StreamMuxerBox;
|
use libp2p_core::muxing::StreamMuxerBox;
|
||||||
use libp2p::core::transport::choice::OrTransport;
|
use libp2p_core::transport::choice::OrTransport;
|
||||||
use libp2p::core::transport::{Boxed, MemoryTransport, Transport};
|
use libp2p_core::transport::{Boxed, MemoryTransport, Transport};
|
||||||
use libp2p::core::PublicKey;
|
use libp2p_core::PublicKey;
|
||||||
use libp2p::core::{identity, upgrade, PeerId};
|
use libp2p_core::{identity, upgrade, PeerId};
|
||||||
use libp2p::ping;
|
use libp2p_ping as ping;
|
||||||
use libp2p::plaintext::PlainText2Config;
|
use libp2p_plaintext::PlainText2Config;
|
||||||
use libp2p::relay::v2::client;
|
use libp2p_relay::v2::client;
|
||||||
use libp2p::relay::v2::relay;
|
use libp2p_relay::v2::relay;
|
||||||
use libp2p::swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -338,12 +338,16 @@ where
|
|||||||
transport
|
transport
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(PlainText2Config { local_public_key })
|
.authenticate(PlainText2Config { local_public_key })
|
||||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "RelayEvent", event_process = false)]
|
#[behaviour(
|
||||||
|
out_event = "RelayEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct Relay {
|
struct Relay {
|
||||||
relay: relay::Relay,
|
relay: relay::Relay,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
@ -368,7 +372,11 @@ impl From<ping::Event> for RelayEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(out_event = "ClientEvent", event_process = false)]
|
#[behaviour(
|
||||||
|
out_event = "ClientEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct Client {
|
struct Client {
|
||||||
relay: client::Client,
|
relay: client::Client,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
|
@ -30,7 +30,13 @@ void = "1"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-swarm = { path = "../../swarm", features = ["macros", "tokio"] }
|
||||||
|
libp2p-mplex = { path = "../../muxers/mplex" }
|
||||||
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-ping = { path = "../ping" }
|
||||||
|
libp2p-identify = { path = "../identify" }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["tokio"] }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
tokio = { version = "1.15", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] }
|
tokio = { version = "1.15", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] }
|
||||||
|
|
||||||
|
@ -19,13 +19,10 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::identity;
|
use libp2p_core::{identity, multiaddr::Protocol, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::core::PeerId;
|
use libp2p_ping as ping;
|
||||||
use libp2p::multiaddr::Protocol;
|
use libp2p_rendezvous as rendezvous;
|
||||||
use libp2p::ping;
|
use libp2p_swarm::{keep_alive, Swarm, SwarmEvent};
|
||||||
use libp2p::swarm::{keep_alive, SwarmEvent};
|
|
||||||
use libp2p::Swarm;
|
|
||||||
use libp2p::{rendezvous, tokio_development_transport, Multiaddr};
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use void::Void;
|
use void::Void;
|
||||||
|
|
||||||
@ -42,7 +39,11 @@ async fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut swarm = Swarm::with_tokio_executor(
|
let mut swarm = Swarm::with_tokio_executor(
|
||||||
tokio_development_transport(identity.clone()).unwrap(),
|
libp2p_tcp::tokio::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed(),
|
||||||
MyBehaviour {
|
MyBehaviour {
|
||||||
rendezvous: rendezvous::client::Behaviour::new(identity.clone()),
|
rendezvous: rendezvous::client::Behaviour::new(identity.clone()),
|
||||||
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
|
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
|
||||||
@ -143,9 +144,12 @@ impl From<Void> for MyEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(libp2p::swarm::NetworkBehaviour)]
|
#[derive(libp2p_swarm::NetworkBehaviour)]
|
||||||
#[behaviour(event_process = false)]
|
#[behaviour(
|
||||||
#[behaviour(out_event = "MyEvent")]
|
out_event = "MyEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct MyBehaviour {
|
struct MyBehaviour {
|
||||||
rendezvous: rendezvous::client::Behaviour,
|
rendezvous: rendezvous::client::Behaviour,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
|
@ -19,13 +19,11 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::identity;
|
use libp2p_core::{identity, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::core::PeerId;
|
use libp2p_ping as ping;
|
||||||
use libp2p::ping;
|
use libp2p_rendezvous as rendezvous;
|
||||||
use libp2p::swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
|
||||||
use libp2p::Multiaddr;
|
|
||||||
use libp2p::{rendezvous, tokio_development_transport};
|
|
||||||
use libp2p_swarm::AddressScore;
|
use libp2p_swarm::AddressScore;
|
||||||
|
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -40,7 +38,11 @@ async fn main() {
|
|||||||
let identity = identity::Keypair::generate_ed25519();
|
let identity = identity::Keypair::generate_ed25519();
|
||||||
|
|
||||||
let mut swarm = Swarm::with_tokio_executor(
|
let mut swarm = Swarm::with_tokio_executor(
|
||||||
tokio_development_transport(identity.clone()).unwrap(),
|
libp2p_tcp::tokio::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed(),
|
||||||
MyBehaviour {
|
MyBehaviour {
|
||||||
rendezvous: rendezvous::client::Behaviour::new(identity.clone()),
|
rendezvous: rendezvous::client::Behaviour::new(identity.clone()),
|
||||||
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
|
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
|
||||||
@ -130,8 +132,11 @@ impl From<ping::Event> for MyEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(event_process = false)]
|
#[behaviour(
|
||||||
#[behaviour(out_event = "MyEvent")]
|
out_event = "MyEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct MyBehaviour {
|
struct MyBehaviour {
|
||||||
rendezvous: rendezvous::client::Behaviour,
|
rendezvous: rendezvous::client::Behaviour,
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
|
@ -19,13 +19,11 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::identity;
|
use libp2p_core::{identity, upgrade::Version, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::core::PeerId;
|
use libp2p_identify as identify;
|
||||||
use libp2p::identify;
|
use libp2p_ping as ping;
|
||||||
use libp2p::ping;
|
use libp2p_rendezvous as rendezvous;
|
||||||
use libp2p::swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use libp2p::Multiaddr;
|
|
||||||
use libp2p::{rendezvous, tokio_development_transport};
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use void::Void;
|
use void::Void;
|
||||||
|
|
||||||
@ -41,7 +39,11 @@ async fn main() {
|
|||||||
let identity = identity::Keypair::generate_ed25519();
|
let identity = identity::Keypair::generate_ed25519();
|
||||||
|
|
||||||
let mut swarm = Swarm::with_tokio_executor(
|
let mut swarm = Swarm::with_tokio_executor(
|
||||||
tokio_development_transport(identity.clone()).unwrap(),
|
libp2p_tcp::tokio::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed(),
|
||||||
MyBehaviour {
|
MyBehaviour {
|
||||||
identify: identify::Behaviour::new(identify::Config::new(
|
identify: identify::Behaviour::new(identify::Config::new(
|
||||||
"rendezvous-example/1.0.0".to_string(),
|
"rendezvous-example/1.0.0".to_string(),
|
||||||
@ -144,8 +146,11 @@ impl From<Void> for MyEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(event_process = false)]
|
#[behaviour(
|
||||||
#[behaviour(out_event = "MyEvent")]
|
out_event = "MyEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct MyBehaviour {
|
struct MyBehaviour {
|
||||||
identify: identify::Behaviour,
|
identify: identify::Behaviour,
|
||||||
rendezvous: rendezvous::client::Behaviour,
|
rendezvous: rendezvous::client::Behaviour,
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::identity;
|
use libp2p_core::{identity, upgrade::Version, PeerId, Transport};
|
||||||
use libp2p::core::PeerId;
|
use libp2p_identify as identify;
|
||||||
use libp2p::identify;
|
use libp2p_ping as ping;
|
||||||
use libp2p::ping;
|
use libp2p_rendezvous as rendezvous;
|
||||||
use libp2p::swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use libp2p::{rendezvous, tokio_development_transport};
|
|
||||||
use void::Void;
|
use void::Void;
|
||||||
|
|
||||||
/// Examples for the rendezvous protocol:
|
/// Examples for the rendezvous protocol:
|
||||||
@ -44,7 +43,11 @@ async fn main() {
|
|||||||
let identity = identity::Keypair::Ed25519(key.into());
|
let identity = identity::Keypair::Ed25519(key.into());
|
||||||
|
|
||||||
let mut swarm = Swarm::with_tokio_executor(
|
let mut swarm = Swarm::with_tokio_executor(
|
||||||
tokio_development_transport(identity.clone()).unwrap(),
|
libp2p_tcp::tokio::Transport::default()
|
||||||
|
.upgrade(Version::V1)
|
||||||
|
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap())
|
||||||
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
|
.boxed(),
|
||||||
MyBehaviour {
|
MyBehaviour {
|
||||||
identify: identify::Behaviour::new(identify::Config::new(
|
identify: identify::Behaviour::new(identify::Config::new(
|
||||||
"rendezvous-example/1.0.0".to_string(),
|
"rendezvous-example/1.0.0".to_string(),
|
||||||
@ -131,8 +134,11 @@ impl From<Void> for MyEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(event_process = false)]
|
#[behaviour(
|
||||||
#[behaviour(out_event = "MyEvent")]
|
out_event = "MyEvent",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct MyBehaviour {
|
struct MyBehaviour {
|
||||||
identify: identify::Behaviour,
|
identify: identify::Behaviour,
|
||||||
rendezvous: rendezvous::server::Behaviour,
|
rendezvous: rendezvous::server::Behaviour,
|
||||||
|
@ -22,14 +22,14 @@ use async_trait::async_trait;
|
|||||||
use futures::stream::FusedStream;
|
use futures::stream::FusedStream;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use futures::{future, Stream};
|
use futures::{future, Stream};
|
||||||
use libp2p::core::transport::upgrade::Version;
|
use libp2p_core::transport::upgrade::Version;
|
||||||
use libp2p::core::transport::MemoryTransport;
|
use libp2p_core::transport::MemoryTransport;
|
||||||
use libp2p::core::upgrade::SelectUpgrade;
|
use libp2p_core::upgrade::SelectUpgrade;
|
||||||
use libp2p::core::{identity, Multiaddr, PeerId, Transport};
|
use libp2p_core::{identity, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::mplex::MplexConfig;
|
use libp2p_mplex::MplexConfig;
|
||||||
use libp2p::noise::NoiseAuthenticated;
|
use libp2p_noise::NoiseAuthenticated;
|
||||||
use libp2p::swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
use libp2p_swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
||||||
use libp2p::yamux::YamuxConfig;
|
use libp2p_yamux::YamuxConfig;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -107,15 +107,15 @@ where
|
|||||||
macro_rules! assert_behaviour_events {
|
macro_rules! assert_behaviour_events {
|
||||||
($swarm: ident: $pat: pat, || $body: block) => {
|
($swarm: ident: $pat: pat, || $body: block) => {
|
||||||
match await_event_or_timeout(&mut $swarm).await {
|
match await_event_or_timeout(&mut $swarm).await {
|
||||||
libp2p::swarm::SwarmEvent::Behaviour($pat) => $body,
|
libp2p_swarm::SwarmEvent::Behaviour($pat) => $body,
|
||||||
_ => panic!("Unexpected combination of events emitted, check logs for details"),
|
_ => panic!("Unexpected combination of events emitted, check logs for details"),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($swarm1: ident: $pat1: pat, $swarm2: ident: $pat2: pat, || $body: block) => {
|
($swarm1: ident: $pat1: pat, $swarm2: ident: $pat2: pat, || $body: block) => {
|
||||||
match await_events_or_timeout(&mut $swarm1, &mut $swarm2).await {
|
match await_events_or_timeout(&mut $swarm1, &mut $swarm2).await {
|
||||||
(
|
(
|
||||||
libp2p::swarm::SwarmEvent::Behaviour($pat1),
|
libp2p_swarm::SwarmEvent::Behaviour($pat1),
|
||||||
libp2p::swarm::SwarmEvent::Behaviour($pat2),
|
libp2p_swarm::SwarmEvent::Behaviour($pat2),
|
||||||
) => $body,
|
) => $body,
|
||||||
_ => panic!("Unexpected combination of events emitted, check logs for details"),
|
_ => panic!("Unexpected combination of events emitted, check logs for details"),
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ pub mod harness;
|
|||||||
use crate::harness::{await_event_or_timeout, await_events_or_timeout, new_swarm, SwarmExt};
|
use crate::harness::{await_event_or_timeout, await_events_or_timeout, new_swarm, SwarmExt};
|
||||||
use futures::stream::FuturesUnordered;
|
use futures::stream::FuturesUnordered;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::identity;
|
use libp2p_core::identity;
|
||||||
use libp2p::rendezvous;
|
use libp2p_rendezvous as rendezvous;
|
||||||
use libp2p::swarm::{DialError, Swarm, SwarmEvent};
|
use libp2p_swarm::{DialError, Swarm, SwarmEvent};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -366,8 +366,12 @@ async fn new_impersonating_client() -> Swarm<rendezvous::client::Behaviour> {
|
|||||||
eve
|
eve
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(libp2p::swarm::NetworkBehaviour)]
|
#[derive(libp2p_swarm::NetworkBehaviour)]
|
||||||
#[behaviour(event_process = false, out_event = "CombinedEvent")]
|
#[behaviour(
|
||||||
|
event_process = false,
|
||||||
|
out_event = "CombinedEvent",
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct CombinedBehaviour {
|
struct CombinedBehaviour {
|
||||||
client: rendezvous::client::Behaviour,
|
client: rendezvous::client::Behaviour,
|
||||||
server: rendezvous::server::Behaviour,
|
server: rendezvous::server::Behaviour,
|
||||||
|
@ -25,7 +25,9 @@ unsigned-varint = { version = "0.7", features = ["std", "futures"] }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-noise = { path = "../../transports/noise" }
|
||||||
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
|
@ -22,18 +22,17 @@
|
|||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::{channel::mpsc, prelude::*, AsyncWriteExt};
|
use futures::{channel::mpsc, prelude::*, AsyncWriteExt};
|
||||||
use libp2p::core::{
|
use libp2p_core::{
|
||||||
identity,
|
identity,
|
||||||
muxing::StreamMuxerBox,
|
muxing::StreamMuxerBox,
|
||||||
transport,
|
transport,
|
||||||
upgrade::{self, read_length_prefixed, write_length_prefixed},
|
upgrade::{self, read_length_prefixed, write_length_prefixed},
|
||||||
Multiaddr, PeerId,
|
Multiaddr, PeerId, Transport,
|
||||||
};
|
};
|
||||||
use libp2p::noise::NoiseAuthenticated;
|
use libp2p_noise::NoiseAuthenticated;
|
||||||
use libp2p::request_response::*;
|
use libp2p_request_response::*;
|
||||||
use libp2p::swarm::{Swarm, SwarmEvent};
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
use libp2p::tcp;
|
use libp2p_tcp as tcp;
|
||||||
use libp2p_core::Transport;
|
|
||||||
use rand::{self, Rng};
|
use rand::{self, Rng};
|
||||||
use std::{io, iter};
|
use std::{io, iter};
|
||||||
|
|
||||||
@ -302,7 +301,7 @@ fn mk_transport() -> (PeerId, transport::Boxed<(PeerId, StreamMuxerBox)>) {
|
|||||||
tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
|
tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(NoiseAuthenticated::xx(&id_keys).unwrap())
|
.authenticate(NoiseAuthenticated::xx(&id_keys).unwrap())
|
||||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -174,8 +174,7 @@
|
|||||||
//! [`Transport`] to the [`NetworkBehaviour`].
|
//! [`Transport`] to the [`NetworkBehaviour`].
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use libp2p::{identity, PeerId, ping};
|
//! use libp2p::{identity, PeerId, ping, Swarm};
|
||||||
//! use libp2p::swarm::Swarm;
|
|
||||||
//! use std::error::Error;
|
//! use std::error::Error;
|
||||||
//!
|
//!
|
||||||
//! #[async_std::main]
|
//! #[async_std::main]
|
||||||
@ -226,8 +225,7 @@
|
|||||||
//! remote peer.
|
//! remote peer.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use libp2p::{identity, Multiaddr, PeerId, ping};
|
//! use libp2p::{identity, Multiaddr, PeerId, ping, Swarm, swarm::dial_opts::DialOpts};
|
||||||
//! use libp2p::swarm::{Swarm, dial_opts::DialOpts};
|
|
||||||
//! use std::error::Error;
|
//! use std::error::Error;
|
||||||
//!
|
//!
|
||||||
//! #[async_std::main]
|
//! #[async_std::main]
|
||||||
@ -271,8 +269,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use futures::prelude::*;
|
//! use futures::prelude::*;
|
||||||
//! use libp2p::swarm::{Swarm, SwarmEvent, dial_opts::DialOpts};
|
//! use libp2p::{identity, Multiaddr, PeerId, ping, swarm::{Swarm, SwarmEvent, dial_opts::DialOpts}};
|
||||||
//! use libp2p::{identity, Multiaddr, PeerId, ping};
|
|
||||||
//! use std::error::Error;
|
//! use std::error::Error;
|
||||||
//!
|
//!
|
||||||
//! #[async_std::main]
|
//! #[async_std::main]
|
||||||
|
@ -17,7 +17,7 @@ flate2 = "1.0"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-tcp = { path = "../tcp", features = ["async-io"] }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use futures::{future, prelude::*};
|
use futures::{future, prelude::*};
|
||||||
use libp2p::core::{transport::Transport, upgrade};
|
use libp2p_core::{transport::Transport, upgrade};
|
||||||
use libp2p::deflate::DeflateConfig;
|
use libp2p_deflate::DeflateConfig;
|
||||||
use libp2p::tcp;
|
use libp2p_tcp as tcp;
|
||||||
use quickcheck::{QuickCheck, TestResult};
|
use quickcheck::{QuickCheck, TestResult};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
|
@ -573,7 +573,7 @@ fn invalid_data(e: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> io::E
|
|||||||
io::Error::new(io::ErrorKind::InvalidData, e)
|
io::Error::new(io::ErrorKind::InvalidData, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, any(feature = "tokio", feature = "async-std")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
|
@ -31,11 +31,11 @@ snow = { version = "0.9.0", features = ["default-resolver"], default-features =
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-io = "1.2.0"
|
async-io = "1.2.0"
|
||||||
|
ed25519-compact = "1.0.11"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-tcp = { path = "../tcp", features = ["async-io"] }
|
||||||
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
|
||||||
libsodium-sys-stable = { version = "1.19.22", features = ["fetch-latest"] }
|
libsodium-sys-stable = { version = "1.19.22", features = ["fetch-latest"] }
|
||||||
ed25519-compact = "2.0.2"
|
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = "0.11"
|
prost-build = "0.11"
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use libp2p_core::{identity, Transport, upgrade};
|
//! use libp2p_core::{identity, Transport, upgrade};
|
||||||
//! use libp2p::tcp::TcpTransport;
|
//! use libp2p_tcp::TcpTransport;
|
||||||
//! use libp2p::noise::{Keypair, X25519Spec, NoiseAuthenticated};
|
//! use libp2p_noise::{Keypair, X25519Spec, NoiseAuthenticated};
|
||||||
//!
|
//!
|
||||||
//! # fn main() {
|
//! # fn main() {
|
||||||
//! let id_keys = identity::Keypair::generate_ed25519();
|
//! let id_keys = identity::Keypair::generate_ed25519();
|
||||||
|
@ -23,14 +23,14 @@ use futures::{
|
|||||||
future::{self, Either},
|
future::{self, Either},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use libp2p::core::identity;
|
use libp2p_core::transport::Transport;
|
||||||
use libp2p::core::transport::{self, Transport};
|
use libp2p_core::upgrade::{apply_inbound, apply_outbound, Negotiated};
|
||||||
use libp2p::core::upgrade::{self, apply_inbound, apply_outbound, Negotiated};
|
use libp2p_core::{identity, transport, upgrade};
|
||||||
use libp2p::noise::{
|
use libp2p_noise::{
|
||||||
Keypair, NoiseAuthenticated, NoiseConfig, NoiseOutput, RemoteIdentity, X25519Spec, X25519,
|
Keypair, NoiseAuthenticated, NoiseConfig, NoiseError, NoiseOutput, RemoteIdentity, X25519Spec,
|
||||||
|
X25519,
|
||||||
};
|
};
|
||||||
use libp2p::tcp;
|
use libp2p_tcp as tcp;
|
||||||
use libp2p_noise::NoiseError;
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use quickcheck::*;
|
use quickcheck::*;
|
||||||
use std::{convert::TryInto, io, net::TcpStream};
|
use std::{convert::TryInto, io, net::TcpStream};
|
||||||
|
@ -38,8 +38,10 @@ rustc-args = ["--cfg", "docsrs"]
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = { version = "1.12.0", features = ["attributes"] }
|
async-std = { version = "1.12.0", features = ["attributes"] }
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
libp2p = { path = "../..", features = ["tcp", "yamux", "noise", "async-std"] }
|
|
||||||
libp2p-muxer-test-harness = { path = "../../muxers/test-harness" }
|
libp2p-muxer-test-harness = { path = "../../muxers/test-harness" }
|
||||||
|
libp2p-noise = { path = "../noise" }
|
||||||
|
libp2p-tcp = { path = "../tcp", features = ["async-io"] }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
quickcheck = "1"
|
quickcheck = "1"
|
||||||
tokio = { version = "1.21.1", features = ["macros", "rt-multi-thread", "time"] }
|
tokio = { version = "1.21.1", features = ["macros", "rt-multi-thread", "time"] }
|
||||||
|
|
||||||
|
@ -4,14 +4,14 @@ use futures::channel::{mpsc, oneshot};
|
|||||||
use futures::future::{poll_fn, Either};
|
use futures::future::{poll_fn, Either};
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use futures::{future, AsyncReadExt, AsyncWriteExt, FutureExt, SinkExt};
|
use futures::{future, AsyncReadExt, AsyncWriteExt, FutureExt, SinkExt};
|
||||||
use libp2p::core::multiaddr::Protocol;
|
|
||||||
use libp2p::core::Transport;
|
|
||||||
use libp2p::{noise, tcp, yamux, Multiaddr};
|
|
||||||
use libp2p_core::either::EitherOutput;
|
use libp2p_core::either::EitherOutput;
|
||||||
use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt, SubstreamBox};
|
use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt, SubstreamBox};
|
||||||
use libp2p_core::transport::{Boxed, OrTransport, TransportEvent};
|
use libp2p_core::transport::{Boxed, OrTransport, TransportEvent};
|
||||||
use libp2p_core::{upgrade, PeerId};
|
use libp2p_core::{multiaddr::Protocol, upgrade, Multiaddr, PeerId, Transport};
|
||||||
|
use libp2p_noise as noise;
|
||||||
use libp2p_quic as quic;
|
use libp2p_quic as quic;
|
||||||
|
use libp2p_tcp as tcp;
|
||||||
|
use libp2p_yamux as yamux;
|
||||||
use quic::Provider;
|
use quic::Provider;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@ -94,7 +94,7 @@ async fn ipv4_dial_ipv6() {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
#[ignore] // Transport currently does not validate PeerId. Enable once we make use of PeerId validation in rustls.
|
#[ignore] // Transport currently does not validate PeerId. Enable once we make use of PeerId validation in rustls.
|
||||||
async fn wrong_peerid() {
|
async fn wrong_peerid() {
|
||||||
use libp2p::PeerId;
|
use libp2p_core::PeerId;
|
||||||
|
|
||||||
let (a_peer_id, mut a_transport) = create_default_transport::<quic::async_std::Provider>();
|
let (a_peer_id, mut a_transport) = create_default_transport::<quic::async_std::Provider>();
|
||||||
let (b_peer_id, mut b_transport) = create_default_transport::<quic::async_std::Provider>();
|
let (b_peer_id, mut b_transport) = create_default_transport::<quic::async_std::Provider>();
|
||||||
@ -189,7 +189,7 @@ async fn draft_29_support() {
|
|||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|
||||||
use futures::{future::poll_fn, select};
|
use futures::{future::poll_fn, select};
|
||||||
use libp2p::TransportError;
|
use libp2p_core::transport::TransportError;
|
||||||
|
|
||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
@ -379,8 +379,8 @@ macro_rules! swap_protocol {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_tls_keypair() -> libp2p::identity::Keypair {
|
fn generate_tls_keypair() -> libp2p_core::identity::Keypair {
|
||||||
libp2p::identity::Keypair::generate_ed25519()
|
libp2p_core::identity::Keypair::generate_ed25519()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_default_transport<P: Provider>() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) {
|
fn create_default_transport<P: Provider>() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) {
|
||||||
|
@ -28,7 +28,9 @@ features = ["dangerous_configuration"] # Must enable this to allow for custom ve
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
hex-literal = "0.3.4"
|
hex-literal = "0.3.4"
|
||||||
libp2p = { path = "../..", features = ["yamux", "rsa", "ecdsa", "secp256k1"], default-features = false }
|
libp2p-core = { path = "../../core", features = ["rsa", "ecdsa", "secp256k1"] }
|
||||||
|
libp2p-swarm = { path = "../../swarm" }
|
||||||
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
tokio = { version = "1.21.1", features = ["full"] }
|
tokio = { version = "1.21.1", features = ["full"] }
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use futures::{future, StreamExt};
|
use futures::{future, StreamExt};
|
||||||
use libp2p::multiaddr::Protocol;
|
use libp2p_core::multiaddr::Protocol;
|
||||||
use libp2p::swarm::{keep_alive, SwarmEvent};
|
|
||||||
use libp2p::Swarm;
|
|
||||||
use libp2p_core::transport::MemoryTransport;
|
use libp2p_core::transport::MemoryTransport;
|
||||||
use libp2p_core::upgrade::Version;
|
use libp2p_core::upgrade::Version;
|
||||||
use libp2p_core::Transport;
|
use libp2p_core::Transport;
|
||||||
|
use libp2p_swarm::{keep_alive, Swarm, SwarmEvent};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn can_establish_connection() {
|
async fn can_establish_connection() {
|
||||||
@ -57,12 +56,12 @@ async fn can_establish_connection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_swarm() -> Swarm<keep_alive::Behaviour> {
|
fn make_swarm() -> Swarm<keep_alive::Behaviour> {
|
||||||
let identity = libp2p::identity::Keypair::generate_ed25519();
|
let identity = libp2p_core::identity::Keypair::generate_ed25519();
|
||||||
|
|
||||||
let transport = MemoryTransport::default()
|
let transport = MemoryTransport::default()
|
||||||
.upgrade(Version::V1)
|
.upgrade(Version::V1)
|
||||||
.authenticate(libp2p_tls::Config::new(&identity).unwrap())
|
.authenticate(libp2p_tls::Config::new(&identity).unwrap())
|
||||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
Swarm::without_executor(
|
Swarm::without_executor(
|
||||||
|
@ -45,10 +45,12 @@ prost-build = "0.11"
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
hex-literal = "0.3"
|
hex-literal = "0.3"
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-swarm = { path = "../../swarm", features = ["macros", "tokio"] }
|
||||||
|
libp2p-ping = { path = "../../protocols/ping" }
|
||||||
tokio = { version = "1.19", features = ["full"] }
|
tokio = { version = "1.19", features = ["full"] }
|
||||||
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
|
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
|
||||||
void = "1"
|
void = "1"
|
||||||
|
quickcheck = "1.0.3"
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "smoke"
|
name = "smoke"
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::swarm::{keep_alive, NetworkBehaviour};
|
|
||||||
use libp2p::Transport;
|
|
||||||
use libp2p::{ping, Swarm};
|
|
||||||
use libp2p_core::identity;
|
use libp2p_core::identity;
|
||||||
use libp2p_core::muxing::StreamMuxerBox;
|
use libp2p_core::muxing::StreamMuxerBox;
|
||||||
|
use libp2p_core::Transport;
|
||||||
|
use libp2p_ping as ping;
|
||||||
|
use libp2p_swarm::{keep_alive, NetworkBehaviour, Swarm};
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use void::Void;
|
use void::Void;
|
||||||
|
|
||||||
@ -41,7 +41,11 @@ fn create_swarm() -> Result<Swarm<Behaviour>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(NetworkBehaviour, Default)]
|
#[derive(NetworkBehaviour, Default)]
|
||||||
#[behaviour(out_event = "Event", event_process = false)]
|
#[behaviour(
|
||||||
|
out_event = "Event",
|
||||||
|
event_process = false,
|
||||||
|
prelude = "libp2p_swarm::derive_prelude"
|
||||||
|
)]
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
ping: ping::Behaviour,
|
ping: ping::Behaviour,
|
||||||
keep_alive: keep_alive::Behaviour,
|
keep_alive: keep_alive::Behaviour,
|
||||||
|
@ -18,469 +18,355 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use anyhow::Result;
|
use futures::channel::mpsc;
|
||||||
use async_trait::async_trait;
|
use futures::future::{BoxFuture, Either};
|
||||||
use futures::{
|
use futures::stream::StreamExt;
|
||||||
future::{select, Either, FutureExt},
|
use futures::{future, ready, AsyncReadExt, AsyncWriteExt, FutureExt, SinkExt};
|
||||||
io::{AsyncRead, AsyncWrite, AsyncWriteExt},
|
use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt};
|
||||||
stream::StreamExt,
|
use libp2p_core::transport::{Boxed, TransportEvent};
|
||||||
};
|
use libp2p_core::{Multiaddr, PeerId, Transport};
|
||||||
use libp2p::core::{identity, muxing::StreamMuxerBox, upgrade, Transport as _};
|
use libp2p_webrtc as webrtc;
|
||||||
use libp2p::request_response::{
|
|
||||||
ProtocolName, ProtocolSupport, RequestResponse, RequestResponseCodec, RequestResponseConfig,
|
|
||||||
RequestResponseEvent, RequestResponseMessage,
|
|
||||||
};
|
|
||||||
use libp2p::swarm::{Swarm, SwarmEvent};
|
|
||||||
use libp2p::webrtc::tokio as webrtc;
|
|
||||||
use rand::{thread_rng, RngCore};
|
use rand::{thread_rng, RngCore};
|
||||||
|
use std::future::Future;
|
||||||
use std::{io, iter};
|
use std::num::NonZeroU8;
|
||||||
|
use std::pin::Pin;
|
||||||
|
use std::task::{Context, Poll};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn smoke() -> Result<()> {
|
async fn smoke() {
|
||||||
let _ = env_logger::builder().is_test(true).try_init();
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let (a_peer_id, mut a_transport) = create_transport();
|
||||||
|
let (b_peer_id, mut b_transport) = create_transport();
|
||||||
|
|
||||||
let mut a = create_swarm()?;
|
let addr = start_listening(&mut a_transport, "/ip4/127.0.0.1/udp/0/webrtc").await;
|
||||||
let mut b = create_swarm()?;
|
start_listening(&mut b_transport, "/ip4/127.0.0.1/udp/0/webrtc").await;
|
||||||
|
let ((a_connected, _, _), (b_connected, _)) =
|
||||||
|
connect(&mut a_transport, &mut b_transport, addr).await;
|
||||||
|
|
||||||
Swarm::listen_on(&mut a, "/ip4/127.0.0.1/udp/0/webrtc".parse()?)?;
|
assert_eq!(a_connected, b_peer_id);
|
||||||
Swarm::listen_on(&mut b, "/ip4/127.0.0.1/udp/0/webrtc".parse()?)?;
|
assert_eq!(b_connected, a_peer_id);
|
||||||
|
|
||||||
let addr = match a.next().await {
|
|
||||||
Some(SwarmEvent::NewListenAddr { address, .. }) => address,
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
// skip other interface addresses
|
|
||||||
while a.next().now_or_never().is_some() {}
|
|
||||||
|
|
||||||
let _ = match b.next().await {
|
|
||||||
Some(SwarmEvent::NewListenAddr { address, .. }) => address,
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
// skip other interface addresses
|
|
||||||
while b.next().now_or_never().is_some() {}
|
|
||||||
|
|
||||||
let mut data = vec![0; 4096];
|
|
||||||
rng.fill_bytes(&mut data);
|
|
||||||
|
|
||||||
b.behaviour_mut()
|
|
||||||
.add_address(Swarm::local_peer_id(&a), addr);
|
|
||||||
b.behaviour_mut()
|
|
||||||
.send_request(Swarm::local_peer_id(&a), Ping(data.clone()));
|
|
||||||
|
|
||||||
match b.next().await {
|
|
||||||
Some(SwarmEvent::Dialing(_)) => {}
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Left((Some(SwarmEvent::IncomingConnection { .. }), _)) => {}
|
|
||||||
Either::Left((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Right(_) => panic!("b completed first"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Left((Some(SwarmEvent::ConnectionEstablished { .. }), _)) => {}
|
|
||||||
Either::Left((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Right((Some(SwarmEvent::ConnectionEstablished { .. }), _)) => {}
|
|
||||||
Either::Right((e, _)) => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Left((Some(SwarmEvent::ConnectionEstablished { .. }), _)) => {}
|
|
||||||
Either::Left((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Right((Some(SwarmEvent::ConnectionEstablished { .. }), _)) => {}
|
|
||||||
Either::Right((e, _)) => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(b.next().now_or_never().is_none());
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Left((
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::Message {
|
|
||||||
message:
|
|
||||||
RequestResponseMessage::Request {
|
|
||||||
request: Ping(ping),
|
|
||||||
channel,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
})),
|
|
||||||
_,
|
|
||||||
)) => {
|
|
||||||
a.behaviour_mut()
|
|
||||||
.send_response(channel, Pong(ping))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
Either::Left((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Right(_) => panic!("b completed first"),
|
|
||||||
}
|
|
||||||
|
|
||||||
match a.next().await {
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::ResponseSent { .. })) => {}
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Right((
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::Message {
|
|
||||||
message:
|
|
||||||
RequestResponseMessage::Response {
|
|
||||||
response: Pong(pong),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
})),
|
|
||||||
_,
|
|
||||||
)) => assert_eq!(data, pong),
|
|
||||||
Either::Right((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Left(_) => panic!("a completed first"),
|
|
||||||
}
|
|
||||||
|
|
||||||
a.behaviour_mut().send_request(
|
|
||||||
Swarm::local_peer_id(&b),
|
|
||||||
Ping(b"another substream".to_vec()),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(a.next().now_or_never().is_none());
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Right((
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::Message {
|
|
||||||
message:
|
|
||||||
RequestResponseMessage::Request {
|
|
||||||
request: Ping(data),
|
|
||||||
channel,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
})),
|
|
||||||
_,
|
|
||||||
)) => {
|
|
||||||
b.behaviour_mut()
|
|
||||||
.send_response(channel, Pong(data))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
Either::Right((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Left(_) => panic!("a completed first"),
|
|
||||||
}
|
|
||||||
|
|
||||||
match b.next().await {
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::ResponseSent { .. })) => {}
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
let pair = select(a.next(), b.next());
|
|
||||||
match pair.await {
|
|
||||||
Either::Left((
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::Message {
|
|
||||||
message:
|
|
||||||
RequestResponseMessage::Response {
|
|
||||||
response: Pong(data),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
})),
|
|
||||||
_,
|
|
||||||
)) => assert_eq!(data, b"another substream".to_vec()),
|
|
||||||
Either::Left((e, _)) => panic!("{:?}", e),
|
|
||||||
Either::Right(_) => panic!("b completed first"),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
// Note: This test should likely be ported to the muxer compliance test suite.
|
||||||
async fn dial_failure() -> Result<()> {
|
#[test]
|
||||||
let _ = env_logger::builder().is_test(true).try_init();
|
fn concurrent_connections_and_streams_tokio() {
|
||||||
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
let mut a = create_swarm()?;
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
let mut b = create_swarm()?;
|
let _guard = rt.enter();
|
||||||
|
quickcheck::QuickCheck::new()
|
||||||
Swarm::listen_on(&mut a, "/ip4/127.0.0.1/udp/0/webrtc".parse()?)?;
|
.min_tests_passed(1)
|
||||||
Swarm::listen_on(&mut b, "/ip4/127.0.0.1/udp/0/webrtc".parse()?)?;
|
.quickcheck(prop as fn(_, _) -> _);
|
||||||
|
|
||||||
let addr = match a.next().await {
|
|
||||||
Some(SwarmEvent::NewListenAddr { address, .. }) => address,
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
// skip other interface addresses
|
|
||||||
while a.next().now_or_never().is_some() {}
|
|
||||||
|
|
||||||
let _ = match b.next().await {
|
|
||||||
Some(SwarmEvent::NewListenAddr { address, .. }) => address,
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
// skip other interface addresses
|
|
||||||
while b.next().now_or_never().is_some() {}
|
|
||||||
|
|
||||||
let a_peer_id = &Swarm::local_peer_id(&a).clone();
|
|
||||||
drop(a); // stop a swarm so b can never reach it
|
|
||||||
|
|
||||||
b.behaviour_mut().add_address(a_peer_id, addr);
|
|
||||||
b.behaviour_mut()
|
|
||||||
.send_request(a_peer_id, Ping(b"hello world".to_vec()));
|
|
||||||
|
|
||||||
match b.next().await {
|
|
||||||
Some(SwarmEvent::Dialing(_)) => {}
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
match b.next().await {
|
|
||||||
Some(SwarmEvent::OutgoingConnectionError { .. }) => {}
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
match b.next().await {
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::OutboundFailure { .. })) => {}
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
fn generate_tls_keypair() -> libp2p_core::identity::Keypair {
|
||||||
async fn concurrent_connections_and_streams() {
|
libp2p_core::identity::Keypair::generate_ed25519()
|
||||||
let _ = env_logger::builder().is_test(true).try_init();
|
}
|
||||||
|
|
||||||
let num_listeners = 3usize;
|
fn create_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) {
|
||||||
let num_streams = 8usize;
|
let keypair = generate_tls_keypair();
|
||||||
|
let peer_id = keypair.public().to_peer_id();
|
||||||
|
|
||||||
let mut data = vec![0; 4096];
|
let transport = webrtc::tokio::Transport::new(
|
||||||
rand::thread_rng().fill_bytes(&mut data);
|
keypair,
|
||||||
let mut listeners = vec![];
|
webrtc::tokio::Certificate::generate(&mut thread_rng()).unwrap(),
|
||||||
|
)
|
||||||
|
.map(|(p, c), _| (p, StreamMuxerBox::new(c)))
|
||||||
|
.boxed();
|
||||||
|
|
||||||
|
(peer_id, transport)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn start_listening(transport: &mut Boxed<(PeerId, StreamMuxerBox)>, addr: &str) -> Multiaddr {
|
||||||
|
transport.listen_on(addr.parse().unwrap()).unwrap();
|
||||||
|
match transport.next().await {
|
||||||
|
Some(TransportEvent::NewAddress { listen_addr, .. }) => listen_addr,
|
||||||
|
e => panic!("{:?}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prop(number_listeners: NonZeroU8, number_streams: NonZeroU8) -> quickcheck::TestResult {
|
||||||
|
const BUFFER_SIZE: usize = 4096 * 10;
|
||||||
|
|
||||||
|
let number_listeners = u8::from(number_listeners) as usize;
|
||||||
|
let number_streams = u8::from(number_streams) as usize;
|
||||||
|
|
||||||
|
if number_listeners > 10 || number_streams > 10 {
|
||||||
|
return quickcheck::TestResult::discard();
|
||||||
|
}
|
||||||
|
|
||||||
|
let (listeners_tx, mut listeners_rx) = mpsc::channel(number_listeners);
|
||||||
|
|
||||||
|
log::info!("Creating {number_streams} streams on {number_listeners} connections");
|
||||||
|
|
||||||
// Spawn the listener nodes.
|
// Spawn the listener nodes.
|
||||||
for _ in 0..num_listeners {
|
for _ in 0..number_listeners {
|
||||||
let mut listener = create_swarm().unwrap();
|
tokio::spawn({
|
||||||
Swarm::listen_on(
|
let mut listeners_tx = listeners_tx.clone();
|
||||||
&mut listener,
|
|
||||||
"/ip4/127.0.0.1/udp/0/webrtc".parse().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Wait to listen on address.
|
async move {
|
||||||
let addr = match listener.next().await {
|
let (peer_id, mut listener) = create_transport();
|
||||||
Some(SwarmEvent::NewListenAddr { address, .. }) => address,
|
let addr = start_listening(&mut listener, "/ip4/127.0.0.1/udp/0/webrtc").await;
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
listeners.push((*listener.local_peer_id(), addr));
|
listeners_tx.send((peer_id, addr)).await.unwrap();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
loop {
|
||||||
loop {
|
if let TransportEvent::Incoming { upgrade, .. } =
|
||||||
match listener.next().await {
|
listener.select_next_some().await
|
||||||
Some(SwarmEvent::IncomingConnection { .. }) => {
|
{
|
||||||
log::debug!("listener IncomingConnection");
|
let (_, connection) = upgrade.await.unwrap();
|
||||||
}
|
|
||||||
Some(SwarmEvent::ConnectionEstablished { .. }) => {
|
tokio::spawn(answer_inbound_streams::<BUFFER_SIZE>(connection));
|
||||||
log::debug!("listener ConnectionEstablished");
|
|
||||||
}
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::Message {
|
|
||||||
message:
|
|
||||||
RequestResponseMessage::Request {
|
|
||||||
request: Ping(ping),
|
|
||||||
channel,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
})) => {
|
|
||||||
log::debug!("listener got Message");
|
|
||||||
listener
|
|
||||||
.behaviour_mut()
|
|
||||||
.send_response(channel, Pong(ping))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::ResponseSent { .. })) => {
|
|
||||||
log::debug!("listener ResponseSent");
|
|
||||||
}
|
|
||||||
Some(SwarmEvent::ConnectionClosed { .. }) => {}
|
|
||||||
Some(SwarmEvent::NewListenAddr { .. }) => {
|
|
||||||
log::debug!("listener NewListenAddr");
|
|
||||||
}
|
|
||||||
Some(e) => {
|
|
||||||
panic!("unexpected event {:?}", e);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
panic!("listener stopped");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dialer = create_swarm().unwrap();
|
let (completed_streams_tx, completed_streams_rx) =
|
||||||
Swarm::listen_on(&mut dialer, "/ip4/127.0.0.1/udp/0/webrtc".parse().unwrap()).unwrap();
|
mpsc::channel(number_streams * number_listeners);
|
||||||
|
|
||||||
// Wait to listen on address.
|
|
||||||
match dialer.next().await {
|
|
||||||
Some(SwarmEvent::NewListenAddr { address, .. }) => address,
|
|
||||||
e => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
// For each listener node start `number_streams` requests.
|
// For each listener node start `number_streams` requests.
|
||||||
for (listener_peer_id, listener_addr) in &listeners {
|
tokio::spawn(async move {
|
||||||
dialer
|
let (_, mut dialer) = create_transport();
|
||||||
.behaviour_mut()
|
|
||||||
.add_address(listener_peer_id, listener_addr.clone());
|
|
||||||
|
|
||||||
dialer.dial(*listener_peer_id).unwrap();
|
while let Some((_, listener_addr)) = listeners_rx.next().await {
|
||||||
|
let (_, connection) = Dial::new(&mut dialer, listener_addr.clone()).await;
|
||||||
|
|
||||||
|
tokio::spawn(open_outbound_streams::<BUFFER_SIZE>(
|
||||||
|
connection,
|
||||||
|
number_streams,
|
||||||
|
completed_streams_tx.clone(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drive the dialer.
|
||||||
|
loop {
|
||||||
|
dialer.next().await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let completed_streams = number_streams * number_listeners;
|
||||||
|
|
||||||
|
// Wait for all streams to complete.
|
||||||
|
tokio::runtime::Handle::current()
|
||||||
|
.block_on(tokio::time::timeout(
|
||||||
|
Duration::from_secs(30),
|
||||||
|
completed_streams_rx
|
||||||
|
.take(completed_streams)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
quickcheck::TestResult::passed()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn answer_inbound_streams<const BUFFER_SIZE: usize>(mut connection: StreamMuxerBox) {
|
||||||
|
loop {
|
||||||
|
let mut inbound_stream = match future::poll_fn(|cx| {
|
||||||
|
let _ = connection.poll_unpin(cx)?;
|
||||||
|
|
||||||
|
connection.poll_inbound_unpin(cx)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
// FIXME: Need to write _some_ data before we can read on both sides.
|
||||||
|
// Do a ping-pong exchange.
|
||||||
|
{
|
||||||
|
let mut pong = [0u8; 4];
|
||||||
|
inbound_stream.write_all(b"PING").await.unwrap();
|
||||||
|
inbound_stream.flush().await.unwrap();
|
||||||
|
inbound_stream.read_exact(&mut pong).await.unwrap();
|
||||||
|
assert_eq!(&pong, b"PONG");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut data = vec![0; BUFFER_SIZE];
|
||||||
|
|
||||||
|
inbound_stream.read_exact(&mut data).await.unwrap();
|
||||||
|
inbound_stream.write_all(&data).await.unwrap();
|
||||||
|
inbound_stream.close().await.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn open_outbound_streams<const BUFFER_SIZE: usize>(
|
||||||
|
mut connection: StreamMuxerBox,
|
||||||
|
number_streams: usize,
|
||||||
|
completed_streams_tx: mpsc::Sender<()>,
|
||||||
|
) {
|
||||||
|
for _ in 0..number_streams {
|
||||||
|
let mut outbound_stream = future::poll_fn(|cx| {
|
||||||
|
let _ = connection.poll_unpin(cx)?;
|
||||||
|
|
||||||
|
connection.poll_outbound_unpin(cx)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
tokio::spawn({
|
||||||
|
let mut completed_streams_tx = completed_streams_tx.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
|
// FIXME: Need to write _some_ data before we can read on both sides.
|
||||||
|
// Do a ping-pong exchange.
|
||||||
|
{
|
||||||
|
let mut ping = [0u8; 4];
|
||||||
|
outbound_stream.write_all(b"PONG").await.unwrap();
|
||||||
|
outbound_stream.flush().await.unwrap();
|
||||||
|
outbound_stream.read_exact(&mut ping).await.unwrap();
|
||||||
|
assert_eq!(&ping, b"PING");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut data = vec![0; BUFFER_SIZE];
|
||||||
|
rand::thread_rng().fill_bytes(&mut data);
|
||||||
|
|
||||||
|
let mut received = Vec::new();
|
||||||
|
|
||||||
|
outbound_stream.write_all(&data).await.unwrap();
|
||||||
|
outbound_stream.flush().await.unwrap();
|
||||||
|
outbound_stream.read_to_end(&mut received).await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(received, data);
|
||||||
|
|
||||||
|
completed_streams_tx.send(()).await.unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for responses to each request.
|
log::info!("Created {number_streams} streams");
|
||||||
let mut num_responses = 0;
|
|
||||||
loop {
|
while future::poll_fn(|cx| connection.poll_unpin(cx))
|
||||||
match dialer.next().await {
|
.await
|
||||||
Some(SwarmEvent::Dialing(_)) => {
|
.is_ok()
|
||||||
log::debug!("dialer Dialing");
|
{}
|
||||||
}
|
}
|
||||||
Some(SwarmEvent::ConnectionEstablished { peer_id, .. }) => {
|
|
||||||
log::debug!("dialer Connection established");
|
async fn connect(
|
||||||
for _ in 0..num_streams {
|
a_transport: &mut Boxed<(PeerId, StreamMuxerBox)>,
|
||||||
dialer
|
b_transport: &mut Boxed<(PeerId, StreamMuxerBox)>,
|
||||||
.behaviour_mut()
|
addr: Multiaddr,
|
||||||
.send_request(&peer_id, Ping(data.clone()));
|
) -> (
|
||||||
|
(PeerId, Multiaddr, StreamMuxerBox),
|
||||||
|
(PeerId, StreamMuxerBox),
|
||||||
|
) {
|
||||||
|
match futures::future::select(
|
||||||
|
ListenUpgrade::new(a_transport),
|
||||||
|
Dial::new(b_transport, addr),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Either::Left((listen_done, dial)) => {
|
||||||
|
let mut pending_dial = dial;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match future::select(pending_dial, a_transport.next()).await {
|
||||||
|
Either::Left((dial_done, _)) => return (listen_done, dial_done),
|
||||||
|
Either::Right((_, dial)) => {
|
||||||
|
pending_dial = dial;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(SwarmEvent::Behaviour(RequestResponseEvent::Message {
|
}
|
||||||
message:
|
Either::Right((dial_done, listen)) => {
|
||||||
RequestResponseMessage::Response {
|
let mut pending_listen = listen;
|
||||||
response: Pong(pong),
|
|
||||||
..
|
loop {
|
||||||
},
|
match future::select(pending_listen, b_transport.next()).await {
|
||||||
..
|
Either::Left((listen_done, _)) => return (listen_done, dial_done),
|
||||||
})) => {
|
Either::Right((_, listen)) => {
|
||||||
log::debug!("dialer got Message");
|
pending_listen = listen;
|
||||||
num_responses += 1;
|
}
|
||||||
assert_eq!(data, pong);
|
|
||||||
let should_be = num_listeners * num_streams;
|
|
||||||
log::debug!(
|
|
||||||
"num of responses: {}, num of listeners * num of streams: {}",
|
|
||||||
num_responses,
|
|
||||||
should_be
|
|
||||||
);
|
|
||||||
if num_responses == should_be {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(SwarmEvent::ConnectionClosed { .. }) => {
|
|
||||||
log::debug!("dialer ConnectionClosed");
|
|
||||||
}
|
|
||||||
Some(SwarmEvent::NewListenAddr { .. }) => {
|
|
||||||
log::debug!("dialer NewListenAddr");
|
|
||||||
}
|
|
||||||
e => {
|
|
||||||
panic!("unexpected event {:?}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
struct ListenUpgrade<'a> {
|
||||||
struct PingProtocol();
|
listener: &'a mut Boxed<(PeerId, StreamMuxerBox)>,
|
||||||
|
listener_upgrade_task: Option<BoxFuture<'static, (PeerId, Multiaddr, StreamMuxerBox)>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
impl<'a> ListenUpgrade<'a> {
|
||||||
struct PingCodec();
|
pub fn new(listener: &'a mut Boxed<(PeerId, StreamMuxerBox)>) -> Self {
|
||||||
|
Self {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
listener,
|
||||||
struct Ping(Vec<u8>);
|
listener_upgrade_task: None,
|
||||||
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
struct Pong(Vec<u8>);
|
|
||||||
|
|
||||||
impl ProtocolName for PingProtocol {
|
|
||||||
fn protocol_name(&self) -> &[u8] {
|
|
||||||
"/ping/1".as_bytes()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
struct Dial<'a> {
|
||||||
impl RequestResponseCodec for PingCodec {
|
dialer: &'a mut Boxed<(PeerId, StreamMuxerBox)>,
|
||||||
type Protocol = PingProtocol;
|
dial_task: BoxFuture<'static, (PeerId, StreamMuxerBox)>,
|
||||||
type Request = Ping;
|
}
|
||||||
type Response = Pong;
|
|
||||||
|
|
||||||
async fn read_request<T>(&mut self, _: &PingProtocol, io: &mut T) -> io::Result<Self::Request>
|
impl<'a> Dial<'a> {
|
||||||
where
|
fn new(dialer: &'a mut Boxed<(PeerId, StreamMuxerBox)>, addr: Multiaddr) -> Self {
|
||||||
T: AsyncRead + Unpin + Send,
|
Self {
|
||||||
{
|
dial_task: dialer.dial(addr).unwrap().map(|r| r.unwrap()).boxed(),
|
||||||
upgrade::read_length_prefixed(io, 4096)
|
dialer,
|
||||||
.map(|res| match res {
|
}
|
||||||
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
|
|
||||||
Ok(vec) if vec.is_empty() => Err(io::ErrorKind::UnexpectedEof.into()),
|
|
||||||
Ok(vec) => Ok(Ping(vec)),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_response<T>(&mut self, _: &PingProtocol, io: &mut T) -> io::Result<Self::Response>
|
|
||||||
where
|
|
||||||
T: AsyncRead + Unpin + Send,
|
|
||||||
{
|
|
||||||
upgrade::read_length_prefixed(io, 4096)
|
|
||||||
.map(|res| match res {
|
|
||||||
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
|
|
||||||
Ok(vec) if vec.is_empty() => Err(io::ErrorKind::UnexpectedEof.into()),
|
|
||||||
Ok(vec) => Ok(Pong(vec)),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn write_request<T>(
|
|
||||||
&mut self,
|
|
||||||
_: &PingProtocol,
|
|
||||||
io: &mut T,
|
|
||||||
Ping(data): Ping,
|
|
||||||
) -> io::Result<()>
|
|
||||||
where
|
|
||||||
T: AsyncWrite + Unpin + Send,
|
|
||||||
{
|
|
||||||
upgrade::write_length_prefixed(io, data).await?;
|
|
||||||
io.close().await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn write_response<T>(
|
|
||||||
&mut self,
|
|
||||||
_: &PingProtocol,
|
|
||||||
io: &mut T,
|
|
||||||
Pong(data): Pong,
|
|
||||||
) -> io::Result<()>
|
|
||||||
where
|
|
||||||
T: AsyncWrite + Unpin + Send,
|
|
||||||
{
|
|
||||||
upgrade::write_length_prefixed(io, data).await?;
|
|
||||||
io.close().await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_swarm() -> Result<Swarm<RequestResponse<PingCodec>>> {
|
impl Future for Dial<'_> {
|
||||||
let id_keys = identity::Keypair::generate_ed25519();
|
type Output = (PeerId, StreamMuxerBox);
|
||||||
let peer_id = id_keys.public().to_peer_id();
|
|
||||||
let transport = webrtc::Transport::new(
|
|
||||||
id_keys,
|
|
||||||
webrtc::Certificate::generate(&mut thread_rng()).unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let protocols = iter::once((PingProtocol(), ProtocolSupport::Full));
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let cfg = RequestResponseConfig::default();
|
loop {
|
||||||
let behaviour = RequestResponse::new(PingCodec(), protocols, cfg);
|
match self.dialer.poll_next_unpin(cx) {
|
||||||
let transport = transport
|
Poll::Ready(_) => {
|
||||||
.map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn)))
|
continue;
|
||||||
.boxed();
|
}
|
||||||
|
Poll::Pending => {}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Swarm::with_tokio_executor(transport, behaviour, peer_id))
|
let conn = ready!(self.dial_task.poll_unpin(cx));
|
||||||
|
return Poll::Ready(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Future for ListenUpgrade<'_> {
|
||||||
|
type Output = (PeerId, Multiaddr, StreamMuxerBox);
|
||||||
|
|
||||||
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
loop {
|
||||||
|
match dbg!(self.listener.poll_next_unpin(cx)) {
|
||||||
|
Poll::Ready(Some(TransportEvent::Incoming {
|
||||||
|
upgrade,
|
||||||
|
send_back_addr,
|
||||||
|
..
|
||||||
|
})) => {
|
||||||
|
self.listener_upgrade_task = Some(
|
||||||
|
async move {
|
||||||
|
let (peer, conn) = upgrade.await.unwrap();
|
||||||
|
|
||||||
|
(peer, send_back_addr, conn)
|
||||||
|
}
|
||||||
|
.boxed(),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Poll::Ready(None) => unreachable!("stream never ends"),
|
||||||
|
Poll::Ready(Some(_)) => continue,
|
||||||
|
Poll::Pending => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let conn = match self.listener_upgrade_task.as_mut() {
|
||||||
|
None => return Poll::Pending,
|
||||||
|
Some(inner) => ready!(inner.poll_unpin(cx)),
|
||||||
|
};
|
||||||
|
|
||||||
|
return Poll::Ready(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ url = "2.1"
|
|||||||
webpki-roots = "0.22"
|
webpki-roots = "0.22"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
libp2p = { path = "../..", features = ["full"] }
|
libp2p-tcp = { path = "../tcp", features = ["async-io"] }
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
# More information: https://docs.rs/about/builds#cross-compiling
|
# More information: https://docs.rs/about/builds#cross-compiling
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
|
@ -221,8 +221,8 @@ where
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::WsConfig;
|
use super::WsConfig;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::core::{multiaddr::Protocol, Multiaddr, PeerId, Transport};
|
use libp2p_core::{multiaddr::Protocol, Multiaddr, PeerId, Transport};
|
||||||
use libp2p::tcp;
|
use libp2p_tcp as tcp;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dialer_connects_to_listener_ipv4() {
|
fn dialer_connects_to_listener_ipv4() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user