diff --git a/.circleci/config.yml b/.circleci/config.yml index 49824420..bfe78746 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,6 @@ jobs: test: machine: enabled: true - docker_layer_caching: true steps: - checkout - run: diff --git a/core/Cargo.toml b/core/Cargo.toml index 4f039c35..2bf1ae35 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -24,20 +24,20 @@ multihash = { package = "parity-multihash", version = "0.1.0", path = "../misc/m multistream-select = { version = "0.5.0", path = "../misc/multistream-select" } futures-preview = { version = "= 0.3.0-alpha.18", features = ["compat", "io-compat"] } parking_lot = "0.8" -protobuf = "2.3" +protobuf = "2.8" quick-error = "1.2" rand = "0.6" rw-stream-sink = { version = "0.1.1", path = "../misc/rw-stream-sink" } -libsecp256k1 = { version = "0.3.0", optional = true } +libsecp256k1 = { version = "0.3.1", optional = true } sha2 = "0.8.0" smallvec = "0.6" wasm-timer = "0.1" unsigned-varint = "0.2" void = "1" -zeroize = "0.9" +zeroize = "1" [target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies] -ring = { version = "0.14", features = ["use_heap"], default-features = false } +ring = { version = "^0.16", features = ["alloc", "std"], default-features = false } untrusted = { version = "0.6" } [dev-dependencies] diff --git a/core/regen_structs_proto.sh b/core/regen_structs_proto.sh index 7a0caead..0dd24a54 100755 --- a/core/regen_structs_proto.sh +++ b/core/regen_structs_proto.sh @@ -1,13 +1,3 @@ #!/bin/sh -# This script regenerates the `src/structs_proto.rs` and `src/keys_proto.rs` files from -# `structs.proto` and `keys.proto`. - -sudo 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 . keys.proto" - -sudo chown $USER:$USER keys.rs -mv -f keys.rs ./src/keys_proto.rs +../scripts/protobuf/gen.sh src/keys.proto diff --git a/core/src/identity/rsa.rs b/core/src/identity/rsa.rs index a94df94f..1e20f72d 100644 --- a/core/src/identity/rsa.rs +++ b/core/src/identity/rsa.rs @@ -27,7 +27,6 @@ use ring::rand::SystemRandom; use ring::signature::{self, RsaKeyPair, RSA_PKCS1_SHA256, RSA_PKCS1_2048_8192_SHA256}; use ring::signature::KeyPair; use std::sync::Arc; -use untrusted::Input; use zeroize::Zeroize; /// An RSA keypair. @@ -40,7 +39,7 @@ impl Keypair { /// /// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5 pub fn from_pkcs8(der: &mut [u8]) -> Result { - let kp = RsaKeyPair::from_pkcs8(Input::from(&der[..])) + let kp = RsaKeyPair::from_pkcs8(&der) .map_err(|e| DecodingError::new("RSA PKCS#8 PrivateKeyInfo").source(e))?; der.zeroize(); Ok(Keypair(Arc::new(kp))) @@ -69,10 +68,8 @@ pub struct PublicKey(Vec); impl PublicKey { /// Verify an RSA signature on a message using the public key. pub fn verify(&self, msg: &[u8], sig: &[u8]) -> bool { - signature::verify(&RSA_PKCS1_2048_8192_SHA256, - Input::from(&self.0), - Input::from(msg), - Input::from(sig)).is_ok() + let key = signature::UnparsedPublicKey::new(&RSA_PKCS1_2048_8192_SHA256, &self.0); + key.verify(msg, sig).is_ok() } /// Encode the RSA public key in DER as a PKCS#1 RSAPublicKey structure, diff --git a/core/keys.proto b/core/src/keys.proto similarity index 91% rename from core/keys.proto rename to core/src/keys.proto index 786c7a74..ac0bca8b 100644 --- a/core/keys.proto +++ b/core/src/keys.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + enum KeyType { RSA = 0; Ed25519 = 1; diff --git a/core/src/keys_proto.rs b/core/src/keys_proto.rs index f7460bd4..9afba371 100644 --- a/core/src/keys_proto.rs +++ b/core/src/keys_proto.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.3.0. Do not edit +// This file is generated by rust-protobuf 2.8.1. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 @@ -17,10 +17,15 @@ #![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `src/keys.proto` use protobuf::Message as Message_imported_for_functions; use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1; + #[derive(PartialEq,Clone,Default)] pub struct PublicKey { // message fields @@ -31,6 +36,12 @@ pub struct PublicKey { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a PublicKey { + fn default() -> &'a PublicKey { + ::default_instance() + } +} + impl PublicKey { pub fn new() -> PublicKey { ::std::default::Default::default() @@ -38,6 +49,10 @@ impl PublicKey { // required .KeyType Type = 1; + + pub fn get_Type(&self) -> KeyType { + self.Type.unwrap_or(KeyType::RSA) + } pub fn clear_Type(&mut self) { self.Type = ::std::option::Option::None; } @@ -51,12 +66,15 @@ impl PublicKey { self.Type = ::std::option::Option::Some(v); } - pub fn get_Type(&self) -> KeyType { - self.Type.unwrap_or(KeyType::RSA) - } - // required bytes Data = 2; + + pub fn get_Data(&self) -> &[u8] { + match self.Data.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_Data(&mut self) { self.Data.clear(); } @@ -83,13 +101,6 @@ impl PublicKey { pub fn take_Data(&mut self) -> ::std::vec::Vec { self.Data.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - - pub fn get_Data(&self) -> &[u8] { - match self.Data.as_ref() { - Some(v) => &v, - None => &[], - } - } } impl ::protobuf::Message for PublicKey { @@ -217,8 +228,8 @@ impl ::protobuf::Message for PublicKey { impl ::protobuf::Clear for PublicKey { fn clear(&mut self) { - self.clear_Type(); - self.clear_Data(); + self.Type = ::std::option::Option::None; + self.Data.clear(); self.unknown_fields.clear(); } } @@ -230,7 +241,7 @@ impl ::std::fmt::Debug for PublicKey { } impl ::protobuf::reflect::ProtobufValue for PublicKey { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -245,6 +256,12 @@ pub struct PrivateKey { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a PrivateKey { + fn default() -> &'a PrivateKey { + ::default_instance() + } +} + impl PrivateKey { pub fn new() -> PrivateKey { ::std::default::Default::default() @@ -252,6 +269,10 @@ impl PrivateKey { // required .KeyType Type = 1; + + pub fn get_Type(&self) -> KeyType { + self.Type.unwrap_or(KeyType::RSA) + } pub fn clear_Type(&mut self) { self.Type = ::std::option::Option::None; } @@ -265,12 +286,15 @@ impl PrivateKey { self.Type = ::std::option::Option::Some(v); } - pub fn get_Type(&self) -> KeyType { - self.Type.unwrap_or(KeyType::RSA) - } - // required bytes Data = 2; + + pub fn get_Data(&self) -> &[u8] { + match self.Data.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_Data(&mut self) { self.Data.clear(); } @@ -297,13 +321,6 @@ impl PrivateKey { pub fn take_Data(&mut self) -> ::std::vec::Vec { self.Data.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - - pub fn get_Data(&self) -> &[u8] { - match self.Data.as_ref() { - Some(v) => &v, - None => &[], - } - } } impl ::protobuf::Message for PrivateKey { @@ -431,8 +448,8 @@ impl ::protobuf::Message for PrivateKey { impl ::protobuf::Clear for PrivateKey { fn clear(&mut self) { - self.clear_Type(); - self.clear_Data(); + self.Type = ::std::option::Option::None; + self.Data.clear(); self.unknown_fields.clear(); } } @@ -444,7 +461,7 @@ impl ::std::fmt::Debug for PrivateKey { } impl ::protobuf::reflect::ProtobufValue for PrivateKey { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -502,41 +519,41 @@ impl ::std::default::Default for KeyType { } impl ::protobuf::reflect::ProtobufValue for KeyType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\nkeys.proto\"=\n\tPublicKey\x12\x1c\n\x04Type\x18\x01\x20\x02(\x0e2\ - \x08.KeyTypeR\x04type\x12\x12\n\x04Data\x18\x02\x20\x02(\x0cR\x04data\">\ - \n\nPrivateKey\x12\x1c\n\x04Type\x18\x01\x20\x02(\x0e2\x08.KeyTypeR\x04t\ - ype\x12\x12\n\x04Data\x18\x02\x20\x02(\x0cR\x04data*.\n\x07KeyType\x12\ - \x07\n\x03RSA\x10\0\x12\x0b\n\x07Ed25519\x10\x01\x12\r\n\tSecp256k1\x10\ - \x02J\xdf\x03\n\x06\x12\x04\0\0\x0e\x01\n\n\n\x02\x05\0\x12\x04\0\0\x04\ - \x01\n\n\n\x03\x05\0\x01\x12\x03\0\x05\x0c\n\x0b\n\x04\x05\0\x02\0\x12\ - \x03\x01\x02\n\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x01\x02\x05\n\x0c\n\ - \x05\x05\0\x02\0\x02\x12\x03\x01\x08\t\n\x0b\n\x04\x05\0\x02\x01\x12\x03\ - \x02\x02\x0e\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x02\x02\t\n\x0c\n\x05\ - \x05\0\x02\x01\x02\x12\x03\x02\x0c\r\n\x0b\n\x04\x05\0\x02\x02\x12\x03\ - \x03\x02\x10\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x03\x02\x0b\n\x0c\n\ - \x05\x05\0\x02\x02\x02\x12\x03\x03\x0e\x0f\n\n\n\x02\x04\0\x12\x04\x06\0\ - \t\x01\n\n\n\x03\x04\0\x01\x12\x03\x06\x08\x11\n\x0b\n\x04\x04\0\x02\0\ - \x12\x03\x07\x02\x1c\n\x0c\n\x05\x04\0\x02\0\x04\x12\x03\x07\x02\n\n\x0c\ - \n\x05\x04\0\x02\0\x06\x12\x03\x07\x0b\x12\n\x0c\n\x05\x04\0\x02\0\x01\ - \x12\x03\x07\x13\x17\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x07\x1a\x1b\n\ - \x0b\n\x04\x04\0\x02\x01\x12\x03\x08\x02\x1a\n\x0c\n\x05\x04\0\x02\x01\ - \x04\x12\x03\x08\x02\n\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x08\x0b\x10\ - \n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x08\x11\x15\n\x0c\n\x05\x04\0\x02\ - \x01\x03\x12\x03\x08\x18\x19\n\n\n\x02\x04\x01\x12\x04\x0b\0\x0e\x01\n\n\ - \n\x03\x04\x01\x01\x12\x03\x0b\x08\x12\n\x0b\n\x04\x04\x01\x02\0\x12\x03\ - \x0c\x02\x1c\n\x0c\n\x05\x04\x01\x02\0\x04\x12\x03\x0c\x02\n\n\x0c\n\x05\ - \x04\x01\x02\0\x06\x12\x03\x0c\x0b\x12\n\x0c\n\x05\x04\x01\x02\0\x01\x12\ - \x03\x0c\x13\x17\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x0c\x1a\x1b\n\x0b\ - \n\x04\x04\x01\x02\x01\x12\x03\r\x02\x1a\n\x0c\n\x05\x04\x01\x02\x01\x04\ - \x12\x03\r\x02\n\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\r\x0b\x10\n\x0c\ - \n\x05\x04\x01\x02\x01\x01\x12\x03\r\x11\x15\n\x0c\n\x05\x04\x01\x02\x01\ - \x03\x12\x03\r\x18\x19\ + \n\x0esrc/keys.proto\"=\n\tPublicKey\x12\x1c\n\x04Type\x18\x01\x20\x02(\ + \x0e2\x08.KeyTypeR\x04Type\x12\x12\n\x04Data\x18\x02\x20\x02(\x0cR\x04Da\ + ta\">\n\nPrivateKey\x12\x1c\n\x04Type\x18\x01\x20\x02(\x0e2\x08.KeyTypeR\ + \x04Type\x12\x12\n\x04Data\x18\x02\x20\x02(\x0cR\x04Data*.\n\x07KeyType\ + \x12\x07\n\x03RSA\x10\0\x12\x0b\n\x07Ed25519\x10\x01\x12\r\n\tSecp256k1\ + \x10\x02J\xe9\x03\n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\x03\0\0\ + \x12\n\n\n\x02\x05\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x05\0\x01\x12\x03\ + \x02\x05\x0c\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x02\n\n\x0c\n\x05\x05\0\ + \x02\0\x01\x12\x03\x03\x02\x05\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\ + \x08\t\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x02\x0e\n\x0c\n\x05\x05\0\ + \x02\x01\x01\x12\x03\x04\x02\t\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\ + \x0c\r\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x02\x10\n\x0c\n\x05\x05\0\ + \x02\x02\x01\x12\x03\x05\x02\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\ + \x05\x0e\x0f\n\n\n\x02\x04\0\x12\x04\x08\0\x0b\x01\n\n\n\x03\x04\0\x01\ + \x12\x03\x08\x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\t\x02\x1c\n\x0c\n\ + \x05\x04\0\x02\0\x04\x12\x03\t\x02\n\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\ + \t\x0b\x12\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\t\x13\x17\n\x0c\n\x05\x04\ + \0\x02\0\x03\x12\x03\t\x1a\x1b\n\x0b\n\x04\x04\0\x02\x01\x12\x03\n\x02\ + \x1a\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\n\x02\n\n\x0c\n\x05\x04\0\x02\ + \x01\x05\x12\x03\n\x0b\x10\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\n\x11\ + \x15\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\n\x18\x19\n\n\n\x02\x04\x01\ + \x12\x04\r\0\x10\x01\n\n\n\x03\x04\x01\x01\x12\x03\r\x08\x12\n\x0b\n\x04\ + \x04\x01\x02\0\x12\x03\x0e\x02\x1c\n\x0c\n\x05\x04\x01\x02\0\x04\x12\x03\ + \x0e\x02\n\n\x0c\n\x05\x04\x01\x02\0\x06\x12\x03\x0e\x0b\x12\n\x0c\n\x05\ + \x04\x01\x02\0\x01\x12\x03\x0e\x13\x17\n\x0c\n\x05\x04\x01\x02\0\x03\x12\ + \x03\x0e\x1a\x1b\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x0f\x02\x1a\n\x0c\n\ + \x05\x04\x01\x02\x01\x04\x12\x03\x0f\x02\n\n\x0c\n\x05\x04\x01\x02\x01\ + \x05\x12\x03\x0f\x0b\x10\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x0f\x11\ + \x15\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x0f\x18\x19\ "; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index dd60c43d..d9dc34e1 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -219,7 +219,7 @@ impl Into for PeerId { quick_error! { #[derive(Debug)] pub enum ParseError { - B58(e: bs58::decode::DecodeError) { + B58(e: bs58::decode::Error) { display("base-58 decode error: {}", e) cause(e) from() diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs index bee0c8d7..f5347ca4 100644 --- a/core/tests/transport_upgrade.rs +++ b/core/tests/transport_upgrade.rs @@ -110,7 +110,7 @@ fn upgrade_pipeline() { }); let listen_addr: Multiaddr = format!("/memory/{}", random::()).parse().unwrap(); - + async_std::task::spawn({ let listen_addr = listen_addr.clone(); let dialer_id = dialer_id.clone(); diff --git a/examples/distributed-key-value-store.rs b/examples/distributed-key-value-store.rs new file mode 100644 index 00000000..d8f649d8 --- /dev/null +++ b/examples/distributed-key-value-store.rs @@ -0,0 +1,209 @@ +// Copyright 20l9 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. + +//! A basic key value store demonstrating libp2p and the mDNS and Kademlia protocols. +//! +//! 1. Using two terminal windows, start two instances. If you local network +//! allows mDNS, they will automatically connect. +//! +//! 2. Type `PUT my-key my-value` in terminal one and hit return. +//! +//! 3. Type `GET my-key` in terminal two and hit return. +//! +//! 4. Close with Ctrl-c. + +use futures::prelude::*; +use libp2p::kad::record::store::MemoryStore; +use libp2p::kad::{record::Key, Kademlia, KademliaEvent, PutRecordOk, Quorum, Record}; +use libp2p::{ + build_development_transport, identity, + mdns::{Mdns, MdnsEvent}, + swarm::NetworkBehaviourEventProcess, + tokio_codec::{FramedRead, LinesCodec}, + tokio_io::{AsyncRead, AsyncWrite}, + NetworkBehaviour, PeerId, Swarm, +}; + +fn main() { + env_logger::init(); + + // Create a random key for ourselves. + let local_key = identity::Keypair::generate_ed25519(); + let local_peer_id = PeerId::from(local_key.public()); + + // Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol. + let transport = build_development_transport(local_key); + + // We create a custom network behaviour that combines Kademlia and mDNS. + #[derive(NetworkBehaviour)] + struct MyBehaviour { + kademlia: Kademlia, + mdns: Mdns, + } + + impl NetworkBehaviourEventProcess + for MyBehaviour + { + // Called when `mdns` produces an event. + fn inject_event(&mut self, event: MdnsEvent) { + if let MdnsEvent::Discovered(list) = event { + for (peer_id, multiaddr) in list { + self.kademlia.add_address(&peer_id, multiaddr); + } + } + } + } + + impl NetworkBehaviourEventProcess + for MyBehaviour + { + // Called when `kademlia` produces an event. + fn inject_event(&mut self, message: KademliaEvent) { + match message { + KademliaEvent::GetRecordResult(Ok(result)) => { + for Record { key, value, .. } in result.records { + println!( + "Got record {:?} {:?}", + std::str::from_utf8(key.as_ref()).unwrap(), + std::str::from_utf8(&value).unwrap(), + ); + } + } + KademliaEvent::GetRecordResult(Err(err)) => { + eprintln!("Failed to get record: {:?}", err); + } + KademliaEvent::PutRecordResult(Ok(PutRecordOk { key })) => { + println!( + "Successfully put record {:?}", + std::str::from_utf8(key.as_ref()).unwrap() + ); + } + KademliaEvent::PutRecordResult(Err(err)) => { + eprintln!("Failed to put record: {:?}", err); + } + _ => {} + } + } + } + + // Create a swarm to manage peers and events. + let mut swarm = { + // Create a Kademlia behaviour. + let store = MemoryStore::new(local_peer_id.clone()); + let kademlia = Kademlia::new(local_peer_id.clone(), store); + + let behaviour = MyBehaviour { + kademlia, + mdns: Mdns::new().expect("Failed to create mDNS service"), + }; + + Swarm::new(transport, behaviour, local_peer_id) + }; + + // Read full lines from stdin. + let stdin = tokio_stdin_stdout::stdin(0); + let mut framed_stdin = FramedRead::new(stdin, LinesCodec::new()); + + // Listen on all interfaces and whatever port the OS assigns. + Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse().unwrap()).unwrap(); + + // Kick it off. + let mut listening = false; + tokio::run(futures::future::poll_fn(move || { + loop { + match framed_stdin.poll().expect("Error while polling stdin") { + Async::Ready(Some(line)) => { + handle_input_line(&mut swarm.kademlia, line); + } + Async::Ready(None) => panic!("Stdin closed"), + Async::NotReady => break, + }; + } + + loop { + match swarm.poll().expect("Error while polling swarm") { + Async::Ready(Some(_)) => {} + Async::Ready(None) | Async::NotReady => { + if !listening { + if let Some(a) = Swarm::listeners(&swarm).next() { + println!("Listening on {:?}", a); + listening = true; + } + } + break; + } + } + } + + Ok(Async::NotReady) + })); +} + +fn handle_input_line( + kademlia: &mut Kademlia, + line: String, +) { + let mut args = line.split(" "); + + match args.next() { + Some("GET") => { + let key = { + match args.next() { + Some(key) => Key::new(&key), + None => { + eprintln!("Expected key"); + return; + } + } + }; + kademlia.get_record(&key, Quorum::One); + } + Some("PUT") => { + let key = { + match args.next() { + Some(key) => Key::new(&key), + None => { + eprintln!("Expected key"); + return; + } + } + }; + let value = { + match args.next() { + Some(value) => value.as_bytes().to_vec(), + None => { + eprintln!("Expected value"); + return; + } + } + }; + let record = Record { + key, + value, + publisher: None, + expires: None, + }; + kademlia.put_record(record, Quorum::One); + } + _ => { + eprintln!("expected GET or PUT"); + } + } +} diff --git a/examples/ipfs-kad.rs b/examples/ipfs-kad.rs index 26eb6fb5..7ee1f88e 100644 --- a/examples/ipfs-kad.rs +++ b/examples/ipfs-kad.rs @@ -48,10 +48,6 @@ fn main() { // Create a swarm to manage peers and events. let mut swarm = { // Create a Kademlia behaviour. - // Note that normally the Kademlia process starts by performing lots of request in order - // to insert our local node in the DHT. However here we use `without_init` because this - // example is very ephemeral and we don't want to pollute the DHT. In a real world - // application, you want to use `new` instead. let mut cfg = KademliaConfig::default(); cfg.set_query_timeout(Duration::from_secs(5 * 60)); let store = MemoryStore::new(local_peer_id.clone()); diff --git a/misc/multiaddr/src/errors.rs b/misc/multiaddr/src/errors.rs index 4330226f..26363583 100644 --- a/misc/multiaddr/src/errors.rs +++ b/misc/multiaddr/src/errors.rs @@ -57,8 +57,8 @@ impl From for Error { } } -impl From for Error { - fn from(err: bs58::decode::DecodeError) -> Error { +impl From for Error { + fn from(err: bs58::decode::Error) -> Error { Error::ParsingError(err.into()) } } diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 61bab93b..230eca27 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -17,6 +17,6 @@ fnv = "1.0" futures-preview = "0.3.0-alpha.18" libp2p-core = { version = "0.12.0", path = "../../core" } libp2p-swarm = { version = "0.2.0", path = "../../swarm" } -protobuf = "2.3" +protobuf = "2.8" rand = "0.6" smallvec = "0.6.5" diff --git a/protocols/floodsub/regen_structs_proto.sh b/protocols/floodsub/regen_structs_proto.sh index fa704817..95a6bda2 100755 --- a/protocols/floodsub/regen_structs_proto.sh +++ b/protocols/floodsub/regen_structs_proto.sh @@ -1,13 +1,3 @@ #!/bin/sh -# This script regenerates the `src/rpc_proto.rs` file from `rpc.proto`. - -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 . rpc.proto" - -sudo chown $USER:$USER *.rs - -mv -f rpc.rs ./src/rpc_proto.rs +../../scripts/protobuf/gen.sh src/rpc.proto diff --git a/protocols/floodsub/rpc.proto b/protocols/floodsub/src/rpc.proto similarity index 98% rename from protocols/floodsub/rpc.proto rename to protocols/floodsub/src/rpc.proto index f43d3c16..08d137ad 100644 --- a/protocols/floodsub/rpc.proto +++ b/protocols/floodsub/src/rpc.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package floodsub.pb; message RPC { diff --git a/protocols/floodsub/src/rpc_proto.rs b/protocols/floodsub/src/rpc_proto.rs index 2cfc54e4..522d097c 100644 --- a/protocols/floodsub/src/rpc_proto.rs +++ b/protocols/floodsub/src/rpc_proto.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.3.0. Do not edit +// This file is generated by rust-protobuf 2.8.1. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 @@ -17,10 +17,15 @@ #![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `src/rpc.proto` use protobuf::Message as Message_imported_for_functions; use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1; + #[derive(PartialEq,Clone,Default)] pub struct RPC { // message fields @@ -31,6 +36,12 @@ pub struct RPC { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a RPC { + fn default() -> &'a RPC { + ::default_instance() + } +} + impl RPC { pub fn new() -> RPC { ::std::default::Default::default() @@ -38,6 +49,10 @@ impl RPC { // repeated .floodsub.pb.RPC.SubOpts subscriptions = 1; + + pub fn get_subscriptions(&self) -> &[RPC_SubOpts] { + &self.subscriptions + } pub fn clear_subscriptions(&mut self) { self.subscriptions.clear(); } @@ -57,12 +72,12 @@ impl RPC { ::std::mem::replace(&mut self.subscriptions, ::protobuf::RepeatedField::new()) } - pub fn get_subscriptions(&self) -> &[RPC_SubOpts] { - &self.subscriptions - } - // repeated .floodsub.pb.Message publish = 2; + + pub fn get_publish(&self) -> &[Message] { + &self.publish + } pub fn clear_publish(&mut self) { self.publish.clear(); } @@ -81,10 +96,6 @@ impl RPC { pub fn take_publish(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.publish, ::protobuf::RepeatedField::new()) } - - pub fn get_publish(&self) -> &[Message] { - &self.publish - } } impl ::protobuf::Message for RPC { @@ -222,8 +233,8 @@ impl ::protobuf::Message for RPC { impl ::protobuf::Clear for RPC { fn clear(&mut self) { - self.clear_subscriptions(); - self.clear_publish(); + self.subscriptions.clear(); + self.publish.clear(); self.unknown_fields.clear(); } } @@ -235,7 +246,7 @@ impl ::std::fmt::Debug for RPC { } impl ::protobuf::reflect::ProtobufValue for RPC { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -250,6 +261,12 @@ pub struct RPC_SubOpts { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a RPC_SubOpts { + fn default() -> &'a RPC_SubOpts { + ::default_instance() + } +} + impl RPC_SubOpts { pub fn new() -> RPC_SubOpts { ::std::default::Default::default() @@ -257,6 +274,10 @@ impl RPC_SubOpts { // optional bool subscribe = 1; + + pub fn get_subscribe(&self) -> bool { + self.subscribe.unwrap_or(false) + } pub fn clear_subscribe(&mut self) { self.subscribe = ::std::option::Option::None; } @@ -270,12 +291,15 @@ impl RPC_SubOpts { self.subscribe = ::std::option::Option::Some(v); } - pub fn get_subscribe(&self) -> bool { - self.subscribe.unwrap_or(false) - } - // optional string topicid = 2; + + pub fn get_topicid(&self) -> &str { + match self.topicid.as_ref() { + Some(v) => &v, + None => "", + } + } pub fn clear_topicid(&mut self) { self.topicid.clear(); } @@ -302,13 +326,6 @@ impl RPC_SubOpts { pub fn take_topicid(&mut self) -> ::std::string::String { self.topicid.take().unwrap_or_else(|| ::std::string::String::new()) } - - pub fn get_topicid(&self) -> &str { - match self.topicid.as_ref() { - Some(v) => &v, - None => "", - } - } } impl ::protobuf::Message for RPC_SubOpts { @@ -434,8 +451,8 @@ impl ::protobuf::Message for RPC_SubOpts { impl ::protobuf::Clear for RPC_SubOpts { fn clear(&mut self) { - self.clear_subscribe(); - self.clear_topicid(); + self.subscribe = ::std::option::Option::None; + self.topicid.clear(); self.unknown_fields.clear(); } } @@ -447,7 +464,7 @@ impl ::std::fmt::Debug for RPC_SubOpts { } impl ::protobuf::reflect::ProtobufValue for RPC_SubOpts { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -464,6 +481,12 @@ pub struct Message { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Message { + fn default() -> &'a Message { + ::default_instance() + } +} + impl Message { pub fn new() -> Message { ::std::default::Default::default() @@ -471,6 +494,13 @@ impl Message { // optional bytes from = 1; + + pub fn get_from(&self) -> &[u8] { + match self.from.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_from(&mut self) { self.from.clear(); } @@ -498,15 +528,15 @@ impl Message { self.from.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_from(&self) -> &[u8] { - match self.from.as_ref() { + // optional bytes data = 2; + + + pub fn get_data(&self) -> &[u8] { + match self.data.as_ref() { Some(v) => &v, None => &[], } } - - // optional bytes data = 2; - pub fn clear_data(&mut self) { self.data.clear(); } @@ -534,15 +564,15 @@ impl Message { self.data.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_data(&self) -> &[u8] { - match self.data.as_ref() { + // optional bytes seqno = 3; + + + pub fn get_seqno(&self) -> &[u8] { + match self.seqno.as_ref() { Some(v) => &v, None => &[], } } - - // optional bytes seqno = 3; - pub fn clear_seqno(&mut self) { self.seqno.clear(); } @@ -570,15 +600,12 @@ impl Message { self.seqno.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_seqno(&self) -> &[u8] { - match self.seqno.as_ref() { - Some(v) => &v, - None => &[], - } - } - // repeated string topicIDs = 4; + + pub fn get_topicIDs(&self) -> &[::std::string::String] { + &self.topicIDs + } pub fn clear_topicIDs(&mut self) { self.topicIDs.clear(); } @@ -597,10 +624,6 @@ impl Message { pub fn take_topicIDs(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { ::std::mem::replace(&mut self.topicIDs, ::protobuf::RepeatedField::new()) } - - pub fn get_topicIDs(&self) -> &[::std::string::String] { - &self.topicIDs - } } impl ::protobuf::Message for Message { @@ -750,10 +773,10 @@ impl ::protobuf::Message for Message { impl ::protobuf::Clear for Message { fn clear(&mut self) { - self.clear_from(); - self.clear_data(); - self.clear_seqno(); - self.clear_topicIDs(); + self.from.clear(); + self.data.clear(); + self.seqno.clear(); + self.topicIDs.clear(); self.unknown_fields.clear(); } } @@ -765,7 +788,7 @@ impl ::std::fmt::Debug for Message { } impl ::protobuf::reflect::ProtobufValue for Message { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -781,6 +804,12 @@ pub struct TopicDescriptor { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a TopicDescriptor { + fn default() -> &'a TopicDescriptor { + ::default_instance() + } +} + impl TopicDescriptor { pub fn new() -> TopicDescriptor { ::std::default::Default::default() @@ -788,6 +817,13 @@ impl TopicDescriptor { // optional string name = 1; + + pub fn get_name(&self) -> &str { + match self.name.as_ref() { + Some(v) => &v, + None => "", + } + } pub fn clear_name(&mut self) { self.name.clear(); } @@ -815,15 +851,12 @@ impl TopicDescriptor { self.name.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_name(&self) -> &str { - match self.name.as_ref() { - Some(v) => &v, - None => "", - } - } - // optional .floodsub.pb.TopicDescriptor.AuthOpts auth = 2; + + pub fn get_auth(&self) -> &TopicDescriptor_AuthOpts { + self.auth.as_ref().unwrap_or_else(|| TopicDescriptor_AuthOpts::default_instance()) + } pub fn clear_auth(&mut self) { self.auth.clear(); } @@ -851,12 +884,12 @@ impl TopicDescriptor { self.auth.take().unwrap_or_else(|| TopicDescriptor_AuthOpts::new()) } - pub fn get_auth(&self) -> &TopicDescriptor_AuthOpts { - self.auth.as_ref().unwrap_or_else(|| TopicDescriptor_AuthOpts::default_instance()) - } - // optional .floodsub.pb.TopicDescriptor.EncOpts enc = 3; + + pub fn get_enc(&self) -> &TopicDescriptor_EncOpts { + self.enc.as_ref().unwrap_or_else(|| TopicDescriptor_EncOpts::default_instance()) + } pub fn clear_enc(&mut self) { self.enc.clear(); } @@ -883,10 +916,6 @@ impl TopicDescriptor { pub fn take_enc(&mut self) -> TopicDescriptor_EncOpts { self.enc.take().unwrap_or_else(|| TopicDescriptor_EncOpts::new()) } - - pub fn get_enc(&self) -> &TopicDescriptor_EncOpts { - self.enc.as_ref().unwrap_or_else(|| TopicDescriptor_EncOpts::default_instance()) - } } impl ::protobuf::Message for TopicDescriptor { @@ -1038,9 +1067,9 @@ impl ::protobuf::Message for TopicDescriptor { impl ::protobuf::Clear for TopicDescriptor { fn clear(&mut self) { - self.clear_name(); - self.clear_auth(); - self.clear_enc(); + self.name.clear(); + self.auth.clear(); + self.enc.clear(); self.unknown_fields.clear(); } } @@ -1052,7 +1081,7 @@ impl ::std::fmt::Debug for TopicDescriptor { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1067,6 +1096,12 @@ pub struct TopicDescriptor_AuthOpts { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a TopicDescriptor_AuthOpts { + fn default() -> &'a TopicDescriptor_AuthOpts { + ::default_instance() + } +} + impl TopicDescriptor_AuthOpts { pub fn new() -> TopicDescriptor_AuthOpts { ::std::default::Default::default() @@ -1074,6 +1109,10 @@ impl TopicDescriptor_AuthOpts { // optional .floodsub.pb.TopicDescriptor.AuthOpts.AuthMode mode = 1; + + pub fn get_mode(&self) -> TopicDescriptor_AuthOpts_AuthMode { + self.mode.unwrap_or(TopicDescriptor_AuthOpts_AuthMode::NONE) + } pub fn clear_mode(&mut self) { self.mode = ::std::option::Option::None; } @@ -1087,12 +1126,12 @@ impl TopicDescriptor_AuthOpts { self.mode = ::std::option::Option::Some(v); } - pub fn get_mode(&self) -> TopicDescriptor_AuthOpts_AuthMode { - self.mode.unwrap_or(TopicDescriptor_AuthOpts_AuthMode::NONE) - } - // repeated bytes keys = 2; + + pub fn get_keys(&self) -> &[::std::vec::Vec] { + &self.keys + } pub fn clear_keys(&mut self) { self.keys.clear(); } @@ -1111,10 +1150,6 @@ impl TopicDescriptor_AuthOpts { pub fn take_keys(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { ::std::mem::replace(&mut self.keys, ::protobuf::RepeatedField::new()) } - - pub fn get_keys(&self) -> &[::std::vec::Vec] { - &self.keys - } } impl ::protobuf::Message for TopicDescriptor_AuthOpts { @@ -1236,8 +1271,8 @@ impl ::protobuf::Message for TopicDescriptor_AuthOpts { impl ::protobuf::Clear for TopicDescriptor_AuthOpts { fn clear(&mut self) { - self.clear_mode(); - self.clear_keys(); + self.mode = ::std::option::Option::None; + self.keys.clear(); self.unknown_fields.clear(); } } @@ -1249,7 +1284,7 @@ impl ::std::fmt::Debug for TopicDescriptor_AuthOpts { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_AuthOpts { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1307,7 +1342,7 @@ impl ::std::default::Default for TopicDescriptor_AuthOpts_AuthMode { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_AuthOpts_AuthMode { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } @@ -1322,6 +1357,12 @@ pub struct TopicDescriptor_EncOpts { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a TopicDescriptor_EncOpts { + fn default() -> &'a TopicDescriptor_EncOpts { + ::default_instance() + } +} + impl TopicDescriptor_EncOpts { pub fn new() -> TopicDescriptor_EncOpts { ::std::default::Default::default() @@ -1329,6 +1370,10 @@ impl TopicDescriptor_EncOpts { // optional .floodsub.pb.TopicDescriptor.EncOpts.EncMode mode = 1; + + pub fn get_mode(&self) -> TopicDescriptor_EncOpts_EncMode { + self.mode.unwrap_or(TopicDescriptor_EncOpts_EncMode::NONE) + } pub fn clear_mode(&mut self) { self.mode = ::std::option::Option::None; } @@ -1342,12 +1387,12 @@ impl TopicDescriptor_EncOpts { self.mode = ::std::option::Option::Some(v); } - pub fn get_mode(&self) -> TopicDescriptor_EncOpts_EncMode { - self.mode.unwrap_or(TopicDescriptor_EncOpts_EncMode::NONE) - } - // repeated bytes keyHashes = 2; + + pub fn get_keyHashes(&self) -> &[::std::vec::Vec] { + &self.keyHashes + } pub fn clear_keyHashes(&mut self) { self.keyHashes.clear(); } @@ -1366,10 +1411,6 @@ impl TopicDescriptor_EncOpts { pub fn take_keyHashes(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { ::std::mem::replace(&mut self.keyHashes, ::protobuf::RepeatedField::new()) } - - pub fn get_keyHashes(&self) -> &[::std::vec::Vec] { - &self.keyHashes - } } impl ::protobuf::Message for TopicDescriptor_EncOpts { @@ -1491,8 +1532,8 @@ impl ::protobuf::Message for TopicDescriptor_EncOpts { impl ::protobuf::Clear for TopicDescriptor_EncOpts { fn clear(&mut self) { - self.clear_mode(); - self.clear_keyHashes(); + self.mode = ::std::option::Option::None; + self.keyHashes.clear(); self.unknown_fields.clear(); } } @@ -1504,7 +1545,7 @@ impl ::std::fmt::Debug for TopicDescriptor_EncOpts { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_EncOpts { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1562,119 +1603,120 @@ impl ::std::default::Default for TopicDescriptor_EncOpts_EncMode { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_EncOpts_EncMode { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\trpc.proto\x12\x0bfloodsub.pb\"\xb8\x01\n\x03RPC\x12>\n\rsubscription\ - s\x18\x01\x20\x03(\x0b2\x18.floodsub.pb.RPC.SubOptsR\rsubscriptions\x12.\ - \n\x07publish\x18\x02\x20\x03(\x0b2\x14.floodsub.pb.MessageR\x07publish\ - \x1aA\n\x07SubOpts\x12\x1c\n\tsubscribe\x18\x01\x20\x01(\x08R\tsubscribe\ - \x12\x18\n\x07topicid\x18\x02\x20\x01(\tR\x07topicid\"c\n\x07Message\x12\ - \x12\n\x04from\x18\x01\x20\x01(\x0cR\x04from\x12\x12\n\x04data\x18\x02\ - \x20\x01(\x0cR\x04data\x12\x14\n\x05seqno\x18\x03\x20\x01(\x0cR\x05seqno\ - \x12\x1a\n\x08topicIDs\x18\x04\x20\x03(\tR\x08topicIDs\"\xbe\x03\n\x0fTo\ - picDescriptor\x12\x12\n\x04name\x18\x01\x20\x01(\tR\x04name\x129\n\x04au\ - th\x18\x02\x20\x01(\x0b2%.floodsub.pb.TopicDescriptor.AuthOptsR\x04auth\ - \x126\n\x03enc\x18\x03\x20\x01(\x0b2$.floodsub.pb.TopicDescriptor.EncOpt\ - sR\x03enc\x1a\x8a\x01\n\x08AuthOpts\x12B\n\x04mode\x18\x01\x20\x01(\x0e2\ - ..floodsub.pb.TopicDescriptor.AuthOpts.AuthModeR\x04mode\x12\x12\n\x04ke\ - ys\x18\x02\x20\x03(\x0cR\x04keys\"&\n\x08AuthMode\x12\x08\n\x04NONE\x10\ - \0\x12\x07\n\x03KEY\x10\x01\x12\x07\n\x03WOT\x10\x02\x1a\x96\x01\n\x07En\ - cOpts\x12@\n\x04mode\x18\x01\x20\x01(\x0e2,.floodsub.pb.TopicDescriptor.\ - EncOpts.EncModeR\x04mode\x12\x1c\n\tkeyHashes\x18\x02\x20\x03(\x0cR\tkey\ - Hashes\"+\n\x07EncMode\x12\x08\n\x04NONE\x10\0\x12\r\n\tSHAREDKEY\x10\ - \x01\x12\x07\n\x03WOT\x10\x02J\xc2\x10\n\x06\x12\x04\0\0.\x01\n\x08\n\ - \x01\x02\x12\x03\0\x08\x13\n\n\n\x02\x04\0\x12\x04\x02\0\n\x01\n\n\n\x03\ - \x04\0\x01\x12\x03\x02\x08\x0b\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x08+\ - \n\x0c\n\x05\x04\0\x02\0\x04\x12\x03\x03\x08\x10\n\x0c\n\x05\x04\0\x02\0\ - \x06\x12\x03\x03\x11\x18\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x19&\n\ - \x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03)*\n\x0b\n\x04\x04\0\x02\x01\x12\ - \x03\x04\x08%\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x04\x08\x10\n\x0c\n\ - \x05\x04\0\x02\x01\x06\x12\x03\x04\x11\x18\n\x0c\n\x05\x04\0\x02\x01\x01\ - \x12\x03\x04\x19\x20\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04#$\n\x0c\n\ - \x04\x04\0\x03\0\x12\x04\x06\x08\t\t\n\x0c\n\x05\x04\0\x03\0\x01\x12\x03\ - \x06\x10\x17\n(\n\x06\x04\0\x03\0\x02\0\x12\x03\x07\x10,\"\x19\x20subscr\ - ibe\x20or\x20unsubcribe\n\n\x0e\n\x07\x04\0\x03\0\x02\0\x04\x12\x03\x07\ - \x10\x18\n\x0e\n\x07\x04\0\x03\0\x02\0\x05\x12\x03\x07\x19\x1d\n\x0e\n\ - \x07\x04\0\x03\0\x02\0\x01\x12\x03\x07\x1e'\n\x0e\n\x07\x04\0\x03\0\x02\ - \0\x03\x12\x03\x07*+\n\r\n\x06\x04\0\x03\0\x02\x01\x12\x03\x08\x10,\n\ - \x0e\n\x07\x04\0\x03\0\x02\x01\x04\x12\x03\x08\x10\x18\n\x0e\n\x07\x04\0\ - \x03\0\x02\x01\x05\x12\x03\x08\x19\x1f\n\x0e\n\x07\x04\0\x03\0\x02\x01\ - \x01\x12\x03\x08\x20'\n\x0e\n\x07\x04\0\x03\0\x02\x01\x03\x12\x03\x08*+\ - \n\n\n\x02\x04\x01\x12\x04\x0c\0\x11\x01\n\n\n\x03\x04\x01\x01\x12\x03\ - \x0c\x08\x0f\n\x0b\n\x04\x04\x01\x02\0\x12\x03\r\x08\x20\n\x0c\n\x05\x04\ - \x01\x02\0\x04\x12\x03\r\x08\x10\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\r\ - \x11\x16\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\r\x17\x1b\n\x0c\n\x05\x04\ - \x01\x02\0\x03\x12\x03\r\x1e\x1f\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x0e\ - \x08\x20\n\x0c\n\x05\x04\x01\x02\x01\x04\x12\x03\x0e\x08\x10\n\x0c\n\x05\ - \x04\x01\x02\x01\x05\x12\x03\x0e\x11\x16\n\x0c\n\x05\x04\x01\x02\x01\x01\ - \x12\x03\x0e\x17\x1b\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x0e\x1e\x1f\ - \n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x0f\x08!\n\x0c\n\x05\x04\x01\x02\ - \x02\x04\x12\x03\x0f\x08\x10\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\x0f\ - \x11\x16\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\x0f\x17\x1c\n\x0c\n\x05\ - \x04\x01\x02\x02\x03\x12\x03\x0f\x1f\x20\n\x0b\n\x04\x04\x01\x02\x03\x12\ - \x03\x10\x08%\n\x0c\n\x05\x04\x01\x02\x03\x04\x12\x03\x10\x08\x10\n\x0c\ - \n\x05\x04\x01\x02\x03\x05\x12\x03\x10\x11\x17\n\x0c\n\x05\x04\x01\x02\ - \x03\x01\x12\x03\x10\x18\x20\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x10\ - #$\nC\n\x02\x04\x02\x12\x04\x14\0.\x01\x1a7\x20topicID\x20=\x20hash(topi\ - cDescriptor);\x20(not\x20the\x20topic.name)\n\n\n\n\x03\x04\x02\x01\x12\ - \x03\x14\x08\x17\n\x0b\n\x04\x04\x02\x02\0\x12\x03\x15\x08!\n\x0c\n\x05\ - \x04\x02\x02\0\x04\x12\x03\x15\x08\x10\n\x0c\n\x05\x04\x02\x02\0\x05\x12\ - \x03\x15\x11\x17\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x15\x18\x1c\n\x0c\ - \n\x05\x04\x02\x02\0\x03\x12\x03\x15\x1f\x20\n\x0b\n\x04\x04\x02\x02\x01\ - \x12\x03\x16\x08#\n\x0c\n\x05\x04\x02\x02\x01\x04\x12\x03\x16\x08\x10\n\ - \x0c\n\x05\x04\x02\x02\x01\x06\x12\x03\x16\x11\x19\n\x0c\n\x05\x04\x02\ - \x02\x01\x01\x12\x03\x16\x1a\x1e\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\ - \x16!\"\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x17\x08!\n\x0c\n\x05\x04\x02\ - \x02\x02\x04\x12\x03\x17\x08\x10\n\x0c\n\x05\x04\x02\x02\x02\x06\x12\x03\ - \x17\x11\x18\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\x03\x17\x19\x1c\n\x0c\n\ - \x05\x04\x02\x02\x02\x03\x12\x03\x17\x1f\x20\n\x0c\n\x04\x04\x02\x03\0\ - \x12\x04\x19\x08\"\t\n\x0c\n\x05\x04\x02\x03\0\x01\x12\x03\x19\x10\x18\n\ - \r\n\x06\x04\x02\x03\0\x02\0\x12\x03\x1a\x10+\n\x0e\n\x07\x04\x02\x03\0\ - \x02\0\x04\x12\x03\x1a\x10\x18\n\x0e\n\x07\x04\x02\x03\0\x02\0\x06\x12\ - \x03\x1a\x19!\n\x0e\n\x07\x04\x02\x03\0\x02\0\x01\x12\x03\x1a\"&\n\x0e\n\ - \x07\x04\x02\x03\0\x02\0\x03\x12\x03\x1a)*\n#\n\x06\x04\x02\x03\0\x02\ - \x01\x12\x03\x1b\x10(\"\x14\x20root\x20keys\x20to\x20trust\n\n\x0e\n\x07\ - \x04\x02\x03\0\x02\x01\x04\x12\x03\x1b\x10\x18\n\x0e\n\x07\x04\x02\x03\0\ - \x02\x01\x05\x12\x03\x1b\x19\x1e\n\x0e\n\x07\x04\x02\x03\0\x02\x01\x01\ - \x12\x03\x1b\x1f#\n\x0e\n\x07\x04\x02\x03\0\x02\x01\x03\x12\x03\x1b&'\n\ - \x0e\n\x06\x04\x02\x03\0\x04\0\x12\x04\x1d\x10!\x11\n\x0e\n\x07\x04\x02\ - \x03\0\x04\0\x01\x12\x03\x1d\x15\x1d\n8\n\x08\x04\x02\x03\0\x04\0\x02\0\ - \x12\x03\x1e\x18!\"'\x20no\x20authentication,\x20anyone\x20can\x20publis\ - h\n\n\x10\n\t\x04\x02\x03\0\x04\0\x02\0\x01\x12\x03\x1e\x18\x1c\n\x10\n\ - \t\x04\x02\x03\0\x04\0\x02\0\x02\x12\x03\x1e\x1f\x20\nT\n\x08\x04\x02\ - \x03\0\x04\0\x02\x01\x12\x03\x1f\x18\x20\"C\x20only\x20messages\x20signe\ - d\x20by\x20keys\x20in\x20the\x20topic\x20descriptor\x20are\x20accepted\n\ - \n\x10\n\t\x04\x02\x03\0\x04\0\x02\x01\x01\x12\x03\x1f\x18\x1b\n\x10\n\t\ - \x04\x02\x03\0\x04\0\x02\x01\x02\x12\x03\x1f\x1e\x1f\nM\n\x08\x04\x02\ - \x03\0\x04\0\x02\x02\x12\x03\x20\x18\x20\"<\x20web\x20of\x20trust,\x20ce\ - rtificates\x20can\x20allow\x20publisher\x20set\x20to\x20grow\n\n\x10\n\t\ - \x04\x02\x03\0\x04\0\x02\x02\x01\x12\x03\x20\x18\x1b\n\x10\n\t\x04\x02\ - \x03\0\x04\0\x02\x02\x02\x12\x03\x20\x1e\x1f\n\x0c\n\x04\x04\x02\x03\x01\ - \x12\x04$\x08-\t\n\x0c\n\x05\x04\x02\x03\x01\x01\x12\x03$\x10\x17\n\r\n\ - \x06\x04\x02\x03\x01\x02\0\x12\x03%\x10*\n\x0e\n\x07\x04\x02\x03\x01\x02\ - \0\x04\x12\x03%\x10\x18\n\x0e\n\x07\x04\x02\x03\x01\x02\0\x06\x12\x03%\ - \x19\x20\n\x0e\n\x07\x04\x02\x03\x01\x02\0\x01\x12\x03%!%\n\x0e\n\x07\ - \x04\x02\x03\x01\x02\0\x03\x12\x03%()\n<\n\x06\x04\x02\x03\x01\x02\x01\ - \x12\x03&\x10-\"-\x20the\x20hashes\x20of\x20the\x20shared\x20keys\x20use\ - d\x20(salted)\n\n\x0e\n\x07\x04\x02\x03\x01\x02\x01\x04\x12\x03&\x10\x18\ - \n\x0e\n\x07\x04\x02\x03\x01\x02\x01\x05\x12\x03&\x19\x1e\n\x0e\n\x07\ - \x04\x02\x03\x01\x02\x01\x01\x12\x03&\x1f(\n\x0e\n\x07\x04\x02\x03\x01\ - \x02\x01\x03\x12\x03&+,\n\x0e\n\x06\x04\x02\x03\x01\x04\0\x12\x04(\x10,\ - \x11\n\x0e\n\x07\x04\x02\x03\x01\x04\0\x01\x12\x03(\x15\x1c\n1\n\x08\x04\ - \x02\x03\x01\x04\0\x02\0\x12\x03)\x18!\"\x20\x20no\x20encryption,\x20any\ - one\x20can\x20read\n\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\0\x01\x12\x03)\ - \x18\x1c\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\0\x02\x12\x03)\x1f\x20\n9\n\ - \x08\x04\x02\x03\x01\x04\0\x02\x01\x12\x03*\x18&\"(\x20messages\x20are\ - \x20encrypted\x20with\x20shared\x20key\n\n\x10\n\t\x04\x02\x03\x01\x04\0\ - \x02\x01\x01\x12\x03*\x18!\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\x01\x02\ - \x12\x03*$%\nM\n\x08\x04\x02\x03\x01\x04\0\x02\x02\x12\x03+\x18\x20\"<\ - \x20web\x20of\x20trust,\x20certificates\x20can\x20allow\x20publisher\x20\ - set\x20to\x20grow\n\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\x02\x01\x12\x03+\ - \x18\x1b\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\x02\x02\x12\x03+\x1e\x1f\ + \n\rsrc/rpc.proto\x12\x0bfloodsub.pb\"\xb8\x01\n\x03RPC\x12>\n\rsubscrip\ + tions\x18\x01\x20\x03(\x0b2\x18.floodsub.pb.RPC.SubOptsR\rsubscriptions\ + \x12.\n\x07publish\x18\x02\x20\x03(\x0b2\x14.floodsub.pb.MessageR\x07pub\ + lish\x1aA\n\x07SubOpts\x12\x1c\n\tsubscribe\x18\x01\x20\x01(\x08R\tsubsc\ + ribe\x12\x18\n\x07topicid\x18\x02\x20\x01(\tR\x07topicid\"c\n\x07Message\ + \x12\x12\n\x04from\x18\x01\x20\x01(\x0cR\x04from\x12\x12\n\x04data\x18\ + \x02\x20\x01(\x0cR\x04data\x12\x14\n\x05seqno\x18\x03\x20\x01(\x0cR\x05s\ + eqno\x12\x1a\n\x08topicIDs\x18\x04\x20\x03(\tR\x08topicIDs\"\xbe\x03\n\ + \x0fTopicDescriptor\x12\x12\n\x04name\x18\x01\x20\x01(\tR\x04name\x129\n\ + \x04auth\x18\x02\x20\x01(\x0b2%.floodsub.pb.TopicDescriptor.AuthOptsR\ + \x04auth\x126\n\x03enc\x18\x03\x20\x01(\x0b2$.floodsub.pb.TopicDescripto\ + r.EncOptsR\x03enc\x1a\x8a\x01\n\x08AuthOpts\x12B\n\x04mode\x18\x01\x20\ + \x01(\x0e2..floodsub.pb.TopicDescriptor.AuthOpts.AuthModeR\x04mode\x12\ + \x12\n\x04keys\x18\x02\x20\x03(\x0cR\x04keys\"&\n\x08AuthMode\x12\x08\n\ + \x04NONE\x10\0\x12\x07\n\x03KEY\x10\x01\x12\x07\n\x03WOT\x10\x02\x1a\x96\ + \x01\n\x07EncOpts\x12@\n\x04mode\x18\x01\x20\x01(\x0e2,.floodsub.pb.Topi\ + cDescriptor.EncOpts.EncModeR\x04mode\x12\x1c\n\tkeyHashes\x18\x02\x20\ + \x03(\x0cR\tkeyHashes\"+\n\x07EncMode\x12\x08\n\x04NONE\x10\0\x12\r\n\tS\ + HAREDKEY\x10\x01\x12\x07\n\x03WOT\x10\x02J\xcc\x10\n\x06\x12\x04\0\00\ + \x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x02\x08\x13\ + \n\n\n\x02\x04\0\x12\x04\x04\0\x0c\x01\n\n\n\x03\x04\0\x01\x12\x03\x04\ + \x08\x0b\n\x0b\n\x04\x04\0\x02\0\x12\x03\x05\x08+\n\x0c\n\x05\x04\0\x02\ + \0\x04\x12\x03\x05\x08\x10\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x05\x11\ + \x18\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x05\x19&\n\x0c\n\x05\x04\0\x02\ + \0\x03\x12\x03\x05)*\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x06\x08%\n\x0c\n\ + \x05\x04\0\x02\x01\x04\x12\x03\x06\x08\x10\n\x0c\n\x05\x04\0\x02\x01\x06\ + \x12\x03\x06\x11\x18\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x06\x19\x20\n\ + \x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x06#$\n\x0c\n\x04\x04\0\x03\0\x12\ + \x04\x08\x08\x0b\t\n\x0c\n\x05\x04\0\x03\0\x01\x12\x03\x08\x10\x17\n(\n\ + \x06\x04\0\x03\0\x02\0\x12\x03\t\x10,\"\x19\x20subscribe\x20or\x20unsubc\ + ribe\n\n\x0e\n\x07\x04\0\x03\0\x02\0\x04\x12\x03\t\x10\x18\n\x0e\n\x07\ + \x04\0\x03\0\x02\0\x05\x12\x03\t\x19\x1d\n\x0e\n\x07\x04\0\x03\0\x02\0\ + \x01\x12\x03\t\x1e'\n\x0e\n\x07\x04\0\x03\0\x02\0\x03\x12\x03\t*+\n\r\n\ + \x06\x04\0\x03\0\x02\x01\x12\x03\n\x10,\n\x0e\n\x07\x04\0\x03\0\x02\x01\ + \x04\x12\x03\n\x10\x18\n\x0e\n\x07\x04\0\x03\0\x02\x01\x05\x12\x03\n\x19\ + \x1f\n\x0e\n\x07\x04\0\x03\0\x02\x01\x01\x12\x03\n\x20'\n\x0e\n\x07\x04\ + \0\x03\0\x02\x01\x03\x12\x03\n*+\n\n\n\x02\x04\x01\x12\x04\x0e\0\x13\x01\ + \n\n\n\x03\x04\x01\x01\x12\x03\x0e\x08\x0f\n\x0b\n\x04\x04\x01\x02\0\x12\ + \x03\x0f\x08\x20\n\x0c\n\x05\x04\x01\x02\0\x04\x12\x03\x0f\x08\x10\n\x0c\ + \n\x05\x04\x01\x02\0\x05\x12\x03\x0f\x11\x16\n\x0c\n\x05\x04\x01\x02\0\ + \x01\x12\x03\x0f\x17\x1b\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x0f\x1e\ + \x1f\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x10\x08\x20\n\x0c\n\x05\x04\x01\ + \x02\x01\x04\x12\x03\x10\x08\x10\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\ + \x10\x11\x16\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x10\x17\x1b\n\x0c\n\ + \x05\x04\x01\x02\x01\x03\x12\x03\x10\x1e\x1f\n\x0b\n\x04\x04\x01\x02\x02\ + \x12\x03\x11\x08!\n\x0c\n\x05\x04\x01\x02\x02\x04\x12\x03\x11\x08\x10\n\ + \x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\x11\x11\x16\n\x0c\n\x05\x04\x01\ + \x02\x02\x01\x12\x03\x11\x17\x1c\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\ + \x11\x1f\x20\n\x0b\n\x04\x04\x01\x02\x03\x12\x03\x12\x08%\n\x0c\n\x05\ + \x04\x01\x02\x03\x04\x12\x03\x12\x08\x10\n\x0c\n\x05\x04\x01\x02\x03\x05\ + \x12\x03\x12\x11\x17\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x12\x18\x20\ + \n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x12#$\nC\n\x02\x04\x02\x12\x04\ + \x16\00\x01\x1a7\x20topicID\x20=\x20hash(topicDescriptor);\x20(not\x20th\ + e\x20topic.name)\n\n\n\n\x03\x04\x02\x01\x12\x03\x16\x08\x17\n\x0b\n\x04\ + \x04\x02\x02\0\x12\x03\x17\x08!\n\x0c\n\x05\x04\x02\x02\0\x04\x12\x03\ + \x17\x08\x10\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x17\x11\x17\n\x0c\n\ + \x05\x04\x02\x02\0\x01\x12\x03\x17\x18\x1c\n\x0c\n\x05\x04\x02\x02\0\x03\ + \x12\x03\x17\x1f\x20\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x18\x08#\n\x0c\ + \n\x05\x04\x02\x02\x01\x04\x12\x03\x18\x08\x10\n\x0c\n\x05\x04\x02\x02\ + \x01\x06\x12\x03\x18\x11\x19\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x18\ + \x1a\x1e\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x18!\"\n\x0b\n\x04\x04\ + \x02\x02\x02\x12\x03\x19\x08!\n\x0c\n\x05\x04\x02\x02\x02\x04\x12\x03\ + \x19\x08\x10\n\x0c\n\x05\x04\x02\x02\x02\x06\x12\x03\x19\x11\x18\n\x0c\n\ + \x05\x04\x02\x02\x02\x01\x12\x03\x19\x19\x1c\n\x0c\n\x05\x04\x02\x02\x02\ + \x03\x12\x03\x19\x1f\x20\n\x0c\n\x04\x04\x02\x03\0\x12\x04\x1b\x08$\t\n\ + \x0c\n\x05\x04\x02\x03\0\x01\x12\x03\x1b\x10\x18\n\r\n\x06\x04\x02\x03\0\ + \x02\0\x12\x03\x1c\x10+\n\x0e\n\x07\x04\x02\x03\0\x02\0\x04\x12\x03\x1c\ + \x10\x18\n\x0e\n\x07\x04\x02\x03\0\x02\0\x06\x12\x03\x1c\x19!\n\x0e\n\ + \x07\x04\x02\x03\0\x02\0\x01\x12\x03\x1c\"&\n\x0e\n\x07\x04\x02\x03\0\ + \x02\0\x03\x12\x03\x1c)*\n#\n\x06\x04\x02\x03\0\x02\x01\x12\x03\x1d\x10(\ + \"\x14\x20root\x20keys\x20to\x20trust\n\n\x0e\n\x07\x04\x02\x03\0\x02\ + \x01\x04\x12\x03\x1d\x10\x18\n\x0e\n\x07\x04\x02\x03\0\x02\x01\x05\x12\ + \x03\x1d\x19\x1e\n\x0e\n\x07\x04\x02\x03\0\x02\x01\x01\x12\x03\x1d\x1f#\ + \n\x0e\n\x07\x04\x02\x03\0\x02\x01\x03\x12\x03\x1d&'\n\x0e\n\x06\x04\x02\ + \x03\0\x04\0\x12\x04\x1f\x10#\x11\n\x0e\n\x07\x04\x02\x03\0\x04\0\x01\ + \x12\x03\x1f\x15\x1d\n8\n\x08\x04\x02\x03\0\x04\0\x02\0\x12\x03\x20\x18!\ + \"'\x20no\x20authentication,\x20anyone\x20can\x20publish\n\n\x10\n\t\x04\ + \x02\x03\0\x04\0\x02\0\x01\x12\x03\x20\x18\x1c\n\x10\n\t\x04\x02\x03\0\ + \x04\0\x02\0\x02\x12\x03\x20\x1f\x20\nT\n\x08\x04\x02\x03\0\x04\0\x02\ + \x01\x12\x03!\x18\x20\"C\x20only\x20messages\x20signed\x20by\x20keys\x20\ + in\x20the\x20topic\x20descriptor\x20are\x20accepted\n\n\x10\n\t\x04\x02\ + \x03\0\x04\0\x02\x01\x01\x12\x03!\x18\x1b\n\x10\n\t\x04\x02\x03\0\x04\0\ + \x02\x01\x02\x12\x03!\x1e\x1f\nM\n\x08\x04\x02\x03\0\x04\0\x02\x02\x12\ + \x03\"\x18\x20\"<\x20web\x20of\x20trust,\x20certificates\x20can\x20allow\ + \x20publisher\x20set\x20to\x20grow\n\n\x10\n\t\x04\x02\x03\0\x04\0\x02\ + \x02\x01\x12\x03\"\x18\x1b\n\x10\n\t\x04\x02\x03\0\x04\0\x02\x02\x02\x12\ + \x03\"\x1e\x1f\n\x0c\n\x04\x04\x02\x03\x01\x12\x04&\x08/\t\n\x0c\n\x05\ + \x04\x02\x03\x01\x01\x12\x03&\x10\x17\n\r\n\x06\x04\x02\x03\x01\x02\0\ + \x12\x03'\x10*\n\x0e\n\x07\x04\x02\x03\x01\x02\0\x04\x12\x03'\x10\x18\n\ + \x0e\n\x07\x04\x02\x03\x01\x02\0\x06\x12\x03'\x19\x20\n\x0e\n\x07\x04\ + \x02\x03\x01\x02\0\x01\x12\x03'!%\n\x0e\n\x07\x04\x02\x03\x01\x02\0\x03\ + \x12\x03'()\n<\n\x06\x04\x02\x03\x01\x02\x01\x12\x03(\x10-\"-\x20the\x20\ + hashes\x20of\x20the\x20shared\x20keys\x20used\x20(salted)\n\n\x0e\n\x07\ + \x04\x02\x03\x01\x02\x01\x04\x12\x03(\x10\x18\n\x0e\n\x07\x04\x02\x03\ + \x01\x02\x01\x05\x12\x03(\x19\x1e\n\x0e\n\x07\x04\x02\x03\x01\x02\x01\ + \x01\x12\x03(\x1f(\n\x0e\n\x07\x04\x02\x03\x01\x02\x01\x03\x12\x03(+,\n\ + \x0e\n\x06\x04\x02\x03\x01\x04\0\x12\x04*\x10.\x11\n\x0e\n\x07\x04\x02\ + \x03\x01\x04\0\x01\x12\x03*\x15\x1c\n1\n\x08\x04\x02\x03\x01\x04\0\x02\0\ + \x12\x03+\x18!\"\x20\x20no\x20encryption,\x20anyone\x20can\x20read\n\n\ + \x10\n\t\x04\x02\x03\x01\x04\0\x02\0\x01\x12\x03+\x18\x1c\n\x10\n\t\x04\ + \x02\x03\x01\x04\0\x02\0\x02\x12\x03+\x1f\x20\n9\n\x08\x04\x02\x03\x01\ + \x04\0\x02\x01\x12\x03,\x18&\"(\x20messages\x20are\x20encrypted\x20with\ + \x20shared\x20key\n\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\x01\x01\x12\x03,\ + \x18!\n\x10\n\t\x04\x02\x03\x01\x04\0\x02\x01\x02\x12\x03,$%\nM\n\x08\ + \x04\x02\x03\x01\x04\0\x02\x02\x12\x03-\x18\x20\"<\x20web\x20of\x20trust\ + ,\x20certificates\x20can\x20allow\x20publisher\x20set\x20to\x20grow\n\n\ + \x10\n\t\x04\x02\x03\x01\x04\0\x02\x02\x01\x12\x03-\x18\x1b\n\x10\n\t\ + \x04\x02\x03\x01\x04\0\x02\x02\x02\x12\x03-\x1e\x1f\ "; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 5c1432dc..1875127c 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -17,7 +17,7 @@ libp2p-core = { version = "0.12.0", path = "../../core" } libp2p-swarm = { version = "0.2.0", path = "../../swarm" } log = "0.4.1" multiaddr = { package = "parity-multiaddr", version = "0.5.0", path = "../../misc/multiaddr" } -protobuf = "2.3" +protobuf = "2.8" smallvec = "0.6" wasm-timer = "0.2" unsigned-varint = { git = "https://github.com/tomaka/unsigned-varint", branch = "futures-codec", features = ["codec"] } diff --git a/protocols/identify/regen_structs_proto.sh b/protocols/identify/regen_structs_proto.sh index 621f0313..603ec9a8 100755 --- a/protocols/identify/regen_structs_proto.sh +++ b/protocols/identify/regen_structs_proto.sh @@ -1,13 +1,3 @@ #!/bin/sh -# This script regenerates the `src/structs_proto.rs` file from `structs.proto`. - -sudo 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 . structs.proto" - -sudo chown $USER:$USER *.rs - -mv -f structs.rs ./src/structs_proto.rs +../../scripts/protobuf/gen.sh src/structs.proto diff --git a/protocols/identify/structs.proto b/protocols/identify/src/structs.proto similarity index 98% rename from protocols/identify/structs.proto rename to protocols/identify/src/structs.proto index 0ff074e6..ab01a1c3 100644 --- a/protocols/identify/structs.proto +++ b/protocols/identify/src/structs.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message Identify { // protocolVersion determines compatibility between peers optional string protocolVersion = 5; // e.g. ipfs/1.0.0 diff --git a/protocols/identify/src/structs_proto.rs b/protocols/identify/src/structs_proto.rs index 6524cebf..6a9e10c7 100644 --- a/protocols/identify/src/structs_proto.rs +++ b/protocols/identify/src/structs_proto.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.3.0. Do not edit +// This file is generated by rust-protobuf 2.8.1. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 @@ -17,10 +17,15 @@ #![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `src/structs.proto` use protobuf::Message as Message_imported_for_functions; use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1; + #[derive(PartialEq,Clone,Default)] pub struct Identify { // message fields @@ -35,6 +40,12 @@ pub struct Identify { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Identify { + fn default() -> &'a Identify { + ::default_instance() + } +} + impl Identify { pub fn new() -> Identify { ::std::default::Default::default() @@ -42,6 +53,13 @@ impl Identify { // optional string protocolVersion = 5; + + pub fn get_protocolVersion(&self) -> &str { + match self.protocolVersion.as_ref() { + Some(v) => &v, + None => "", + } + } pub fn clear_protocolVersion(&mut self) { self.protocolVersion.clear(); } @@ -69,15 +87,15 @@ impl Identify { self.protocolVersion.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_protocolVersion(&self) -> &str { - match self.protocolVersion.as_ref() { + // optional string agentVersion = 6; + + + pub fn get_agentVersion(&self) -> &str { + match self.agentVersion.as_ref() { Some(v) => &v, None => "", } } - - // optional string agentVersion = 6; - pub fn clear_agentVersion(&mut self) { self.agentVersion.clear(); } @@ -105,15 +123,15 @@ impl Identify { self.agentVersion.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_agentVersion(&self) -> &str { - match self.agentVersion.as_ref() { - Some(v) => &v, - None => "", - } - } - // optional bytes publicKey = 1; + + pub fn get_publicKey(&self) -> &[u8] { + match self.publicKey.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_publicKey(&mut self) { self.publicKey.clear(); } @@ -141,15 +159,12 @@ impl Identify { self.publicKey.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_publicKey(&self) -> &[u8] { - match self.publicKey.as_ref() { - Some(v) => &v, - None => &[], - } - } - // repeated bytes listenAddrs = 2; + + pub fn get_listenAddrs(&self) -> &[::std::vec::Vec] { + &self.listenAddrs + } pub fn clear_listenAddrs(&mut self) { self.listenAddrs.clear(); } @@ -169,12 +184,15 @@ impl Identify { ::std::mem::replace(&mut self.listenAddrs, ::protobuf::RepeatedField::new()) } - pub fn get_listenAddrs(&self) -> &[::std::vec::Vec] { - &self.listenAddrs - } - // optional bytes observedAddr = 4; + + pub fn get_observedAddr(&self) -> &[u8] { + match self.observedAddr.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_observedAddr(&mut self) { self.observedAddr.clear(); } @@ -202,15 +220,12 @@ impl Identify { self.observedAddr.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_observedAddr(&self) -> &[u8] { - match self.observedAddr.as_ref() { - Some(v) => &v, - None => &[], - } - } - // repeated string protocols = 3; + + pub fn get_protocols(&self) -> &[::std::string::String] { + &self.protocols + } pub fn clear_protocols(&mut self) { self.protocols.clear(); } @@ -229,10 +244,6 @@ impl Identify { pub fn take_protocols(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { ::std::mem::replace(&mut self.protocols, ::protobuf::RepeatedField::new()) } - - pub fn get_protocols(&self) -> &[::std::string::String] { - &self.protocols - } } impl ::protobuf::Message for Identify { @@ -410,12 +421,12 @@ impl ::protobuf::Message for Identify { impl ::protobuf::Clear for Identify { fn clear(&mut self) { - self.clear_protocolVersion(); - self.clear_agentVersion(); - self.clear_publicKey(); - self.clear_listenAddrs(); - self.clear_observedAddr(); - self.clear_protocols(); + self.protocolVersion.clear(); + self.agentVersion.clear(); + self.publicKey.clear(); + self.listenAddrs.clear(); + self.observedAddr.clear(); + self.protocols.clear(); self.unknown_fields.clear(); } } @@ -427,56 +438,57 @@ impl ::std::fmt::Debug for Identify { } impl ::protobuf::reflect::ProtobufValue for Identify { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rstructs.proto\"\xda\x01\n\x08Identify\x12(\n\x0fprotocolVersion\x18\ - \x05\x20\x01(\tR\x0fprotocolVersion\x12\"\n\x0cagentVersion\x18\x06\x20\ - \x01(\tR\x0cagentVersion\x12\x1c\n\tpublicKey\x18\x01\x20\x01(\x0cR\tpub\ - licKey\x12\x20\n\x0blistenAddrs\x18\x02\x20\x03(\x0cR\x0blistenAddrs\x12\ - \"\n\x0cobservedAddr\x18\x04\x20\x01(\x0cR\x0cobservedAddr\x12\x1c\n\tpr\ - otocols\x18\x03\x20\x03(\tR\tprotocolsJ\xc2\t\n\x06\x12\x04\0\0\x16\x01\ - \n\n\n\x02\x04\0\x12\x04\0\0\x16\x01\n\n\n\x03\x04\0\x01\x12\x03\0\x08\ - \x10\nX\n\x04\x04\0\x02\0\x12\x03\x02\x02&\x1a8\x20protocolVersion\x20de\ - termines\x20compatibility\x20between\x20peers\n\"\x11\x20e.g.\x20ipfs/1.\ - 0.0\n\n\x0c\n\x05\x04\0\x02\0\x04\x12\x03\x02\x02\n\n\x0c\n\x05\x04\0\ - \x02\0\x05\x12\x03\x02\x0b\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x02\ - \x12!\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x02$%\n\x9f\x01\n\x04\x04\0\ - \x02\x01\x12\x03\x06\x02#\x1a|\x20agentVersion\x20is\x20like\x20a\x20Use\ - rAgent\x20string\x20in\x20browsers,\x20or\x20client\x20version\x20in\x20\ - bittorrent\n\x20includes\x20the\x20client\x20name\x20and\x20client.\n\"\ - \x14\x20e.g.\x20go-ipfs/0.1.0\n\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\ - \x06\x02\n\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x06\x0b\x11\n\x0c\n\x05\ - \x04\0\x02\x01\x01\x12\x03\x06\x12\x1e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ - \x03\x06!\"\n\xe3\x01\n\x04\x04\0\x02\x02\x12\x03\x0b\x02\x1f\x1a\xd5\ - \x01\x20publicKey\x20is\x20this\x20node's\x20public\x20key\x20(which\x20\ - also\x20gives\x20its\x20node.ID)\n\x20-\x20may\x20not\x20need\x20to\x20b\ - e\x20sent,\x20as\x20secure\x20channel\x20implies\x20it\x20has\x20been\ - \x20sent.\n\x20-\x20then\x20again,\x20if\x20we\x20change\x20/\x20disable\ - \x20secure\x20channel,\x20may\x20still\x20want\x20it.\n\n\x0c\n\x05\x04\ - \0\x02\x02\x04\x12\x03\x0b\x02\n\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\ - \x0b\x0b\x10\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x0b\x11\x1a\n\x0c\n\ - \x05\x04\0\x02\x02\x03\x12\x03\x0b\x1d\x1e\n]\n\x04\x04\0\x02\x03\x12\ - \x03\x0e\x02!\x1aP\x20listenAddrs\x20are\x20the\x20multiaddrs\x20the\x20\ - sender\x20node\x20listens\x20for\x20open\x20connections\x20on\n\n\x0c\n\ - \x05\x04\0\x02\x03\x04\x12\x03\x0e\x02\n\n\x0c\n\x05\x04\0\x02\x03\x05\ - \x12\x03\x0e\x0b\x10\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x0e\x11\x1c\n\ - \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x0e\x1f\x20\n\x81\x02\n\x04\x04\0\ - \x02\x04\x12\x03\x13\x02\"\x1a\xf3\x01\x20oservedAddr\x20is\x20the\x20mu\ - ltiaddr\x20of\x20the\x20remote\x20endpoint\x20that\x20the\x20sender\x20n\ - ode\x20perceives\n\x20this\x20is\x20useful\x20information\x20to\x20conve\ - y\x20to\x20the\x20other\x20side,\x20as\x20it\x20helps\x20the\x20remote\ - \x20endpoint\n\x20determine\x20whether\x20its\x20connection\x20to\x20the\ - \x20local\x20peer\x20goes\x20through\x20NAT.\n\n\x0c\n\x05\x04\0\x02\x04\ - \x04\x12\x03\x13\x02\n\n\x0c\n\x05\x04\0\x02\x04\x05\x12\x03\x13\x0b\x10\ - \n\x0c\n\x05\x04\0\x02\x04\x01\x12\x03\x13\x11\x1d\n\x0c\n\x05\x04\0\x02\ - \x04\x03\x12\x03\x13\x20!\n\x0b\n\x04\x04\0\x02\x05\x12\x03\x15\x02\x20\ - \n\x0c\n\x05\x04\0\x02\x05\x04\x12\x03\x15\x02\n\n\x0c\n\x05\x04\0\x02\ - \x05\x05\x12\x03\x15\x0b\x11\n\x0c\n\x05\x04\0\x02\x05\x01\x12\x03\x15\ - \x12\x1b\n\x0c\n\x05\x04\0\x02\x05\x03\x12\x03\x15\x1e\x1f\ + \n\x11src/structs.proto\"\xda\x01\n\x08Identify\x12(\n\x0fprotocolVersio\ + n\x18\x05\x20\x01(\tR\x0fprotocolVersion\x12\"\n\x0cagentVersion\x18\x06\ + \x20\x01(\tR\x0cagentVersion\x12\x1c\n\tpublicKey\x18\x01\x20\x01(\x0cR\ + \tpublicKey\x12\x20\n\x0blistenAddrs\x18\x02\x20\x03(\x0cR\x0blistenAddr\ + s\x12\"\n\x0cobservedAddr\x18\x04\x20\x01(\x0cR\x0cobservedAddr\x12\x1c\ + \n\tprotocols\x18\x03\x20\x03(\tR\tprotocolsJ\xcc\t\n\x06\x12\x04\0\0\ + \x18\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\ + \x18\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x10\nX\n\x04\x04\0\x02\0\ + \x12\x03\x04\x02&\x1a8\x20protocolVersion\x20determines\x20compatibility\ + \x20between\x20peers\n\"\x11\x20e.g.\x20ipfs/1.0.0\n\n\x0c\n\x05\x04\0\ + \x02\0\x04\x12\x03\x04\x02\n\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x04\x0b\ + \x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x04\x12!\n\x0c\n\x05\x04\0\x02\ + \0\x03\x12\x03\x04$%\n\x9f\x01\n\x04\x04\0\x02\x01\x12\x03\x08\x02#\x1a|\ + \x20agentVersion\x20is\x20like\x20a\x20UserAgent\x20string\x20in\x20brow\ + sers,\x20or\x20client\x20version\x20in\x20bittorrent\n\x20includes\x20th\ + e\x20client\x20name\x20and\x20client.\n\"\x14\x20e.g.\x20go-ipfs/0.1.0\n\ + \n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x08\x02\n\n\x0c\n\x05\x04\0\x02\ + \x01\x05\x12\x03\x08\x0b\x11\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x08\ + \x12\x1e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x08!\"\n\xe3\x01\n\x04\ + \x04\0\x02\x02\x12\x03\r\x02\x1f\x1a\xd5\x01\x20publicKey\x20is\x20this\ + \x20node's\x20public\x20key\x20(which\x20also\x20gives\x20its\x20node.ID\ + )\n\x20-\x20may\x20not\x20need\x20to\x20be\x20sent,\x20as\x20secure\x20c\ + hannel\x20implies\x20it\x20has\x20been\x20sent.\n\x20-\x20then\x20again,\ + \x20if\x20we\x20change\x20/\x20disable\x20secure\x20channel,\x20may\x20s\ + till\x20want\x20it.\n\n\x0c\n\x05\x04\0\x02\x02\x04\x12\x03\r\x02\n\n\ + \x0c\n\x05\x04\0\x02\x02\x05\x12\x03\r\x0b\x10\n\x0c\n\x05\x04\0\x02\x02\ + \x01\x12\x03\r\x11\x1a\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\r\x1d\x1e\n\ + ]\n\x04\x04\0\x02\x03\x12\x03\x10\x02!\x1aP\x20listenAddrs\x20are\x20the\ + \x20multiaddrs\x20the\x20sender\x20node\x20listens\x20for\x20open\x20con\ + nections\x20on\n\n\x0c\n\x05\x04\0\x02\x03\x04\x12\x03\x10\x02\n\n\x0c\n\ + \x05\x04\0\x02\x03\x05\x12\x03\x10\x0b\x10\n\x0c\n\x05\x04\0\x02\x03\x01\ + \x12\x03\x10\x11\x1c\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x10\x1f\x20\n\ + \x81\x02\n\x04\x04\0\x02\x04\x12\x03\x15\x02\"\x1a\xf3\x01\x20oservedAdd\ + r\x20is\x20the\x20multiaddr\x20of\x20the\x20remote\x20endpoint\x20that\ + \x20the\x20sender\x20node\x20perceives\n\x20this\x20is\x20useful\x20info\ + rmation\x20to\x20convey\x20to\x20the\x20other\x20side,\x20as\x20it\x20he\ + lps\x20the\x20remote\x20endpoint\n\x20determine\x20whether\x20its\x20con\ + nection\x20to\x20the\x20local\x20peer\x20goes\x20through\x20NAT.\n\n\x0c\ + \n\x05\x04\0\x02\x04\x04\x12\x03\x15\x02\n\n\x0c\n\x05\x04\0\x02\x04\x05\ + \x12\x03\x15\x0b\x10\n\x0c\n\x05\x04\0\x02\x04\x01\x12\x03\x15\x11\x1d\n\ + \x0c\n\x05\x04\0\x02\x04\x03\x12\x03\x15\x20!\n\x0b\n\x04\x04\0\x02\x05\ + \x12\x03\x17\x02\x20\n\x0c\n\x05\x04\0\x02\x05\x04\x12\x03\x17\x02\n\n\ + \x0c\n\x05\x04\0\x02\x05\x05\x12\x03\x17\x0b\x11\n\x0c\n\x05\x04\0\x02\ + \x05\x01\x12\x03\x17\x12\x1b\n\x0c\n\x05\x04\0\x02\x05\x03\x12\x03\x17\ + \x1e\x1f\ "; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index ccd796f6..efd44241 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -21,7 +21,7 @@ libp2p-core = { version = "0.12.0", path = "../../core" } libp2p-swarm = { version = "0.2.0", path = "../../swarm" } multiaddr = { package = "parity-multiaddr", version = "0.5.0", path = "../../misc/multiaddr" } multihash = { package = "parity-multihash", version = "0.1.0", path = "../../misc/multihash" } -protobuf = "2.3" +protobuf = "2.8" rand = "0.6.0" sha2 = "0.8.0" smallvec = "0.6" diff --git a/protocols/kad/regen_dht_proto.sh b/protocols/kad/regen_dht_proto.sh index 703ed009..0747c2a6 100755 --- a/protocols/kad/regen_dht_proto.sh +++ b/protocols/kad/regen_dht_proto.sh @@ -1,13 +1,3 @@ #!/bin/sh -# This script regenerates the `src/dht_proto.rs` file from `dht.proto`. - -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.6.0 protobuf-codegen; \ - protoc --rust_out . dht.proto;" - -sudo chown $USER:$USER *.rs - -mv -f dht.rs ./src/protobuf_structs/dht.rs +../../scripts/protobuf/gen.sh src/dht.proto diff --git a/protocols/kad/dht.proto b/protocols/kad/src/dht.proto similarity index 100% rename from protocols/kad/dht.proto rename to protocols/kad/src/dht.proto diff --git a/protocols/kad/src/protobuf_structs/dht.rs b/protocols/kad/src/dht_proto.rs similarity index 90% rename from protocols/kad/src/protobuf_structs/dht.rs rename to protocols/kad/src/dht_proto.rs index 97dcf105..3154d78b 100644 --- a/protocols/kad/src/protobuf_structs/dht.rs +++ b/protocols/kad/src/dht_proto.rs @@ -1,9 +1,9 @@ -// This file is generated by rust-protobuf 2.6.0. Do not edit +// This file is generated by rust-protobuf 2.8.1. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 #![allow(unknown_lints)] -#![allow(clippy)] +#![allow(clippy::all)] #![cfg_attr(rustfmt, rustfmt_skip)] @@ -17,10 +17,15 @@ #![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `src/dht.proto` use protobuf::Message as Message_imported_for_functions; use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1; + #[derive(PartialEq,Clone,Default)] pub struct Record { // message fields @@ -170,7 +175,7 @@ impl ::protobuf::Message for Record { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -225,7 +230,7 @@ impl ::protobuf::Message for Record { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if !self.key.is_empty() { os.write_bytes(1, &self.key)?; } @@ -257,13 +262,13 @@ impl ::protobuf::Message for Record { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -340,7 +345,7 @@ impl ::protobuf::Clear for Record { } impl ::std::fmt::Debug for Record { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } @@ -536,7 +541,7 @@ impl ::protobuf::Message for Message { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -600,7 +605,7 @@ impl ::protobuf::Message for Message { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if self.field_type != Message_MessageType::PUT_VALUE { os.write_enum(1, self.field_type.value())?; } @@ -641,13 +646,13 @@ impl ::protobuf::Message for Message { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -730,7 +735,7 @@ impl ::protobuf::Clear for Message { } impl ::std::fmt::Debug for Message { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } @@ -835,7 +840,7 @@ impl ::protobuf::Message for Message_Peer { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -874,7 +879,7 @@ impl ::protobuf::Message for Message_Peer { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if !self.id.is_empty() { os.write_bytes(1, &self.id)?; } @@ -900,13 +905,13 @@ impl ::protobuf::Message for Message_Peer { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -971,7 +976,7 @@ impl ::protobuf::Clear for Message_Peer { } impl ::std::fmt::Debug for Message_Peer { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } @@ -1111,43 +1116,43 @@ impl ::protobuf::reflect::ProtobufValue for Message_ConnectionType { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\tdht.proto\x12\x06dht.pb\"\x86\x01\n\x06Record\x12\x10\n\x03key\x18\ - \x01\x20\x01(\x0cR\x03key\x12\x14\n\x05value\x18\x02\x20\x01(\x0cR\x05va\ - lue\x12\"\n\x0ctimeReceived\x18\x05\x20\x01(\tR\x0ctimeReceived\x12\x1d\ - \n\tpublisher\x18\x9a\x05\x20\x01(\x0cR\tpublisher\x12\x11\n\x03ttl\x18\ - \x89\x06\x20\x01(\rR\x03ttl\"\xc4\x04\n\x07Message\x12/\n\x04type\x18\ - \x01\x20\x01(\x0e2\x1b.dht.pb.Message.MessageTypeR\x04type\x12(\n\x0fclu\ - sterLevelRaw\x18\n\x20\x01(\x05R\x0fclusterLevelRaw\x12\x10\n\x03key\x18\ - \x02\x20\x01(\x0cR\x03key\x12&\n\x06record\x18\x03\x20\x01(\x0b2\x0e.dht\ - .pb.RecordR\x06record\x126\n\x0bcloserPeers\x18\x08\x20\x03(\x0b2\x14.dh\ - t.pb.Message.PeerR\x0bcloserPeers\x12:\n\rproviderPeers\x18\t\x20\x03(\ - \x0b2\x14.dht.pb.Message.PeerR\rproviderPeers\x1al\n\x04Peer\x12\x0e\n\ - \x02id\x18\x01\x20\x01(\x0cR\x02id\x12\x14\n\x05addrs\x18\x02\x20\x03(\ - \x0cR\x05addrs\x12>\n\nconnection\x18\x03\x20\x01(\x0e2\x1e.dht.pb.Messa\ - ge.ConnectionTypeR\nconnection\"i\n\x0bMessageType\x12\r\n\tPUT_VALUE\ - \x10\0\x12\r\n\tGET_VALUE\x10\x01\x12\x10\n\x0cADD_PROVIDER\x10\x02\x12\ - \x11\n\rGET_PROVIDERS\x10\x03\x12\r\n\tFIND_NODE\x10\x04\x12\x08\n\x04PI\ - NG\x10\x05\"W\n\x0eConnectionType\x12\x11\n\rNOT_CONNECTED\x10\0\x12\r\n\ - \tCONNECTED\x10\x01\x12\x0f\n\x0bCAN_CONNECT\x10\x02\x12\x12\n\x0eCANNOT\ - _CONNECT\x10\x03J\xbe\x18\n\x06\x12\x04\0\0X\x01\n\x08\n\x01\x0c\x12\x03\ - \0\0\x12\n\x08\n\x01\x02\x12\x03\x01\x08\x0e\nX\n\x02\x04\0\x12\x04\x05\ - \0\x1c\x01\x1aL\x20Record\x20represents\x20a\x20dht\x20record\x20that\ - \x20contains\x20a\x20value\n\x20for\x20a\x20key\x20value\x20pair\n\n\n\n\ - \x03\x04\0\x01\x12\x03\x05\x08\x0e\n2\n\x04\x04\0\x02\0\x12\x03\x07\x08\ - \x16\x1a%\x20The\x20key\x20that\x20references\x20this\x20record\n\n\r\n\ - \x05\x04\0\x02\0\x04\x12\x04\x07\x08\x05\x10\n\x0c\n\x05\x04\0\x02\0\x05\ - \x12\x03\x07\x08\r\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x07\x0e\x11\n\x0c\ - \n\x05\x04\0\x02\0\x03\x12\x03\x07\x14\x15\n6\n\x04\x04\0\x02\x01\x12\ - \x03\n\x08\x18\x1a)\x20The\x20actual\x20value\x20this\x20record\x20is\ - \x20storing\n\n\r\n\x05\x04\0\x02\x01\x04\x12\x04\n\x08\x07\x16\n\x0c\n\ - \x05\x04\0\x02\x01\x05\x12\x03\n\x08\r\n\x0c\n\x05\x04\0\x02\x01\x01\x12\ - \x03\n\x0e\x13\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\n\x16\x17\n\xfc\x01\ - \n\x04\x04\0\x02\x02\x12\x03\x13\x08\x20\x1a/\x20Time\x20the\x20record\ - \x20was\x20received,\x20set\x20by\x20receiver\n2\xbd\x01\x20Note:\x20The\ - se\x20fields\x20were\x20removed\x20from\x20the\x20Record\x20message\n\ - \x20hash\x20of\x20the\x20authors\x20public\x20key\noptional\x20string\ - \x20author\x20=\x203;\n\x20A\x20PKI\x20signature\x20for\x20the\x20key+va\ - lue+author\noptional\x20bytes\x20signature\x20=\x204;\n\n\r\n\x05\x04\0\ + \n\rsrc/dht.proto\x12\x06dht.pb\"\x86\x01\n\x06Record\x12\x10\n\x03key\ + \x18\x01\x20\x01(\x0cR\x03key\x12\x14\n\x05value\x18\x02\x20\x01(\x0cR\ + \x05value\x12\"\n\x0ctimeReceived\x18\x05\x20\x01(\tR\x0ctimeReceived\ + \x12\x1d\n\tpublisher\x18\x9a\x05\x20\x01(\x0cR\tpublisher\x12\x11\n\x03\ + ttl\x18\x89\x06\x20\x01(\rR\x03ttl\"\xc4\x04\n\x07Message\x12/\n\x04type\ + \x18\x01\x20\x01(\x0e2\x1b.dht.pb.Message.MessageTypeR\x04type\x12(\n\ + \x0fclusterLevelRaw\x18\n\x20\x01(\x05R\x0fclusterLevelRaw\x12\x10\n\x03\ + key\x18\x02\x20\x01(\x0cR\x03key\x12&\n\x06record\x18\x03\x20\x01(\x0b2\ + \x0e.dht.pb.RecordR\x06record\x126\n\x0bcloserPeers\x18\x08\x20\x03(\x0b\ + 2\x14.dht.pb.Message.PeerR\x0bcloserPeers\x12:\n\rproviderPeers\x18\t\ + \x20\x03(\x0b2\x14.dht.pb.Message.PeerR\rproviderPeers\x1al\n\x04Peer\ + \x12\x0e\n\x02id\x18\x01\x20\x01(\x0cR\x02id\x12\x14\n\x05addrs\x18\x02\ + \x20\x03(\x0cR\x05addrs\x12>\n\nconnection\x18\x03\x20\x01(\x0e2\x1e.dht\ + .pb.Message.ConnectionTypeR\nconnection\"i\n\x0bMessageType\x12\r\n\tPUT\ + _VALUE\x10\0\x12\r\n\tGET_VALUE\x10\x01\x12\x10\n\x0cADD_PROVIDER\x10\ + \x02\x12\x11\n\rGET_PROVIDERS\x10\x03\x12\r\n\tFIND_NODE\x10\x04\x12\x08\ + \n\x04PING\x10\x05\"W\n\x0eConnectionType\x12\x11\n\rNOT_CONNECTED\x10\0\ + \x12\r\n\tCONNECTED\x10\x01\x12\x0f\n\x0bCAN_CONNECT\x10\x02\x12\x12\n\ + \x0eCANNOT_CONNECT\x10\x03J\xbe\x18\n\x06\x12\x04\0\0X\x01\n\x08\n\x01\ + \x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x01\x08\x0e\nX\n\x02\x04\0\ + \x12\x04\x05\0\x1c\x01\x1aL\x20Record\x20represents\x20a\x20dht\x20recor\ + d\x20that\x20contains\x20a\x20value\n\x20for\x20a\x20key\x20value\x20pai\ + r\n\n\n\n\x03\x04\0\x01\x12\x03\x05\x08\x0e\n2\n\x04\x04\0\x02\0\x12\x03\ + \x07\x08\x16\x1a%\x20The\x20key\x20that\x20references\x20this\x20record\ + \n\n\r\n\x05\x04\0\x02\0\x04\x12\x04\x07\x08\x05\x10\n\x0c\n\x05\x04\0\ + \x02\0\x05\x12\x03\x07\x08\r\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x07\x0e\ + \x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x07\x14\x15\n6\n\x04\x04\0\x02\ + \x01\x12\x03\n\x08\x18\x1a)\x20The\x20actual\x20value\x20this\x20record\ + \x20is\x20storing\n\n\r\n\x05\x04\0\x02\x01\x04\x12\x04\n\x08\x07\x16\n\ + \x0c\n\x05\x04\0\x02\x01\x05\x12\x03\n\x08\r\n\x0c\n\x05\x04\0\x02\x01\ + \x01\x12\x03\n\x0e\x13\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\n\x16\x17\n\ + \xfc\x01\n\x04\x04\0\x02\x02\x12\x03\x13\x08\x20\x1a/\x20Time\x20the\x20\ + record\x20was\x20received,\x20set\x20by\x20receiver\n2\xbd\x01\x20Note:\ + \x20These\x20fields\x20were\x20removed\x20from\x20the\x20Record\x20messa\ + ge\n\x20hash\x20of\x20the\x20authors\x20public\x20key\noptional\x20strin\ + g\x20author\x20=\x203;\n\x20A\x20PKI\x20signature\x20for\x20the\x20key+v\ + alue+author\noptional\x20bytes\x20signature\x20=\x204;\n\n\r\n\x05\x04\0\ \x02\x02\x04\x12\x04\x13\x08\n\x18\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\ \x13\x08\x0e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x13\x0f\x1b\n\x0c\n\ \x05\x04\0\x02\x02\x03\x12\x03\x13\x1e\x1f\nX\n\x04\x04\0\x02\x03\x12\ diff --git a/protocols/kad/src/lib.rs b/protocols/kad/src/lib.rs index e5ee1b69..b20a6e02 100644 --- a/protocols/kad/src/lib.rs +++ b/protocols/kad/src/lib.rs @@ -32,7 +32,7 @@ pub mod record; mod addresses; mod behaviour; mod jobs; -mod protobuf_structs; +mod dht_proto; mod query; pub use addresses::Addresses; diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 68984a47..3f937929 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -32,7 +32,7 @@ use bytes::BytesMut; use codec::UviBytes; -use crate::protobuf_structs::dht as proto; +use crate::dht_proto as proto; use crate::record::{self, Record}; use futures::prelude::*; use futures_codec::Framed; diff --git a/protocols/noise/Cargo.toml b/protocols/noise/Cargo.toml index 724f1baf..86ee6442 100644 --- a/protocols/noise/Cargo.toml +++ b/protocols/noise/Cargo.toml @@ -14,17 +14,17 @@ futures-preview = "0.3.0-alpha.18" lazy_static = "1.2" libp2p-core = { version = "0.12.0", path = "../../core" } log = "0.4" -protobuf = "2.3" -rand = "0.6.5" -ring = { version = "0.14", features = ["use_heap"], default-features = false } -snow = { version = "0.5.2", features = ["ring-resolver"], default-features = false } +protobuf = "2.8" +rand = "^0.7" +ring = { version = "^0.16", features = ["alloc"], default-features = false } +snow = { version = "0.6.1", features = ["ring-resolver"], default-features = false } tokio-io = "0.1" x25519-dalek = "0.5" -zeroize = "0.9" +zeroize = "1" [dev-dependencies] env_logger = "0.6" libp2p-tcp = { version = "0.12.0", path = "../../transports/tcp" } quickcheck = "0.8" tokio = "0.1" -sodiumoxide = "0.2" +sodiumoxide = "^0.2.5" diff --git a/protocols/noise/make_proto.sh b/protocols/noise/make_proto.sh deleted file mode 100755 index 5819ebfa..00000000 --- a/protocols/noise/make_proto.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -sudo 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 ./src/io/handshake/ ./src/io/handshake/payload.proto" - -sudo chown $USER:$USER ./src/io/handshake/payload.rs diff --git a/protocols/noise/regen_structs_proto.sh b/protocols/noise/regen_structs_proto.sh new file mode 100755 index 00000000..3e694f56 --- /dev/null +++ b/protocols/noise/regen_structs_proto.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +../../scripts/protobuf/gen.sh ./src/io/handshake/payload.proto diff --git a/protocols/noise/src/error.rs b/protocols/noise/src/error.rs index b074a45c..a3972e27 100644 --- a/protocols/noise/src/error.rs +++ b/protocols/noise/src/error.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use libp2p_core::identity; -use snow::SnowError; +use snow::error::Error as SnowError; use std::{error::Error, fmt, io}; /// libp2p_noise error type. diff --git a/protocols/noise/src/io.rs b/protocols/noise/src/io.rs index a6fb4143..03964042 100644 --- a/protocols/noise/src/io.rs +++ b/protocols/noise/src/io.rs @@ -55,12 +55,48 @@ impl Buffer { } } +/// A passthrough enum for the two kinds of state machines in `snow` +pub(crate) enum SnowState { + Transport(snow::TransportState), + Handshake(snow::HandshakeState) +} + +impl SnowState { + pub fn read_message(&mut self, message: &[u8], payload: &mut [u8]) -> Result { + match self { + SnowState::Handshake(session) => session.read_message(message, payload), + SnowState::Transport(session) => session.read_message(message, payload), + } + } + + pub fn write_message(&mut self, message: &[u8], payload: &mut [u8]) -> Result { + match self { + SnowState::Handshake(session) => session.write_message(message, payload), + SnowState::Transport(session) => session.write_message(message, payload), + } + } + + pub fn get_remote_static(&self) -> Option<&[u8]> { + match self { + SnowState::Handshake(session) => session.get_remote_static(), + SnowState::Transport(session) => session.get_remote_static(), + } + } + + pub fn into_transport_mode(self) -> Result { + match self { + SnowState::Handshake(session) => session.into_transport_mode(), + SnowState::Transport(_) => Err(SnowError::State(StateProblem::HandshakeAlreadyFinished)), + } + } +} + /// A noise session to a remote. /// /// `T` is the type of the underlying I/O resource. pub struct NoiseOutput { io: T, - session: snow::Session, + session: SnowState, buffer: Buffer, read_state: ReadState, write_state: WriteState @@ -76,9 +112,10 @@ impl fmt::Debug for NoiseOutput { } impl NoiseOutput { - fn new(io: T, session: snow::Session) -> Self { + fn new(io: T, session: SnowState) -> Self { NoiseOutput { - io, session, + io, + session, buffer: Buffer { inner: Box::new([0; TOTAL_BUFFER_LEN]) }, read_state: ReadState::Init, write_state: WriteState::Init diff --git a/protocols/noise/src/io/handshake.rs b/protocols/noise/src/io/handshake.rs index f11d6c99..ff966877 100644 --- a/protocols/noise/src/io/handshake.rs +++ b/protocols/noise/src/io/handshake.rs @@ -20,10 +20,11 @@ //! Noise protocol handshake I/O. -mod payload; +mod payload_proto; use crate::error::NoiseError; use crate::protocol::{Protocol, PublicKey, KeypairIdentity}; +use crate::io::SnowState; use libp2p_core::identity; use futures::prelude::*; use futures::task; @@ -271,7 +272,7 @@ impl State { /// Noise handshake pattern. fn new( io: T, - session: Result, + session: Result, identity: KeypairIdentity, identity_x: IdentityExchange ) -> Result { @@ -284,7 +285,7 @@ impl State { session.map(|s| State { identity, - io: NoiseOutput::new(io, s), + io: NoiseOutput::new(io, SnowState::Handshake(s)), dh_remote_pubkey_sig: None, id_remote_pubkey, send_identity @@ -322,7 +323,7 @@ impl State } } }; - Ok((remote, NoiseOutput { session: s, .. self.io })) + Ok((remote, NoiseOutput { session: SnowState::Transport(s), .. self.io })) } } } diff --git a/protocols/noise/src/io/handshake/payload.rs b/protocols/noise/src/io/handshake/payload_proto.rs similarity index 89% rename from protocols/noise/src/io/handshake/payload.rs rename to protocols/noise/src/io/handshake/payload_proto.rs index 3e9bdb34..14583f54 100644 --- a/protocols/noise/src/io/handshake/payload.rs +++ b/protocols/noise/src/io/handshake/payload_proto.rs @@ -1,9 +1,9 @@ -// This file is generated by rust-protobuf 2.3.0. Do not edit +// This file is generated by rust-protobuf 2.8.1. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 #![allow(unknown_lints)] -#![allow(clippy)] +#![allow(clippy::all)] #![cfg_attr(rustfmt, rustfmt_skip)] @@ -17,10 +17,15 @@ #![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `src/io/handshake/payload.proto` use protobuf::Message as Message_imported_for_functions; use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1; + #[derive(PartialEq,Clone,Default)] pub struct Identity { // message fields @@ -31,6 +36,12 @@ pub struct Identity { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Identity { + fn default() -> &'a Identity { + ::default_instance() + } +} + impl Identity { pub fn new() -> Identity { ::std::default::Default::default() @@ -38,6 +49,10 @@ impl Identity { // bytes pubkey = 1; + + pub fn get_pubkey(&self) -> &[u8] { + &self.pubkey + } pub fn clear_pubkey(&mut self) { self.pubkey.clear(); } @@ -58,12 +73,12 @@ impl Identity { ::std::mem::replace(&mut self.pubkey, ::std::vec::Vec::new()) } - pub fn get_pubkey(&self) -> &[u8] { - &self.pubkey - } - // bytes signature = 2; + + pub fn get_signature(&self) -> &[u8] { + &self.signature + } pub fn clear_signature(&mut self) { self.signature.clear(); } @@ -83,10 +98,6 @@ impl Identity { pub fn take_signature(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) } - - pub fn get_signature(&self) -> &[u8] { - &self.signature - } } impl ::protobuf::Message for Identity { @@ -94,7 +105,7 @@ impl ::protobuf::Message for Identity { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -127,7 +138,7 @@ impl ::protobuf::Message for Identity { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if !self.pubkey.is_empty() { os.write_bytes(1, &self.pubkey)?; } @@ -150,13 +161,13 @@ impl ::protobuf::Message for Identity { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -208,14 +219,14 @@ impl ::protobuf::Message for Identity { impl ::protobuf::Clear for Identity { fn clear(&mut self) { - self.clear_pubkey(); - self.clear_signature(); + self.pubkey.clear(); + self.signature.clear(); self.unknown_fields.clear(); } } impl ::std::fmt::Debug for Identity { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } diff --git a/protocols/noise/src/protocol.rs b/protocols/noise/src/protocol.rs index 50d7ffc6..4908c6be 100644 --- a/protocols/noise/src/protocol.rs +++ b/protocols/noise/src/protocol.rs @@ -24,7 +24,7 @@ pub mod x25519; use crate::NoiseError; use libp2p_core::identity; -use rand::FromEntropy; +use rand::SeedableRng; use zeroize::Zeroize; /// The parameters of a Noise protocol, consisting of a choice diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index a05d5d60..f3e58f65 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -10,7 +10,11 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] +bytes = "0.4" futures-preview = "0.3.0-alpha.18" libp2p-core = { version = "0.12.0", path = "../../core" } +log = "0.4.6" void = "1" - +tokio-io = "0.1.12" +protobuf = "2.3" +rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } diff --git a/protocols/plaintext/regen_structs_proto.sh b/protocols/plaintext/regen_structs_proto.sh new file mode 100755 index 00000000..9ac7ab8f --- /dev/null +++ b/protocols/plaintext/regen_structs_proto.sh @@ -0,0 +1,8 @@ +#!/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;" + diff --git a/protocols/plaintext/src/error.rs b/protocols/plaintext/src/error.rs new file mode 100644 index 00000000..2f221763 --- /dev/null +++ b/protocols/plaintext/src/error.rs @@ -0,0 +1,75 @@ +// 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), + + /// Failed to parse the handshake protobuf message. + InvalidPayload(Option), + + /// The peer id of the exchange isn't consistent with the remote public key. + InvalidPeerId, +} + +impl error::Error for PlainTextError { + fn cause(&self) -> Option<&dyn error::Error> { + match *self { + PlainTextError::IoError(ref err) => Some(err), + PlainTextError::InvalidPayload(Some(ref err)) => Some(err), + _ => None, + } + } +} + +impl fmt::Display for PlainTextError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + match self { + PlainTextError::IoError(e) => + write!(f, "I/O error: {}", e), + PlainTextError::InvalidPayload(protobuf_error) => { + match protobuf_error { + Some(e) => write!(f, "Protobuf error: {}", e), + None => f.write_str("Failed to parse one of the handshake protobuf messages") + } + }, + PlainTextError::InvalidPeerId => + f.write_str("The peer id of the exchange isn't consistent with the remote public key"), + } + } +} + +impl From for PlainTextError { + fn from(err: IoError) -> PlainTextError { + PlainTextError::IoError(err) + } +} + +impl From for PlainTextError { + fn from(err: ProtobufError) -> PlainTextError { + PlainTextError::InvalidPayload(Some(err)) + } +} diff --git a/protocols/plaintext/src/handshake.rs b/protocols/plaintext/src/handshake.rs new file mode 100644 index 00000000..8b073937 --- /dev/null +++ b/protocols/plaintext/src/handshake.rs @@ -0,0 +1,153 @@ +// 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::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 { + config: PlainText2Config, + state: T +} + +// HandshakeContext<()> --with_local-> HandshakeContext +struct Local { + // Our local exchange's raw bytes: + exchange_bytes: Vec, +} + +// HandshakeContext --with_remote-> HandshakeContext +pub struct Remote { + // The remote's peer ID: + pub peer_id: PeerId, + // The remote's public key: + pub public_key: PublicKey, +} + +impl HandshakeContext { + fn new(config: PlainText2Config) -> Result { + let mut exchange = Exchange::new(); + exchange.set_id(config.local_public_key.clone().into_peer_id().into_bytes()); + exchange.set_pubkey(config.local_public_key.clone().into_protobuf_encoding()); + let exchange_bytes = exchange.write_to_bytes()?; + + Ok(Self { + config, + state: Local { + exchange_bytes + } + }) + } + + fn with_remote(self, exchange_bytes: BytesMut) -> Result, PlainTextError> { + let mut prop = match protobuf::parse_from_bytes::(&exchange_bytes) { + Ok(prop) => prop, + Err(e) => { + debug!("failed to parse remote's exchange protobuf message"); + return Err(PlainTextError::InvalidPayload(Some(e))); + }, + }; + + let pb_pubkey = prop.take_pubkey(); + let public_key = match PublicKey::from_protobuf_encoding(pb_pubkey.as_slice()) { + Ok(p) => p, + Err(_) => { + debug!("failed to parse remote's exchange's pubkey protobuf"); + return Err(PlainTextError::InvalidPayload(None)); + }, + }; + let peer_id = match PeerId::from_bytes(prop.take_id()) { + Ok(p) => p, + Err(_) => { + debug!("failed to parse remote's exchange's id protobuf"); + return Err(PlainTextError::InvalidPayload(None)); + }, + }; + + // Check the validity of the remote's `Exchange`. + if peer_id != public_key.clone().into_peer_id() { + debug!("The remote's `PeerId` of the exchange isn't consist with the remote public key"); + return Err(PlainTextError::InvalidPeerId) + } + + Ok(HandshakeContext { + config: self.config, + state: Remote { + peer_id, + public_key, + } + }) + } +} + +pub fn handshake(socket: S, config: PlainText2Config) + -> impl Future, Remote), Error = PlainTextError> +where + S: AsyncRead + AsyncWrite + Send, +{ + let socket = length_delimited::Builder::new() + .big_endian() + .length_field_length(4) + .new_framed(socket); + + future::ok::<_, PlainTextError>(()) + .and_then(|_| { + trace!("starting handshake"); + Ok(HandshakeContext::new(config)?) + }) + // Send our local `Exchange`. + .and_then(|context| { + trace!("sending exchange to remote"); + socket.send(BytesMut::from(context.state.exchange_bytes.clone())) + .from_err() + .map(|s| (s, context)) + }) + // Receive the remote's `Exchange`. + .and_then(move |(socket, context)| { + trace!("receiving the remote's exchange"); + socket.into_future() + .map_err(|(e, _)| e.into()) + .and_then(move |(prop_raw, socket)| { + let context = match prop_raw { + Some(p) => context.with_remote(p)?, + None => { + debug!("unexpected eof while waiting for remote's exchange"); + let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof"); + return Err(err.into()); + } + }; + + trace!("received exchange from remote; pubkey = {:?}", context.state.public_key); + Ok((socket, context.state)) + }) + }) +} diff --git a/protocols/plaintext/src/lib.rs b/protocols/plaintext/src/lib.rs index c4cda8e6..e5605e11 100644 --- a/protocols/plaintext/src/lib.rs +++ b/protocols/plaintext/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018 Parity Technologies (UK) Ltd. +// 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"), @@ -21,12 +21,21 @@ use futures::future::{self, Ready}; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, upgrade::Negotiated}; use std::iter; +use tokio_io::{AsyncRead, AsyncWrite}; +use tokio_io::codec::length_delimited::Framed; +use crate::error::PlainTextError; use void::Void; +use futures::future::FutureResult; +use crate::handshake::Remote; + +mod error; +mod handshake; +mod pb; #[derive(Debug, Copy, Clone)] -pub struct PlainTextConfig; +pub struct PlainText1Config; -impl UpgradeInfo for PlainTextConfig { +impl UpgradeInfo for PlainText1Config { type Info = &'static [u8]; type InfoIter = iter::Once; @@ -35,7 +44,7 @@ impl UpgradeInfo for PlainTextConfig { } } -impl InboundUpgrade for PlainTextConfig { +impl InboundUpgrade for PlainText1Config { type Output = Negotiated; type Error = Void; type Future = Ready, Self::Error>>; @@ -45,7 +54,7 @@ impl InboundUpgrade for PlainTextConfig { } } -impl OutboundUpgrade for PlainTextConfig { +impl OutboundUpgrade for PlainText1Config { type Output = Negotiated; type Error = Void; type Future = Ready, Self::Error>>; @@ -55,3 +64,160 @@ impl OutboundUpgrade for PlainTextConfig { } } +#[derive(Clone)] +pub struct PlainText2Config { + pub local_public_key: identity::PublicKey, +} + +impl UpgradeInfo for PlainText2Config { + type Info = &'static [u8]; + type InfoIter = iter::Once; + + fn protocol_info(&self) -> Self::InfoIter { + iter::once(b"/plaintext/2.0.0") + } +} + +impl InboundUpgrade for PlainText2Config +where + C: AsyncRead + AsyncWrite + Send + 'static +{ + type Output = (PeerId, PlainTextOutput>); + type Error = PlainTextError; + type Future = Box + Send>; + + fn upgrade_inbound(self, socket: Negotiated, _: Self::Info) -> Self::Future { + Box::new(self.handshake(socket)) + } +} + +impl OutboundUpgrade for PlainText2Config +where + C: AsyncRead + AsyncWrite + Send + 'static +{ + type Output = (PeerId, PlainTextOutput>); + type Error = PlainTextError; + type Future = Box + Send>; + + fn upgrade_outbound(self, socket: Negotiated, _: Self::Info) -> Self::Future { + Box::new(self.handshake(socket)) + } +} + +impl PlainText2Config { + fn handshake(self, socket: T) -> impl Future), Error = PlainTextError> + where + T: AsyncRead + AsyncWrite + Send + 'static + { + debug!("Starting plaintext upgrade"); + PlainTextMiddleware::handshake(socket, self) + .map(|(stream_sink, remote)| { + let mapped = stream_sink.map_err(map_err as fn(_) -> _); + ( + remote.peer_id, + PlainTextOutput { + stream: RwStreamSink::new(mapped), + remote_key: remote.public_key, + } + ) + }) + } +} + +#[inline] +fn map_err(err: io::Error) -> io::Error { + debug!("error during plaintext handshake {:?}", err); + io::Error::new(io::ErrorKind::InvalidData, err) +} + +pub struct PlainTextMiddleware { + inner: Framed, +} + +impl PlainTextMiddleware +where + S: AsyncRead + AsyncWrite + Send, +{ + fn handshake(socket: S, config: PlainText2Config) + -> impl Future, Remote), Error = PlainTextError> + { + handshake::handshake(socket, config).map(|(inner, remote)| { + (PlainTextMiddleware { inner }, remote) + }) + } +} + +impl Sink for PlainTextMiddleware +where + S: AsyncRead + AsyncWrite, +{ + type SinkItem = BytesMut; + type SinkError = io::Error; + + #[inline] + fn start_send(&mut self, item: Self::SinkItem) -> StartSend { + self.inner.start_send(item) + } + + #[inline] + fn poll_complete(&mut self) -> Poll<(), Self::SinkError> { + self.inner.poll_complete() + } + + #[inline] + fn close(&mut self) -> Poll<(), Self::SinkError> { + self.inner.close() + } +} + +impl Stream for PlainTextMiddleware +where + S: AsyncRead + AsyncWrite, +{ + type Item = BytesMut; + type Error = io::Error; + + #[inline] + fn poll(&mut self) -> Poll, Self::Error> { + self.inner.poll() + } +} + +/// Output of the plaintext protocol. +pub struct PlainTextOutput +where + S: AsyncRead + AsyncWrite, +{ + /// The plaintext stream. + pub stream: RwStreamSink, fn(io::Error) -> io::Error>>, + /// The public key of the remote. + pub remote_key: PublicKey, +} + +impl std::io::Read for PlainTextOutput { + fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + self.stream.read(buf) + } +} + +impl AsyncRead for PlainTextOutput { + unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool { + self.stream.prepare_uninitialized_buffer(buf) + } +} + +impl std::io::Write for PlainTextOutput { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.stream.write(buf) + } + + fn flush(&mut self) -> std::io::Result<()> { + self.stream.flush() + } +} + +impl AsyncWrite for PlainTextOutput { + fn shutdown(&mut self) -> Poll<(), io::Error> { + self.stream.shutdown() + } +} diff --git a/protocols/kad/src/protobuf_structs/mod.rs b/protocols/plaintext/src/pb.rs similarity index 94% rename from protocols/kad/src/protobuf_structs/mod.rs rename to protocols/plaintext/src/pb.rs index 614bc875..64e83e5d 100644 --- a/protocols/kad/src/protobuf_structs/mod.rs +++ b/protocols/plaintext/src/pb.rs @@ -1,4 +1,4 @@ -// Copyright 2017 Parity Technologies (UK) Ltd. +// 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"), @@ -18,4 +18,4 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -pub mod dht; +pub mod structs; diff --git a/protocols/plaintext/src/pb/structs.rs b/protocols/plaintext/src/pb/structs.rs new file mode 100644 index 00000000..85da2b49 --- /dev/null +++ b/protocols/plaintext/src/pb/structs.rs @@ -0,0 +1,278 @@ +// This file is generated by rust-protobuf 2.3.0. Do not edit +// @generated + +// https://github.com/Manishearth/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy)] + +#![cfg_attr(rustfmt, rustfmt_skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unsafe_code)] +#![allow(unused_imports)] +#![allow(unused_results)] + +use protobuf::Message as Message_imported_for_functions; +use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; + +#[derive(PartialEq,Clone,Default)] +pub struct Exchange { + // message fields + id: ::protobuf::SingularField<::std::vec::Vec>, + pubkey: ::protobuf::SingularField<::std::vec::Vec>, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl Exchange { + pub fn new() -> Exchange { + ::std::default::Default::default() + } + + // optional bytes id = 1; + + pub fn clear_id(&mut self) { + self.id.clear(); + } + + pub fn has_id(&self) -> bool { + self.id.is_some() + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::vec::Vec) { + self.id = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::vec::Vec { + if self.id.is_none() { + self.id.set_default(); + } + self.id.as_mut().unwrap() + } + + // Take field + pub fn take_id(&mut self) -> ::std::vec::Vec { + self.id.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_id(&self) -> &[u8] { + match self.id.as_ref() { + Some(v) => &v, + None => &[], + } + } + + // optional bytes pubkey = 2; + + pub fn clear_pubkey(&mut self) { + self.pubkey.clear(); + } + + pub fn has_pubkey(&self) -> bool { + self.pubkey.is_some() + } + + // Param is passed by value, moved + pub fn set_pubkey(&mut self, v: ::std::vec::Vec) { + self.pubkey = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_pubkey(&mut self) -> &mut ::std::vec::Vec { + if self.pubkey.is_none() { + self.pubkey.set_default(); + } + self.pubkey.as_mut().unwrap() + } + + // Take field + pub fn take_pubkey(&mut self) -> ::std::vec::Vec { + self.pubkey.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_pubkey(&self) -> &[u8] { + match self.pubkey.as_ref() { + Some(v) => &v, + None => &[], + } + } +} + +impl ::protobuf::Message for Exchange { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.id)?; + }, + 2 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.pubkey)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if let Some(ref v) = self.id.as_ref() { + my_size += ::protobuf::rt::bytes_size(1, &v); + } + if let Some(ref v) = self.pubkey.as_ref() { + my_size += ::protobuf::rt::bytes_size(2, &v); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if let Some(ref v) = self.id.as_ref() { + os.write_bytes(1, &v)?; + } + if let Some(ref v) = self.pubkey.as_ref() { + os.write_bytes(2, &v)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> Exchange { + Exchange::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, + }; + unsafe { + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "id", + |m: &Exchange| { &m.id }, + |m: &mut Exchange| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "pubkey", + |m: &Exchange| { &m.pubkey }, + |m: &mut Exchange| { &mut m.pubkey }, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Exchange", + fields, + file_descriptor_proto() + ) + }) + } + } + + fn default_instance() -> &'static Exchange { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Exchange, + }; + unsafe { + instance.get(Exchange::new) + } + } +} + +impl ::protobuf::Clear for Exchange { + fn clear(&mut self) { + self.clear_id(); + self.clear_pubkey(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Exchange { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Exchange { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n!protocols/plaintext/structs.proto\"2\n\x08Exchange\x12\x0e\n\x02id\ + \x18\x01\x20\x01(\x0cR\x02id\x12\x16\n\x06pubkey\x18\x02\x20\x01(\x0cR\ + \x06pubkeyJ\xb4\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\x01\x0c\x12\x03\0\ + \0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\ + \x02\x08\x10\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x02\x18\n\x0c\n\x05\x04\ + \0\x02\0\x04\x12\x03\x03\x02\n\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\ + \x0b\x10\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x11\x13\n\x0c\n\x05\x04\ + \0\x02\0\x03\x12\x03\x03\x16\x17\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\ + \x02\x1c\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x04\x02\n\n\x0c\n\x05\x04\ + \0\x02\x01\x05\x12\x03\x04\x0b\x10\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\ + \x04\x11\x17\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x1a\x1b\ +"; + +static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, +}; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + unsafe { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) + } +} diff --git a/protocols/plaintext/structs.proto b/protocols/plaintext/structs.proto new file mode 100644 index 00000000..cf99ad02 --- /dev/null +++ b/protocols/plaintext/structs.proto @@ -0,0 +1,6 @@ +syntax = "proto2"; + +message Exchange { + optional bytes id = 1; + optional bytes pubkey = 2; +} diff --git a/protocols/secio/Cargo.toml b/protocols/secio/Cargo.toml index 8d1c8de1..8f241f79 100644 --- a/protocols/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -15,7 +15,7 @@ futures-preview = "0.3.0-alpha.18" futures_codec = "0.2.5" libp2p-core = { version = "0.12.0", path = "../../core" } log = "0.4.6" -protobuf = "2.3" +protobuf = "2.8" rand = "0.6.5" aes-ctr = "0.3" aesni = { version = "0.6", features = ["nocheck"], optional = true } @@ -28,7 +28,7 @@ hmac = "0.7.0" unsigned-varint = { git = "https://github.com/tomaka/unsigned-varint", branch = "futures-codec", features = ["codec"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -ring = { version = "0.14", features = ["use_heap"], default-features = false } +ring = { version = "^0.16", features = ["alloc"], default-features = false } untrusted = { version = "0.6" } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/protocols/secio/regen_structs_proto.sh b/protocols/secio/regen_structs_proto.sh index 621f0313..603ec9a8 100755 --- a/protocols/secio/regen_structs_proto.sh +++ b/protocols/secio/regen_structs_proto.sh @@ -1,13 +1,3 @@ #!/bin/sh -# This script regenerates the `src/structs_proto.rs` file from `structs.proto`. - -sudo 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 . structs.proto" - -sudo chown $USER:$USER *.rs - -mv -f structs.rs ./src/structs_proto.rs +../../scripts/protobuf/gen.sh src/structs.proto diff --git a/protocols/secio/src/exchange/impl_ring.rs b/protocols/secio/src/exchange/impl_ring.rs index 888dc963..b7f42be7 100644 --- a/protocols/secio/src/exchange/impl_ring.rs +++ b/protocols/secio/src/exchange/impl_ring.rs @@ -25,7 +25,6 @@ use futures::{future, prelude::*}; use log::debug; use ring::agreement as ring_agreement; use ring::rand as ring_rand; -use untrusted::Input as UntrustedInput; impl Into<&'static ring_agreement::Algorithm> for KeyAgreement { #[inline] @@ -64,8 +63,8 @@ pub fn generate_agreement(algorithm: KeyAgreement) -> impl Future impl Future, SecioError>> { - let ret = ring_agreement::agree_ephemeral(my_private_key, algorithm.into(), - UntrustedInput::from(other_public_key), + let ret = ring_agreement::agree_ephemeral(my_private_key, + &ring_agreement::UnparsedPublicKey::new(algorithm.into(), other_public_key), SecioError::SecretGenerationFailed, |key_material| Ok(key_material.to_vec())); future::ready(ret) diff --git a/protocols/secio/structs.proto b/protocols/secio/src/structs.proto similarity index 92% rename from protocols/secio/structs.proto rename to protocols/secio/src/structs.proto index bdd1eecc..a35de4c8 100644 --- a/protocols/secio/structs.proto +++ b/protocols/secio/src/structs.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package spipe.pb; message Propose { diff --git a/protocols/secio/src/structs_proto.rs b/protocols/secio/src/structs_proto.rs index fdc4316a..a5bb19e7 100644 --- a/protocols/secio/src/structs_proto.rs +++ b/protocols/secio/src/structs_proto.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.3.0. Do not edit +// This file is generated by rust-protobuf 2.8.1. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 @@ -17,10 +17,15 @@ #![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `src/structs.proto` use protobuf::Message as Message_imported_for_functions; use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1; + #[derive(PartialEq,Clone,Default)] pub struct Propose { // message fields @@ -34,6 +39,12 @@ pub struct Propose { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Propose { + fn default() -> &'a Propose { + ::default_instance() + } +} + impl Propose { pub fn new() -> Propose { ::std::default::Default::default() @@ -41,6 +52,13 @@ impl Propose { // optional bytes rand = 1; + + pub fn get_rand(&self) -> &[u8] { + match self.rand.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_rand(&mut self) { self.rand.clear(); } @@ -68,15 +86,15 @@ impl Propose { self.rand.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_rand(&self) -> &[u8] { - match self.rand.as_ref() { + // optional bytes pubkey = 2; + + + pub fn get_pubkey(&self) -> &[u8] { + match self.pubkey.as_ref() { Some(v) => &v, None => &[], } } - - // optional bytes pubkey = 2; - pub fn clear_pubkey(&mut self) { self.pubkey.clear(); } @@ -104,15 +122,15 @@ impl Propose { self.pubkey.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_pubkey(&self) -> &[u8] { - match self.pubkey.as_ref() { - Some(v) => &v, - None => &[], - } - } - // optional string exchanges = 3; + + pub fn get_exchanges(&self) -> &str { + match self.exchanges.as_ref() { + Some(v) => &v, + None => "", + } + } pub fn clear_exchanges(&mut self) { self.exchanges.clear(); } @@ -140,15 +158,15 @@ impl Propose { self.exchanges.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_exchanges(&self) -> &str { - match self.exchanges.as_ref() { + // optional string ciphers = 4; + + + pub fn get_ciphers(&self) -> &str { + match self.ciphers.as_ref() { Some(v) => &v, None => "", } } - - // optional string ciphers = 4; - pub fn clear_ciphers(&mut self) { self.ciphers.clear(); } @@ -176,15 +194,15 @@ impl Propose { self.ciphers.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_ciphers(&self) -> &str { - match self.ciphers.as_ref() { + // optional string hashes = 5; + + + pub fn get_hashes(&self) -> &str { + match self.hashes.as_ref() { Some(v) => &v, None => "", } } - - // optional string hashes = 5; - pub fn clear_hashes(&mut self) { self.hashes.clear(); } @@ -211,13 +229,6 @@ impl Propose { pub fn take_hashes(&mut self) -> ::std::string::String { self.hashes.take().unwrap_or_else(|| ::std::string::String::new()) } - - pub fn get_hashes(&self) -> &str { - match self.hashes.as_ref() { - Some(v) => &v, - None => "", - } - } } impl ::protobuf::Message for Propose { @@ -381,11 +392,11 @@ impl ::protobuf::Message for Propose { impl ::protobuf::Clear for Propose { fn clear(&mut self) { - self.clear_rand(); - self.clear_pubkey(); - self.clear_exchanges(); - self.clear_ciphers(); - self.clear_hashes(); + self.rand.clear(); + self.pubkey.clear(); + self.exchanges.clear(); + self.ciphers.clear(); + self.hashes.clear(); self.unknown_fields.clear(); } } @@ -397,7 +408,7 @@ impl ::std::fmt::Debug for Propose { } impl ::protobuf::reflect::ProtobufValue for Propose { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -412,6 +423,12 @@ pub struct Exchange { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Exchange { + fn default() -> &'a Exchange { + ::default_instance() + } +} + impl Exchange { pub fn new() -> Exchange { ::std::default::Default::default() @@ -419,6 +436,13 @@ impl Exchange { // optional bytes epubkey = 1; + + pub fn get_epubkey(&self) -> &[u8] { + match self.epubkey.as_ref() { + Some(v) => &v, + None => &[], + } + } pub fn clear_epubkey(&mut self) { self.epubkey.clear(); } @@ -446,15 +470,15 @@ impl Exchange { self.epubkey.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - pub fn get_epubkey(&self) -> &[u8] { - match self.epubkey.as_ref() { + // optional bytes signature = 2; + + + pub fn get_signature(&self) -> &[u8] { + match self.signature.as_ref() { Some(v) => &v, None => &[], } } - - // optional bytes signature = 2; - pub fn clear_signature(&mut self) { self.signature.clear(); } @@ -481,13 +505,6 @@ impl Exchange { pub fn take_signature(&mut self) -> ::std::vec::Vec { self.signature.take().unwrap_or_else(|| ::std::vec::Vec::new()) } - - pub fn get_signature(&self) -> &[u8] { - match self.signature.as_ref() { - Some(v) => &v, - None => &[], - } - } } impl ::protobuf::Message for Exchange { @@ -609,8 +626,8 @@ impl ::protobuf::Message for Exchange { impl ::protobuf::Clear for Exchange { fn clear(&mut self) { - self.clear_epubkey(); - self.clear_signature(); + self.epubkey.clear(); + self.signature.clear(); self.unknown_fields.clear(); } } @@ -622,45 +639,46 @@ impl ::std::fmt::Debug for Exchange { } impl ::protobuf::reflect::ProtobufValue for Exchange { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rstructs.proto\x12\x08spipe.pb\"\x85\x01\n\x07Propose\x12\x12\n\x04ra\ - nd\x18\x01\x20\x01(\x0cR\x04rand\x12\x16\n\x06pubkey\x18\x02\x20\x01(\ - \x0cR\x06pubkey\x12\x1c\n\texchanges\x18\x03\x20\x01(\tR\texchanges\x12\ - \x18\n\x07ciphers\x18\x04\x20\x01(\tR\x07ciphers\x12\x16\n\x06hashes\x18\ - \x05\x20\x01(\tR\x06hashes\"B\n\x08Exchange\x12\x18\n\x07epubkey\x18\x01\ - \x20\x01(\x0cR\x07epubkey\x12\x1c\n\tsignature\x18\x02\x20\x01(\x0cR\tsi\ - gnatureJ\xa5\x04\n\x06\x12\x04\0\0\r\x01\n\x08\n\x01\x02\x12\x03\0\x08\ - \x10\n\n\n\x02\x04\0\x12\x04\x02\0\x08\x01\n\n\n\x03\x04\0\x01\x12\x03\ - \x02\x08\x0f\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x08\x20\n\x0c\n\x05\x04\ - \0\x02\0\x04\x12\x03\x03\x08\x10\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\ - \x11\x16\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x17\x1b\n\x0c\n\x05\x04\ - \0\x02\0\x03\x12\x03\x03\x1e\x1f\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\ - \x08\"\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x04\x08\x10\n\x0c\n\x05\x04\ - \0\x02\x01\x05\x12\x03\x04\x11\x16\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\ - \x04\x17\x1d\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x20!\n\x0b\n\x04\ - \x04\0\x02\x02\x12\x03\x05\x08&\n\x0c\n\x05\x04\0\x02\x02\x04\x12\x03\ - \x05\x08\x10\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x11\x17\n\x0c\n\ - \x05\x04\0\x02\x02\x01\x12\x03\x05\x18!\n\x0c\n\x05\x04\0\x02\x02\x03\ - \x12\x03\x05$%\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x08$\n\x0c\n\x05\ - \x04\0\x02\x03\x04\x12\x03\x06\x08\x10\n\x0c\n\x05\x04\0\x02\x03\x05\x12\ - \x03\x06\x11\x17\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x18\x1f\n\x0c\ - \n\x05\x04\0\x02\x03\x03\x12\x03\x06\"#\n\x0b\n\x04\x04\0\x02\x04\x12\ - \x03\x07\x08#\n\x0c\n\x05\x04\0\x02\x04\x04\x12\x03\x07\x08\x10\n\x0c\n\ - \x05\x04\0\x02\x04\x05\x12\x03\x07\x11\x17\n\x0c\n\x05\x04\0\x02\x04\x01\ - \x12\x03\x07\x18\x1e\n\x0c\n\x05\x04\0\x02\x04\x03\x12\x03\x07!\"\n\n\n\ - \x02\x04\x01\x12\x04\n\0\r\x01\n\n\n\x03\x04\x01\x01\x12\x03\n\x08\x10\n\ - \x0b\n\x04\x04\x01\x02\0\x12\x03\x0b\x08#\n\x0c\n\x05\x04\x01\x02\0\x04\ - \x12\x03\x0b\x08\x10\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x0b\x11\x16\n\ - \x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x0b\x17\x1e\n\x0c\n\x05\x04\x01\x02\ - \0\x03\x12\x03\x0b!\"\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x0c\x08%\n\x0c\ - \n\x05\x04\x01\x02\x01\x04\x12\x03\x0c\x08\x10\n\x0c\n\x05\x04\x01\x02\ - \x01\x05\x12\x03\x0c\x11\x16\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x0c\ - \x17\x20\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x0c#$\ + \n\x11src/structs.proto\x12\x08spipe.pb\"\x85\x01\n\x07Propose\x12\x12\n\ + \x04rand\x18\x01\x20\x01(\x0cR\x04rand\x12\x16\n\x06pubkey\x18\x02\x20\ + \x01(\x0cR\x06pubkey\x12\x1c\n\texchanges\x18\x03\x20\x01(\tR\texchanges\ + \x12\x18\n\x07ciphers\x18\x04\x20\x01(\tR\x07ciphers\x12\x16\n\x06hashes\ + \x18\x05\x20\x01(\tR\x06hashes\"B\n\x08Exchange\x12\x18\n\x07epubkey\x18\ + \x01\x20\x01(\x0cR\x07epubkey\x12\x1c\n\tsignature\x18\x02\x20\x01(\x0cR\ + \tsignatureJ\xaf\x04\n\x06\x12\x04\0\0\x0f\x01\n\x08\n\x01\x0c\x12\x03\0\ + \0\x12\n\x08\n\x01\x02\x12\x03\x02\x08\x10\n\n\n\x02\x04\0\x12\x04\x04\0\ + \n\x01\n\n\n\x03\x04\0\x01\x12\x03\x04\x08\x0f\n\x0b\n\x04\x04\0\x02\0\ + \x12\x03\x05\x08\x20\n\x0c\n\x05\x04\0\x02\0\x04\x12\x03\x05\x08\x10\n\ + \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x05\x11\x16\n\x0c\n\x05\x04\0\x02\0\ + \x01\x12\x03\x05\x17\x1b\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x05\x1e\x1f\ + \n\x0b\n\x04\x04\0\x02\x01\x12\x03\x06\x08\"\n\x0c\n\x05\x04\0\x02\x01\ + \x04\x12\x03\x06\x08\x10\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x06\x11\ + \x16\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x06\x17\x1d\n\x0c\n\x05\x04\0\ + \x02\x01\x03\x12\x03\x06\x20!\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x07\x08&\ + \n\x0c\n\x05\x04\0\x02\x02\x04\x12\x03\x07\x08\x10\n\x0c\n\x05\x04\0\x02\ + \x02\x05\x12\x03\x07\x11\x17\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x07\ + \x18!\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x07$%\n\x0b\n\x04\x04\0\x02\ + \x03\x12\x03\x08\x08$\n\x0c\n\x05\x04\0\x02\x03\x04\x12\x03\x08\x08\x10\ + \n\x0c\n\x05\x04\0\x02\x03\x05\x12\x03\x08\x11\x17\n\x0c\n\x05\x04\0\x02\ + \x03\x01\x12\x03\x08\x18\x1f\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x08\"\ + #\n\x0b\n\x04\x04\0\x02\x04\x12\x03\t\x08#\n\x0c\n\x05\x04\0\x02\x04\x04\ + \x12\x03\t\x08\x10\n\x0c\n\x05\x04\0\x02\x04\x05\x12\x03\t\x11\x17\n\x0c\ + \n\x05\x04\0\x02\x04\x01\x12\x03\t\x18\x1e\n\x0c\n\x05\x04\0\x02\x04\x03\ + \x12\x03\t!\"\n\n\n\x02\x04\x01\x12\x04\x0c\0\x0f\x01\n\n\n\x03\x04\x01\ + \x01\x12\x03\x0c\x08\x10\n\x0b\n\x04\x04\x01\x02\0\x12\x03\r\x08#\n\x0c\ + \n\x05\x04\x01\x02\0\x04\x12\x03\r\x08\x10\n\x0c\n\x05\x04\x01\x02\0\x05\ + \x12\x03\r\x11\x16\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\r\x17\x1e\n\x0c\ + \n\x05\x04\x01\x02\0\x03\x12\x03\r!\"\n\x0b\n\x04\x04\x01\x02\x01\x12\ + \x03\x0e\x08%\n\x0c\n\x05\x04\x01\x02\x01\x04\x12\x03\x0e\x08\x10\n\x0c\ + \n\x05\x04\x01\x02\x01\x05\x12\x03\x0e\x11\x16\n\x0c\n\x05\x04\x01\x02\ + \x01\x01\x12\x03\x0e\x17\x20\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x0e\ + #$\ "; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { diff --git a/scripts/protobuf/Dockerfile b/scripts/protobuf/Dockerfile new file mode 100644 index 00000000..48ac8c05 --- /dev/null +++ b/scripts/protobuf/Dockerfile @@ -0,0 +1,5 @@ +FROM rust:1.38 + +RUN apt-get update && apt-get install -y protobuf-compiler + +RUN cargo install --version 2.8.1 protobuf-codegen diff --git a/scripts/protobuf/gen.sh b/scripts/protobuf/gen.sh new file mode 100755 index 00000000..9fcf0626 --- /dev/null +++ b/scripts/protobuf/gen.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# exit immediately when a command fails +set -e +# only exit with zero if all commands of the pipeline exit successfully +set -o pipefail +# error on unset variables +set -u +# print each command before executing it +set -x + + +# The source .proto file. +SOURCE_PROTO_FILE=$1 + +DEST_FOLDER=$(dirname "$SOURCE_PROTO_FILE") + +# The .rs file generated via protoc. +TMP_GEN_RUST_FILE=${SOURCE_PROTO_FILE/proto/rs} + +# The above with `_proto` injected. +FINAL_GEN_RUST_FILE=${TMP_GEN_RUST_FILE/.rs/_proto.rs} + + +sudo docker build -t rust-libp2p-protobuf-builder $(dirname "$0") + +sudo docker run --rm \ + -v `pwd`:/usr/code:z \ + -u="$(id -u):$(id -g)" \ + -w /usr/code \ + rust-libp2p-protobuf-builder \ + /bin/bash -c " \ + protoc --rust_out $DEST_FOLDER $SOURCE_PROTO_FILE" + + +mv $TMP_GEN_RUST_FILE $FINAL_GEN_RUST_FILE diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 1801d1cb..30e7c8b5 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -13,13 +13,13 @@ categories = ["network-programming", "asynchronous"] bytes = "0.4.12" either = "1.5.3" futures-preview = "= 0.3.0-alpha.18" -futures-rustls = "0.12.0-alpha" +#futures-rustls = "0.12.0-alpha" # TODO: https://github.com/quininer/tokio-rustls/issues/51 libp2p-core = { version = "0.12.0", path = "../../core" } log = "0.4.8" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } soketto = { git = "https://github.com/paritytech/soketto.git", branch = "develop", features = ["deflate"] } url = "2.1.0" -webpki-roots = "0.16.0" +webpki-roots = "0.17.0" [dev-dependencies] libp2p-tcp = { version = "0.12.0", path = "../tcp" } diff --git a/transports/websocket/src/tls.rs b/transports/websocket/src/tls.rs index b8e0f04c..d526176a 100644 --- a/transports/websocket/src/tls.rs +++ b/transports/websocket/src/tls.rs @@ -128,7 +128,7 @@ impl Builder { } pub(crate) fn dns_name_ref(name: &str) -> Result, Error> { - webpki::DNSNameRef::try_from_ascii_str(name).map_err(|()| Error::InvalidDnsName(name.into())) + webpki::DNSNameRef::try_from_ascii_str(name).map_err(|_| Error::InvalidDnsName(name.into())) } // Error //////////////////////////////////////////////////////////////////////////////////////////