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