mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-30 10:11:33 +00:00
committed by
Pierre Krieger
parent
56ca46eb7a
commit
445ae17904
@ -23,7 +23,6 @@ pub mod choice;
|
|||||||
pub mod denied;
|
pub mod denied;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod plaintext;
|
pub mod plaintext;
|
||||||
pub mod simple;
|
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
|
|
||||||
pub use self::apply::apply;
|
pub use self::apply::apply;
|
||||||
@ -31,5 +30,4 @@ pub use self::choice::{or, OrUpgrade};
|
|||||||
pub use self::denied::DeniedConnectionUpgrade;
|
pub use self::denied::DeniedConnectionUpgrade;
|
||||||
pub use self::map::map;
|
pub use self::map::map;
|
||||||
pub use self::plaintext::PlainTextConfig;
|
pub use self::plaintext::PlainTextConfig;
|
||||||
pub use self::simple::SimpleProtocol;
|
|
||||||
pub use self::traits::{ConnectionUpgrade, Endpoint};
|
pub use self::traits::{ConnectionUpgrade, Endpoint};
|
||||||
|
@ -16,6 +16,7 @@ libp2p-ping = { path = "../ping" }
|
|||||||
libp2p-relay = { path = "../relay" }
|
libp2p-relay = { path = "../relay" }
|
||||||
libp2p-core = { path = "../core" }
|
libp2p-core = { path = "../core" }
|
||||||
libp2p-websocket = { path = "../websocket" }
|
libp2p-websocket = { path = "../websocket" }
|
||||||
|
tokio-io = "0.1"
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
|
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
|
||||||
libp2p-dns = { path = "../dns" }
|
libp2p-dns = { path = "../dns" }
|
||||||
|
@ -28,8 +28,9 @@ extern crate tokio_io;
|
|||||||
use futures::sync::oneshot;
|
use futures::sync::oneshot;
|
||||||
use futures::{Future, Sink, Stream};
|
use futures::{Future, Sink, Stream};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use libp2p::SimpleProtocol;
|
||||||
use libp2p::core::Transport;
|
use libp2p::core::Transport;
|
||||||
use libp2p::core::upgrade::{self, SimpleProtocol};
|
use libp2p::core::upgrade;
|
||||||
use libp2p::tcp::TcpConfig;
|
use libp2p::tcp::TcpConfig;
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
use tokio_io::AsyncRead;
|
use tokio_io::AsyncRead;
|
||||||
|
@ -28,8 +28,9 @@ extern crate tokio_io;
|
|||||||
use futures::future::{loop_fn, Future, IntoFuture, Loop};
|
use futures::future::{loop_fn, Future, IntoFuture, Loop};
|
||||||
use futures::{Sink, Stream};
|
use futures::{Sink, Stream};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use libp2p::SimpleProtocol;
|
||||||
use libp2p::core::Transport;
|
use libp2p::core::Transport;
|
||||||
use libp2p::core::upgrade::{self, SimpleProtocol};
|
use libp2p::core::upgrade;
|
||||||
use libp2p::tcp::TcpConfig;
|
use libp2p::tcp::TcpConfig;
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
use tokio_io::AsyncRead;
|
use tokio_io::AsyncRead;
|
||||||
|
@ -56,9 +56,10 @@ extern crate structopt;
|
|||||||
extern crate tokio_core;
|
extern crate tokio_core;
|
||||||
extern crate tokio_io;
|
extern crate tokio_io;
|
||||||
|
|
||||||
|
use libp2p::SimpleProtocol;
|
||||||
use libp2p::core::Multiaddr;
|
use libp2p::core::Multiaddr;
|
||||||
use libp2p::core::transport::Transport;
|
use libp2p::core::transport::Transport;
|
||||||
use libp2p::core::upgrade::{self, SimpleProtocol};
|
use libp2p::core::upgrade;
|
||||||
use futures::{future::{self, Either, Loop, loop_fn}, prelude::*};
|
use futures::{future::{self, Either, Loop, loop_fn}, prelude::*};
|
||||||
use libp2p::peerstore::{PeerAccess, PeerId, Peerstore, memory_peerstore::MemoryPeerstore};
|
use libp2p::peerstore::{PeerAccess, PeerId, Peerstore, memory_peerstore::MemoryPeerstore};
|
||||||
use libp2p::relay::{RelayConfig, RelayTransport};
|
use libp2p::relay::{RelayConfig, RelayTransport};
|
||||||
|
@ -23,6 +23,7 @@ pub extern crate futures;
|
|||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
pub extern crate tokio_core;
|
pub extern crate tokio_core;
|
||||||
pub extern crate multiaddr;
|
pub extern crate multiaddr;
|
||||||
|
pub extern crate tokio_io;
|
||||||
|
|
||||||
pub extern crate libp2p_core as core;
|
pub extern crate libp2p_core as core;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
@ -42,9 +43,12 @@ pub extern crate libp2p_secio as secio;
|
|||||||
pub extern crate libp2p_tcp_transport as tcp;
|
pub extern crate libp2p_tcp_transport as tcp;
|
||||||
pub extern crate libp2p_websocket as websocket;
|
pub extern crate libp2p_websocket as websocket;
|
||||||
|
|
||||||
|
pub mod simple;
|
||||||
|
|
||||||
pub use self::core::{Transport, ConnectionUpgrade, swarm};
|
pub use self::core::{Transport, ConnectionUpgrade, swarm};
|
||||||
pub use self::multiaddr::Multiaddr;
|
pub use self::multiaddr::Multiaddr;
|
||||||
pub use self::peerstore::PeerId;
|
pub use self::peerstore::PeerId;
|
||||||
|
pub use self::simple::SimpleProtocol;
|
||||||
|
|
||||||
/// Implementation of `Transport` that supports the most common protocols.
|
/// Implementation of `Transport` that supports the most common protocols.
|
||||||
///
|
///
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::future::FromErr;
|
use core::upgrade::{ConnectionUpgrade, Endpoint};
|
||||||
use futures::prelude::*;
|
use futures::{future::FromErr, prelude::*};
|
||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
use std::{iter, io::Error as IoError, sync::Arc};
|
use std::{iter, io::Error as IoError, sync::Arc};
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
use upgrade::{ConnectionUpgrade, Endpoint};
|
|
||||||
|
|
||||||
/// Implementation of `ConnectionUpgrade`. Convenient to use with small protocols.
|
/// Implementation of `ConnectionUpgrade`. Convenient to use with small protocols.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
@ -20,8 +20,7 @@
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use core::{ConnectionUpgrade, Endpoint, Transport};
|
use core::{ConnectionUpgrade, Endpoint, Transport};
|
||||||
use core::upgrade::SimpleProtocol;
|
use futures::{stream, future::{self, Either::{A, B}, FutureResult}, prelude::*};
|
||||||
use futures::{stream, future::{self, Either::{A, B}}, prelude::*};
|
|
||||||
use message::{CircuitRelay, CircuitRelay_Peer, CircuitRelay_Status, CircuitRelay_Type};
|
use message::{CircuitRelay, CircuitRelay_Peer, CircuitRelay_Status, CircuitRelay_Type};
|
||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
use peerstore::{PeerAccess, PeerId, Peerstore};
|
use peerstore::{PeerAccess, PeerId, Peerstore};
|
||||||
@ -137,8 +136,7 @@ where
|
|||||||
|
|
||||||
let stop = stop_message(&from, &dest);
|
let stop = stop_message(&from, &dest);
|
||||||
|
|
||||||
let upgrade = SimpleProtocol::new("/libp2p/relay/circuit/0.1.0", Ok);
|
let transport = self.transport.with_upgrade(TrivialUpgrade);
|
||||||
let transport = self.transport.with_upgrade(upgrade);
|
|
||||||
let dest_id = dest.id;
|
let dest_id = dest.id;
|
||||||
let future = stream::iter_ok(dest.addrs.into_iter())
|
let future = stream::iter_ok(dest.addrs.into_iter())
|
||||||
.and_then(move |dest_addr| {
|
.and_then(move |dest_addr| {
|
||||||
@ -240,6 +238,28 @@ fn stop_message(from: &Peer, dest: &Peer) -> CircuitRelay {
|
|||||||
msg
|
msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
struct TrivialUpgrade;
|
||||||
|
|
||||||
|
impl<C> ConnectionUpgrade<C> for TrivialUpgrade
|
||||||
|
where
|
||||||
|
C: AsyncRead + AsyncWrite + 'static
|
||||||
|
{
|
||||||
|
type NamesIter = iter::Once<(Bytes, Self::UpgradeIdentifier)>;
|
||||||
|
type UpgradeIdentifier = ();
|
||||||
|
|
||||||
|
fn protocol_names(&self) -> Self::NamesIter {
|
||||||
|
iter::once((Bytes::from("/libp2p/relay/circuit/0.1.0"), ()))
|
||||||
|
}
|
||||||
|
|
||||||
|
type Output = C;
|
||||||
|
type Future = FutureResult<Self::Output, io::Error>;
|
||||||
|
|
||||||
|
fn upgrade(self, conn: C, _: (), _: Endpoint, _: &Multiaddr) -> Self::Future {
|
||||||
|
future::ok(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Source(pub(crate) CircuitRelay);
|
pub(crate) struct Source(pub(crate) CircuitRelay);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user