mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-01 02:31:33 +00:00
Move the transport timeout to libp2p_core (#764)
This commit is contained in:
@ -28,7 +28,6 @@ libp2p-ratelimit = { path = "./transports/ratelimit" }
|
|||||||
libp2p-core = { path = "./core" }
|
libp2p-core = { path = "./core" }
|
||||||
libp2p-core-derive = { path = "./misc/core-derive" }
|
libp2p-core-derive = { path = "./misc/core-derive" }
|
||||||
libp2p-secio = { path = "./protocols/secio", default-features = false }
|
libp2p-secio = { path = "./protocols/secio", default-features = false }
|
||||||
libp2p-transport-timeout = { path = "./transports/timeout" }
|
|
||||||
libp2p-uds = { path = "./transports/uds" }
|
libp2p-uds = { path = "./transports/uds" }
|
||||||
libp2p-websocket = { path = "./transports/websocket", optional = true }
|
libp2p-websocket = { path = "./transports/websocket", optional = true }
|
||||||
libp2p-yamux = { path = "./muxers/yamux" }
|
libp2p-yamux = { path = "./muxers/yamux" }
|
||||||
@ -72,7 +71,6 @@ members = [
|
|||||||
"transports/dns",
|
"transports/dns",
|
||||||
"transports/ratelimit",
|
"transports/ratelimit",
|
||||||
"transports/tcp",
|
"transports/tcp",
|
||||||
"transports/timeout",
|
|
||||||
"transports/uds",
|
"transports/uds",
|
||||||
"transports/websocket"
|
"transports/websocket"
|
||||||
]
|
]
|
||||||
|
@ -33,6 +33,7 @@ use crate::{InboundUpgrade, OutboundUpgrade, nodes::raw_swarm::ConnectedPoint};
|
|||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
|
use std::time::Duration;
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
pub mod and_then;
|
pub mod and_then;
|
||||||
@ -42,6 +43,7 @@ pub mod map;
|
|||||||
pub mod map_err;
|
pub mod map_err;
|
||||||
pub mod map_err_dial;
|
pub mod map_err_dial;
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
pub mod timeout;
|
||||||
pub mod upgrade;
|
pub mod upgrade;
|
||||||
|
|
||||||
pub use self::choice::OrTransport;
|
pub use self::choice::OrTransport;
|
||||||
@ -198,4 +200,34 @@ pub trait Transport {
|
|||||||
{
|
{
|
||||||
and_then::AndThen::new(self, upgrade)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,8 @@
|
|||||||
//! The timeout includes the upgrading process.
|
//! The timeout includes the upgrading process.
|
||||||
// TODO: add example
|
// TODO: add example
|
||||||
|
|
||||||
#[macro_use]
|
use crate::{Multiaddr, Transport};
|
||||||
extern crate futures;
|
|
||||||
extern crate libp2p_core;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate tokio_timer;
|
|
||||||
|
|
||||||
use futures::{Async, Future, Poll, Stream};
|
use futures::{Async, Future, Poll, Stream};
|
||||||
use libp2p_core::{Multiaddr, Transport};
|
|
||||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio_timer::Timeout;
|
use tokio_timer::Timeout;
|
@ -154,7 +154,6 @@ pub extern crate libp2p_ratelimit as ratelimit;
|
|||||||
pub extern crate libp2p_secio as secio;
|
pub extern crate libp2p_secio as secio;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
pub extern crate libp2p_tcp as tcp;
|
pub extern crate libp2p_tcp as tcp;
|
||||||
pub extern crate libp2p_transport_timeout as transport_timeout;
|
|
||||||
pub extern crate libp2p_uds as uds;
|
pub extern crate libp2p_uds as uds;
|
||||||
#[cfg(feature = "libp2p-websocket")]
|
#[cfg(feature = "libp2p-websocket")]
|
||||||
pub extern crate libp2p_websocket as 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::multiaddr::Multiaddr;
|
||||||
pub use self::simple::SimpleProtocol;
|
pub use self::simple::SimpleProtocol;
|
||||||
pub use self::transport_ext::TransportExt;
|
pub use self::transport_ext::TransportExt;
|
||||||
pub use self::transport_timeout::TransportTimeout;
|
|
||||||
|
|
||||||
/// Implementation of `Transport` that supports the most common protocols.
|
/// Implementation of `Transport` that supports the most common protocols.
|
||||||
///
|
///
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
|
|
||||||
use ratelimit::RateLimited;
|
use ratelimit::RateLimited;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::time::Duration;
|
|
||||||
use tokio_executor::DefaultExecutor;
|
use tokio_executor::DefaultExecutor;
|
||||||
use transport_timeout::TransportTimeout;
|
|
||||||
use Transport;
|
use Transport;
|
||||||
|
|
||||||
/// Trait automatically implemented on all objects that implement `Transport`. Provides some
|
/// Trait automatically implemented on all objects that implement `Transport`. Provides some
|
||||||
@ -38,41 +36,10 @@ use Transport;
|
|||||||
/// use std::time::Duration;
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let _transport = TcpConfig::new()
|
/// let _transport = TcpConfig::new()
|
||||||
/// .with_timeout(Duration::from_secs(20))
|
|
||||||
/// .with_rate_limit(1024 * 1024, 1024 * 1024);
|
/// .with_rate_limit(1024 * 1024, 1024 * 1024);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
pub trait TransportExt: Transport {
|
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.
|
/// Adds a maximum transfer rate to the sockets created with the transport.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_rate_limit(
|
fn with_rate_limit(
|
||||||
|
@ -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"
|
|
Reference in New Issue
Block a user