Skip to content

Commit

Permalink
feat(plaintext): remove Plaintext1Config
Browse files Browse the repository at this point in the history
`Plaintext2Config` works with the upgrade infrastructure and is thus preferable.

Related: #3915.

Pull-Request: #3940.
  • Loading branch information
thomaseizinger authored May 15, 2023
1 parent adcc10b commit 5c785b9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 62 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions transports/plaintext/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
- Raise MSRV to 1.65.
See [PR 3715].

- Remove `Plaintext1Config`.
Use `Plaintext2Config` instead.
See [PR 3915].

[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3915]: https://github.com/libp2p/rust-libp2p/pull/3915

## 0.39.1

Expand Down
1 change: 0 additions & 1 deletion transports/plaintext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ libp2p-identity = { workspace = true }
log = "0.4.8"
quick-protobuf = "0.8"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
void = "1.0.2"

[dev-dependencies]
env_logger = "0.10.0"
Expand Down
60 changes: 0 additions & 60 deletions transports/plaintext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::error::PlainTextError;

use bytes::Bytes;
use futures::future::BoxFuture;
use futures::future::{self, Ready};
use futures::prelude::*;
use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use libp2p_identity as identity;
Expand All @@ -38,7 +37,6 @@ use std::{
pin::Pin,
task::{Context, Poll},
};
use void::Void;

mod error;
mod handshake;
Expand All @@ -48,64 +46,6 @@ mod proto {
pub(crate) use self::structs::Exchange;
}

/// `PlainText1Config` is an insecure connection handshake for testing purposes only.
///
/// > **Note**: Given that `PlainText1Config` has no notion of exchanging peer identity information it is not compatible
/// > with the `libp2p_core::transport::upgrade::Builder` pattern. See
/// > [`PlainText2Config`](struct.PlainText2Config.html) if compatibility is needed. Even though not compatible with the
/// > Builder pattern one can still do an upgrade *manually*:
///
/// ```
/// # use libp2p_core::transport::{ Transport, memory::MemoryTransport };
/// # use libp2p_plaintext::PlainText1Config;
/// #
/// MemoryTransport::default()
/// .and_then(move |io, endpoint| {
/// libp2p_core::upgrade::apply(
/// io,
/// PlainText1Config{},
/// endpoint,
/// libp2p_core::transport::upgrade::Version::V1,
/// )
/// })
/// .map(|plaintext, _endpoint| {
/// unimplemented!();
/// // let peer_id = somehow_derive_peer_id();
/// // return (peer_id, plaintext);
/// });
/// ```
#[derive(Debug, Copy, Clone)]
pub struct PlainText1Config;

impl UpgradeInfo for PlainText1Config {
type Info = &'static str;
type InfoIter = iter::Once<Self::Info>;

fn protocol_info(&self) -> Self::InfoIter {
iter::once("/plaintext/1.0.0")
}
}

impl<C> InboundUpgrade<C> for PlainText1Config {
type Output = C;
type Error = Void;
type Future = Ready<Result<C, Self::Error>>;

fn upgrade_inbound(self, i: C, _: Self::Info) -> Self::Future {
future::ready(Ok(i))
}
}

impl<C> OutboundUpgrade<C> for PlainText1Config {
type Output = C;
type Error = Void;
type Future = Ready<Result<C, Self::Error>>;

fn upgrade_outbound(self, i: C, _: Self::Info) -> Self::Future {
future::ready(Ok(i))
}
}

/// `PlainText2Config` is an insecure connection handshake for testing purposes only, implementing
/// the libp2p plaintext connection handshake specification.
#[derive(Clone)]
Expand Down

0 comments on commit 5c785b9

Please sign in to comment.