The secio
protocol is a middleware that will encrypt and decrypt communications going
through a socket (or anything that implements AsyncRead + AsyncWrite
).
Usage
The SecioConfig
implements [InboundUpgrade
] and [OutboundUpgrade
] and thus
serves as a connection upgrade for authentication of a transport.
See authenticate
.
# fn main() {
use futures::prelude::*;
use libp2p_secio::{SecioConfig, SecioOutput};
use libp2p_core::{PeerId, Multiaddr, identity, upgrade};
use libp2p_core::transport::Transport;
use libp2p_mplex::MplexConfig;
use libp2p_tcp::TcpConfig;
// Create a local peer identity.
let local_keys = identity::Keypair::generate_ed25519();
// Create a `Transport`.
let transport = TcpConfig::new()
.upgrade(upgrade::Version::V1)
.authenticate(SecioConfig::new(local_keys.clone()))
.multiplex(MplexConfig::default());
// The transport can be used with a `Network` from `libp2p-core`, or a
// `Swarm` from from `libp2p-swarm`. See the documentation of these
// crates for mode details.
// let network = Network::new(transport, local_keys.public().into_peer_id());
// let swarm = Swarm::new(transport, behaviour, local_keys.public().into_peer_id());
# }