Move the transport timeout to libp2p_core (#764)

This commit is contained in:
Pierre Krieger
2018-12-11 10:56:24 +01:00
committed by GitHub
parent 2253c82b86
commit 581778ba92
6 changed files with 33 additions and 60 deletions

View File

@ -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"
]

View File

@ -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<Self>
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<Self>
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<Self>
where
Self: Sized,
{
timeout::TransportTimeout::with_ingoing_timeout(self, timeout)
}
}

View File

@ -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;

View File

@ -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.
///

View File

@ -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<Self>
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<Self>
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<Self>
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(

View File

@ -1,15 +0,0 @@
[package]
name = "libp2p-transport-timeout"
description = "Transport timeout adapter for libp2p"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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"