-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement /plaintext/2.0.0 #1236
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
Changes from 18 commits
e686c2f
6ba9ca7
cfe8cb5
f8ff1a6
8f0a332
bc0e506
0df77db
63380bf
f67d038
8ca690b
279b053
8155338
037da03
9b4c606
b8ae8c4
be57a76
f0e5a18
7b35c0d
abe8499
3c2f796
154a23c
c7e7bcc
0eeaabf
91a5b9f
624741f
ea14d39
e4b56fd
15f5320
76a1842
5282e84
af56ce4
354a2e3
1850fca
dbdf4e8
131740a
c9157f7
58a9c45
0ba3d48
452e4f3
1ad1b6b
97fb0ca
228744a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/sh | ||
|
|
||
| docker run --rm -v "`pwd`/../../":/usr/code:z -w /usr/code rust /bin/bash -c " \ | ||
| apt-get update; \ | ||
| apt-get install -y protobuf-compiler; \ | ||
| cargo install --version 2.3.0 protobuf-codegen; \ | ||
| protoc --rust_out=./protocols/plaintext/src/pb ./protocols/plaintext/structs.proto; \ | ||
| protoc --rust_out=./protocols/plaintext/src/pb ./core/keys.proto;" | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||
| // Copyright 2019 Parity Technologies (UK) Ltd. | ||||||
| // | ||||||
| // Permission is hereby granted, free of charge, to any person obtaining a | ||||||
| // copy of this software and associated documentation files (the "Software"), | ||||||
| // to deal in the Software without restriction, including without limitation | ||||||
| // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||||
| // and/or sell copies of the Software, and to permit persons to whom the | ||||||
| // Software is furnished to do so, subject to the following conditions: | ||||||
| // | ||||||
| // The above copyright notice and this permission notice shall be included in | ||||||
| // all copies or substantial portions of the Software. | ||||||
| // | ||||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||||||
| // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||||
| // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||||
| // DEALINGS IN THE SOFTWARE. | ||||||
|
|
||||||
| use std::error; | ||||||
| use std::fmt; | ||||||
| use std::io::Error as IoError; | ||||||
| use protobuf::error::ProtobufError; | ||||||
|
|
||||||
| #[derive(Debug)] | ||||||
| pub enum PlainTextError { | ||||||
| /// I/O error. | ||||||
| IoError(IoError), | ||||||
|
|
||||||
| /// Protocol buffer error. | ||||||
| ProtobufError(ProtobufError), | ||||||
|
|
||||||
| /// Failed to parse one of the handshake protobuf messages. | ||||||
| HandshakeParsingFailure, | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is to collapse 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). |
||||||
| /// There is no protocol supported by both the local and remote hosts. | ||||||
| NoSupportIntersection, | ||||||
|
||||||
|
|
||||||
| /// The peer id of the exchange isn't consist with the remote public key. | ||||||
ackintosh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| PeerIdValidationFailed, | ||||||
|
||||||
| PeerIdValidationFailed, | |
| InvalidPeerId, |
ackintosh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ackintosh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ackintosh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,198 @@ | ||||||
| // Copyright 2019 Parity Technologies (UK) Ltd. | ||||||
| // | ||||||
| // Permission is hereby granted, free of charge, to any person obtaining a | ||||||
| // copy of this software and associated documentation files (the "Software"), | ||||||
| // to deal in the Software without restriction, including without limitation | ||||||
| // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||||
| // and/or sell copies of the Software, and to permit persons to whom the | ||||||
| // Software is furnished to do so, subject to the following conditions: | ||||||
| // | ||||||
| // The above copyright notice and this permission notice shall be included in | ||||||
| // all copies or substantial portions of the Software. | ||||||
| // | ||||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||||||
| // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||||
| // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||||
| // DEALINGS IN THE SOFTWARE. | ||||||
|
|
||||||
| use bytes::BytesMut; | ||||||
| use std::io::{Error as IoError, ErrorKind as IoErrorKind}; | ||||||
| use futures::Future; | ||||||
| use futures::future; | ||||||
| use futures::sink::Sink; | ||||||
| use futures::stream::Stream; | ||||||
| use libp2p_core::{PublicKey, PeerId}; | ||||||
| use log::{debug, trace}; | ||||||
| use crate::pb::keys::{PublicKey as PbPublicKey, KeyType}; | ||||||
| use crate::pb::structs::Exchange; | ||||||
| use tokio_io::{AsyncRead, AsyncWrite}; | ||||||
| use tokio_io::codec::length_delimited; | ||||||
| use tokio_io::codec::length_delimited::Framed; | ||||||
| use protobuf::Message; | ||||||
| use crate::error::PlainTextError; | ||||||
| use crate::PlainText2Config; | ||||||
|
|
||||||
| struct HandShakeContext<T> { | ||||||
|
||||||
| struct HandShakeContext<T> { | |
| struct HandshakeContext<T> { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this to impl HandshakeContext<Local>, i.e. directly constructing a HandshakeContext<Local>? The step from HandshakeContext<()> to HandshakeContext<Local> seems superfluous.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. into_protobuf_encoding will encode a full PublicKey protobuf structure, including type and data, but this field should only contain the data. To avoid unnecessary code duplication, I think you can just declare pubkey as bytes instead of PublicKey in the protobuf, and then put the result of into_protobuf_encoding into it, because embedded messages and protobuf bytes types use the same encoding (type-2). That should also simplify the protobuf generation (i.e. no need to cross-reference core/keys.proto).
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As indicated in another comment, I don't think this is right (i.e. is conforming to the spec and thus not interoperable with other implementations) because it expects the data to contain a full public key encoding, including the type. pb_pubkey should just be bytes (Vec<u8>) here.
romanb marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| -> impl Future<Item = (Framed<S, BytesMut>, PublicKey), Error = PlainTextError> | |
| -> impl Future<Item = (Framed<S, BytesMut>, Remote), Error = PlainTextError> |
This should allow you to extract the PeerId from the Remote instead of reconstructing it again from the public key in PlainText2Config::handshake. It requires making Remote pub, of course, but handshake remains an internal module. Alternatively, you could return a nested tuple of peer ID and public key.
tomaka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ackintosh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Ok((socket, context.state.public_key)) | |
| Ok((socket, context.state)) |
Uh oh!
There was an error while loading. Please reload this page.