refactor(plaintext): rename symbols to follow naming convention

Related: #2217.

Pull-Request: #4535.
This commit is contained in:
Thomas Eizinger 2023-09-28 05:42:45 +10:00 committed by GitHub
parent f6b5a1376a
commit fffd47b69f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 98 additions and 102 deletions

2
Cargo.lock generated
View File

@ -2868,7 +2868,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-plaintext" name = "libp2p-plaintext"
version = "0.40.0" version = "0.40.1"
dependencies = [ dependencies = [
"asynchronous-codec", "asynchronous-codec",
"bytes", "bytes",

View File

@ -92,7 +92,7 @@ libp2p-muxer-test-harness = { path = "muxers/test-harness" }
libp2p-noise = { version = "0.43.1", path = "transports/noise" } libp2p-noise = { version = "0.43.1", path = "transports/noise" }
libp2p-perf = { version = "0.2.0", path = "protocols/perf" } libp2p-perf = { version = "0.2.0", path = "protocols/perf" }
libp2p-ping = { version = "0.43.1", path = "protocols/ping" } libp2p-ping = { version = "0.43.1", path = "protocols/ping" }
libp2p-plaintext = { version = "0.40.0", path = "transports/plaintext" } libp2p-plaintext = { version = "0.40.1", path = "transports/plaintext" }
libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } libp2p-pnet = { version = "0.23.0", path = "transports/pnet" }
libp2p-quic = { version = "0.9.2", path = "transports/quic" } libp2p-quic = { version = "0.9.2", path = "transports/quic" }
libp2p-relay = { version = "0.16.1", path = "protocols/relay" } libp2p-relay = { version = "0.16.1", path = "protocols/relay" }

View File

@ -32,7 +32,7 @@ use libp2p_core::{multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, T
use libp2p_identity as identity; use libp2p_identity as identity;
use libp2p_identity::PeerId; use libp2p_identity::PeerId;
use libp2p_mplex as mplex; use libp2p_mplex as mplex;
use libp2p_plaintext::PlainText2Config; use libp2p_plaintext as plaintext;
use std::pin::Pin; use std::pin::Pin;
use std::time::Duration; use std::time::Duration;
@ -166,30 +166,28 @@ fn run(
} }
fn tcp_transport(split_send_size: usize) -> BenchTransport { fn tcp_transport(split_send_size: usize) -> BenchTransport {
let key = identity::Keypair::generate_ed25519();
let local_public_key = key.public();
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);
libp2p_tcp::async_io::Transport::new(libp2p_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(plaintext::Config::new(
&identity::Keypair::generate_ed25519(),
))
.multiplex(mplex) .multiplex(mplex)
.timeout(Duration::from_secs(5)) .timeout(Duration::from_secs(5))
.boxed() .boxed()
} }
fn mem_transport(split_send_size: usize) -> BenchTransport { fn mem_transport(split_send_size: usize) -> BenchTransport {
let key = identity::Keypair::generate_ed25519();
let local_public_key = key.public();
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);
transport::MemoryTransport::default() transport::MemoryTransport::default()
.upgrade(upgrade::Version::V1) .upgrade(upgrade::Version::V1)
.authenticate(PlainText2Config { local_public_key }) .authenticate(plaintext::Config::new(
&identity::Keypair::generate_ed25519(),
))
.multiplex(mplex) .multiplex(mplex)
.timeout(Duration::from_secs(5)) .timeout(Duration::from_secs(5))
.boxed() .boxed()

View File

@ -24,7 +24,7 @@ use libp2p_core::transport::{MemoryTransport, Transport};
use libp2p_dcutr as dcutr; use libp2p_dcutr as dcutr;
use libp2p_identity as identity; use libp2p_identity as identity;
use libp2p_identity::PeerId; use libp2p_identity::PeerId;
use libp2p_plaintext::PlainText2Config; use libp2p_plaintext as plaintext;
use libp2p_relay as relay; use libp2p_relay as relay;
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
use libp2p_swarm_test::SwarmExt as _; use libp2p_swarm_test::SwarmExt as _;
@ -111,8 +111,7 @@ fn build_relay() -> Swarm<relay::Behaviour> {
fn build_client() -> Swarm<Client> { fn build_client() -> Swarm<Client> {
let local_key = identity::Keypair::generate_ed25519(); let local_key = identity::Keypair::generate_ed25519();
let local_public_key = local_key.public(); let local_peer_id = local_key.public().to_peer_id();
let local_peer_id = local_public_key.to_peer_id();
let (relay_transport, behaviour) = relay::client::new(local_peer_id); let (relay_transport, behaviour) = relay::client::new(local_peer_id);
@ -120,7 +119,7 @@ fn build_client() -> Swarm<Client> {
.or_transport(MemoryTransport::default()) .or_transport(MemoryTransport::default())
.or_transport(libp2p_tcp::async_io::Transport::default()) .or_transport(libp2p_tcp::async_io::Transport::default())
.upgrade(Version::V1) .upgrade(Version::V1)
.authenticate(PlainText2Config { local_public_key }) .authenticate(plaintext::Config::new(&local_key))
.multiplex(libp2p_yamux::Config::default()) .multiplex(libp2p_yamux::Config::default())
.boxed(); .boxed();

View File

@ -30,9 +30,8 @@ use libp2p_core::transport::{Boxed, MemoryTransport, Transport};
use libp2p_core::upgrade; use libp2p_core::upgrade;
use libp2p_identity as identity; use libp2p_identity as identity;
use libp2p_identity::PeerId; use libp2p_identity::PeerId;
use libp2p_identity::PublicKey;
use libp2p_ping as ping; use libp2p_ping as ping;
use libp2p_plaintext::PlainText2Config; use libp2p_plaintext as plaintext;
use libp2p_relay as relay; use libp2p_relay as relay;
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
use std::time::Duration; use std::time::Duration;
@ -307,10 +306,9 @@ fn reuse_connection() {
fn build_relay() -> Swarm<Relay> { fn build_relay() -> Swarm<Relay> {
let local_key = identity::Keypair::generate_ed25519(); let local_key = identity::Keypair::generate_ed25519();
let local_public_key = local_key.public(); let local_peer_id = local_key.public().to_peer_id();
let local_peer_id = local_public_key.to_peer_id();
let transport = upgrade_transport(MemoryTransport::default().boxed(), local_public_key); let transport = upgrade_transport(MemoryTransport::default().boxed(), &local_key);
SwarmBuilder::with_async_std_executor( SwarmBuilder::with_async_std_executor(
transport, transport,
@ -331,13 +329,12 @@ fn build_relay() -> Swarm<Relay> {
fn build_client() -> Swarm<Client> { fn build_client() -> Swarm<Client> {
let local_key = identity::Keypair::generate_ed25519(); let local_key = identity::Keypair::generate_ed25519();
let local_public_key = local_key.public(); let local_peer_id = local_key.public().to_peer_id();
let local_peer_id = local_public_key.to_peer_id();
let (relay_transport, behaviour) = relay::client::new(local_peer_id); let (relay_transport, behaviour) = relay::client::new(local_peer_id);
let transport = upgrade_transport( let transport = upgrade_transport(
OrTransport::new(relay_transport, MemoryTransport::default()).boxed(), OrTransport::new(relay_transport, MemoryTransport::default()).boxed(),
local_public_key, &local_key,
); );
SwarmBuilder::with_async_std_executor( SwarmBuilder::with_async_std_executor(
@ -353,14 +350,14 @@ fn build_client() -> Swarm<Client> {
fn upgrade_transport<StreamSink>( fn upgrade_transport<StreamSink>(
transport: Boxed<StreamSink>, transport: Boxed<StreamSink>,
local_public_key: PublicKey, identity: &identity::Keypair,
) -> Boxed<(PeerId, StreamMuxerBox)> ) -> Boxed<(PeerId, StreamMuxerBox)>
where where
StreamSink: AsyncRead + AsyncWrite + Send + Unpin + 'static, StreamSink: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{ {
transport transport
.upgrade(upgrade::Version::V1) .upgrade(upgrade::Version::V1)
.authenticate(PlainText2Config { local_public_key }) .authenticate(plaintext::Config::new(identity))
.multiplex(libp2p_yamux::Config::default()) .multiplex(libp2p_yamux::Config::default())
.boxed() .boxed()
} }

View File

@ -25,7 +25,7 @@ use libp2p_core::{
multiaddr::Protocol, transport::MemoryTransport, upgrade::Version, Multiaddr, Transport, multiaddr::Protocol, transport::MemoryTransport, upgrade::Version, Multiaddr, Transport,
}; };
use libp2p_identity::{Keypair, PeerId}; use libp2p_identity::{Keypair, PeerId};
use libp2p_plaintext::PlainText2Config; use libp2p_plaintext as plaintext;
use libp2p_swarm::dial_opts::PeerCondition; use libp2p_swarm::dial_opts::PeerCondition;
use libp2p_swarm::{ use libp2p_swarm::{
dial_opts::DialOpts, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent, THandlerErr, dial_opts::DialOpts, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent, THandlerErr,
@ -41,8 +41,8 @@ pub trait SwarmExt {
/// Create a new [`Swarm`] with an ephemeral identity. /// Create a new [`Swarm`] with an ephemeral identity.
/// ///
/// The swarm will use a [`MemoryTransport`] together with [`PlainText2Config`] authentication layer and /// The swarm will use a [`MemoryTransport`] together with a [`plaintext::Config`] authentication layer and
/// yamux as the multiplexer. However, these details should not be relied upon by the test /// [`yamux::Config`] as the multiplexer. However, these details should not be relied upon by the test
/// and may change at any time. /// and may change at any time.
fn new_ephemeral(behaviour_fn: impl FnOnce(Keypair) -> Self::NB) -> Self fn new_ephemeral(behaviour_fn: impl FnOnce(Keypair) -> Self::NB) -> Self
where where
@ -211,9 +211,7 @@ where
let transport = MemoryTransport::default() let transport = MemoryTransport::default()
.or_transport(libp2p_tcp::async_io::Transport::default()) .or_transport(libp2p_tcp::async_io::Transport::default())
.upgrade(Version::V1) .upgrade(Version::V1)
.authenticate(PlainText2Config { .authenticate(plaintext::Config::new(&identity))
local_public_key: identity.public(),
})
.multiplex(yamux::Config::default()) .multiplex(yamux::Config::default())
.timeout(Duration::from_secs(20)) .timeout(Duration::from_secs(20))
.boxed(); .boxed();

View File

@ -1848,9 +1848,7 @@ mod tests {
let local_public_key = id_keys.public(); let local_public_key = id_keys.public();
let transport = transport::MemoryTransport::default() let transport = transport::MemoryTransport::default()
.upgrade(upgrade::Version::V1) .upgrade(upgrade::Version::V1)
.authenticate(plaintext::PlainText2Config { .authenticate(plaintext::Config::new(&id_keys))
local_public_key: local_public_key.clone(),
})
.multiplex(yamux::Config::default()) .multiplex(yamux::Config::default())
.boxed(); .boxed();
let behaviour = CallTraceBehaviour::new(MockBehaviour::new(dummy::ConnectionHandler)); let behaviour = CallTraceBehaviour::new(MockBehaviour::new(dummy::ConnectionHandler));

View File

@ -1,3 +1,8 @@
## 0.40.1 - unreleased
- Rename `Plaintext2Config` to `Config` to follow naming conventions across repository.
See [PR 4535](https://github.com/libp2p/rust-libp2p/pull/4535).
## 0.40.0 ## 0.40.0
- Raise MSRV to 1.65. - Raise MSRV to 1.65.

View File

@ -3,7 +3,7 @@ name = "libp2p-plaintext"
edition = "2021" edition = "2021"
rust-version = { workspace = true } rust-version = { workspace = true }
description = "Plaintext encryption dummy protocol for libp2p" description = "Plaintext encryption dummy protocol for libp2p"
version = "0.40.0" version = "0.40.1"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT" license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p" repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -23,9 +23,9 @@ use std::fmt;
use std::io::Error as IoError; use std::io::Error as IoError;
#[derive(Debug)] #[derive(Debug)]
pub enum PlainTextError { pub enum Error {
/// I/O error. /// I/O error.
IoError(IoError), Io(IoError),
/// Failed to parse the handshake protobuf message. /// Failed to parse the handshake protobuf message.
InvalidPayload(DecodeError), InvalidPayload(DecodeError),
@ -55,52 +55,52 @@ impl error::Error for DecodeError {
} }
} }
impl error::Error for PlainTextError { impl error::Error for Error {
fn cause(&self) -> Option<&dyn error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
PlainTextError::IoError(ref err) => Some(err), Error::Io(ref err) => Some(err),
PlainTextError::InvalidPayload(ref err) => Some(err), Error::InvalidPayload(ref err) => Some(err),
PlainTextError::InvalidPublicKey(ref err) => Some(err), Error::InvalidPublicKey(ref err) => Some(err),
PlainTextError::InvalidPeerId(ref err) => Some(err), Error::InvalidPeerId(ref err) => Some(err),
_ => None, _ => None,
} }
} }
} }
impl fmt::Display for PlainTextError { impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self { match self {
PlainTextError::IoError(e) => write!(f, "I/O error: {e}"), Error::Io(e) => write!(f, "I/O error: {e}"),
PlainTextError::InvalidPayload(_) => f.write_str("Failed to decode protobuf"), Error::InvalidPayload(_) => f.write_str("Failed to decode protobuf"),
PlainTextError::PeerIdMismatch => f.write_str( Error::PeerIdMismatch => f.write_str(
"The peer id of the exchange isn't consistent with the remote public key", "The peer id of the exchange isn't consistent with the remote public key",
), ),
PlainTextError::InvalidPublicKey(_) => f.write_str("Failed to decode public key"), Error::InvalidPublicKey(_) => f.write_str("Failed to decode public key"),
PlainTextError::InvalidPeerId(_) => f.write_str("Failed to decode PeerId"), Error::InvalidPeerId(_) => f.write_str("Failed to decode PeerId"),
} }
} }
} }
impl From<IoError> for PlainTextError { impl From<IoError> for Error {
fn from(err: IoError) -> PlainTextError { fn from(err: IoError) -> Error {
PlainTextError::IoError(err) Error::Io(err)
} }
} }
impl From<DecodeError> for PlainTextError { impl From<DecodeError> for Error {
fn from(err: DecodeError) -> PlainTextError { fn from(err: DecodeError) -> Error {
PlainTextError::InvalidPayload(err) Error::InvalidPayload(err)
} }
} }
impl From<libp2p_identity::DecodingError> for PlainTextError { impl From<libp2p_identity::DecodingError> for Error {
fn from(err: libp2p_identity::DecodingError) -> PlainTextError { fn from(err: libp2p_identity::DecodingError) -> Error {
PlainTextError::InvalidPublicKey(err) Error::InvalidPublicKey(err)
} }
} }
impl From<libp2p_identity::ParseError> for PlainTextError { impl From<libp2p_identity::ParseError> for Error {
fn from(err: libp2p_identity::ParseError) -> PlainTextError { fn from(err: libp2p_identity::ParseError) -> Error {
PlainTextError::InvalidPeerId(err) Error::InvalidPeerId(err)
} }
} }

View File

@ -18,9 +18,9 @@
// 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 crate::error::{DecodeError, PlainTextError}; use crate::error::{DecodeError, Error};
use crate::proto::Exchange; use crate::proto::Exchange;
use crate::PlainText2Config; use crate::Config;
use asynchronous_codec::{Framed, FramedParts}; use asynchronous_codec::{Framed, FramedParts};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
@ -32,7 +32,7 @@ use std::io::{Error as IoError, ErrorKind as IoErrorKind};
use unsigned_varint::codec::UviBytes; use unsigned_varint::codec::UviBytes;
struct HandshakeContext<T> { struct HandshakeContext<T> {
config: PlainText2Config, config: Config,
state: T, state: T,
} }
@ -50,7 +50,8 @@ pub(crate) struct Remote {
} }
impl HandshakeContext<Local> { impl HandshakeContext<Local> {
fn new(config: PlainText2Config) -> Self { fn new(config: Config) -> Self {
#[allow(deprecated)]
let exchange = Exchange { let exchange = Exchange {
id: Some(config.local_public_key.to_peer_id().to_bytes()), id: Some(config.local_public_key.to_peer_id().to_bytes()),
pubkey: Some(config.local_public_key.encode_protobuf()), pubkey: Some(config.local_public_key.encode_protobuf()),
@ -69,10 +70,7 @@ impl HandshakeContext<Local> {
} }
} }
fn with_remote( fn with_remote(self, exchange_bytes: BytesMut) -> Result<HandshakeContext<Remote>, Error> {
self,
exchange_bytes: BytesMut,
) -> Result<HandshakeContext<Remote>, PlainTextError> {
let mut reader = BytesReader::from_bytes(&exchange_bytes); let mut reader = BytesReader::from_bytes(&exchange_bytes);
let prop = Exchange::from_reader(&mut reader, &exchange_bytes).map_err(DecodeError)?; let prop = Exchange::from_reader(&mut reader, &exchange_bytes).map_err(DecodeError)?;
@ -81,7 +79,7 @@ impl HandshakeContext<Local> {
// Check the validity of the remote's `Exchange`. // Check the validity of the remote's `Exchange`.
if peer_id != public_key.to_peer_id() { if peer_id != public_key.to_peer_id() {
return Err(PlainTextError::PeerIdMismatch); return Err(Error::PeerIdMismatch);
} }
Ok(HandshakeContext { Ok(HandshakeContext {
@ -94,10 +92,7 @@ impl HandshakeContext<Local> {
} }
} }
pub(crate) async fn handshake<S>( pub(crate) async fn handshake<S>(socket: S, config: Config) -> Result<(S, Remote, Bytes), Error>
socket: S,
config: PlainText2Config,
) -> Result<(S, Remote, Bytes), PlainTextError>
where where
S: AsyncRead + AsyncWrite + Send + Unpin, S: AsyncRead + AsyncWrite + Send + Unpin,
{ {

View File

@ -22,7 +22,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use crate::error::PlainTextError; use crate::error::Error;
use bytes::Bytes; use bytes::Bytes;
use futures::future::BoxFuture; use futures::future::BoxFuture;
@ -46,14 +46,29 @@ mod proto {
pub(crate) use self::structs::Exchange; pub(crate) use self::structs::Exchange;
} }
/// `PlainText2Config` is an insecure connection handshake for testing purposes only, implementing #[deprecated(note = "Has been renamed to `Config`.")]
/// the libp2p plaintext connection handshake specification. pub type PlainText2Config = Config;
#[deprecated(note = "Has been renamed to `Output`.")]
pub type PlainTextOutput<T> = Output<T>;
/// [`Config`] is an insecure connection handshake for testing purposes only.
#[derive(Clone)] #[derive(Clone)]
pub struct PlainText2Config { pub struct Config {
#[deprecated(note = "Will be made private in the future, please use `Config::new` instead!")]
pub local_public_key: identity::PublicKey, pub local_public_key: identity::PublicKey,
} }
impl UpgradeInfo for PlainText2Config { impl Config {
#[allow(deprecated)]
pub fn new(identity: &identity::Keypair) -> Self {
Self {
local_public_key: identity.public(),
}
}
}
impl UpgradeInfo for Config {
type Info = &'static str; type Info = &'static str;
type InfoIter = iter::Once<Self::Info>; type InfoIter = iter::Once<Self::Info>;
@ -62,12 +77,12 @@ impl UpgradeInfo for PlainText2Config {
} }
} }
impl<C> InboundUpgrade<C> for PlainText2Config impl<C> InboundUpgrade<C> for Config
where where
C: AsyncRead + AsyncWrite + Send + Unpin + 'static, C: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{ {
type Output = (PeerId, PlainTextOutput<C>); type Output = (PeerId, Output<C>);
type Error = PlainTextError; type Error = Error;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>; type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future { fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future {
@ -75,12 +90,12 @@ where
} }
} }
impl<C> OutboundUpgrade<C> for PlainText2Config impl<C> OutboundUpgrade<C> for Config
where where
C: AsyncRead + AsyncWrite + Send + Unpin + 'static, C: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{ {
type Output = (PeerId, PlainTextOutput<C>); type Output = (PeerId, Output<C>);
type Error = PlainTextError; type Error = Error;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>; type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future { fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future {
@ -88,8 +103,8 @@ where
} }
} }
impl PlainText2Config { impl Config {
async fn handshake<T>(self, socket: T) -> Result<(PeerId, PlainTextOutput<T>), PlainTextError> async fn handshake<T>(self, socket: T) -> Result<(PeerId, Output<T>), Error>
where where
T: AsyncRead + AsyncWrite + Send + Unpin + 'static, T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{ {
@ -99,7 +114,7 @@ impl PlainText2Config {
Ok(( Ok((
remote.peer_id, remote.peer_id,
PlainTextOutput { Output {
socket, socket,
remote_key: remote.public_key, remote_key: remote.public_key,
read_buffer, read_buffer,
@ -109,7 +124,7 @@ impl PlainText2Config {
} }
/// Output of the plaintext protocol. /// Output of the plaintext protocol.
pub struct PlainTextOutput<S> pub struct Output<S>
where where
S: AsyncRead + AsyncWrite + Unpin, S: AsyncRead + AsyncWrite + Unpin,
{ {
@ -123,7 +138,7 @@ where
read_buffer: Bytes, read_buffer: Bytes,
} }
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRead for PlainTextOutput<S> { impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRead for Output<S> {
fn poll_read( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context<'_>, cx: &mut Context<'_>,
@ -139,7 +154,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRead for PlainTextOutput<S> {
} }
} }
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncWrite for PlainTextOutput<S> { impl<S: AsyncRead + AsyncWrite + Unpin> AsyncWrite for Output<S> {
fn poll_write( fn poll_write(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context<'_>, cx: &mut Context<'_>,

View File

@ -21,7 +21,7 @@
use futures::io::{AsyncReadExt, AsyncWriteExt}; use futures::io::{AsyncReadExt, AsyncWriteExt};
use libp2p_core::InboundUpgrade; use libp2p_core::InboundUpgrade;
use libp2p_identity as identity; use libp2p_identity as identity;
use libp2p_plaintext::PlainText2Config; use libp2p_plaintext as plaintext;
use log::debug; use log::debug;
use quickcheck::QuickCheck; use quickcheck::QuickCheck;
@ -34,10 +34,7 @@ fn variable_msg_length() {
let msg_to_receive = msg; let msg_to_receive = msg;
let server_id = identity::Keypair::generate_ed25519(); let server_id = identity::Keypair::generate_ed25519();
let server_id_public = server_id.public();
let client_id = identity::Keypair::generate_ed25519(); let client_id = identity::Keypair::generate_ed25519();
let client_id_public = client_id.public();
let (server, client) = futures_ringbuf::Endpoint::pair(100, 100); let (server, client) = futures_ringbuf::Endpoint::pair(100, 100);
@ -46,14 +43,8 @@ fn variable_msg_length() {
(received_client_id, mut server_channel), (received_client_id, mut server_channel),
(received_server_id, mut client_channel), (received_server_id, mut client_channel),
) = futures::future::try_join( ) = futures::future::try_join(
PlainText2Config { plaintext::Config::new(&server_id).upgrade_inbound(server, ""),
local_public_key: server_id_public, plaintext::Config::new(&client_id).upgrade_inbound(client, ""),
}
.upgrade_inbound(server, ""),
PlainText2Config {
local_public_key: client_id_public,
}
.upgrade_inbound(client, ""),
) )
.await .await
.unwrap(); .unwrap();