mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 10:31:21 +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:
65
src/lib.rs
65
src/lib.rs
@ -82,20 +82,21 @@
|
||||
//! *upgraded*. Upgrading a transport is the process of negotiating an additional protocol
|
||||
//! with the remote, mediated through a negotiation protocol called [`multistream-select`].
|
||||
//!
|
||||
//! Example ([`secio`] + [`yamux`] Protocol Upgrade):
|
||||
//! Example ([`noise`] + [`yamux`] Protocol Upgrade):
|
||||
//!
|
||||
//! ```rust
|
||||
//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), feature = "tcp-async-std", feature = "secio", feature = "yamux"))] {
|
||||
//! use libp2p::{Transport, core::upgrade, tcp::TcpConfig, secio::SecioConfig, identity::Keypair, 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, noise, identity::Keypair, yamux};
|
||||
//! 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 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
|
||||
//! secio and yamux protocols
|
||||
//! on all connections.
|
||||
//! noise and yamux protocols on all connections.
|
||||
//!
|
||||
//! ## Network Behaviour
|
||||
//!
|
||||
@ -128,7 +129,7 @@
|
||||
//! implements [`StreamMuxer`] (e.g. [`Yamux`]). The peer ID must be the
|
||||
//! identity of the remote peer of the established connection, which is
|
||||
//! 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.
|
||||
//! 3. Creating a struct that implements the [`NetworkBehaviour`] trait and combines all 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
|
||||
//! 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.
|
||||
//!
|
||||
//! [`Keypair`]: identity::Keypair
|
||||
@ -212,10 +213,6 @@ pub use libp2p_ping as ping;
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "plaintext")))]
|
||||
#[doc(inline)]
|
||||
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)]
|
||||
pub use libp2p_swarm as swarm;
|
||||
#[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)))
|
||||
}
|
||||
|
||||
|
||||
/// 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.
|
||||
#[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 = "secio", feature = "mplex", feature = "yamux"))))]
|
||||
pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
|
||||
#[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 = "noise", feature = "mplex", feature = "yamux", feature = "pnet"))))]
|
||||
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>
|
||||
{
|
||||
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))
|
||||
};
|
||||
|
||||
Ok(transport
|
||||
.upgrade(core::upgrade::Version::V1)
|
||||
.authenticate(secio::SecioConfig::new(keypair))
|
||||
.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))
|
||||
};
|
||||
let noise_keys = noise::Keypair::<noise::X25519Spec>::new()
|
||||
.into_authentic(&keypair)
|
||||
.expect("Signing libp2p-noise static DH keypair failed.");
|
||||
|
||||
Ok(transport
|
||||
.and_then(move |socket, _| PnetConfig::new(psk).handshake(socket))
|
||||
.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()))
|
||||
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
|
||||
.timeout(std::time::Duration::from_secs(20)))
|
||||
|
Reference in New Issue
Block a user