diff --git a/.circleci/config.yml b/.circleci/config.yml index f834b7c0..1d49d265 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,9 +64,9 @@ jobs: - restore_cache: key: integration-test-cache - run: - command: cargo run -p example --example ping-client -- /ip4/127.0.0.1/tcp/4001 + command: cargo run -p libp2p --example ping-client -- /ip4/127.0.0.1/tcp/4001 - run: - command: cargo run -p example --example echo-dialer -- /ip4/127.0.0.1/tcp/10333 + command: cargo run -p libp2p --example echo-dialer -- /ip4/127.0.0.1/tcp/10333 - save_cache: key: integration-test-cache paths: diff --git a/Cargo.toml b/Cargo.toml index 09b46c04..2b78a88c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ members = [ "circular-buffer", "datastore", "dns", - "example", "floodsub", "identify", "kad", diff --git a/example/Cargo.toml b/example/Cargo.toml deleted file mode 100644 index c76c30bd..00000000 --- a/example/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "example" -version = "0.1.0" -authors = ["pierre "] - -[dependencies] -bigint = "4.2" -bytes = "0.4" -env_logger = "0.5.4" -futures = "0.1" -multiaddr = "0.3" -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-relay = { path = "../relay" } -libp2p-secio = { path = "../secio" } -libp2p-core = { path = "../core" } -libp2p-tcp-transport = { path = "../tcp-transport" } -libp2p-websocket = { path = "../websocket" } -rand = "0.4" -structopt = "0.2" -tokio-core = "0.1" -tokio-io = "0.1" -tokio-stdin = "0.1" diff --git a/example/README.md b/example/README.md deleted file mode 100644 index 0b76d424..00000000 --- a/example/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Examples - -Running one of the examples: - -```sh -cargo run --example -``` - -The follow examples exist: - -- `echo-dialer` will attempt to connect to `/ip4/127.0.0.1/tcp/10333`, negotiate the `/echo/1.0.0` - protocol, then send the `"hello world"` message. Compatible with the `echo-server` example. -- `echo-server` will listen on `/ip4/0.0.0.0/tcp/10333`, negotiate the `/echo/1.0.0` protocol with - each incoming connection, then send back any entering message. Compatible with the `echo-dialer` - example. -- `ping-client` will try to connect to `/ip4/127.0.0.1/tcp/4001`, which is the default address of - your local IPFS node if you're running one. It will then open a substream and ping the node. - -## How the keys were generated - -The keys used in the examples were generated like this: - -```sh -openssl genrsa -out private.pem 2048 -openssl rsa -in private.pem -outform DER -pubout -out public.der -openssl pkcs8 -in private.pem -topk8 -nocrypt -out private.pk8 -rm private.pem # optional -``` diff --git a/example/src/lib.rs b/example/src/lib.rs deleted file mode 100644 index 790445f4..00000000 --- a/example/src/lib.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 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. - -extern crate libp2p_peerstore; -extern crate libp2p_core; -extern crate multiaddr; - -use libp2p_peerstore::{PeerAccess, PeerId, Peerstore}; -use multiaddr::Multiaddr; -use std::time::Duration; - -/// Stores initial addresses on the given peer store. Uses a very large timeout. -pub fn ipfs_bootstrap

(peer_store: P) -where - P: Peerstore + Clone, -{ - const ADDRESSES: &[&str] = &[ - "/ip4/127.0.0.1/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", - // TODO: add some bootstrap nodes here - ]; - - let ttl = Duration::from_secs(100 * 365 * 24 * 3600); - - for address in ADDRESSES.iter() { - let mut multiaddr = address - .parse::() - .expect("failed to parse hard-coded multiaddr"); - - let ipfs_component = multiaddr.pop().expect("hard-coded multiaddr is empty"); - let peer = match ipfs_component { - multiaddr::AddrComponent::IPFS(key) => { - PeerId::from_bytes(key).expect("invalid peer id") - } - _ => panic!("hard-coded multiaddr didn't end with /ipfs/"), - }; - - peer_store - .clone() - .peer_or_create(&peer) - .add_addr(multiaddr, ttl.clone()); - } -} diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 2c6bb00e..94f3f2b6 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -16,8 +16,17 @@ libp2p-peerstore = { path = "../peerstore" } libp2p-ping = { path = "../ping" } libp2p-ratelimit = { path = "../ratelimit" } libp2p-relay = { path = "../relay" } -#libp2p-secio = { path = "../secio" } +libp2p-secio = { path = "../secio" } libp2p-core = { path = "../core" } libp2p-tcp-transport = { path = "../tcp-transport" } libp2p-websocket = { path = "../websocket" } tokio-core = "0.1" + +[dev-dependencies] +bigint = "4.2" +env_logger = "0.5.4" +rand = "0.4" +structopt = "0.2" +tokio-core = "0.1" +tokio-io = "0.1" +tokio-stdin = "0.1" diff --git a/libp2p/examples/README.md b/libp2p/examples/README.md new file mode 100644 index 00000000..28a90908 --- /dev/null +++ b/libp2p/examples/README.md @@ -0,0 +1,10 @@ +# How the keys were generated + +The keys used in the examples were generated like this: + +```sh +openssl genrsa -out private.pem 2048 +openssl rsa -in private.pem -outform DER -pubout -out public.der +openssl pkcs8 -in private.pem -topk8 -nocrypt -out private.pk8 +rm private.pem # optional +``` diff --git a/example/examples/echo-dialer.rs b/libp2p/examples/echo-dialer.rs similarity index 91% rename from example/examples/echo-dialer.rs rename to libp2p/examples/echo-dialer.rs index 9f047d67..4573366c 100644 --- a/example/examples/echo-dialer.rs +++ b/libp2p/examples/echo-dialer.rs @@ -21,24 +21,20 @@ extern crate bytes; extern crate env_logger; extern crate futures; -extern crate libp2p_mplex as multiplex; -extern crate libp2p_secio as secio; -extern crate libp2p_core as swarm; -extern crate libp2p_tcp_transport as tcp; -extern crate libp2p_websocket as websocket; +extern crate libp2p; extern crate tokio_core; extern crate tokio_io; use futures::sync::oneshot; use futures::{Future, Sink, Stream}; use std::env; -use swarm::Transport; -use swarm::upgrade::{self, DeniedConnectionUpgrade, SimpleProtocol}; -use tcp::TcpConfig; +use libp2p::core::Transport; +use libp2p::core::upgrade::{self, DeniedConnectionUpgrade, SimpleProtocol}; +use libp2p::tcp::TcpConfig; use tokio_core::reactor::Core; use tokio_io::AsyncRead; use tokio_io::codec::BytesCodec; -use websocket::WsConfig; +use libp2p::websocket::WsConfig; fn main() { env_logger::init(); @@ -68,8 +64,8 @@ fn main() { let secio = { let private_key = include_bytes!("test-private-key.pk8"); let public_key = include_bytes!("test-public-key.der").to_vec(); - secio::SecioConfig { - key: secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), + libp2p::secio::SecioConfig { + key: libp2p::secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), } }; @@ -77,7 +73,7 @@ fn main() { }) // On top of plaintext or secio, we will use the multiplex protocol. - .with_upgrade(multiplex::MultiplexConfig::new()) + .with_upgrade(libp2p::mplex::MultiplexConfig::new()) // The object returned by the call to `with_upgrade(MultiplexConfig::new())` can't be used as a // `Transport` because the output of the upgrade is not a stream but a controller for // muxing. We have to explicitly call `into_connection_reuse()` in order to turn this into @@ -88,7 +84,7 @@ fn main() { // connections for us. The second parameter we pass is the connection upgrade that is accepted // by the listening part. We don't want to accept anything, so we pass a dummy object that // represents a connection that is always denied. - let (swarm_controller, swarm_future) = swarm::swarm( + let (swarm_controller, swarm_future) = libp2p::core::swarm( transport.clone().with_upgrade(DeniedConnectionUpgrade), |_socket, _client_addr| -> Result<(), _> { unreachable!("All incoming connections should have been denied") diff --git a/example/examples/echo-server.rs b/libp2p/examples/echo-server.rs similarity index 92% rename from example/examples/echo-server.rs rename to libp2p/examples/echo-server.rs index f735d33a..31e53fed 100644 --- a/example/examples/echo-server.rs +++ b/libp2p/examples/echo-server.rs @@ -21,24 +21,20 @@ extern crate bytes; extern crate env_logger; extern crate futures; -extern crate libp2p_mplex as multiplex; -extern crate libp2p_secio as secio; -extern crate libp2p_core as swarm; -extern crate libp2p_tcp_transport as tcp; -extern crate libp2p_websocket as websocket; +extern crate libp2p; extern crate tokio_core; extern crate tokio_io; use futures::future::{loop_fn, Future, IntoFuture, Loop}; use futures::{Sink, Stream}; use std::env; -use swarm::Transport; -use swarm::upgrade::{self, SimpleProtocol}; -use tcp::TcpConfig; +use libp2p::core::Transport; +use libp2p::core::upgrade::{self, SimpleProtocol}; +use libp2p::tcp::TcpConfig; use tokio_core::reactor::Core; use tokio_io::AsyncRead; use tokio_io::codec::BytesCodec; -use websocket::WsConfig; +use libp2p::websocket::WsConfig; fn main() { env_logger::init(); @@ -67,8 +63,8 @@ fn main() { let secio = { let private_key = include_bytes!("test-private-key.pk8"); let public_key = include_bytes!("test-public-key.der").to_vec(); - secio::SecioConfig { - key: secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), + libp2p::secio::SecioConfig { + key: libp2p::secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), } }; @@ -76,7 +72,7 @@ fn main() { }) // On top of plaintext or secio, we will use the multiplex protocol. - .with_upgrade(multiplex::MultiplexConfig::new()) + .with_upgrade(libp2p::mplex::MultiplexConfig::new()) // The object returned by the call to `with_upgrade(MultiplexConfig::new())` can't be used as a // `Transport` because the output of the upgrade is not a stream but a controller for // muxing. We have to explicitly call `into_connection_reuse()` in order to turn this into @@ -99,7 +95,7 @@ fn main() { // Let's put this `transport` into a *swarm*. The swarm will handle all the incoming and // outgoing connections for us. - let (swarm_controller, swarm_future) = swarm::swarm( + let (swarm_controller, swarm_future) = libp2p::core::swarm( transport.clone().with_upgrade(proto), |socket, client_addr| { println!("Successfully negotiated protocol with {}", client_addr); diff --git a/example/examples/floodsub.rs b/libp2p/examples/floodsub.rs similarity index 86% rename from example/examples/floodsub.rs rename to libp2p/examples/floodsub.rs index eba699fb..5fc92eaa 100644 --- a/example/examples/floodsub.rs +++ b/libp2p/examples/floodsub.rs @@ -21,13 +21,7 @@ extern crate bytes; extern crate env_logger; extern crate futures; -extern crate libp2p_floodsub as floodsub; -extern crate libp2p_mplex as multiplex; -extern crate libp2p_peerstore as peerstore; -extern crate libp2p_secio as secio; -extern crate libp2p_core as swarm; -extern crate libp2p_tcp_transport as tcp; -extern crate libp2p_websocket as websocket; +extern crate libp2p; extern crate rand; extern crate tokio_core; extern crate tokio_io; @@ -35,13 +29,13 @@ extern crate tokio_stdin; use futures::Stream; use futures::future::Future; -use peerstore::PeerId; use std::{env, mem}; -use swarm::upgrade; -use swarm::{Multiaddr, Transport}; -use tcp::TcpConfig; +use libp2p::core::upgrade; +use libp2p::core::{Multiaddr, Transport}; +use libp2p::peerstore::PeerId; +use libp2p::tcp::TcpConfig; use tokio_core::reactor::Core; -use websocket::WsConfig; +use libp2p::websocket::WsConfig; fn main() { env_logger::init(); @@ -70,8 +64,8 @@ fn main() { let secio = { let private_key = include_bytes!("test-private-key.pk8"); let public_key = include_bytes!("test-public-key.der").to_vec(); - secio::SecioConfig { - key: secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), + libp2p::secio::SecioConfig { + key: libp2p::secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), } }; @@ -79,7 +73,7 @@ fn main() { }) // On top of plaintext or secio, we will use the multiplex protocol. - .with_upgrade(multiplex::MultiplexConfig::new()) + .with_upgrade(libp2p::mplex::MultiplexConfig::new()) // The object returned by the call to `with_upgrade(MultiplexConfig::new())` can't be used as a // `Transport` because the output of the upgrade is not a stream but a controller for // muxing. We have to explicitly call `into_connection_reuse()` in order to turn this into @@ -97,11 +91,11 @@ fn main() { PeerId::from_public_key(&key) }; - let (floodsub_upgrade, floodsub_rx) = floodsub::FloodSubUpgrade::new(my_id); + let (floodsub_upgrade, floodsub_rx) = libp2p::floodsub::FloodSubUpgrade::new(my_id); // Let's put this `transport` into a *swarm*. The swarm will handle all the incoming and // outgoing connections for us. - let (swarm_controller, swarm_future) = swarm::swarm( + let (swarm_controller, swarm_future) = libp2p::core::swarm( transport.clone().with_upgrade(floodsub_upgrade.clone()), |socket, client_addr| { println!("Successfully negotiated protocol with {}", client_addr); @@ -114,9 +108,9 @@ fn main() { .expect("unsupported multiaddr"); println!("Now listening on {:?}", address); - let topic = floodsub::TopicBuilder::new("chat").build(); + let topic = libp2p::floodsub::TopicBuilder::new("chat").build(); - let floodsub_ctl = floodsub::FloodSubController::new(&floodsub_upgrade); + let floodsub_ctl = libp2p::floodsub::FloodSubController::new(&floodsub_upgrade); floodsub_ctl.subscribe(&topic); let floodsub_rx = floodsub_rx.for_each(|msg| { diff --git a/example/examples/kademlia.rs b/libp2p/examples/kademlia.rs similarity index 72% rename from example/examples/kademlia.rs rename to libp2p/examples/kademlia.rs index 5212993c..1a51f24e 100644 --- a/example/examples/kademlia.rs +++ b/libp2p/examples/kademlia.rs @@ -21,27 +21,21 @@ extern crate bigint; extern crate bytes; extern crate env_logger; -extern crate example; extern crate futures; -extern crate libp2p_identify as identify; -extern crate libp2p_kad as kad; -extern crate libp2p_mplex as multiplex; -extern crate libp2p_peerstore as peerstore; -extern crate libp2p_secio as secio; -extern crate libp2p_core as swarm; -extern crate libp2p_tcp_transport as tcp; +extern crate libp2p; extern crate tokio_core; extern crate tokio_io; use bigint::U512; use futures::future::Future; -use peerstore::PeerId; +use libp2p::peerstore::{PeerAccess, PeerId, Peerstore}; +use libp2p::Multiaddr; use std::env; use std::sync::Arc; use std::time::Duration; -use swarm::Transport; -use swarm::upgrade; -use tcp::TcpConfig; +use libp2p::core::Transport; +use libp2p::core::upgrade; +use libp2p::tcp::TcpConfig; use tokio_core::reactor::Core; fn main() { @@ -59,8 +53,8 @@ fn main() { // We start by building the tokio engine that will run all the sockets. let mut core = Core::new().unwrap(); - let peer_store = Arc::new(peerstore::memory_peerstore::MemoryPeerstore::empty()); - example::ipfs_bootstrap(&*peer_store); + let peer_store = Arc::new(libp2p::peerstore::memory_peerstore::MemoryPeerstore::empty()); + ipfs_bootstrap(&*peer_store); // Now let's build the transport stack. // We create a `TcpConfig` that indicates that we want TCP/IP. @@ -74,8 +68,8 @@ fn main() { let secio = { let private_key = include_bytes!("test-private-key.pk8"); let public_key = include_bytes!("test-public-key.der").to_vec(); - secio::SecioConfig { - key: secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), + libp2p::secio::SecioConfig { + key: libp2p::secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), } }; @@ -83,14 +77,14 @@ fn main() { }) // On top of plaintext or secio, we will use the multiplex protocol. - .with_upgrade(multiplex::MultiplexConfig::new()) + .with_upgrade(libp2p::mplex::MultiplexConfig::new()) // The object returned by the call to `with_upgrade(MultiplexConfig::new())` can't be used as a // `Transport` because the output of the upgrade is not a stream but a controller for // muxing. We have to explicitly call `into_connection_reuse()` in order to turn this into // a `Transport`. .into_connection_reuse(); - - let transport = identify::IdentifyTransport::new(transport, peer_store.clone()) + + let transport = libp2p::identify::IdentifyTransport::new(transport, peer_store.clone()) .map(|id_out, _, _| { id_out.socket }); @@ -104,7 +98,7 @@ fn main() { // Let's put this `transport` into a Kademlia *swarm*. The swarm will handle all the incoming // and outgoing connections for us. - let kad_config = kad::KademliaConfig { + let kad_config = libp2p::kad::KademliaConfig { parallelism: 3, record_store: (), peer_store: peer_store, @@ -112,13 +106,13 @@ fn main() { timeout: Duration::from_secs(2), }; - let kad_ctl_proto = kad::KademliaControllerPrototype::new(kad_config); + let kad_ctl_proto = libp2p::kad::KademliaControllerPrototype::new(kad_config); - let proto = kad::KademliaUpgrade::from_prototype(&kad_ctl_proto); + let proto = libp2p::kad::KademliaUpgrade::from_prototype(&kad_ctl_proto); // Let's put this `transport` into a *swarm*. The swarm will handle all the incoming and // outgoing connections for us. - let (swarm_controller, swarm_future) = swarm::swarm( + let (swarm_controller, swarm_future) = libp2p::core::swarm( transport.clone().with_upgrade(proto.clone()), |upgrade, _| upgrade, ); @@ -156,3 +150,35 @@ fn main() { .map_err(|(err, _)| err), ).unwrap(); } + +/// Stores initial addresses on the given peer store. Uses a very large timeout. +pub fn ipfs_bootstrap

(peer_store: P) +where + P: Peerstore + Clone, +{ + const ADDRESSES: &[&str] = &[ + "/ip4/127.0.0.1/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", + // TODO: add some bootstrap nodes here + ]; + + let ttl = Duration::from_secs(100 * 365 * 24 * 3600); + + for address in ADDRESSES.iter() { + let mut multiaddr = address + .parse::() + .expect("failed to parse hard-coded multiaddr"); + + let ipfs_component = multiaddr.pop().expect("hard-coded multiaddr is empty"); + let peer = match ipfs_component { + libp2p::multiaddr::AddrComponent::IPFS(key) => { + PeerId::from_bytes(key).expect("invalid peer id") + } + _ => panic!("hard-coded multiaddr didn't end with /ipfs/"), + }; + + peer_store + .clone() + .peer_or_create(&peer) + .add_addr(multiaddr, ttl.clone()); + } +} diff --git a/example/examples/ping-client.rs b/libp2p/examples/ping-client.rs similarity index 88% rename from example/examples/ping-client.rs rename to libp2p/examples/ping-client.rs index 2b64d565..b5891562 100644 --- a/example/examples/ping-client.rs +++ b/libp2p/examples/ping-client.rs @@ -21,20 +21,16 @@ extern crate bytes; extern crate env_logger; extern crate futures; -extern crate libp2p_mplex as multiplex; -extern crate libp2p_ping as ping; -extern crate libp2p_secio as secio; -extern crate libp2p_core as swarm; -extern crate libp2p_tcp_transport as tcp; +extern crate libp2p; extern crate tokio_core; extern crate tokio_io; use futures::Future; use futures::sync::oneshot; use std::env; -use swarm::Transport; -use swarm::upgrade::{self, DeniedConnectionUpgrade}; -use tcp::TcpConfig; +use libp2p::core::Transport; +use libp2p::core::upgrade::{self, DeniedConnectionUpgrade}; +use libp2p::tcp::TcpConfig; use tokio_core::reactor::Core; fn main() { @@ -60,8 +56,8 @@ fn main() { let secio = { let private_key = include_bytes!("test-private-key.pk8"); let public_key = include_bytes!("test-public-key.der").to_vec(); - secio::SecioConfig { - key: secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), + libp2p::secio::SecioConfig { + key: libp2p::secio::SecioKeyPair::rsa_from_pkcs8(private_key, public_key).unwrap(), } }; @@ -69,7 +65,7 @@ fn main() { }) // On top of plaintext or secio, we will use the multiplex protocol. - .with_upgrade(multiplex::MultiplexConfig::new()) + .with_upgrade(libp2p::mplex::MultiplexConfig::new()) // The object returned by the call to `with_upgrade(MultiplexConfig::new())` can't be used as a // `Transport` because the output of the upgrade is not a stream but a controller for // muxing. We have to explicitly call `into_connection_reuse()` in order to turn this into @@ -80,7 +76,7 @@ fn main() { // connections for us. The second parameter we pass is the connection upgrade that is accepted // by the listening part. We don't want to accept anything, so we pass a dummy object that // represents a connection that is always denied. - let (swarm_controller, swarm_future) = swarm::swarm( + let (swarm_controller, swarm_future) = libp2p::core::swarm( transport.clone().with_upgrade(DeniedConnectionUpgrade), |_socket, _client_addr| -> Result<(), _> { unreachable!("All incoming connections should have been denied") @@ -91,7 +87,7 @@ fn main() { let (tx, rx) = oneshot::channel(); swarm_controller .dial_custom_handler(target_addr.parse().expect("invalid multiaddr"), - transport.with_upgrade(ping::Ping), + transport.with_upgrade(libp2p::ping::Ping), |(mut pinger, future), _| { let ping = pinger.ping().map_err(|_| unreachable!()).inspect(|_| { println!("Received pong from the remote"); diff --git a/example/examples/random_peerid.rs b/libp2p/examples/random_peerid.rs similarity index 95% rename from example/examples/random_peerid.rs rename to libp2p/examples/random_peerid.rs index 9ca15f5c..3b53f5db 100644 --- a/example/examples/random_peerid.rs +++ b/libp2p/examples/random_peerid.rs @@ -18,10 +18,10 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate libp2p_peerstore; +extern crate libp2p; extern crate rand; -use libp2p_peerstore::PeerId; +use libp2p::peerstore::PeerId; fn main() { let pid = { diff --git a/example/examples/relay.rs b/libp2p/examples/relay.rs similarity index 91% rename from example/examples/relay.rs rename to libp2p/examples/relay.rs index 54383a24..832f4b6d 100644 --- a/example/examples/relay.rs +++ b/libp2p/examples/relay.rs @@ -49,26 +49,22 @@ extern crate bytes; extern crate env_logger; extern crate futures; -extern crate libp2p_mplex as multiplex; -extern crate libp2p_peerstore as peerstore; -extern crate libp2p_relay as relay; -extern crate libp2p_core as core; -extern crate libp2p_tcp_transport as tcp; +extern crate libp2p; extern crate rand; #[macro_use] extern crate structopt; extern crate tokio_core; extern crate tokio_io; -use core::Multiaddr; -use core::transport::Transport; -use core::upgrade::{self, SimpleProtocol}; +use libp2p::core::Multiaddr; +use libp2p::core::transport::Transport; +use libp2p::core::upgrade::{self, SimpleProtocol}; use futures::{future::{self, Either, Loop, loop_fn}, prelude::*}; -use peerstore::{PeerAccess, PeerId, Peerstore, memory_peerstore::MemoryPeerstore}; -use relay::{RelayConfig, RelayTransport}; +use libp2p::peerstore::{PeerAccess, PeerId, Peerstore, memory_peerstore::MemoryPeerstore}; +use libp2p::relay::{RelayConfig, RelayTransport}; use std::{error::Error, iter, str::FromStr, sync::Arc, time::Duration}; use structopt::StructOpt; -use tcp::TcpConfig; +use libp2p::tcp::TcpConfig; use tokio_core::reactor::Core; use tokio_io::{AsyncRead, codec::BytesCodec}; @@ -135,7 +131,7 @@ fn run_dialer(opts: DialerOpts) -> Result<(), Box> { RelayTransport::new(opts.me, tcp, store, iter::once(opts.relay)).with_dummy_muxing() }; - let (control, future) = core::swarm(transport.clone(), |_, _| { + let (control, future) = libp2p::core::swarm(transport.clone(), |_, _| { future::ok(()) }); @@ -176,16 +172,16 @@ fn run_listener(opts: ListenerOpts) -> Result<(), Box> { let upgraded = transport.with_upgrade(relay) .and_then(|out, endpoint, addr| { match out { - relay::Output::Sealed(future) => { + libp2p::relay::Output::Sealed(future) => { Either::A(future.map(Either::A)) } - relay::Output::Stream(socket) => { + libp2p::relay::Output::Stream(socket) => { Either::B(upgrade::apply(socket, echo, endpoint, addr).map(Either::B)) } } }); - let (control, future) = core::swarm(upgraded, |out, _| { + let (control, future) = libp2p::core::swarm(upgraded, |out, _| { match out { Either::A(()) => Either::A(future::ok(())), Either::B((socket, _)) => Either::B(loop_fn(socket, move |socket| { diff --git a/example/examples/test-private-key.pk8 b/libp2p/examples/test-private-key.pk8 similarity index 100% rename from example/examples/test-private-key.pk8 rename to libp2p/examples/test-private-key.pk8 diff --git a/example/examples/test-public-key.der b/libp2p/examples/test-public-key.der similarity index 100% rename from example/examples/test-public-key.der rename to libp2p/examples/test-public-key.der diff --git a/libp2p/src/lib.rs b/libp2p/src/lib.rs index bb23d308..38fbddfc 100644 --- a/libp2p/src/lib.rs +++ b/libp2p/src/lib.rs @@ -33,7 +33,7 @@ pub extern crate libp2p_peerstore as peerstore; pub extern crate libp2p_ping as ping; pub extern crate libp2p_ratelimit as ratelimit; pub extern crate libp2p_relay as relay; -//pub extern crate libp2p_secio as secio; +pub extern crate libp2p_secio as secio; pub extern crate libp2p_tcp_transport as tcp; pub extern crate libp2p_websocket as websocket;