diff --git a/Cargo.toml b/Cargo.toml index 24e37830..07cdeb65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ libp2p-ratelimit = { path = "./transports/ratelimit" } libp2p-core = { path = "./core" } libp2p-core-derive = { path = "./misc/core-derive" } libp2p-secio = { path = "./protocols/secio", default-features = false } -libp2p-transport-timeout = { path = "./transports/timeout" } libp2p-uds = { path = "./transports/uds" } libp2p-websocket = { path = "./transports/websocket", optional = true } libp2p-yamux = { path = "./muxers/yamux" } @@ -72,7 +71,6 @@ members = [ "transports/dns", "transports/ratelimit", "transports/tcp", - "transports/timeout", "transports/uds", "transports/websocket" ] diff --git a/core/src/transport/mod.rs b/core/src/transport/mod.rs index bee8f4c5..75b10486 100644 --- a/core/src/transport/mod.rs +++ b/core/src/transport/mod.rs @@ -33,6 +33,7 @@ use crate::{InboundUpgrade, OutboundUpgrade, nodes::raw_swarm::ConnectedPoint}; use futures::prelude::*; use multiaddr::Multiaddr; use std::io::Error as IoError; +use std::time::Duration; use tokio_io::{AsyncRead, AsyncWrite}; pub mod and_then; @@ -42,6 +43,7 @@ pub mod map; pub mod map_err; pub mod map_err_dial; pub mod memory; +pub mod timeout; pub mod upgrade; pub use self::choice::OrTransport; @@ -198,4 +200,34 @@ pub trait Transport { { and_then::AndThen::new(self, upgrade) } + + /// Adds a timeout to the connection and upgrade steps for all the sockets created by + /// the transport. + #[inline] + fn with_timeout(self, timeout: Duration) -> timeout::TransportTimeout + where + Self: Sized, + { + timeout::TransportTimeout::new(self, timeout) + } + + /// Adds a timeout to the connection and upgrade steps for all the outgoing sockets created + /// by the transport. + #[inline] + fn with_outbound_timeout(self, timeout: Duration) -> timeout::TransportTimeout + where + Self: Sized, + { + timeout::TransportTimeout::with_outgoing_timeout(self, timeout) + } + + /// Adds a timeout to the connection and upgrade steps for all the incoming sockets created + /// by the transport. + #[inline] + fn with_inbound_timeout(self, timeout: Duration) -> timeout::TransportTimeout + where + Self: Sized, + { + timeout::TransportTimeout::with_ingoing_timeout(self, timeout) + } } diff --git a/transports/timeout/src/lib.rs b/core/src/transport/timeout.rs similarity index 97% rename from transports/timeout/src/lib.rs rename to core/src/transport/timeout.rs index fa0b39c5..b22c733d 100644 --- a/transports/timeout/src/lib.rs +++ b/core/src/transport/timeout.rs @@ -23,15 +23,8 @@ //! The timeout includes the upgrading process. // TODO: add example -#[macro_use] -extern crate futures; -extern crate libp2p_core; -#[macro_use] -extern crate log; -extern crate tokio_timer; - +use crate::{Multiaddr, Transport}; use futures::{Async, Future, Poll, Stream}; -use libp2p_core::{Multiaddr, Transport}; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; use std::time::Duration; use tokio_timer::Timeout; diff --git a/src/lib.rs b/src/lib.rs index 27b09391..41636cf3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,7 +154,6 @@ pub extern crate libp2p_ratelimit as ratelimit; pub extern crate libp2p_secio as secio; #[cfg(not(target_os = "emscripten"))] pub extern crate libp2p_tcp as tcp; -pub extern crate libp2p_transport_timeout as transport_timeout; pub extern crate libp2p_uds as uds; #[cfg(feature = "libp2p-websocket")] pub extern crate libp2p_websocket as websocket; @@ -172,7 +171,6 @@ pub use libp2p_core_derive::NetworkBehaviour; pub use self::multiaddr::Multiaddr; pub use self::simple::SimpleProtocol; pub use self::transport_ext::TransportExt; -pub use self::transport_timeout::TransportTimeout; /// Implementation of `Transport` that supports the most common protocols. /// diff --git a/src/transport_ext.rs b/src/transport_ext.rs index 2d9c8e71..1eaf798c 100644 --- a/src/transport_ext.rs +++ b/src/transport_ext.rs @@ -22,9 +22,7 @@ use ratelimit::RateLimited; use std::io; -use std::time::Duration; use tokio_executor::DefaultExecutor; -use transport_timeout::TransportTimeout; use Transport; /// Trait automatically implemented on all objects that implement `Transport`. Provides some @@ -38,41 +36,10 @@ use Transport; /// use std::time::Duration; /// /// let _transport = TcpConfig::new() -/// .with_timeout(Duration::from_secs(20)) /// .with_rate_limit(1024 * 1024, 1024 * 1024); /// ``` /// pub trait TransportExt: Transport { - /// Adds a timeout to the connection and upgrade steps for all the sockets created by - /// the transport. - #[inline] - fn with_timeout(self, timeout: Duration) -> TransportTimeout - where - Self: Sized, - { - TransportTimeout::new(self, timeout) - } - - /// Adds a timeout to the connection and upgrade steps for all the outgoing sockets created - /// by the transport. - #[inline] - fn with_outbound_timeout(self, timeout: Duration) -> TransportTimeout - where - Self: Sized, - { - TransportTimeout::with_outgoing_timeout(self, timeout) - } - - /// Adds a timeout to the connection and upgrade steps for all the incoming sockets created - /// by the transport. - #[inline] - fn with_inbound_timeout(self, timeout: Duration) -> TransportTimeout - where - Self: Sized, - { - TransportTimeout::with_ingoing_timeout(self, timeout) - } - /// Adds a maximum transfer rate to the sockets created with the transport. #[inline] fn with_rate_limit( diff --git a/transports/timeout/Cargo.toml b/transports/timeout/Cargo.toml deleted file mode 100644 index 64fd2f36..00000000 --- a/transports/timeout/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "libp2p-transport-timeout" -description = "Transport timeout adapter for libp2p" -version = "0.1.0" -authors = ["Parity Technologies "] -license = "MIT" -repository = "https://github.com/libp2p/rust-libp2p" -keywords = ["peer-to-peer", "libp2p", "networking"] -categories = ["network-programming", "asynchronous"] - -[dependencies] -futures = "0.1" -libp2p-core = { path = "../../core" } -log = "0.4.1" -tokio-timer = "0.2.6"