Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement /plaintext/2.0.0 #1236

Merged
merged 42 commits into from
Oct 11, 2019
Merged

Implement /plaintext/2.0.0 #1236

merged 42 commits into from
Oct 11, 2019

Conversation

ackintosh
Copy link
Contributor

@ackintosh ackintosh commented Sep 2, 2019

This PR closes #1208 🚀

TODO:

  • Keep PlainTextConfig as PlainText1Config
    • put the new config as PlainText2Config
  • Validation
    • the given peer id is consistent with the given public key

Copy link
Member

@tomaka tomaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
I think, however, that we should keep plaintext 1, as this is a very low-maintenance low-effort burden.
Could you keep the current PlainTextConfig and name it PlainText1Config, and name your new object the PlainText2Config?

}

pub struct PlainTextMiddleware<S> {
pub inner: Framed<S, BytesMut>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't be public.


fn upgrade_outbound(self, socket: Negotiated<C>, _: Self::Info) -> Self::Future {
Box::new(self.handshake(socket))
// future::ok(i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out code that should be removed.


fn upgrade_inbound(self, socket: Negotiated<C>, _: Self::Info) -> Self::Future {
Box::new(self.handshake(socket))
// future::ok(i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out code that should be removed.

#[derive(Clone)]
pub struct PlainTextConfig {
// peerId: PeerId,
pub key: identity::Keypair,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this was a PublicKey instead of a Keypair.


#[derive(Clone)]
pub struct PlainTextConfig {
// peerId: PeerId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code to remove.

@ackintosh
Copy link
Contributor Author

Thank you for your review!

I think, however, that we should keep plaintext 1, as this is a very low-maintenance low-effort burden.

That makes sense. 💡

I'll update entire the codes to compatible to the plaintext/2.0.0 spec (and to include your advice) as this PR is still draft. 😃

@ackintosh
Copy link
Contributor Author

I've added a TODO section to the first comment on this PR. 📝

@ackintosh
Copy link
Contributor Author

I've tested that examples/ping works fine with the sample code below:

pub fn build_tcp_ws_plaintext_mplex_yamux(keypair: identity::Keypair)
    -> impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone
{
    // An another keys for testing the validation
    let _another_keys = identity::Keypair::generate_ed25519();

    CommonTransport::new()
        .with_upgrade(PlainText2Config { pubkey: keypair.public(), peer_id: keypair.public().into_peer_id() })
        .and_then(move |output, endpoint| {
            let peer_id = output.remote_key.into_peer_id();
            let peer_id2 = peer_id.clone();
            let upgrade = core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new())
                // TODO: use a single `.map` instead of two maps
                .map_inbound(move |muxer| (peer_id, muxer))
                .map_outbound(move |muxer| (peer_id2, muxer));
            core::upgrade::apply(output.stream, upgrade, endpoint)
                .map(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer)))
        })
        .with_timeout(Duration::from_secs(20))
}
  • example/ping.rs
// ...
// ...
-    let transport = libp2p::build_development_transport(id_keys);
+    let transport = libp2p::build_tcp_ws_plaintext_mplex_yamux(id_keys);
// ...
// ...

Yes, there is no test codes about plaintext/2.0.0 yet. I'm going to add test codes in another PR. 😄💦

@ackintosh
Copy link
Contributor Author

https://circleci.com/gh/libp2p/rust-libp2p/15485?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

error[E0599]: no variant or associated item named Rsa found for type libp2p_core::identity::PublicKey in the current scope
--> protocols/plaintext/src/handshake.rs:86:24
|
86 | PublicKey::Rsa(_) => KeyType::RSA,
| ^^^ variant or associated item not found in libp2p_core::identity::PublicKey

Hmm... I couldn't find how fix it. In my local machine, it is done successfully. 🙄
@tomaka I'd appreciate it if you could help me. 🙏🙏

@ackintosh ackintosh marked this pull request as ready for review September 6, 2019 13:36
@ackintosh
Copy link
Contributor Author

ackintosh commented Sep 7, 2019

error[E0599]: no variant or associated item named Rsa found for type libp2p_core::identity::PublicKey in the current scope

It seems that the error is related to this 👀 :

#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
pub mod rsa;

but still I can't find how fix the error as I'm new to Rust and WASM...

@ackintosh
Copy link
Contributor Author

Ok, the CI has passed!

@tomaka This PR is ready for review. 🙏

protocols/plaintext/src/handshake.rs Outdated Show resolved Hide resolved
@@ -55,3 +70,130 @@ impl<C> OutboundUpgrade<C> for PlainTextConfig {
}
}

#[derive(Clone)]
pub struct PlainText2Config {
pub peer_id: PeerId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that's the remote's PeerId? If so that should be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the other conversation, this seems to be our local PeerId. I think it should be automatically generated from the pubkey then, and not provided by the configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the PeerId via abe8499

#[derive(Clone)]
pub struct PlainText2Config {
pub peer_id: PeerId,
pub pubkey: identity::PublicKey,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's our local public key? This fields needs some documentation explaining what it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is our local public key. Is it better to rename from pubkey to local_pubkey ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please, rename to local_public_key.

@romanb
Copy link
Contributor

romanb commented Sep 9, 2019

As a side note, if #1240 is accepted, it would be nice if the output of the Plaintext2Config is (PeerId, PlaintextOutput), so that it can be directly plugged into transport::upgrade::Builder::authenticate from #1240. This was one of the main motivations for the Plaintext v2 protocol - that it can be used as an (insecure, development-only) "authenticator" / "security protocol". It can also be done as a follow-up, of course.

@ackintosh
Copy link
Contributor Author

https://circleci.com/gh/libp2p/rust-libp2p/15741?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

ci/circleci: test-win32

error[E0721]: await is a keyword in the 2018 edition
--> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-backend-0.2.51/src/codegen.rs:454:79
|
454 | wasm_bindgen::__rt::IntoJsResult::into_js_result(#ret.await)
| ^^^^^ help: you can use a raw identifier to stay compatible: r#await

It seems that the Docker image should be updated. cc: @tomaka
https://hub.docker.com/r/tomaka/rust-mingw-docker

$ docker run --rm tomaka/rust-mingw-docker cargo -V
cargo 1.34.0 (6789d8a0a 2019-04-01)

@ackintosh
Copy link
Contributor Author

ackintosh commented Sep 30, 2019

I've finished to update this PR but the CI failed, maybe the failure is not related to changes on this PR.

@ackintosh
Copy link
Contributor Author

The failure will be fixed in #1261

@ackintosh
Copy link
Contributor Author

Thank you @tomaka , I've confirmed the CI has passed.

This PR is ready for your review. @tomaka @romanb 🙏

Copy link
Contributor

@romanb romanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me now, I only made one more suggestion. Thanks for your effort @ackintosh.


/// Failed to parse one of the handshake protobuf messages.
HandshakeParsingFailure,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to collapse HandshakeParsingFailure and ProtobufError into the variant

InvalidPayload(Option<ProtobufError>)

Just a thought, because it seems weird to me to have two different error variants for basically the same kind of error (that all or part of the received message payload is invalid / cannot be parsed).

@ackintosh
Copy link
Contributor Author

@romanb Thanks for your review! I've updated.

@romanb
Copy link
Contributor

romanb commented Oct 11, 2019

@tomaka Is this OK to merge from your point of view?

@tomaka
Copy link
Member

tomaka commented Oct 11, 2019

Yes!

Copy link
Member

@tomaka tomaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub prevents me from merging if I don't explicitly approve 😅

@tomaka tomaka merged commit a61ad92 into libp2p:master Oct 11, 2019
@ackintosh ackintosh deleted the plaintext branch October 17, 2019 10:49
tomaka added a commit that referenced this pull request Oct 28, 2019
* Configurable multistream-select protocol. Add V1Lazy variant. (#1245)

Make the multistream-select protocol (version) configurable
on transport upgrades as well as for individual substreams.

Add a "lazy" variant of multistream-select 1.0 that delays
sending of negotiation protocol frames as much as possible
but is only safe to use under additional assumptions that
go beyond what is required by the multistream-select v1
specification.

* Improve the code readability of the chat example (#1253)

* Add bridged chats (#1252)

* Try fix CI (#1261)

* Print Rust version on CI

* Don't print where not appropriate

* Change caching strategy

* Remove win32 build

* Remove win32 from list

* Update libsecp256k1 dep to 0.3.0 (#1258)

* Update libsecp256k1 dep to 0.3.0

* Sign now cannot fail

* Upgrade url and percent-encoding deps to 2.1.0 (#1267)

* Upgrade percent-encoding dep to 2.1.0

* Upgrade url dep to 2.1.0

* Revert CIPHERS set to null (#1273)

* Update dependency versions (#1265)

* Update versions of many dependencies

* Bump version of rand

* Updates for changed APIs in rand, ring, and webpki

* Replace references to `snow::Session`

`Session` no longer exists in `snow` but the replacement is two structs `HandshakeState` and `TransportState`
Something will have to be done to harmonize `NoiseOutput.session`

* Add precise type for UnparsedPublicKey

* Update data structures/functions to match new snow's API

* Delete diff.diff

Remove accidentally committed diff file

* Remove commented lines in identity/rsa.rs

* Bump libsecp256k1 to 0.3.1

* Implement /plaintext/2.0.0 (#1236)

* WIP

* plaintext/2.0.0

* Refactor protobuf related issues to compatible with the spec

* Rename: new PlainTextConfig -> PlainText2Config

* Keep plaintext/1.0.0 as PlainText1Config

* Config contains pubkey

* Rename: proposition -> exchange

* Add PeerId to Exchange

* Check the validity of the remote's `Exchange`

* Tweak

* Delete unused import

* Add debug log

* Delete unused field: public_key_encoded

* Delete unused field: local

* Delete unused field: exchange_bytes

* The inner instance should not be public

* identity::Publickey::Rsa is not available on wasm

* Delete PeerId from Config as it should be generated from the pubkey

* Catch up for #1240

* Tweak

* Update protocols/plaintext/src/error.rs

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Update protocols/plaintext/src/handshake.rs

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Update protocols/plaintext/src/error.rs

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Update protocols/plaintext/src/error.rs

Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com>

* Update protocols/plaintext/src/error.rs

Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com>

* Rename: pubkey -> local_public_key

* Delete unused error

* Rename: PeerIdValidationFailed -> InvalidPeerId

* Fix: HandShake -> Handshake

* Use bytes insteadof Publickey to avoid code duplication

* Replace with ProtobufError

* Merge HandshakeContext<()> into HandshakeContext<Local>

* Improve the peer ID validation to simplify the handshake

* Propagate Remote to allow extracting the PeerId from the Remote

* Collapse the same kind of errors into the variant

* [noise]: `sodiumoxide 0.2.5` (#1276)

Fixes rustsec/advisory-db#192

* examples/ipfs-kad.rs: Remove outdated reference to `without_init` (#1280)

* CircleCI Test Fix (#1282)

* Disabling "Docker Layer Caching" because it breaks one of the circleci checks

* Bump to trigger CircleCI build

* unbump

* zeroize: Upgrade to v1.0 (#1284)

v1.0 final release is out. Release notes:

iqlusioninc/crates#279

* *: Consolidate protobuf scripts and update to rust-protobuf 2.8.1 (#1275)

* *: Consolidate protobuf generation scripts

* *: Update to rust-protobuf 2.8.1

* *: Mark protobuf generated modules with '_proto'

* examples: Add distributed key value store (#1281)

* examples: Add distributed key value store

This commit adds a basic distributed key value store supporting GET and
PUT commands using Kademlia and mDNS.

* examples/distributed-key-value-store: Fix typo

* Simple Warning Cleanup (#1278)

* Cleaning up warnings - removing unused `use`

* Cleaning up warnings - unused tuple value

* Cleaning up warnings - removing dead code

* Cleaning up warnings - fixing deprecated name

* Cleaning up warnings - removing dead code

* Revert "Cleaning up warnings - removing dead code"

This reverts commit f18a765.

* Enable the std feature of ring (#1289)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement /plaintext/2.0.0
3 participants