mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 11:02:12 +00:00
Deprecate secio. (#1729)
SECIO is removed from all libp2p implementations. See https://blog.ipfs.io/2020-08-07-deprecating-secio/.
This commit is contained in:
parent
c94262d03a
commit
ed5aec14f3
@ -24,7 +24,6 @@ default = [
|
|||||||
"plaintext",
|
"plaintext",
|
||||||
"pnet",
|
"pnet",
|
||||||
"request-response",
|
"request-response",
|
||||||
"secio",
|
|
||||||
"secp256k1",
|
"secp256k1",
|
||||||
"tcp-async-std",
|
"tcp-async-std",
|
||||||
"uds",
|
"uds",
|
||||||
@ -46,7 +45,6 @@ ping = ["libp2p-ping"]
|
|||||||
plaintext = ["libp2p-plaintext"]
|
plaintext = ["libp2p-plaintext"]
|
||||||
pnet = ["libp2p-pnet"]
|
pnet = ["libp2p-pnet"]
|
||||||
request-response = ["libp2p-request-response"]
|
request-response = ["libp2p-request-response"]
|
||||||
secio = ["libp2p-secio"]
|
|
||||||
tcp-async-std = ["libp2p-tcp", "libp2p-tcp/async-std"]
|
tcp-async-std = ["libp2p-tcp", "libp2p-tcp/async-std"]
|
||||||
tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"]
|
tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"]
|
||||||
uds = ["libp2p-uds"]
|
uds = ["libp2p-uds"]
|
||||||
@ -54,7 +52,7 @@ wasm-ext = ["libp2p-wasm-ext"]
|
|||||||
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext/websocket"]
|
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext/websocket"]
|
||||||
websocket = ["libp2p-websocket"]
|
websocket = ["libp2p-websocket"]
|
||||||
yamux = ["libp2p-yamux"]
|
yamux = ["libp2p-yamux"]
|
||||||
secp256k1 = ["libp2p-core/secp256k1", "libp2p-secio/secp256k1"]
|
secp256k1 = ["libp2p-core/secp256k1"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
@ -76,7 +74,6 @@ libp2p-ping = { version = "0.22.0", path = "protocols/ping", optional = true }
|
|||||||
libp2p-plaintext = { version = "0.22.0", path = "protocols/plaintext", optional = true }
|
libp2p-plaintext = { version = "0.22.0", path = "protocols/plaintext", optional = true }
|
||||||
libp2p-pnet = { version = "0.19.1", path = "protocols/pnet", optional = true }
|
libp2p-pnet = { version = "0.19.1", path = "protocols/pnet", optional = true }
|
||||||
libp2p-request-response = { version = "0.3.0", path = "protocols/request-response", optional = true }
|
libp2p-request-response = { version = "0.3.0", path = "protocols/request-response", optional = true }
|
||||||
libp2p-secio = { version = "0.22.0", path = "protocols/secio", default-features = false, optional = true }
|
|
||||||
libp2p-swarm = { version = "0.22.0", path = "swarm" }
|
libp2p-swarm = { version = "0.22.0", path = "swarm" }
|
||||||
libp2p-uds = { version = "0.22.0", path = "transports/uds", optional = true }
|
libp2p-uds = { version = "0.22.0", path = "transports/uds", optional = true }
|
||||||
libp2p-wasm-ext = { version = "0.22.0", path = "transports/wasm-ext", optional = true }
|
libp2p-wasm-ext = { version = "0.22.0", path = "transports/wasm-ext", optional = true }
|
||||||
|
@ -41,7 +41,7 @@ ring = { version = "0.16.9", features = ["alloc", "std"], default-features = fal
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
libp2p-mplex = { path = "../muxers/mplex" }
|
libp2p-mplex = { path = "../muxers/mplex" }
|
||||||
libp2p-secio = { path = "../protocols/secio" }
|
libp2p-noise = { path = "../protocols/noise" }
|
||||||
libp2p-tcp = { path = "../transports/tcp", features = ["async-std"] }
|
libp2p-tcp = { path = "../transports/tcp", features = ["async-std"] }
|
||||||
quickcheck = "0.9.0"
|
quickcheck = "0.9.0"
|
||||||
wasm-timer = "0.2"
|
wasm-timer = "0.2"
|
||||||
|
@ -33,6 +33,7 @@ use libp2p_core::{
|
|||||||
transport,
|
transport,
|
||||||
upgrade,
|
upgrade,
|
||||||
};
|
};
|
||||||
|
use libp2p_noise as noise;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use std::{io, error::Error, fmt, task::Poll};
|
use std::{io, error::Error, fmt, task::Poll};
|
||||||
@ -55,9 +56,10 @@ impl fmt::Display for BoxError {
|
|||||||
fn new_network(cfg: NetworkConfig) -> TestNetwork {
|
fn new_network(cfg: NetworkConfig) -> TestNetwork {
|
||||||
let local_key = identity::Keypair::generate_ed25519();
|
let local_key = identity::Keypair::generate_ed25519();
|
||||||
let local_public_key = local_key.public();
|
let local_public_key = local_key.public();
|
||||||
|
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&local_key).unwrap();
|
||||||
let transport: TestTransport = libp2p_tcp::TcpConfig::new()
|
let transport: TestTransport = libp2p_tcp::TcpConfig::new()
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(libp2p_secio::SecioConfig::new(local_key))
|
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
|
||||||
.multiplex(libp2p_mplex::MplexConfig::new())
|
.multiplex(libp2p_mplex::MplexConfig::new())
|
||||||
.map(|(conn_info, muxer), _| (conn_info, StreamMuxerBox::new(muxer)))
|
.map(|(conn_info, muxer), _| (conn_info, StreamMuxerBox::new(muxer)))
|
||||||
.and_then(|(peer, mplex), _| {
|
.and_then(|(peer, mplex), _| {
|
||||||
|
@ -25,7 +25,7 @@ use libp2p_core::identity;
|
|||||||
use libp2p_core::transport::{Transport, MemoryTransport};
|
use libp2p_core::transport::{Transport, MemoryTransport};
|
||||||
use libp2p_core::upgrade::{self, UpgradeInfo, InboundUpgrade, OutboundUpgrade};
|
use libp2p_core::upgrade::{self, UpgradeInfo, InboundUpgrade, OutboundUpgrade};
|
||||||
use libp2p_mplex::MplexConfig;
|
use libp2p_mplex::MplexConfig;
|
||||||
use libp2p_secio::SecioConfig;
|
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};
|
||||||
@ -81,9 +81,10 @@ where
|
|||||||
fn upgrade_pipeline() {
|
fn upgrade_pipeline() {
|
||||||
let listener_keys = identity::Keypair::generate_ed25519();
|
let listener_keys = identity::Keypair::generate_ed25519();
|
||||||
let listener_id = listener_keys.public().into_peer_id();
|
let listener_id = listener_keys.public().into_peer_id();
|
||||||
|
let listener_noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&listener_keys).unwrap();
|
||||||
let listener_transport = MemoryTransport::default()
|
let listener_transport = MemoryTransport::default()
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(SecioConfig::new(listener_keys))
|
.authenticate(noise::NoiseConfig::xx(listener_noise_keys).into_authenticated())
|
||||||
.apply(HelloUpgrade {})
|
.apply(HelloUpgrade {})
|
||||||
.apply(HelloUpgrade {})
|
.apply(HelloUpgrade {})
|
||||||
.apply(HelloUpgrade {})
|
.apply(HelloUpgrade {})
|
||||||
@ -96,9 +97,10 @@ fn upgrade_pipeline() {
|
|||||||
|
|
||||||
let dialer_keys = identity::Keypair::generate_ed25519();
|
let dialer_keys = identity::Keypair::generate_ed25519();
|
||||||
let dialer_id = dialer_keys.public().into_peer_id();
|
let dialer_id = dialer_keys.public().into_peer_id();
|
||||||
|
let dialer_noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&dialer_keys).unwrap();
|
||||||
let dialer_transport = MemoryTransport::default()
|
let dialer_transport = MemoryTransport::default()
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(SecioConfig::new(dialer_keys))
|
.authenticate(noise::NoiseConfig::xx(dialer_noise_keys).into_authenticated())
|
||||||
.apply(HelloUpgrade {})
|
.apply(HelloUpgrade {})
|
||||||
.apply(HelloUpgrade {})
|
.apply(HelloUpgrade {})
|
||||||
.apply(HelloUpgrade {})
|
.apply(HelloUpgrade {})
|
||||||
|
@ -41,7 +41,7 @@ use libp2p::{
|
|||||||
multiaddr::Protocol,
|
multiaddr::Protocol,
|
||||||
ping::{self, Ping, PingConfig, PingEvent},
|
ping::{self, Ping, PingConfig, PingEvent},
|
||||||
pnet::{PnetConfig, PreSharedKey},
|
pnet::{PnetConfig, PreSharedKey},
|
||||||
secio::SecioConfig,
|
noise,
|
||||||
swarm::NetworkBehaviourEventProcess,
|
swarm::NetworkBehaviourEventProcess,
|
||||||
tcp::TcpConfig,
|
tcp::TcpConfig,
|
||||||
yamux::Config as YamuxConfig,
|
yamux::Config as YamuxConfig,
|
||||||
@ -76,7 +76,8 @@ pub fn build_transport(
|
|||||||
Dial = impl Send,
|
Dial = impl Send,
|
||||||
ListenerUpgrade = impl Send,
|
ListenerUpgrade = impl Send,
|
||||||
> + Clone {
|
> + Clone {
|
||||||
let secio_config = SecioConfig::new(key_pair);
|
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&key_pair).unwrap();
|
||||||
|
let noise_config = noise::NoiseConfig::xx(noise_keys).into_authenticated();
|
||||||
let yamux_config = YamuxConfig::default();
|
let yamux_config = YamuxConfig::default();
|
||||||
|
|
||||||
let base_transport = TcpConfig::new().nodelay(true);
|
let base_transport = TcpConfig::new().nodelay(true);
|
||||||
@ -88,7 +89,7 @@ pub fn build_transport(
|
|||||||
};
|
};
|
||||||
maybe_encrypted
|
maybe_encrypted
|
||||||
.upgrade(Version::V1)
|
.upgrade(Version::V1)
|
||||||
.authenticate(secio_config)
|
.authenticate(noise_config)
|
||||||
.multiplex(yamux_config)
|
.multiplex(yamux_config)
|
||||||
.timeout(Duration::from_secs(20))
|
.timeout(Duration::from_secs(20))
|
||||||
}
|
}
|
||||||
|
@ -103,11 +103,11 @@
|
|||||||
//! #extern crate futures;
|
//! #extern crate futures;
|
||||||
//! #extern crate tokio;
|
//! #extern crate tokio;
|
||||||
//! #use libp2p::gossipsub::GossipsubEvent;
|
//! #use libp2p::gossipsub::GossipsubEvent;
|
||||||
//! #use libp2p::{gossipsub, secio,
|
//! #use libp2p::{identity, gossipsub,
|
||||||
//! # tokio_codec::{FramedRead, LinesCodec},
|
//! # tokio_codec::{FramedRead, LinesCodec},
|
||||||
//! #};
|
//! #};
|
||||||
//! let local_key = secio::SecioKeyPair::ed25519_generated().unwrap();
|
//! let local_key = identity::Keypair::generate_ed25519();
|
||||||
//! let local_pub_key = local_key.to_public_key();
|
//! let local_pub_key = local_key.public();
|
||||||
//!
|
//!
|
||||||
//! // Set up an encrypted TCP Transport over the Mplex and Yamux protocols
|
//! // Set up an encrypted TCP Transport over the Mplex and Yamux protocols
|
||||||
//! let transport = libp2p::build_development_transport(local_key);
|
//! let transport = libp2p::build_development_transport(local_key);
|
||||||
|
@ -21,7 +21,7 @@ wasm-timer = "0.2"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
libp2p-mplex = { path = "../../muxers/mplex" }
|
libp2p-mplex = { path = "../../muxers/mplex" }
|
||||||
libp2p-secio = { path = "../../protocols/secio" }
|
libp2p-noise = { path = "../../protocols/noise" }
|
||||||
libp2p-tcp = { path = "../../transports/tcp", features = ["async-std"] }
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-std"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -277,8 +277,8 @@ mod tests {
|
|||||||
Transport,
|
Transport,
|
||||||
upgrade
|
upgrade
|
||||||
};
|
};
|
||||||
|
use libp2p_noise as noise;
|
||||||
use libp2p_tcp::TcpConfig;
|
use libp2p_tcp::TcpConfig;
|
||||||
use libp2p_secio::SecioConfig;
|
|
||||||
use libp2p_swarm::{Swarm, SwarmEvent};
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
use libp2p_mplex::MplexConfig;
|
use libp2p_mplex::MplexConfig;
|
||||||
use std::{fmt, io};
|
use std::{fmt, io};
|
||||||
@ -291,11 +291,12 @@ mod tests {
|
|||||||
Error = impl fmt::Debug
|
Error = impl fmt::Debug
|
||||||
> + Clone) {
|
> + Clone) {
|
||||||
let id_keys = identity::Keypair::generate_ed25519();
|
let id_keys = identity::Keypair::generate_ed25519();
|
||||||
|
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&id_keys).unwrap();
|
||||||
let pubkey = id_keys.public();
|
let pubkey = id_keys.public();
|
||||||
let transport = TcpConfig::new()
|
let transport = TcpConfig::new()
|
||||||
.nodelay(true)
|
.nodelay(true)
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(SecioConfig::new(id_keys))
|
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
|
||||||
.multiplex(MplexConfig::new());
|
.multiplex(MplexConfig::new());
|
||||||
(pubkey, transport)
|
(pubkey, transport)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ void = "1.0"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures-timer = "3.0"
|
futures-timer = "3.0"
|
||||||
libp2p-secio = { path = "../secio" }
|
libp2p-noise = { path = "../noise" }
|
||||||
libp2p-yamux = { path = "../../muxers/yamux" }
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
quickcheck = "0.9.0"
|
quickcheck = "0.9.0"
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ use libp2p_core::{
|
|||||||
muxing::StreamMuxerBox,
|
muxing::StreamMuxerBox,
|
||||||
upgrade
|
upgrade
|
||||||
};
|
};
|
||||||
use libp2p_secio::SecioConfig;
|
use libp2p_noise as noise;
|
||||||
use libp2p_swarm::Swarm;
|
use libp2p_swarm::Swarm;
|
||||||
use libp2p_yamux as yamux;
|
use libp2p_yamux as yamux;
|
||||||
use quickcheck::*;
|
use quickcheck::*;
|
||||||
@ -58,9 +58,10 @@ fn build_node() -> (Multiaddr, TestSwarm) {
|
|||||||
fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) {
|
fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) {
|
||||||
let local_key = identity::Keypair::generate_ed25519();
|
let local_key = identity::Keypair::generate_ed25519();
|
||||||
let local_public_key = local_key.public();
|
let local_public_key = local_key.public();
|
||||||
|
let noise_keys = noise::Keypair::<noise::X25519>::new().into_authentic(&local_key).unwrap();
|
||||||
let transport = MemoryTransport::default()
|
let transport = MemoryTransport::default()
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(SecioConfig::new(local_key))
|
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
|
||||||
.multiplex(yamux::Config::default())
|
.multiplex(yamux::Config::default())
|
||||||
.map(|(p, m), _| (p, StreamMuxerBox::new(m)))
|
.map(|(p, m), _| (p, StreamMuxerBox::new(m)))
|
||||||
.map_err(|e| -> io::Error { panic!("Failed to create transport: {:?}", e); })
|
.map_err(|e| -> io::Error { panic!("Failed to create transport: {:?}", e); })
|
||||||
|
@ -21,6 +21,6 @@ wasm-timer = "0.2"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.2"
|
async-std = "1.6.2"
|
||||||
libp2p-tcp = { path = "../../transports/tcp", features = ["async-std"] }
|
libp2p-tcp = { path = "../../transports/tcp", features = ["async-std"] }
|
||||||
libp2p-secio = { path = "../../protocols/secio" }
|
libp2p-noise = { path = "../../protocols/noise" }
|
||||||
libp2p-yamux = { path = "../../muxers/yamux" }
|
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||||
quickcheck = "0.9.0"
|
quickcheck = "0.9.0"
|
||||||
|
@ -28,8 +28,8 @@ use libp2p_core::{
|
|||||||
transport::{Transport, boxed::Boxed},
|
transport::{Transport, boxed::Boxed},
|
||||||
upgrade
|
upgrade
|
||||||
};
|
};
|
||||||
|
use libp2p_noise as noise;
|
||||||
use libp2p_ping::*;
|
use libp2p_ping::*;
|
||||||
use libp2p_secio::SecioConfig;
|
|
||||||
use libp2p_swarm::{Swarm, SwarmEvent};
|
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||||
use libp2p_tcp::TcpConfig;
|
use libp2p_tcp::TcpConfig;
|
||||||
use futures::{prelude::*, channel::mpsc};
|
use futures::{prelude::*, channel::mpsc};
|
||||||
@ -201,10 +201,11 @@ fn mk_transport() -> (
|
|||||||
) {
|
) {
|
||||||
let id_keys = identity::Keypair::generate_ed25519();
|
let id_keys = identity::Keypair::generate_ed25519();
|
||||||
let peer_id = id_keys.public().into_peer_id();
|
let peer_id = id_keys.public().into_peer_id();
|
||||||
|
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&id_keys).unwrap();
|
||||||
let transport = TcpConfig::new()
|
let transport = TcpConfig::new()
|
||||||
.nodelay(true)
|
.nodelay(true)
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(SecioConfig::new(id_keys))
|
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
|
||||||
.multiplex(libp2p_yamux::Config::default())
|
.multiplex(libp2p_yamux::Config::default())
|
||||||
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
|
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
|
||||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
# 0.22.0 [unreleased]
|
# 0.22.0 [unreleased]
|
||||||
|
|
||||||
|
- As of this release, SECIO is deprecated. Please use `libp2p-noise` instead.
|
||||||
|
For some more context, [see here](https://blog.ipfs.io/2020-08-07-deprecating-secio/).
|
||||||
|
|
||||||
- Bump `libp2p-core` dependency.
|
- Bump `libp2p-core` dependency.
|
||||||
|
|
||||||
# 0.21.0 [2020-08-18]
|
# 0.21.0 [2020-08-18]
|
||||||
|
@ -9,6 +9,9 @@ repository = "https://github.com/libp2p/rust-libp2p"
|
|||||||
keywords = ["peer-to-peer", "libp2p", "networking"]
|
keywords = ["peer-to-peer", "libp2p", "networking"]
|
||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
|
||||||
|
[badges]
|
||||||
|
maintenance = { status = "deprecated" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aes-ctr = "0.3"
|
aes-ctr = "0.3"
|
||||||
aesni = { version = "0.6", features = ["nocheck"], optional = true }
|
aesni = { version = "0.6", features = ["nocheck"], optional = true }
|
||||||
|
65
src/lib.rs
65
src/lib.rs
@ -82,20 +82,21 @@
|
|||||||
//! *upgraded*. Upgrading a transport is the process of negotiating an additional protocol
|
//! *upgraded*. Upgrading a transport is the process of negotiating an additional protocol
|
||||||
//! with the remote, mediated through a negotiation protocol called [`multistream-select`].
|
//! with the remote, mediated through a negotiation protocol called [`multistream-select`].
|
||||||
//!
|
//!
|
||||||
//! Example ([`secio`] + [`yamux`] Protocol Upgrade):
|
//! Example ([`noise`] + [`yamux`] Protocol Upgrade):
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), feature = "tcp-async-std", feature = "secio", feature = "yamux"))] {
|
//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), feature = "tcp-async-std", feature = "noise", feature = "yamux"))] {
|
||||||
//! use libp2p::{Transport, core::upgrade, tcp::TcpConfig, secio::SecioConfig, identity::Keypair, yamux};
|
//! use libp2p::{Transport, core::upgrade, tcp::TcpConfig, noise, identity::Keypair, yamux};
|
||||||
//! let tcp = TcpConfig::new();
|
//! let tcp = TcpConfig::new();
|
||||||
//! let secio = SecioConfig::new(Keypair::generate_ed25519());
|
//! let id_keys = Keypair::generate_ed25519();
|
||||||
|
//! let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&id_keys).unwrap();
|
||||||
|
//! let noise = noise::NoiseConfig::xx(noise_keys).into_authenticated();
|
||||||
//! let yamux = yamux::Config::default();
|
//! let yamux = yamux::Config::default();
|
||||||
//! let transport = tcp.upgrade(upgrade::Version::V1).authenticate(secio).multiplex(yamux);
|
//! let transport = tcp.upgrade(upgrade::Version::V1).authenticate(noise).multiplex(yamux);
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//! In this example, `transport` is a new [`Transport`] that negotiates the
|
//! In this example, `transport` is a new [`Transport`] that negotiates the
|
||||||
//! secio and yamux protocols
|
//! noise and yamux protocols on all connections.
|
||||||
//! on all connections.
|
|
||||||
//!
|
//!
|
||||||
//! ## Network Behaviour
|
//! ## Network Behaviour
|
||||||
//!
|
//!
|
||||||
@ -128,7 +129,7 @@
|
|||||||
//! implements [`StreamMuxer`] (e.g. [`Yamux`]). The peer ID must be the
|
//! implements [`StreamMuxer`] (e.g. [`Yamux`]). The peer ID must be the
|
||||||
//! identity of the remote peer of the established connection, which is
|
//! identity of the remote peer of the established connection, which is
|
||||||
//! usually obtained through a transport encryption protocol such as
|
//! usually obtained through a transport encryption protocol such as
|
||||||
//! [`secio`] that authenticates the peer. See the implementation of
|
//! [`noise`] that authenticates the peer. See the implementation of
|
||||||
//! [`build_development_transport`] for an example.
|
//! [`build_development_transport`] for an example.
|
||||||
//! 3. Creating a struct that implements the [`NetworkBehaviour`] trait and combines all the
|
//! 3. Creating a struct that implements the [`NetworkBehaviour`] trait and combines all the
|
||||||
//! desired network behaviours, implementing the event handlers as per the
|
//! desired network behaviours, implementing the event handlers as per the
|
||||||
@ -136,7 +137,7 @@
|
|||||||
//! 4. Instantiating a [`Swarm`] with the transport, the network behaviour and the
|
//! 4. Instantiating a [`Swarm`] with the transport, the network behaviour and the
|
||||||
//! local peer ID from the previous steps.
|
//! local peer ID from the previous steps.
|
||||||
//!
|
//!
|
||||||
//! The swarm instance can then be polled with the [tokio] library, in order to
|
//! The swarm instance can then be polled e.g. with the [tokio] library, in order to
|
||||||
//! continuously drive the network activity of the program.
|
//! continuously drive the network activity of the program.
|
||||||
//!
|
//!
|
||||||
//! [`Keypair`]: identity::Keypair
|
//! [`Keypair`]: identity::Keypair
|
||||||
@ -212,10 +213,6 @@ pub use libp2p_ping as ping;
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "plaintext")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "plaintext")))]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use libp2p_plaintext as plaintext;
|
pub use libp2p_plaintext as plaintext;
|
||||||
#[cfg(feature = "secio")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "secio")))]
|
|
||||||
#[doc(inline)]
|
|
||||||
pub use libp2p_secio as secio;
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use libp2p_swarm as swarm;
|
pub use libp2p_swarm as swarm;
|
||||||
#[cfg(any(feature = "tcp-async-std", feature = "tcp-tokio"))]
|
#[cfg(any(feature = "tcp-async-std", feature = "tcp-tokio"))]
|
||||||
@ -310,14 +307,13 @@ pub fn build_tcp_ws_noise_mplex_yamux(keypair: identity::Keypair)
|
|||||||
.timeout(std::time::Duration::from_secs(20)))
|
.timeout(std::time::Duration::from_secs(20)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Builds an implementation of `Transport` that is suitable for usage with the `Swarm`.
|
/// Builds an implementation of `Transport` that is suitable for usage with the `Swarm`.
|
||||||
///
|
///
|
||||||
/// The implementation supports TCP/IP, WebSockets over TCP/IP, secio as the encryption layer,
|
/// The implementation supports TCP/IP, WebSockets over TCP/IP, noise as the encryption layer,
|
||||||
/// and mplex or yamux as the multiplexing layer.
|
/// and mplex or yamux as the multiplexing layer.
|
||||||
#[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
|
#[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "noise", feature = "mplex", feature = "yamux", feature = "pnet"))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
|
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "noise", feature = "mplex", feature = "yamux", feature = "pnet"))))]
|
||||||
pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
|
pub fn build_tcp_ws_pnet_noise_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey)
|
||||||
-> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
|
-> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
|
||||||
{
|
{
|
||||||
let transport = {
|
let transport = {
|
||||||
@ -330,39 +326,14 @@ pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
|
|||||||
transport.or_transport(websocket::WsConfig::new(trans_clone))
|
transport.or_transport(websocket::WsConfig::new(trans_clone))
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(transport
|
let noise_keys = noise::Keypair::<noise::X25519Spec>::new()
|
||||||
.upgrade(core::upgrade::Version::V1)
|
.into_authentic(&keypair)
|
||||||
.authenticate(secio::SecioConfig::new(keypair))
|
.expect("Signing libp2p-noise static DH keypair failed.");
|
||||||
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
|
|
||||||
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
|
|
||||||
.timeout(std::time::Duration::from_secs(20)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds an implementation of `Transport` that is suitable for usage with the `Swarm`.
|
|
||||||
///
|
|
||||||
/// The implementation supports TCP/IP, WebSockets over TCP/IP, secio as the encryption layer,
|
|
||||||
/// and mplex or yamux as the multiplexing layer.
|
|
||||||
///
|
|
||||||
/// > **Note**: If you ever need to express the type of this `Transport`.
|
|
||||||
#[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))))]
|
|
||||||
pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey)
|
|
||||||
-> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
|
|
||||||
{
|
|
||||||
let transport = {
|
|
||||||
#[cfg(feature = "tcp-async-std")]
|
|
||||||
let tcp = tcp::TcpConfig::new().nodelay(true);
|
|
||||||
#[cfg(feature = "tcp-tokio")]
|
|
||||||
let tcp = tcp::TokioTcpConfig::new().nodelay(true);
|
|
||||||
let transport = dns::DnsConfig::new(tcp)?;
|
|
||||||
let trans_clone = transport.clone();
|
|
||||||
transport.or_transport(websocket::WsConfig::new(trans_clone))
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(transport
|
Ok(transport
|
||||||
.and_then(move |socket, _| PnetConfig::new(psk).handshake(socket))
|
.and_then(move |socket, _| PnetConfig::new(psk).handshake(socket))
|
||||||
.upgrade(core::upgrade::Version::V1)
|
.upgrade(core::upgrade::Version::V1)
|
||||||
.authenticate(secio::SecioConfig::new(keypair))
|
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
|
||||||
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
|
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
|
||||||
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
|
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
|
||||||
.timeout(std::time::Duration::from_secs(20)))
|
.timeout(std::time::Duration::from_secs(20)))
|
||||||
|
@ -21,6 +21,6 @@ void = "1"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
libp2p-mplex = { path = "../muxers/mplex" }
|
libp2p-mplex = { path = "../muxers/mplex" }
|
||||||
libp2p-secio = { path = "../protocols/secio" }
|
libp2p-noise = { path = "../protocols/noise" }
|
||||||
quickcheck = "0.9.0"
|
quickcheck = "0.9.0"
|
||||||
rand = "0.7.2"
|
rand = "0.7.2"
|
||||||
|
@ -1201,6 +1201,7 @@ mod tests {
|
|||||||
transport::{self, dummy::*}
|
transport::{self, dummy::*}
|
||||||
};
|
};
|
||||||
use libp2p_mplex::Multiplex;
|
use libp2p_mplex::Multiplex;
|
||||||
|
use libp2p_noise as noise;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn get_random_id() -> identity::PublicKey {
|
fn get_random_id() -> identity::PublicKey {
|
||||||
@ -1213,17 +1214,18 @@ mod tests {
|
|||||||
T::OutEvent: Clone,
|
T::OutEvent: Clone,
|
||||||
O: Send + 'static
|
O: Send + 'static
|
||||||
{
|
{
|
||||||
let keypair1 = identity::Keypair::generate_ed25519();
|
let id_keys = identity::Keypair::generate_ed25519();
|
||||||
let pubkey1 = keypair1.public();
|
let pubkey = id_keys.public();
|
||||||
let transport1 = transport::MemoryTransport::default()
|
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&id_keys).unwrap();
|
||||||
|
let transport = transport::MemoryTransport::default()
|
||||||
.upgrade(upgrade::Version::V1)
|
.upgrade(upgrade::Version::V1)
|
||||||
.authenticate(libp2p_secio::SecioConfig::new(keypair1))
|
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
|
||||||
.multiplex(libp2p_mplex::MplexConfig::new())
|
.multiplex(libp2p_mplex::MplexConfig::new())
|
||||||
.map(|(p, m), _| (p, StreamMuxerBox::new(m)))
|
.map(|(p, m), _| (p, StreamMuxerBox::new(m)))
|
||||||
.map_err(|e| -> io::Error { panic!("Failed to create transport: {:?}", e); })
|
.map_err(|e| -> io::Error { panic!("Failed to create transport: {:?}", e); })
|
||||||
.boxed();
|
.boxed();
|
||||||
let behaviour1 = CallTraceBehaviour::new(MockBehaviour::new(handler_proto));
|
let behaviour = CallTraceBehaviour::new(MockBehaviour::new(handler_proto));
|
||||||
SwarmBuilder::new(transport1, behaviour1, pubkey1.into()).build()
|
SwarmBuilder::new(transport, behaviour, pubkey.into()).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user