From 2ea49718f320b4cb09a713cade9f6744fa19e2bd Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 29 Aug 2018 11:24:44 +0200 Subject: [PATCH] Clean up directory structure (#426) * Remove unused circular-buffer crate * Move transports into subdirectory * Move misc into subdirectory * Move stores into subdirectory * Move multiplexers * Move protocols * Move libp2p top layer * Fix Test: skip doctest if secio isn't enabled --- Cargo.toml | 117 ++- circular-buffer/Cargo.toml | 8 - circular-buffer/src/lib.rs | 871 ------------------ core/Cargo.toml | 14 +- {libp2p/examples => examples}/echo-dialer.rs | 0 {libp2p/examples => examples}/echo-server.rs | 0 {libp2p/examples => examples}/floodsub.rs | 0 {libp2p/examples => examples}/kademlia.rs | 0 {libp2p/examples => examples}/ping-client.rs | 0 .../examples => examples}/random_peerid.rs | 0 {libp2p/examples => examples}/relay.rs | 0 .../test-rsa-private-key.pk8 | Bin .../test-rsa-public-key.der | Bin libp2p/Cargo.toml | 73 -- {multiaddr => misc/multiaddr}/.gitignore | 0 {multiaddr => misc/multiaddr}/.travis.yml | 0 {multiaddr => misc/multiaddr}/Cargo.toml | 0 {multiaddr => misc/multiaddr}/LICENSE | 0 {multiaddr => misc/multiaddr}/src/errors.rs | 0 {multiaddr => misc/multiaddr}/src/lib.rs | 0 {multiaddr => misc/multiaddr}/src/protocol.rs | 0 {multiaddr => misc/multiaddr}/tests/lib.rs | 0 {multihash => misc/multihash}/.gitignore | 0 {multihash => misc/multihash}/.travis.yml | 0 {multihash => misc/multihash}/Cargo.toml | 0 {multihash => misc/multihash}/LICENSE | 0 {multihash => misc/multihash}/src/errors.rs | 0 {multihash => misc/multihash}/src/hashes.rs | 0 {multihash => misc/multihash}/src/lib.rs | 0 {multihash => misc/multihash}/tests/lib.rs | 0 .../multistream-select}/Cargo.toml | 0 .../multistream-select}/src/dialer_select.rs | 0 .../multistream-select}/src/error.rs | 0 .../src/length_delimited.rs | 0 .../multistream-select}/src/lib.rs | 0 .../src/listener_select.rs | 0 .../src/protocol/dialer.rs | 0 .../multistream-select}/src/protocol/error.rs | 0 .../src/protocol/listener.rs | 0 .../multistream-select}/src/protocol/mod.rs | 0 .../multistream-select}/src/tests.rs | 0 .../rw-stream-sink}/Cargo.toml | 0 .../rw-stream-sink}/src/lib.rs | 0 {mplex => muxers/mplex}/Cargo.toml | 4 +- {mplex => muxers/mplex}/src/codec.rs | 0 {mplex => muxers/mplex}/src/lib.rs | 0 {mplex => muxers/mplex}/tests/two_peers.rs | 0 {yamux => muxers/yamux}/Cargo.toml | 2 +- {yamux => muxers/yamux}/src/lib.rs | 0 {floodsub => protocols/floodsub}/Cargo.toml | 4 +- .../floodsub}/regen_structs_proto.sh | 0 {floodsub => protocols/floodsub}/rpc.proto | 0 {floodsub => protocols/floodsub}/src/lib.rs | 0 .../floodsub}/src/rpc_proto.rs | 0 {floodsub => protocols/floodsub}/src/topic.rs | 0 {identify => protocols/identify}/Cargo.toml | 8 +- .../identify}/regen_structs_proto.sh | 0 .../identify}/src/identify_transport.rs | 0 {identify => protocols/identify}/src/lib.rs | 0 .../identify}/src/peer_id_transport.rs | 0 .../identify}/src/protocol.rs | 0 .../identify}/src/structs_proto.rs | 0 .../identify}/structs.proto | 0 {kad => protocols/kad}/Cargo.toml | 12 +- {kad => protocols/kad}/dht.proto | 0 {kad => protocols/kad}/record.proto | 0 {kad => protocols/kad}/regen_dht_proto.sh | 0 {kad => protocols/kad}/src/high_level.rs | 0 {kad => protocols/kad}/src/kad_server.rs | 0 {kad => protocols/kad}/src/kbucket.rs | 0 {kad => protocols/kad}/src/lib.rs | 0 .../kad}/src/protobuf_structs/dht.rs | 0 .../kad}/src/protobuf_structs/mod.rs | 0 .../kad}/src/protobuf_structs/record.rs | 0 {kad => protocols/kad}/src/protocol.rs | 0 {kad => protocols/kad}/src/query.rs | 0 {ping => protocols/ping}/Cargo.toml | 8 +- {ping => protocols/ping}/src/lib.rs | 0 {secio => protocols/secio}/Cargo.toml | 6 +- .../secio}/regen_structs_proto.sh | 0 .../secio}/src/algo_support.rs | 0 .../secio}/src/codec/decode.rs | 0 .../secio}/src/codec/encode.rs | 0 {secio => protocols/secio}/src/codec/mod.rs | 0 {secio => protocols/secio}/src/error.rs | 0 {secio => protocols/secio}/src/handshake.rs | 0 {secio => protocols/secio}/src/lib.rs | 0 .../secio}/src/stream_cipher.rs | 0 .../secio}/src/structs_proto.rs | 0 {secio => protocols/secio}/structs.proto | 0 .../secio}/tests/test-rsa-private-key-2.pk8 | Bin .../secio}/tests/test-rsa-private-key.pk8 | Bin .../secio}/tests/test-rsa-public-key-2.der | Bin .../secio}/tests/test-rsa-public-key.der | Bin .../tests/test-secp256k1-private-key-2.der | Bin .../tests/test-secp256k1-private-key.der | Bin {libp2p/src => src}/lib.rs | 2 + {libp2p/src => src}/simple.rs | 0 {datastore => stores/datastore}/Cargo.toml | 0 .../datastore}/src/json_file.rs | 0 {datastore => stores/datastore}/src/lib.rs | 0 {datastore => stores/datastore}/src/query.rs | 0 {peerstore => stores/peerstore}/Cargo.toml | 8 +- .../peerstore}/src/json_peerstore.rs | 0 {peerstore => stores/peerstore}/src/lib.rs | 0 .../peerstore}/src/memory_peerstore.rs | 0 .../peerstore}/src/peer_info.rs | 0 .../peerstore}/src/peerstore.rs | 0 .../peerstore}/src/peerstore_tests.rs | 0 {dns => transports/dns}/Cargo.toml | 6 +- {dns => transports/dns}/src/lib.rs | 0 .../ratelimit}/Cargo.toml | 2 +- .../ratelimit}/src/lib.rs | 0 {relay => transports/relay}/Cargo.toml | 6 +- {relay => transports/relay}/src/copy.rs | 0 {relay => transports/relay}/src/lib.rs | 0 {relay => transports/relay}/src/message.proto | 0 {relay => transports/relay}/src/message.rs | 0 {relay => transports/relay}/src/protocol.rs | 0 {relay => transports/relay}/src/transport.rs | 0 {relay => transports/relay}/src/utility.rs | 0 {tcp-transport => transports/tcp}/Cargo.toml | 4 +- {tcp-transport => transports/tcp}/src/lib.rs | 0 .../timeout}/Cargo.toml | 2 +- .../timeout}/src/lib.rs | 0 {uds => transports/uds}/Cargo.toml | 4 +- {uds => transports/uds}/src/lib.rs | 0 .../websocket}/Cargo.toml | 8 +- .../websocket}/src/browser.rs | 0 .../websocket}/src/desktop.rs | 0 .../websocket}/src/lib.rs | 0 131 files changed, 146 insertions(+), 1023 deletions(-) delete mode 100644 circular-buffer/Cargo.toml delete mode 100644 circular-buffer/src/lib.rs rename {libp2p/examples => examples}/echo-dialer.rs (100%) rename {libp2p/examples => examples}/echo-server.rs (100%) rename {libp2p/examples => examples}/floodsub.rs (100%) rename {libp2p/examples => examples}/kademlia.rs (100%) rename {libp2p/examples => examples}/ping-client.rs (100%) rename {libp2p/examples => examples}/random_peerid.rs (100%) rename {libp2p/examples => examples}/relay.rs (100%) rename {libp2p/examples => examples}/test-rsa-private-key.pk8 (100%) rename {libp2p/examples => examples}/test-rsa-public-key.der (100%) delete mode 100644 libp2p/Cargo.toml rename {multiaddr => misc/multiaddr}/.gitignore (100%) rename {multiaddr => misc/multiaddr}/.travis.yml (100%) rename {multiaddr => misc/multiaddr}/Cargo.toml (100%) rename {multiaddr => misc/multiaddr}/LICENSE (100%) rename {multiaddr => misc/multiaddr}/src/errors.rs (100%) rename {multiaddr => misc/multiaddr}/src/lib.rs (100%) rename {multiaddr => misc/multiaddr}/src/protocol.rs (100%) rename {multiaddr => misc/multiaddr}/tests/lib.rs (100%) rename {multihash => misc/multihash}/.gitignore (100%) rename {multihash => misc/multihash}/.travis.yml (100%) rename {multihash => misc/multihash}/Cargo.toml (100%) rename {multihash => misc/multihash}/LICENSE (100%) rename {multihash => misc/multihash}/src/errors.rs (100%) rename {multihash => misc/multihash}/src/hashes.rs (100%) rename {multihash => misc/multihash}/src/lib.rs (100%) rename {multihash => misc/multihash}/tests/lib.rs (100%) rename {multistream-select => misc/multistream-select}/Cargo.toml (100%) rename {multistream-select => misc/multistream-select}/src/dialer_select.rs (100%) rename {multistream-select => misc/multistream-select}/src/error.rs (100%) rename {multistream-select => misc/multistream-select}/src/length_delimited.rs (100%) rename {multistream-select => misc/multistream-select}/src/lib.rs (100%) rename {multistream-select => misc/multistream-select}/src/listener_select.rs (100%) rename {multistream-select => misc/multistream-select}/src/protocol/dialer.rs (100%) rename {multistream-select => misc/multistream-select}/src/protocol/error.rs (100%) rename {multistream-select => misc/multistream-select}/src/protocol/listener.rs (100%) rename {multistream-select => misc/multistream-select}/src/protocol/mod.rs (100%) rename {multistream-select => misc/multistream-select}/src/tests.rs (100%) rename {rw-stream-sink => misc/rw-stream-sink}/Cargo.toml (100%) rename {rw-stream-sink => misc/rw-stream-sink}/src/lib.rs (100%) rename {mplex => muxers/mplex}/Cargo.toml (78%) rename {mplex => muxers/mplex}/src/codec.rs (100%) rename {mplex => muxers/mplex}/src/lib.rs (100%) rename {mplex => muxers/mplex}/tests/two_peers.rs (100%) rename {yamux => muxers/yamux}/Cargo.toml (86%) rename {yamux => muxers/yamux}/src/lib.rs (100%) rename {floodsub => protocols/floodsub}/Cargo.toml (82%) rename {floodsub => protocols/floodsub}/regen_structs_proto.sh (100%) rename {floodsub => protocols/floodsub}/rpc.proto (100%) rename {floodsub => protocols/floodsub}/src/lib.rs (100%) rename {floodsub => protocols/floodsub}/src/rpc_proto.rs (100%) rename {floodsub => protocols/floodsub}/src/topic.rs (100%) rename {identify => protocols/identify}/Cargo.toml (65%) rename {identify => protocols/identify}/regen_structs_proto.sh (100%) rename {identify => protocols/identify}/src/identify_transport.rs (100%) rename {identify => protocols/identify}/src/lib.rs (100%) rename {identify => protocols/identify}/src/peer_id_transport.rs (100%) rename {identify => protocols/identify}/src/protocol.rs (100%) rename {identify => protocols/identify}/src/structs_proto.rs (100%) rename {identify => protocols/identify}/structs.proto (100%) rename {kad => protocols/kad}/Cargo.toml (62%) rename {kad => protocols/kad}/dht.proto (100%) rename {kad => protocols/kad}/record.proto (100%) rename {kad => protocols/kad}/regen_dht_proto.sh (100%) rename {kad => protocols/kad}/src/high_level.rs (100%) rename {kad => protocols/kad}/src/kad_server.rs (100%) rename {kad => protocols/kad}/src/kbucket.rs (100%) rename {kad => protocols/kad}/src/lib.rs (100%) rename {kad => protocols/kad}/src/protobuf_structs/dht.rs (100%) rename {kad => protocols/kad}/src/protobuf_structs/mod.rs (100%) rename {kad => protocols/kad}/src/protobuf_structs/record.rs (100%) rename {kad => protocols/kad}/src/protocol.rs (100%) rename {kad => protocols/kad}/src/query.rs (100%) rename {ping => protocols/ping}/Cargo.toml (60%) rename {ping => protocols/ping}/src/lib.rs (100%) rename {secio => protocols/secio}/Cargo.toml (83%) rename {secio => protocols/secio}/regen_structs_proto.sh (100%) rename {secio => protocols/secio}/src/algo_support.rs (100%) rename {secio => protocols/secio}/src/codec/decode.rs (100%) rename {secio => protocols/secio}/src/codec/encode.rs (100%) rename {secio => protocols/secio}/src/codec/mod.rs (100%) rename {secio => protocols/secio}/src/error.rs (100%) rename {secio => protocols/secio}/src/handshake.rs (100%) rename {secio => protocols/secio}/src/lib.rs (100%) rename {secio => protocols/secio}/src/stream_cipher.rs (100%) rename {secio => protocols/secio}/src/structs_proto.rs (100%) rename {secio => protocols/secio}/structs.proto (100%) rename {secio => protocols/secio}/tests/test-rsa-private-key-2.pk8 (100%) rename {secio => protocols/secio}/tests/test-rsa-private-key.pk8 (100%) rename {secio => protocols/secio}/tests/test-rsa-public-key-2.der (100%) rename {secio => protocols/secio}/tests/test-rsa-public-key.der (100%) rename {secio => protocols/secio}/tests/test-secp256k1-private-key-2.der (100%) rename {secio => protocols/secio}/tests/test-secp256k1-private-key.der (100%) rename {libp2p/src => src}/lib.rs (99%) rename {libp2p/src => src}/simple.rs (100%) rename {datastore => stores/datastore}/Cargo.toml (100%) rename {datastore => stores/datastore}/src/json_file.rs (100%) rename {datastore => stores/datastore}/src/lib.rs (100%) rename {datastore => stores/datastore}/src/query.rs (100%) rename {peerstore => stores/peerstore}/Cargo.toml (61%) rename {peerstore => stores/peerstore}/src/json_peerstore.rs (100%) rename {peerstore => stores/peerstore}/src/lib.rs (100%) rename {peerstore => stores/peerstore}/src/memory_peerstore.rs (100%) rename {peerstore => stores/peerstore}/src/peer_info.rs (100%) rename {peerstore => stores/peerstore}/src/peerstore.rs (100%) rename {peerstore => stores/peerstore}/src/peerstore_tests.rs (100%) rename {dns => transports/dns}/Cargo.toml (61%) rename {dns => transports/dns}/src/lib.rs (100%) rename {ratelimit => transports/ratelimit}/Cargo.toml (87%) rename {ratelimit => transports/ratelimit}/src/lib.rs (100%) rename {relay => transports/relay}/Cargo.toml (68%) rename {relay => transports/relay}/src/copy.rs (100%) rename {relay => transports/relay}/src/lib.rs (100%) rename {relay => transports/relay}/src/message.proto (100%) rename {relay => transports/relay}/src/message.rs (100%) rename {relay => transports/relay}/src/protocol.rs (100%) rename {relay => transports/relay}/src/transport.rs (100%) rename {relay => transports/relay}/src/utility.rs (100%) rename {tcp-transport => transports/tcp}/Cargo.toml (76%) rename {tcp-transport => transports/tcp}/src/lib.rs (100%) rename {transport-timeout => transports/timeout}/Cargo.toml (83%) rename {transport-timeout => transports/timeout}/src/lib.rs (100%) rename {uds => transports/uds}/Cargo.toml (83%) rename {uds => transports/uds}/src/lib.rs (100%) rename {websocket => transports/websocket}/Cargo.toml (74%) rename {websocket => transports/websocket}/src/browser.rs (100%) rename {websocket => transports/websocket}/src/desktop.rs (100%) rename {websocket => transports/websocket}/src/lib.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 190f74a6..ea6c56a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,26 +1,99 @@ +[package] +name = "libp2p" +version = "0.1.0" +authors = ["Parity Technologies "] +license = "MIT" + +[features] +default = ["libp2p-secio", "libp2p-secio-secp256k1"] +libp2p-secio-secp256k1 = ["libp2p-secio/secp256k1"] + +[dependencies] +bytes = "0.4" +futures = "0.1" +multiaddr = { path = "./misc/multiaddr" } +libp2p-mplex = { path = "./muxers/mplex" } +libp2p-identify = { path = "./protocols/identify" } +libp2p-kad = { path = "./protocols/kad" } +libp2p-floodsub = { path = "./protocols/floodsub" } +libp2p-peerstore = { path = "./stores/peerstore" } +libp2p-ping = { path = "./protocols/ping" } +libp2p-ratelimit = { path = "./transports/ratelimit" } +libp2p-relay = { path = "./transports/relay" } +libp2p-core = { path = "./core" } +libp2p-transport-timeout = { path = "./transports/timeout" } +libp2p-uds = { path = "./transports/uds" } +libp2p-websocket = { path = "./transports/websocket" } +libp2p-yamux = { path = "./muxers/yamux" } +tokio-codec = "0.1" +tokio-io = "0.1" + +[target.'cfg(not(target_os = "emscripten"))'.dependencies] +libp2p-dns = { path = "./transports/dns" } +libp2p-secio = { path = "./protocols/secio", optional = true, default-features = false } +libp2p-tcp-transport = { path = "./transports/tcp" } +tokio-current-thread = "0.1" + +[target.'cfg(target_os = "emscripten")'.dependencies] +stdweb = { version = "0.1.3", default-features = false } + +[dev-dependencies] +bigint = "4.2" +env_logger = "0.5.4" +rand = "0.4" +structopt = "0.2" +tokio-current-thread = "0.1" +tokio-io = "0.1" +tokio-stdin = "0.1" + +[[example]] +name = "echo-dialer" +required-features = ["libp2p-secio"] + +[[example]] +name = "echo-server" +required-features = ["libp2p-secio"] + +[[example]] +name = "floodsub" +required-features = ["libp2p-secio"] + +[[example]] +name = "kademlia" +required-features = ["libp2p-secio"] + +[[example]] +name = "ping-client" +required-features = ["libp2p-secio"] + +[[example]] +name = "random_peerid" + +[[example]] +name = "relay" + + [workspace] members = [ - "circular-buffer", - "datastore", - "dns", - "floodsub", - "identify", - "kad", - "libp2p", - "multiaddr", - "multihash", - "mplex", - "multistream-select", - "peerstore", - "ping", - "ratelimit", - "relay", - "rw-stream-sink", - "secio", "core", - "tcp-transport", - "transport-timeout", - "uds", - "websocket", - "yamux" + "misc/multiaddr", + "misc/multihash", + "misc/multistream-select", + "misc/rw-stream-sink", + "transports/dns", + "protocols/floodsub", + "protocols/identify", + "protocols/kad", + "protocols/ping", + "transports/relay", + "protocols/secio", + "muxers/mplex", + "muxers/yamux", + "stores/peerstore", + "stores/datastore", + "transports/tcp", + "transports/uds", + "transports/websocket", + "transports/timeout", + "transports/ratelimit", ] diff --git a/circular-buffer/Cargo.toml b/circular-buffer/Cargo.toml deleted file mode 100644 index f6c691aa..00000000 --- a/circular-buffer/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "circular-buffer" -version = "0.1.0" -authors = ["Parity Technologies "] -license = "MIT" - -[dependencies] -smallvec = { git = "https://github.com/Vurich/rust-smallvec.git", branch = "array-zero" } \ No newline at end of file diff --git a/circular-buffer/src/lib.rs b/circular-buffer/src/lib.rs deleted file mode 100644 index d6fb6f05..00000000 --- a/circular-buffer/src/lib.rs +++ /dev/null @@ -1,871 +0,0 @@ -// Copyright 2017 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. - -#![warn(missing_docs)] - -//! # `circular-buffer` -//! -//! An optimized FIFO queue that allows safe access to the internal storage as a slice (i.e. not -//! just element-by-element). This is useful for circular buffers of bytes. Since it uses -//! `smallvec`'s `Array` trait it can only be backed by an array of static size, this may change in -//! the future. - -extern crate smallvec; - -use std::mem::ManuallyDrop; -use std::ops::Drop; - -pub use smallvec::Array; - -use owned_slice::OwnedSlice; - -/// A slice that owns its elements, but not their storage. This is useful for things like -/// `Vec::retain` and `CircularBuffer::pop_slice`, since these functions can return a slice but the -/// elements of these slices would be leaked after the slice goes out of scope. `OwnedSlice` simply -/// manually drops all its elements when it goes out of scope. -pub mod owned_slice { - use std::mem::ManuallyDrop; - use std::ops::{Deref, DerefMut, Drop}; - - /// A slice that owns its elements, but not their storage. This is useful for things like - /// `Vec::retain` and `CircularBuffer::pop_slice`, since these functions can return a slice but - /// the elements of these slices would be leaked after the slice goes out of scope. `OwnedSlice` - /// simply manually drops all its elements when it goes out of scope. - #[derive(Debug, Eq, PartialEq)] - pub struct OwnedSlice<'a, T: 'a>(&'a mut [T]); - - /// Owning iterator for `OwnedSlice`. - pub struct IntoIter<'a, T: 'a> { - slice: ManuallyDrop>, - index: usize, - } - - impl<'a, T> Iterator for IntoIter<'a, T> { - type Item = T; - - fn next(&mut self) -> Option { - use std::ptr; - - let index = self.index; - - if index >= self.slice.len() { - return None; - } - - self.index += 1; - - unsafe { Some(ptr::read(&self.slice[index])) } - } - } - - impl<'a, T: 'a> IntoIterator for OwnedSlice<'a, T> { - type Item = T; - type IntoIter = IntoIter<'a, T>; - - fn into_iter(self) -> Self::IntoIter { - IntoIter { - slice: ManuallyDrop::new(self), - index: 0, - } - } - } - - impl<'a, T: 'a> OwnedSlice<'a, T> { - /// Construct an owned slice from a mutable slice pointer. - /// - /// # Unsafety - /// You must ensure that the memory pointed to by `inner` will not be accessible after the - /// lifetime of the `OwnedSlice`. - pub unsafe fn new(inner: &'a mut [T]) -> Self { - OwnedSlice(inner) - } - } - - impl<'a, T> AsRef<[T]> for OwnedSlice<'a, T> { - fn as_ref(&self) -> &[T] { - self.0 - } - } - - impl<'a, T> AsMut<[T]> for OwnedSlice<'a, T> { - fn as_mut(&mut self) -> &mut [T] { - self.0 - } - } - - impl<'a, T> Deref for OwnedSlice<'a, T> { - type Target = [T]; - - fn deref(&self) -> &Self::Target { - self.0 - } - } - - impl<'a, T> DerefMut for OwnedSlice<'a, T> { - fn deref_mut(&mut self) -> &mut Self::Target { - self.0 - } - } - - impl<'a, T> Drop for OwnedSlice<'a, T> { - fn drop(&mut self) { - use std::ptr; - - for element in self.iter_mut() { - unsafe { - ptr::drop_in_place(element); - } - } - } - } -} - -/// A fixed-size FIFO queue with safe access to the backing storage. -/// -/// This type allows access to slices of the backing storage, for efficient, safe circular buffers -/// of bytes or other `Copy` types. -#[derive(Debug)] -pub struct CircularBuffer { - // This must be manually dropped, as some or all of the elements may be uninitialized - buffer: ManuallyDrop, - start: usize, - len: usize, -} - -impl Default for CircularBuffer { - fn default() -> Self { - Self::new() - } -} - -impl PartialEq for CircularBuffer -where - B::Item: PartialEq, -{ - fn eq(&self, other: &Self) -> bool { - if self.len() != other.len() { - return false; - } - - for (a, b) in self.iter().zip(other.iter()) { - if a != b { - return false; - } - } - - true - } -} - -impl CircularBuffer { - /// Create an empty `CircularBuffer`. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::<[usize; 4]>::new(); - /// - /// assert!(buffer.is_empty()); - /// ``` - pub fn new() -> Self { - use std::mem; - - CircularBuffer { - buffer: unsafe { mem::uninitialized() }, - start: 0, - len: 0, - } - } - - /// Pop a slice containing the maximum possible contiguous number of elements. Since this buffer - /// is circular it will take a maximum of two calls to this function to drain the buffer - /// entirely. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert_eq!(buffer.pop(), Some(1)); - /// assert!(buffer.push(1).is_none()); - /// - /// assert_eq!( - /// buffer.pop_slice().as_ref().map(|s| &s[..]), - /// Some(&[2, 3, 4][..]) - /// ); - /// assert_eq!(buffer.pop_slice().as_ref().map(|s| &s[..]), Some(&[1][..])); - /// assert!(buffer.pop_slice().is_none()); - /// - /// assert_eq!(buffer.len(), 0); - /// ``` - /// - /// This returns an `OwnedSlice`, which owns the items but not the storage (you cannot have two - /// slices returned from `pop_slice` alive at once, but the elements will be have `drop` called - /// when the slice goes out of scope), if you're using non-`Drop` types you can use - /// `pop_slice_leaky`. - pub fn pop_slice(&mut self) -> Option> { - self.pop_slice_leaky() - .map(|x| unsafe { OwnedSlice::new(x) }) - } - - /// Pop a slice containing the maximum possible contiguous number of elements. Since this buffer - /// is circular it will take a maximum of two calls to this function to drain the buffer - /// entirely. This returns a slice and so any `Drop` types returned from this function will be - /// leaked. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert_eq!(buffer.pop(), Some(1)); - /// assert!(buffer.push(1).is_none()); - /// - /// assert_eq!( - /// buffer.pop_slice_leaky(), - /// Some(&mut [2, 3, 4][..]) - /// ); - /// assert_eq!(buffer.pop_slice_leaky(), Some(&mut [1][..])); - /// assert!(buffer.pop_slice_leaky().is_none()); - /// - /// assert_eq!(buffer.len(), 0); - /// ``` - pub fn pop_slice_leaky(&mut self) -> Option<&mut [B::Item]> { - let len = self.len; - self.pop_first_n_leaky(len) - } - - /// Pop a slice containing up to `n` contiguous elements. Since this buffer is circular it will - /// take a maximum of two calls to this function to drain the buffer entirely. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert_eq!(buffer.pop(), Some(1)); - /// assert!(buffer.push(1).is_none()); - /// - /// assert_eq!(buffer.pop_first_n(2).as_ref().map(<_>::as_ref), Some(&[2, 3][..])); - /// assert_eq!(buffer.pop_first_n(2).as_ref().map(<_>::as_ref), Some(&[4][..])); - /// assert_eq!(buffer.pop_first_n(2).as_ref().map(<_>::as_ref), Some(&[1][..])); - /// assert!(buffer.pop_first_n(2).is_none()); - /// - /// assert_eq!(buffer.len(), 0); - /// ``` - pub fn pop_first_n(&mut self, n: usize) -> Option> { - self.pop_first_n_leaky(n) - .map(|x| unsafe { OwnedSlice::new(x) }) - } - - /// Pop a slice containing up to `n` contiguous elements. Since this buffer is circular it will - /// take a maximum of two calls to this function to drain the buffer entirely. This returns a - /// slice and so any `Drop` types returned from this function will be leaked. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert_eq!(buffer.pop(), Some(1)); - /// assert!(buffer.push(1).is_none()); - /// - /// assert_eq!(buffer.pop_first_n_leaky(2), Some(&mut [2, 3][..])); - /// assert_eq!(buffer.pop_first_n_leaky(2), Some(&mut [4][..])); - /// assert_eq!(buffer.pop_first_n_leaky(2), Some(&mut [1][..])); - /// assert!(buffer.pop_first_n_leaky(2).is_none()); - /// - /// assert_eq!(buffer.len(), 0); - /// ``` - pub fn pop_first_n_leaky(&mut self, n: usize) -> Option<&mut [B::Item]> { - use std::slice; - - if self.is_empty() { - None - } else { - let (start, out_length) = (self.start, self.len.min(B::size() - self.start).min(n)); - - self.advance(out_length); - - unsafe { - Some(slice::from_raw_parts_mut( - self.buffer.ptr_mut().offset(start as isize), - out_length, - )) - } - } - } - - /// A borrowed iterator of this buffer's elements - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// assert_eq!( - /// CircularBuffer::from_array([1, 2, 3, 4]).iter().cloned().collect::>(), - /// vec![1, 2, 3, 4] - /// ); - /// ``` - pub fn iter(&self) -> Iter { - self.into_iter() - } - - /// Iterate over slices of the buffer (of arbitrary size, but in order). - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert_eq!(buffer.pop(), Some(1)); - /// assert!(buffer.push(1).is_none()); - /// - /// let mut iter = buffer.slices(); - /// - /// assert_eq!( - /// iter.collect::>(), - /// vec![&[2, 3, 4][..], &[1]] - /// ); - /// ``` - pub fn slices(&self) -> SlicesIter { - SlicesIter { - buffer: self, - start: self.start, - len: self.len, - } - } - - /// Whether the buffer is empty. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::<[usize; 4]>::new(); - /// - /// assert!(buffer.is_empty()); - /// ``` - pub fn is_empty(&self) -> bool { - self.len == 0 - } - - /// Whether the buffer is full (i.e. it is no longer possible to push new elements without - /// popping old ones first). - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert!(buffer.is_full()); - /// ``` - pub fn is_full(&self) -> bool { - self.len == B::size() - } - - /// The number of elements in the buffer. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer: CircularBuffer<[usize; 4]> = CircularBuffer::from_slice(&[1, 2]).unwrap(); - /// - /// assert_eq!(buffer.len(), 2); - /// - /// assert!(buffer.push(1).is_none()); - /// assert!(buffer.push(2).is_none()); - /// - /// assert_eq!(buffer.len(), 4); - /// ``` - pub fn len(&self) -> usize { - self.len - } - - /// The maximum number of elements this buffer can take. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer: CircularBuffer<[usize; 4]> = CircularBuffer::new(); - /// - /// assert_eq!(buffer.capacity(), 4); - /// ``` - // We inline-always so that this can get const-folded properly. This is really important for - // stuff like `if buf.capacity() > 0 { ... }`. - #[inline(always)] - pub fn capacity(&self) -> usize { - B::size() - } - - /// Append a single element to the end of the buffer, returning it if it could not be added. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer: CircularBuffer<[usize; 4]> = CircularBuffer::new(); - /// - /// assert_eq!(buffer.len(), 0); - /// - /// assert!(buffer.push(1).is_none()); - /// assert!(buffer.push(2).is_none()); - /// assert!(buffer.push(3).is_none()); - /// assert!(buffer.push(4).is_none()); - /// - /// assert!(buffer.push(5).is_some()); - /// - /// assert_eq!(buffer.len(), 4); - /// ``` - pub fn push(&mut self, element: B::Item) -> Option { - use std::ptr; - - debug_assert!(self.len <= B::size()); - - if self.is_full() { - Some(element) - } else { - let dest = (self.start + self.len) % B::size(); - - unsafe { - ptr::write(self.buffer.ptr_mut().offset(dest as isize), element); - } - self.len += 1; - None - } - } - - /// Remove a single element from the start of the buffer. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::from_array([1, 2, 3, 4]); - /// - /// assert_eq!(buffer.pop(), Some(1)); - /// ``` - pub fn pop(&mut self) -> Option { - use std::ptr; - - if self.is_empty() { - None - } else { - let offset = self.start; - self.advance(1); - - unsafe { Some(ptr::read(self.buffer.ptr_mut().offset(offset as _))) } - } - } - - /// Get a borrow to an element at an index safely (if the index is out of bounds, return - /// `None`). - pub fn get(&self, index: usize) -> Option<&B::Item> { - if index < self.len { - unsafe { Some(self.get_unchecked(index)) } - } else { - None - } - } - - /// Get a borrow to an element at an index unsafely (behaviour is undefined if the index is out - /// of bounds). - pub unsafe fn get_unchecked(&self, index: usize) -> &B::Item { - &*self.buffer - .ptr() - .offset(((index + self.start) % B::size()) as isize) - } - - /// Get a mutable borrow to an element at an index safely (if the index is out of bounds, return - /// `None`). - pub fn get_mut(&mut self, index: usize) -> Option<&mut B::Item> { - if index < self.len { - unsafe { Some(self.get_unchecked_mut(index)) } - } else { - None - } - } - - /// Get a mutable borrow to an element at an index unsafely (behaviour is undefined if the index - /// is out of bounds). - pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut B::Item { - &mut *self.buffer - .ptr_mut() - .offset(((index + self.start) % B::size()) as isize) - } - - /// Removes the first `by` elements of the start of the buffer. - /// - /// # Panic - /// - /// Panics if `by` is superior to the number of elements in the buffer. - // This is not unsafe because it can only leak data, not cause uninit to be read. - pub fn advance(&mut self, by: usize) { - assert!(by <= self.len); - - self.start = (self.start + by) % B::size(); - self.len -= by; - } -} - -impl std::ops::Index for CircularBuffer { - type Output = B::Item; - - fn index(&self, index: usize) -> &Self::Output { - if let Some(out) = self.get(index) { - out - } else { - panic!( - "index out of bounds: the len is {} but the index is {}", - self.len, index - ); - } - } -} - -impl std::ops::IndexMut for CircularBuffer { - fn index_mut(&mut self, index: usize) -> &mut Self::Output { - // We need to do this because borrowck isn't smart enough to understand enum variants - let len = self.len; - - if let Some(out) = self.get_mut(index) { - return out; - } else { - panic!( - "index out of bounds: the len is {} but the index is {}", - len, index - ); - } - } -} - -impl Drop for CircularBuffer { - fn drop(&mut self) { - while self.pop_slice().is_some() {} - } -} - -impl IntoIterator for CircularBuffer { - type Item = B::Item; - type IntoIter = IntoIter; - - fn into_iter(self) -> Self::IntoIter { - IntoIter { buffer: self } - } -} - -impl<'a, B: Array + 'a> IntoIterator for &'a CircularBuffer { - type Item = &'a B::Item; - type IntoIter = Iter<'a, B>; - - fn into_iter(self) -> Self::IntoIter { - Iter { - buffer: self, - remaining: self.len(), - } - } -} - -/// The iteration type returning owned elements of the buffer -pub struct IntoIter { - buffer: CircularBuffer, -} - -impl Iterator for IntoIter { - type Item = B::Item; - - fn next(&mut self) -> Option { - self.buffer.pop() - } -} - -/// The iteration type returning borrows to elements of the buffer -pub struct Iter<'a, B: Array + 'a> { - buffer: &'a CircularBuffer, - remaining: usize, -} - -impl<'a, B: Array + 'a> Iterator for Iter<'a, B> { - type Item = &'a B::Item; - - fn next(&mut self) -> Option { - if self.remaining == 0 { - None - } else { - let remaining = self.remaining; - self.remaining -= 1; - self.buffer.get(self.buffer.len() - remaining) - } - } -} - -/// The iteration type for immutable slices of the circular buffer. See `CircularBuffer::slices`. -pub struct SlicesIter<'a, B: Array + 'a> { - buffer: &'a CircularBuffer, - start: usize, - len: usize, -} - -impl<'a, B: Array + 'a> Iterator for SlicesIter<'a, B> { - type Item = &'a [B::Item]; - - fn next(&mut self) -> Option { - use std::slice; - - if self.len == 0 { - None - } else { - let (start, out_length) = (self.start, self.len.min(B::size() - self.start)); - - self.start = (self.start + out_length) % B::size(); - self.len -= out_length; - - unsafe { - Some(slice::from_raw_parts( - self.buffer.buffer.ptr().offset(start as isize), - out_length, - )) - } - } - } -} - -impl CircularBuffer -where - B::Item: Copy, -{ - /// Create a `CircularBuffer` from a slice of elements, returning `None` if not all the elements - /// can fit in the buffer. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// assert!(CircularBuffer::<[usize; 5]>::from_slice(&[1, 2, 3, 4, 5, 6]).is_none()); - /// assert!(CircularBuffer::<[usize; 5]>::from_slice(&[1, 2, 3, 4]).is_some()); - /// ``` - pub fn from_slice(slice: &[B::Item]) -> Option { - let mut out = Self::new(); - if out.extend_from_slice(slice) { - Some(out) - } else { - None - } - } - - /// Create a `CircularBuffer` from a slice of elements, returning the number of elements copied. - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let result = CircularBuffer::<[usize; 5]>::from_slice_prefix( - /// &[1, 2, 3, 4, 5, 6, 7, 8, 9, 20] - /// ); - /// assert_eq!(result, (CircularBuffer::from_array([1, 2, 3, 4, 5]), 5)); - /// ``` - pub fn from_slice_prefix(slice: &[B::Item]) -> (Self, usize) { - let mut out = Self::new(); - let num_copied = out.extend_from_slice_prefix(slice); - (out, num_copied) - } - - /// Create a circular buffer from a fixed-size array - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let result = CircularBuffer::from_array([1, 2, 3, 4, 5]); - /// assert_eq!(result.into_iter().collect::>(), vec![1, 2, 3, 4, 5]); - /// ``` - pub fn from_array(slice: B) -> Self { - CircularBuffer { - buffer: ManuallyDrop::new(slice), - start: 0, - len: B::size(), - } - } - - fn write_slice(&mut self, index: usize, slice: &[B::Item]) -> bool { - use std::ptr; - - let mut offset = 0; - - assert!(index <= self.len); - - if slice.len() > self.capacity() - index { - return false; - } - - while offset < slice.len() { - unsafe { - let dest = (index + self.start + offset) % B::size(); - let copy_len = if dest < self.start { - self.start - dest - } else { - B::size() - dest - }.min(slice.len() - offset); - - let slice_ptr = slice.as_ptr().offset(offset as isize); - let ptr = self.buffer.ptr_mut().offset(dest as isize); - - ptr::copy(slice_ptr, ptr, copy_len); - - self.len = self.len.max(index + offset + copy_len); - offset += copy_len; - } - } - - true - } - - fn write_slice_prefix(&mut self, index: usize, slice: &[B::Item]) -> usize { - use std::ptr; - - let mut offset = 0; - - assert!(index <= self.len); - - while !self.is_full() && offset < slice.len() { - unsafe { - let dest = (index + self.start + offset) % B::size(); - let copy_len = if dest < self.start { - self.start - dest - } else { - B::size() - dest - }.min(slice.len() - offset); - - let slice_ptr = slice.as_ptr().offset(offset as isize); - let ptr = self.buffer.ptr_mut().offset(dest as isize); - - ptr::copy(slice_ptr, ptr, copy_len); - - self.len = self.len.max(index + offset + copy_len); - offset += copy_len; - } - } - - offset - } - - /// Append the elements from a slice to the buffer, returning the number of elements copied - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::<[usize; 5]>::from_slice(&[1, 2]).unwrap(); - /// - /// assert_eq!(buffer.iter().cloned().collect::>(), vec![1, 2]); - /// - /// let consumed = buffer.extend_from_slice_prefix(&[1, 2, 3, 4, 5]); - /// - /// assert_eq!(consumed, 3); - /// assert_eq!(buffer.iter().cloned().collect::>(), vec![1, 2, 1, 2, 3]); - /// ``` - #[inline] - pub fn extend_from_slice_prefix(&mut self, slice: &[B::Item]) -> usize { - let len = self.len(); - self.write_slice_prefix(len, slice) - } - - /// Append the elements from a slice to the buffer iff there is enough space for all the - /// elements - /// - /// ```rust - /// use circular_buffer::CircularBuffer; - /// - /// let mut buffer = CircularBuffer::<[usize; 5]>::from_slice(&[1, 2]).unwrap(); - /// - /// assert_eq!(buffer.iter().cloned().collect::>(), vec![1, 2]); - /// - /// assert!(!buffer.extend_from_slice(&[1, 2, 3, 4, 5])); - /// assert!(buffer.extend_from_slice(&[1, 2, 3])); - /// - /// assert_eq!(buffer.iter().cloned().collect::>(), vec![1, 2, 1, 2, 3]); - /// ``` - #[inline] - pub fn extend_from_slice(&mut self, slice: &[B::Item]) -> bool { - let len = self.len(); - self.write_slice(len, slice) - } -} - -#[cfg(test)] -mod tests { - use super::CircularBuffer; - - #[test] - fn push_pop() { - let mut buffer: CircularBuffer<[usize; 4]> = CircularBuffer::new(); - - assert_eq!(buffer.len(), 0); - - assert!(buffer.push(1).is_none()); - assert!(buffer.push(2).is_none()); - assert!(buffer.push(3).is_none()); - assert!(buffer.push(4).is_none()); - - assert!(buffer.push(5).is_some()); - - assert_eq!(buffer.len(), 4); - - assert_eq!(buffer.pop(), Some(1)); - assert_eq!(buffer.pop(), Some(2)); - assert_eq!(buffer.pop(), Some(3)); - assert_eq!(buffer.pop(), Some(4)); - assert_eq!(buffer.pop(), None); - - assert_eq!(buffer.len(), 0); - } - - #[test] - fn pop_slice() { - let mut buffer: CircularBuffer<[usize; 4]> = CircularBuffer::new(); - - assert_eq!(buffer.len(), 0); - - assert!(buffer.push(1).is_none()); - assert!(buffer.push(2).is_none()); - assert!(buffer.push(3).is_none()); - assert!(buffer.push(4).is_none()); - - assert!(buffer.push(5).is_some()); - - assert_eq!(buffer.len(), 4); - - assert_eq!(buffer.pop(), Some(1)); - assert!(buffer.push(1).is_none()); - - assert_eq!( - buffer.pop_slice().as_ref().map(|s| &s[..]), - Some(&[2, 3, 4][..]) - ); - assert_eq!(buffer.pop_slice().as_ref().map(|s| &s[..]), Some(&[1][..])); - assert!(buffer.pop_slice().is_none()); - - assert_eq!(buffer.len(), 0); - } - - #[test] - fn extend_from_slice() { - let mut buffer: CircularBuffer<[usize; 4]> = CircularBuffer::from_slice(&[1, 2]).unwrap(); - - assert_eq!(buffer.pop(), Some(1)); - assert_eq!(buffer.pop(), Some(2)); - - assert!(buffer.extend_from_slice(&[1, 2, 3, 4])); - - assert_eq!(buffer.iter().cloned().collect::>(), vec![1, 2, 3, 4]) - } -} diff --git a/core/Cargo.toml b/core/Cargo.toml index c9391ec1..1670a647 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -9,21 +9,21 @@ bs58 = "0.2.0" bytes = "0.4" fnv = "1.0" log = "0.4" -multiaddr = { path = "../multiaddr" } -multihash = { path = "../multihash" } -multistream-select = { path = "../multistream-select" } +multiaddr = { path = "../misc/multiaddr" } +multihash = { path = "../misc/multihash" } +multistream-select = { path = "../misc/multistream-select" } futures = { version = "0.1", features = ["use_std"] } parking_lot = "0.6" protobuf = "2.0.2" quick-error = "1.2" -rw-stream-sink = { path = "../rw-stream-sink" } +rw-stream-sink = { path = "../misc/rw-stream-sink" } smallvec = "0.5" tokio-io = "0.1" [dev-dependencies] -libp2p-ping = { path = "../ping" } -libp2p-tcp-transport = { path = "../tcp-transport" } -libp2p-mplex = { path = "../mplex" } +libp2p-ping = { path = "../protocols/ping" } +libp2p-tcp-transport = { path = "../transports/tcp" } +libp2p-mplex = { path = "../muxers/mplex" } rand = "0.5" tokio = "0.1" tokio-codec = "0.1" diff --git a/libp2p/examples/echo-dialer.rs b/examples/echo-dialer.rs similarity index 100% rename from libp2p/examples/echo-dialer.rs rename to examples/echo-dialer.rs diff --git a/libp2p/examples/echo-server.rs b/examples/echo-server.rs similarity index 100% rename from libp2p/examples/echo-server.rs rename to examples/echo-server.rs diff --git a/libp2p/examples/floodsub.rs b/examples/floodsub.rs similarity index 100% rename from libp2p/examples/floodsub.rs rename to examples/floodsub.rs diff --git a/libp2p/examples/kademlia.rs b/examples/kademlia.rs similarity index 100% rename from libp2p/examples/kademlia.rs rename to examples/kademlia.rs diff --git a/libp2p/examples/ping-client.rs b/examples/ping-client.rs similarity index 100% rename from libp2p/examples/ping-client.rs rename to examples/ping-client.rs diff --git a/libp2p/examples/random_peerid.rs b/examples/random_peerid.rs similarity index 100% rename from libp2p/examples/random_peerid.rs rename to examples/random_peerid.rs diff --git a/libp2p/examples/relay.rs b/examples/relay.rs similarity index 100% rename from libp2p/examples/relay.rs rename to examples/relay.rs diff --git a/libp2p/examples/test-rsa-private-key.pk8 b/examples/test-rsa-private-key.pk8 similarity index 100% rename from libp2p/examples/test-rsa-private-key.pk8 rename to examples/test-rsa-private-key.pk8 diff --git a/libp2p/examples/test-rsa-public-key.der b/examples/test-rsa-public-key.der similarity index 100% rename from libp2p/examples/test-rsa-public-key.der rename to examples/test-rsa-public-key.der diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml deleted file mode 100644 index 517eb68e..00000000 --- a/libp2p/Cargo.toml +++ /dev/null @@ -1,73 +0,0 @@ -[package] -name = "libp2p" -version = "0.1.0" -authors = ["Parity Technologies "] -license = "MIT" - -[features] -default = ["libp2p-secio", "libp2p-secio-secp256k1"] -libp2p-secio-secp256k1 = ["libp2p-secio/secp256k1"] - -[dependencies] -bytes = "0.4" -futures = "0.1" -multiaddr = { path = "../multiaddr" } -libp2p-mplex = { path = "../mplex" } -libp2p-identify = { path = "../identify" } -libp2p-kad = { path = "../kad" } -libp2p-floodsub = { path = "../floodsub" } -libp2p-peerstore = { path = "../peerstore" } -libp2p-ping = { path = "../ping" } -libp2p-ratelimit = { path = "../ratelimit" } -libp2p-relay = { path = "../relay" } -libp2p-core = { path = "../core" } -libp2p-transport-timeout = { path = "../transport-timeout" } -libp2p-uds = { path = "../uds" } -libp2p-websocket = { path = "../websocket" } -libp2p-yamux = { path = "../yamux" } -tokio-codec = "0.1" -tokio-io = "0.1" - -[target.'cfg(not(target_os = "emscripten"))'.dependencies] -libp2p-dns = { path = "../dns" } -libp2p-secio = { path = "../secio", optional = true, default-features = false } -libp2p-tcp-transport = { path = "../tcp-transport" } -tokio-current-thread = "0.1" - -[target.'cfg(target_os = "emscripten")'.dependencies] -stdweb = { version = "0.1.3", default-features = false } - -[dev-dependencies] -bigint = "4.2" -env_logger = "0.5.4" -rand = "0.4" -structopt = "0.2" -tokio-current-thread = "0.1" -tokio-io = "0.1" -tokio-stdin = "0.1" - -[[example]] -name = "echo-dialer" -required-features = ["libp2p-secio"] - -[[example]] -name = "echo-server" -required-features = ["libp2p-secio"] - -[[example]] -name = "floodsub" -required-features = ["libp2p-secio"] - -[[example]] -name = "kademlia" -required-features = ["libp2p-secio"] - -[[example]] -name = "ping-client" -required-features = ["libp2p-secio"] - -[[example]] -name = "random_peerid" - -[[example]] -name = "relay" diff --git a/multiaddr/.gitignore b/misc/multiaddr/.gitignore similarity index 100% rename from multiaddr/.gitignore rename to misc/multiaddr/.gitignore diff --git a/multiaddr/.travis.yml b/misc/multiaddr/.travis.yml similarity index 100% rename from multiaddr/.travis.yml rename to misc/multiaddr/.travis.yml diff --git a/multiaddr/Cargo.toml b/misc/multiaddr/Cargo.toml similarity index 100% rename from multiaddr/Cargo.toml rename to misc/multiaddr/Cargo.toml diff --git a/multiaddr/LICENSE b/misc/multiaddr/LICENSE similarity index 100% rename from multiaddr/LICENSE rename to misc/multiaddr/LICENSE diff --git a/multiaddr/src/errors.rs b/misc/multiaddr/src/errors.rs similarity index 100% rename from multiaddr/src/errors.rs rename to misc/multiaddr/src/errors.rs diff --git a/multiaddr/src/lib.rs b/misc/multiaddr/src/lib.rs similarity index 100% rename from multiaddr/src/lib.rs rename to misc/multiaddr/src/lib.rs diff --git a/multiaddr/src/protocol.rs b/misc/multiaddr/src/protocol.rs similarity index 100% rename from multiaddr/src/protocol.rs rename to misc/multiaddr/src/protocol.rs diff --git a/multiaddr/tests/lib.rs b/misc/multiaddr/tests/lib.rs similarity index 100% rename from multiaddr/tests/lib.rs rename to misc/multiaddr/tests/lib.rs diff --git a/multihash/.gitignore b/misc/multihash/.gitignore similarity index 100% rename from multihash/.gitignore rename to misc/multihash/.gitignore diff --git a/multihash/.travis.yml b/misc/multihash/.travis.yml similarity index 100% rename from multihash/.travis.yml rename to misc/multihash/.travis.yml diff --git a/multihash/Cargo.toml b/misc/multihash/Cargo.toml similarity index 100% rename from multihash/Cargo.toml rename to misc/multihash/Cargo.toml diff --git a/multihash/LICENSE b/misc/multihash/LICENSE similarity index 100% rename from multihash/LICENSE rename to misc/multihash/LICENSE diff --git a/multihash/src/errors.rs b/misc/multihash/src/errors.rs similarity index 100% rename from multihash/src/errors.rs rename to misc/multihash/src/errors.rs diff --git a/multihash/src/hashes.rs b/misc/multihash/src/hashes.rs similarity index 100% rename from multihash/src/hashes.rs rename to misc/multihash/src/hashes.rs diff --git a/multihash/src/lib.rs b/misc/multihash/src/lib.rs similarity index 100% rename from multihash/src/lib.rs rename to misc/multihash/src/lib.rs diff --git a/multihash/tests/lib.rs b/misc/multihash/tests/lib.rs similarity index 100% rename from multihash/tests/lib.rs rename to misc/multihash/tests/lib.rs diff --git a/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml similarity index 100% rename from multistream-select/Cargo.toml rename to misc/multistream-select/Cargo.toml diff --git a/multistream-select/src/dialer_select.rs b/misc/multistream-select/src/dialer_select.rs similarity index 100% rename from multistream-select/src/dialer_select.rs rename to misc/multistream-select/src/dialer_select.rs diff --git a/multistream-select/src/error.rs b/misc/multistream-select/src/error.rs similarity index 100% rename from multistream-select/src/error.rs rename to misc/multistream-select/src/error.rs diff --git a/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs similarity index 100% rename from multistream-select/src/length_delimited.rs rename to misc/multistream-select/src/length_delimited.rs diff --git a/multistream-select/src/lib.rs b/misc/multistream-select/src/lib.rs similarity index 100% rename from multistream-select/src/lib.rs rename to misc/multistream-select/src/lib.rs diff --git a/multistream-select/src/listener_select.rs b/misc/multistream-select/src/listener_select.rs similarity index 100% rename from multistream-select/src/listener_select.rs rename to misc/multistream-select/src/listener_select.rs diff --git a/multistream-select/src/protocol/dialer.rs b/misc/multistream-select/src/protocol/dialer.rs similarity index 100% rename from multistream-select/src/protocol/dialer.rs rename to misc/multistream-select/src/protocol/dialer.rs diff --git a/multistream-select/src/protocol/error.rs b/misc/multistream-select/src/protocol/error.rs similarity index 100% rename from multistream-select/src/protocol/error.rs rename to misc/multistream-select/src/protocol/error.rs diff --git a/multistream-select/src/protocol/listener.rs b/misc/multistream-select/src/protocol/listener.rs similarity index 100% rename from multistream-select/src/protocol/listener.rs rename to misc/multistream-select/src/protocol/listener.rs diff --git a/multistream-select/src/protocol/mod.rs b/misc/multistream-select/src/protocol/mod.rs similarity index 100% rename from multistream-select/src/protocol/mod.rs rename to misc/multistream-select/src/protocol/mod.rs diff --git a/multistream-select/src/tests.rs b/misc/multistream-select/src/tests.rs similarity index 100% rename from multistream-select/src/tests.rs rename to misc/multistream-select/src/tests.rs diff --git a/rw-stream-sink/Cargo.toml b/misc/rw-stream-sink/Cargo.toml similarity index 100% rename from rw-stream-sink/Cargo.toml rename to misc/rw-stream-sink/Cargo.toml diff --git a/rw-stream-sink/src/lib.rs b/misc/rw-stream-sink/src/lib.rs similarity index 100% rename from rw-stream-sink/src/lib.rs rename to misc/rw-stream-sink/src/lib.rs diff --git a/mplex/Cargo.toml b/muxers/mplex/Cargo.toml similarity index 78% rename from mplex/Cargo.toml rename to muxers/mplex/Cargo.toml index 49578d8e..fdbce26e 100644 --- a/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" bytes = "0.4.5" fnv = "1.0" futures = "0.1" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4" parking_lot = "0.6" tokio-codec = "0.1" @@ -16,5 +16,5 @@ tokio-io = "0.1" unsigned-varint = { version = "0.1", features = ["codec"] } [dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../../transports/tcp" } tokio-current-thread = "0.1" diff --git a/mplex/src/codec.rs b/muxers/mplex/src/codec.rs similarity index 100% rename from mplex/src/codec.rs rename to muxers/mplex/src/codec.rs diff --git a/mplex/src/lib.rs b/muxers/mplex/src/lib.rs similarity index 100% rename from mplex/src/lib.rs rename to muxers/mplex/src/lib.rs diff --git a/mplex/tests/two_peers.rs b/muxers/mplex/tests/two_peers.rs similarity index 100% rename from mplex/tests/two_peers.rs rename to muxers/mplex/tests/two_peers.rs diff --git a/yamux/Cargo.toml b/muxers/yamux/Cargo.toml similarity index 86% rename from yamux/Cargo.toml rename to muxers/yamux/Cargo.toml index 54b7a72e..e1dd08fc 100644 --- a/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" [dependencies] bytes = "0.4" futures = "0.1" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4" tokio-io = "0.1" yamux = { git = "https://github.com/paritytech/yamux" } diff --git a/yamux/src/lib.rs b/muxers/yamux/src/lib.rs similarity index 100% rename from yamux/src/lib.rs rename to muxers/yamux/src/lib.rs diff --git a/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml similarity index 82% rename from floodsub/Cargo.toml rename to protocols/floodsub/Cargo.toml index 1c5799df..acd29516 100644 --- a/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -10,9 +10,9 @@ byteorder = "1.2.1" bytes = "0.4" fnv = "1.0" futures = "0.1" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } parking_lot = "0.6" protobuf = "2.0.2" smallvec = "0.6.0" diff --git a/floodsub/regen_structs_proto.sh b/protocols/floodsub/regen_structs_proto.sh similarity index 100% rename from floodsub/regen_structs_proto.sh rename to protocols/floodsub/regen_structs_proto.sh diff --git a/floodsub/rpc.proto b/protocols/floodsub/rpc.proto similarity index 100% rename from floodsub/rpc.proto rename to protocols/floodsub/rpc.proto diff --git a/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs similarity index 100% rename from floodsub/src/lib.rs rename to protocols/floodsub/src/lib.rs diff --git a/floodsub/src/rpc_proto.rs b/protocols/floodsub/src/rpc_proto.rs similarity index 100% rename from floodsub/src/rpc_proto.rs rename to protocols/floodsub/src/rpc_proto.rs diff --git a/floodsub/src/topic.rs b/protocols/floodsub/src/topic.rs similarity index 100% rename from floodsub/src/topic.rs rename to protocols/floodsub/src/topic.rs diff --git a/identify/Cargo.toml b/protocols/identify/Cargo.toml similarity index 65% rename from identify/Cargo.toml rename to protocols/identify/Cargo.toml index 2810dffd..4ad2d745 100644 --- a/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -8,10 +8,10 @@ license = "MIT" bytes = "0.4" fnv = "1" futures = "0.1" -libp2p-peerstore = { path = "../peerstore" } -libp2p-core = { path = "../core" } +libp2p-peerstore = { path = "../../stores/peerstore" } +libp2p-core = { path = "../../core" } log = "0.4.1" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } parking_lot = "0.6" protobuf = "2.0.2" tokio-codec = "0.1" @@ -19,5 +19,5 @@ tokio-io = "0.1.0" unsigned-varint = { version = "0.1", features = ["codec"] } [dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../../transports/tcp" } tokio-current-thread = "0.1" diff --git a/identify/regen_structs_proto.sh b/protocols/identify/regen_structs_proto.sh similarity index 100% rename from identify/regen_structs_proto.sh rename to protocols/identify/regen_structs_proto.sh diff --git a/identify/src/identify_transport.rs b/protocols/identify/src/identify_transport.rs similarity index 100% rename from identify/src/identify_transport.rs rename to protocols/identify/src/identify_transport.rs diff --git a/identify/src/lib.rs b/protocols/identify/src/lib.rs similarity index 100% rename from identify/src/lib.rs rename to protocols/identify/src/lib.rs diff --git a/identify/src/peer_id_transport.rs b/protocols/identify/src/peer_id_transport.rs similarity index 100% rename from identify/src/peer_id_transport.rs rename to protocols/identify/src/peer_id_transport.rs diff --git a/identify/src/protocol.rs b/protocols/identify/src/protocol.rs similarity index 100% rename from identify/src/protocol.rs rename to protocols/identify/src/protocol.rs diff --git a/identify/src/structs_proto.rs b/protocols/identify/src/structs_proto.rs similarity index 100% rename from identify/src/structs_proto.rs rename to protocols/identify/src/structs_proto.rs diff --git a/identify/structs.proto b/protocols/identify/structs.proto similarity index 100% rename from identify/structs.proto rename to protocols/identify/structs.proto diff --git a/kad/Cargo.toml b/protocols/kad/Cargo.toml similarity index 62% rename from kad/Cargo.toml rename to protocols/kad/Cargo.toml index c45105aa..c9914c51 100644 --- a/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -9,14 +9,14 @@ arrayvec = "0.4.7" bs58 = "0.2.0" bigint = "4.2" bytes = "0.4" -datastore = { path = "../datastore" } +datastore = { path = "../../stores/datastore" } fnv = "1.0" futures = "0.1" -libp2p-identify = { path = "../identify" } -libp2p-ping = { path = "../ping" } -libp2p-core = { path = "../core" } +libp2p-identify = { path = "../../protocols/identify" } +libp2p-ping = { path = "../../protocols/ping" } +libp2p-core = { path = "../../core" } log = "0.4" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } parking_lot = "0.6" protobuf = "2.0.2" rand = "0.4.2" @@ -27,6 +27,6 @@ tokio-timer = "0.2.6" unsigned-varint = { version = "0.1", features = ["codec"] } [dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../../transports/tcp" } rand = "0.4.2" tokio-current-thread = "0.1" diff --git a/kad/dht.proto b/protocols/kad/dht.proto similarity index 100% rename from kad/dht.proto rename to protocols/kad/dht.proto diff --git a/kad/record.proto b/protocols/kad/record.proto similarity index 100% rename from kad/record.proto rename to protocols/kad/record.proto diff --git a/kad/regen_dht_proto.sh b/protocols/kad/regen_dht_proto.sh similarity index 100% rename from kad/regen_dht_proto.sh rename to protocols/kad/regen_dht_proto.sh diff --git a/kad/src/high_level.rs b/protocols/kad/src/high_level.rs similarity index 100% rename from kad/src/high_level.rs rename to protocols/kad/src/high_level.rs diff --git a/kad/src/kad_server.rs b/protocols/kad/src/kad_server.rs similarity index 100% rename from kad/src/kad_server.rs rename to protocols/kad/src/kad_server.rs diff --git a/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs similarity index 100% rename from kad/src/kbucket.rs rename to protocols/kad/src/kbucket.rs diff --git a/kad/src/lib.rs b/protocols/kad/src/lib.rs similarity index 100% rename from kad/src/lib.rs rename to protocols/kad/src/lib.rs diff --git a/kad/src/protobuf_structs/dht.rs b/protocols/kad/src/protobuf_structs/dht.rs similarity index 100% rename from kad/src/protobuf_structs/dht.rs rename to protocols/kad/src/protobuf_structs/dht.rs diff --git a/kad/src/protobuf_structs/mod.rs b/protocols/kad/src/protobuf_structs/mod.rs similarity index 100% rename from kad/src/protobuf_structs/mod.rs rename to protocols/kad/src/protobuf_structs/mod.rs diff --git a/kad/src/protobuf_structs/record.rs b/protocols/kad/src/protobuf_structs/record.rs similarity index 100% rename from kad/src/protobuf_structs/record.rs rename to protocols/kad/src/protobuf_structs/record.rs diff --git a/kad/src/protocol.rs b/protocols/kad/src/protocol.rs similarity index 100% rename from kad/src/protocol.rs rename to protocols/kad/src/protocol.rs diff --git a/kad/src/query.rs b/protocols/kad/src/query.rs similarity index 100% rename from kad/src/query.rs rename to protocols/kad/src/query.rs diff --git a/ping/Cargo.toml b/protocols/ping/Cargo.toml similarity index 60% rename from ping/Cargo.toml rename to protocols/ping/Cargo.toml index dfa4f844..9e3dd845 100644 --- a/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -6,10 +6,10 @@ license = "MIT" [dependencies] bytes = "0.4" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" -multiaddr = { path = "../multiaddr" } -multistream-select = { path = "../multistream-select" } +multiaddr = { path = "../../misc/multiaddr" } +multistream-select = { path = "../../misc/multistream-select" } futures = "0.1" parking_lot = "0.6" rand = "0.5" @@ -17,6 +17,6 @@ tokio-codec = "0.1" tokio-io = "0.1" [dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../../transports/tcp" } tokio-current-thread = "0.1" tokio-tcp = "0.1" diff --git a/ping/src/lib.rs b/protocols/ping/src/lib.rs similarity index 100% rename from ping/src/lib.rs rename to protocols/ping/src/lib.rs diff --git a/secio/Cargo.toml b/protocols/secio/Cargo.toml similarity index 83% rename from secio/Cargo.toml rename to protocols/secio/Cargo.toml index d20bd98e..19c04640 100644 --- a/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" asn1_der = "0.5" bytes = "0.4" futures = "0.1" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" protobuf = "2.0.2" rand = "0.3.17" @@ -17,7 +17,7 @@ aes-ctr = "0.1.0" aesni = { version = "0.4.1", features = ["nocheck"], optional = true } ctr = { version = "0.1", optional = true } lazy_static = { version = "0.2.11", optional = true } -rw-stream-sink = { path = "../rw-stream-sink" } +rw-stream-sink = { path = "../../misc/rw-stream-sink" } eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", optional = true } tokio-io = "0.1.0" untrusted = "0.6.2" @@ -28,6 +28,6 @@ secp256k1 = ["eth-secp256k1"] aes-all = ["ctr","aesni","lazy_static"] [dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../../transports/tcp" } tokio-current-thread = "0.1" tokio-tcp = "0.1" diff --git a/secio/regen_structs_proto.sh b/protocols/secio/regen_structs_proto.sh similarity index 100% rename from secio/regen_structs_proto.sh rename to protocols/secio/regen_structs_proto.sh diff --git a/secio/src/algo_support.rs b/protocols/secio/src/algo_support.rs similarity index 100% rename from secio/src/algo_support.rs rename to protocols/secio/src/algo_support.rs diff --git a/secio/src/codec/decode.rs b/protocols/secio/src/codec/decode.rs similarity index 100% rename from secio/src/codec/decode.rs rename to protocols/secio/src/codec/decode.rs diff --git a/secio/src/codec/encode.rs b/protocols/secio/src/codec/encode.rs similarity index 100% rename from secio/src/codec/encode.rs rename to protocols/secio/src/codec/encode.rs diff --git a/secio/src/codec/mod.rs b/protocols/secio/src/codec/mod.rs similarity index 100% rename from secio/src/codec/mod.rs rename to protocols/secio/src/codec/mod.rs diff --git a/secio/src/error.rs b/protocols/secio/src/error.rs similarity index 100% rename from secio/src/error.rs rename to protocols/secio/src/error.rs diff --git a/secio/src/handshake.rs b/protocols/secio/src/handshake.rs similarity index 100% rename from secio/src/handshake.rs rename to protocols/secio/src/handshake.rs diff --git a/secio/src/lib.rs b/protocols/secio/src/lib.rs similarity index 100% rename from secio/src/lib.rs rename to protocols/secio/src/lib.rs diff --git a/secio/src/stream_cipher.rs b/protocols/secio/src/stream_cipher.rs similarity index 100% rename from secio/src/stream_cipher.rs rename to protocols/secio/src/stream_cipher.rs diff --git a/secio/src/structs_proto.rs b/protocols/secio/src/structs_proto.rs similarity index 100% rename from secio/src/structs_proto.rs rename to protocols/secio/src/structs_proto.rs diff --git a/secio/structs.proto b/protocols/secio/structs.proto similarity index 100% rename from secio/structs.proto rename to protocols/secio/structs.proto diff --git a/secio/tests/test-rsa-private-key-2.pk8 b/protocols/secio/tests/test-rsa-private-key-2.pk8 similarity index 100% rename from secio/tests/test-rsa-private-key-2.pk8 rename to protocols/secio/tests/test-rsa-private-key-2.pk8 diff --git a/secio/tests/test-rsa-private-key.pk8 b/protocols/secio/tests/test-rsa-private-key.pk8 similarity index 100% rename from secio/tests/test-rsa-private-key.pk8 rename to protocols/secio/tests/test-rsa-private-key.pk8 diff --git a/secio/tests/test-rsa-public-key-2.der b/protocols/secio/tests/test-rsa-public-key-2.der similarity index 100% rename from secio/tests/test-rsa-public-key-2.der rename to protocols/secio/tests/test-rsa-public-key-2.der diff --git a/secio/tests/test-rsa-public-key.der b/protocols/secio/tests/test-rsa-public-key.der similarity index 100% rename from secio/tests/test-rsa-public-key.der rename to protocols/secio/tests/test-rsa-public-key.der diff --git a/secio/tests/test-secp256k1-private-key-2.der b/protocols/secio/tests/test-secp256k1-private-key-2.der similarity index 100% rename from secio/tests/test-secp256k1-private-key-2.der rename to protocols/secio/tests/test-secp256k1-private-key-2.der diff --git a/secio/tests/test-secp256k1-private-key.der b/protocols/secio/tests/test-secp256k1-private-key.der similarity index 100% rename from secio/tests/test-secp256k1-private-key.der rename to protocols/secio/tests/test-secp256k1-private-key.der diff --git a/libp2p/src/lib.rs b/src/lib.rs similarity index 99% rename from libp2p/src/lib.rs rename to src/lib.rs index aeade5b5..76df8774 100644 --- a/libp2p/src/lib.rs +++ b/src/lib.rs @@ -89,6 +89,7 @@ //! Example: //! //! ```rust +//! # #[cfg(all(not(target_os = "emscripten"), feature = "libp2p-secio"))] { //! use libp2p::{Transport, tcp::TcpConfig, secio::{SecioConfig, SecioKeyPair}}; //! let tcp_transport = TcpConfig::new(); //! let secio_upgrade = SecioConfig { @@ -98,6 +99,7 @@ //! // let _ = with_security.dial(...); //! // `with_security` also implements the `Transport` trait, and all the connections opened //! // through it will automatically negotiate the `secio` protocol. +//! # } //! ``` //! //! See the documentation of the `libp2p-core` crate for more details about upgrades. diff --git a/libp2p/src/simple.rs b/src/simple.rs similarity index 100% rename from libp2p/src/simple.rs rename to src/simple.rs diff --git a/datastore/Cargo.toml b/stores/datastore/Cargo.toml similarity index 100% rename from datastore/Cargo.toml rename to stores/datastore/Cargo.toml diff --git a/datastore/src/json_file.rs b/stores/datastore/src/json_file.rs similarity index 100% rename from datastore/src/json_file.rs rename to stores/datastore/src/json_file.rs diff --git a/datastore/src/lib.rs b/stores/datastore/src/lib.rs similarity index 100% rename from datastore/src/lib.rs rename to stores/datastore/src/lib.rs diff --git a/datastore/src/query.rs b/stores/datastore/src/query.rs similarity index 100% rename from datastore/src/query.rs rename to stores/datastore/src/query.rs diff --git a/peerstore/Cargo.toml b/stores/peerstore/Cargo.toml similarity index 61% rename from peerstore/Cargo.toml rename to stores/peerstore/Cargo.toml index 8e36ce86..d75dba46 100644 --- a/peerstore/Cargo.toml +++ b/stores/peerstore/Cargo.toml @@ -6,15 +6,15 @@ license = "MIT" [dependencies] bs58 = "0.2.0" -datastore = { path = "../datastore" } +datastore = { path = "../../stores/datastore" } futures = "0.1.0" owning_ref = "0.3.3" -libp2p-core = { path = "../core" } -multiaddr = { path = "../multiaddr" } +libp2p-core = { path = "../../core" } +multiaddr = { path = "../../misc/multiaddr" } serde = "1.0.70" serde_derive = "1.0.70" [dev-dependencies] tempfile = "2.2" serde_json = "1.0" -multihash = { path = "../multihash" } +multihash = { path = "../../misc/multihash" } diff --git a/peerstore/src/json_peerstore.rs b/stores/peerstore/src/json_peerstore.rs similarity index 100% rename from peerstore/src/json_peerstore.rs rename to stores/peerstore/src/json_peerstore.rs diff --git a/peerstore/src/lib.rs b/stores/peerstore/src/lib.rs similarity index 100% rename from peerstore/src/lib.rs rename to stores/peerstore/src/lib.rs diff --git a/peerstore/src/memory_peerstore.rs b/stores/peerstore/src/memory_peerstore.rs similarity index 100% rename from peerstore/src/memory_peerstore.rs rename to stores/peerstore/src/memory_peerstore.rs diff --git a/peerstore/src/peer_info.rs b/stores/peerstore/src/peer_info.rs similarity index 100% rename from peerstore/src/peer_info.rs rename to stores/peerstore/src/peer_info.rs diff --git a/peerstore/src/peerstore.rs b/stores/peerstore/src/peerstore.rs similarity index 100% rename from peerstore/src/peerstore.rs rename to stores/peerstore/src/peerstore.rs diff --git a/peerstore/src/peerstore_tests.rs b/stores/peerstore/src/peerstore_tests.rs similarity index 100% rename from peerstore/src/peerstore_tests.rs rename to stores/peerstore/src/peerstore_tests.rs diff --git a/dns/Cargo.toml b/transports/dns/Cargo.toml similarity index 61% rename from dns/Cargo.toml rename to transports/dns/Cargo.toml index 31a01ef1..c67135c9 100644 --- a/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -5,12 +5,12 @@ authors = ["Parity Technologies "] license = "MIT" [dependencies] -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" futures = "0.1" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } tokio-dns-unofficial = "0.3" tokio-io = "0.1" [dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../../transports/tcp" } diff --git a/dns/src/lib.rs b/transports/dns/src/lib.rs similarity index 100% rename from dns/src/lib.rs rename to transports/dns/src/lib.rs diff --git a/ratelimit/Cargo.toml b/transports/ratelimit/Cargo.toml similarity index 87% rename from ratelimit/Cargo.toml rename to transports/ratelimit/Cargo.toml index fbfcbc86..f5724c0b 100644 --- a/ratelimit/Cargo.toml +++ b/transports/ratelimit/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" [dependencies] aio-limited = { git = "https://github.com/paritytech/aio-limited.git" } futures = "0.1" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4" tokio-executor = "0.1" tokio-io = "0.1" diff --git a/ratelimit/src/lib.rs b/transports/ratelimit/src/lib.rs similarity index 100% rename from ratelimit/src/lib.rs rename to transports/ratelimit/src/lib.rs diff --git a/relay/Cargo.toml b/transports/relay/Cargo.toml similarity index 68% rename from relay/Cargo.toml rename to transports/relay/Cargo.toml index 651e2e9f..7fb248e6 100644 --- a/relay/Cargo.toml +++ b/transports/relay/Cargo.toml @@ -7,10 +7,10 @@ license = "MIT" [dependencies] bytes = "0.4" futures = "0.1" -libp2p-peerstore = { path = "../peerstore" } -libp2p-core = { path = "../core" } +libp2p-peerstore = { path = "../../stores/peerstore" } +libp2p-core = { path = "../../core" } log = "0.4" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } protobuf = "2.0.2" rand = "0.4" tokio-codec = "0.1" diff --git a/relay/src/copy.rs b/transports/relay/src/copy.rs similarity index 100% rename from relay/src/copy.rs rename to transports/relay/src/copy.rs diff --git a/relay/src/lib.rs b/transports/relay/src/lib.rs similarity index 100% rename from relay/src/lib.rs rename to transports/relay/src/lib.rs diff --git a/relay/src/message.proto b/transports/relay/src/message.proto similarity index 100% rename from relay/src/message.proto rename to transports/relay/src/message.proto diff --git a/relay/src/message.rs b/transports/relay/src/message.rs similarity index 100% rename from relay/src/message.rs rename to transports/relay/src/message.rs diff --git a/relay/src/protocol.rs b/transports/relay/src/protocol.rs similarity index 100% rename from relay/src/protocol.rs rename to transports/relay/src/protocol.rs diff --git a/relay/src/transport.rs b/transports/relay/src/transport.rs similarity index 100% rename from relay/src/transport.rs rename to transports/relay/src/transport.rs diff --git a/relay/src/utility.rs b/transports/relay/src/utility.rs similarity index 100% rename from relay/src/utility.rs rename to transports/relay/src/utility.rs diff --git a/tcp-transport/Cargo.toml b/transports/tcp/Cargo.toml similarity index 76% rename from tcp-transport/Cargo.toml rename to transports/tcp/Cargo.toml index 1eb872e2..51ea0a96 100644 --- a/tcp-transport/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -5,10 +5,10 @@ authors = ["Parity Technologies "] license = "MIT" [dependencies] -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" futures = "0.1" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } tk-listen = "0.2.0" tokio-io = "0.1" tokio-tcp = "0.1" diff --git a/tcp-transport/src/lib.rs b/transports/tcp/src/lib.rs similarity index 100% rename from tcp-transport/src/lib.rs rename to transports/tcp/src/lib.rs diff --git a/transport-timeout/Cargo.toml b/transports/timeout/Cargo.toml similarity index 83% rename from transport-timeout/Cargo.toml rename to transports/timeout/Cargo.toml index e8975e54..ac28842d 100644 --- a/transport-timeout/Cargo.toml +++ b/transports/timeout/Cargo.toml @@ -6,6 +6,6 @@ license = "MIT" [dependencies] futures = "0.1" -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" tokio-timer = "0.2.6" diff --git a/transport-timeout/src/lib.rs b/transports/timeout/src/lib.rs similarity index 100% rename from transport-timeout/src/lib.rs rename to transports/timeout/src/lib.rs diff --git a/uds/Cargo.toml b/transports/uds/Cargo.toml similarity index 83% rename from uds/Cargo.toml rename to transports/uds/Cargo.toml index ac20bf63..0b84a62a 100644 --- a/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -5,10 +5,10 @@ authors = ["Parity Technologies "] description = "Unix domain sockets transport for libp2p" [target.'cfg(all(unix, not(target_os = "emscripten")))'.dependencies] -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } log = "0.4.1" futures = "0.1" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } tokio-uds = "0.2" [target.'cfg(all(unix, not(target_os = "emscripten")))'.dev-dependencies] diff --git a/uds/src/lib.rs b/transports/uds/src/lib.rs similarity index 100% rename from uds/src/lib.rs rename to transports/uds/src/lib.rs diff --git a/websocket/Cargo.toml b/transports/websocket/Cargo.toml similarity index 74% rename from websocket/Cargo.toml rename to transports/websocket/Cargo.toml index a05c99d3..99e1927d 100644 --- a/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -5,11 +5,11 @@ authors = ["Parity Technologies "] license = "MIT" [dependencies] -libp2p-core = { path = "../core" } +libp2p-core = { path = "../../core" } futures = "0.1" -multiaddr = { path = "../multiaddr" } +multiaddr = { path = "../../misc/multiaddr" } log = "0.4.1" -rw-stream-sink = { path = "../rw-stream-sink" } +rw-stream-sink = { path = "../../misc/rw-stream-sink" } tokio-io = "0.1" [target.'cfg(not(target_os = "emscripten"))'.dependencies] @@ -19,5 +19,5 @@ websocket = { version = "0.20.2", default-features = false, features = ["async", stdweb = { version = "0.1.3", default-features = false } [target.'cfg(not(target_os = "emscripten"))'.dev-dependencies] -libp2p-tcp-transport = { path = "../tcp-transport" } +libp2p-tcp-transport = { path = "../tcp" } tokio-current-thread = "0.1" diff --git a/websocket/src/browser.rs b/transports/websocket/src/browser.rs similarity index 100% rename from websocket/src/browser.rs rename to transports/websocket/src/browser.rs diff --git a/websocket/src/desktop.rs b/transports/websocket/src/desktop.rs similarity index 100% rename from websocket/src/desktop.rs rename to transports/websocket/src/desktop.rs diff --git a/websocket/src/lib.rs b/transports/websocket/src/lib.rs similarity index 100% rename from websocket/src/lib.rs rename to transports/websocket/src/lib.rs