例如使用let transport = libp2p::development_transport(local_keys).await?;调用libp2p提供的高级API函数development_transport来创建传输。这个函数封装了传输的创建过程,通常会使用一组默认的配置参数和最佳实践,以便快速启动和测试libp2p应用程序。在这种情况下,local_keys是本地密钥,用于加密和身份验证。有关这个API的未来发展可以看这个ISSUE。
//Creates transport which is a feature of the lib p2p framework
let transport = TokioTcpConfig::new()
//Upgrades version of the transport once connection is established as Version 1 of the multi-stream-select protocol is the version that interacts with the noise protocol
//in short handles protocol negotiation
.upgrade(upgrade::Version::V1)
//Authenticates that channel is secure with the noise XX handshake
.authenticate(libp2p::noise::NoiseConfig::xx(auth_keys).into_authenticated())
//multiplex transport negotiates multiple sub-streams and/or connections on the authenticated transport
.multiplex(mplex::MplexConfig::new())
//boxed allows only output and error types to be captured
.boxed();