mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-18 12:31:22 +00:00
Update root crate to use futures-0.3. (#1315)
Mostly mechanical. Creating a `CommonTransport` yields an `io::Result<_>` now since creating the `DnsConfig` may fail with an `io::Error` when creating the `ThreadPool`. The `DnsConfig` `Transport` impl had to be changed slightly: (a) PR [[1311]] requires some `Send` bounds. (b) The async block had to be changed to work around lifetime inference issues which resulted in an "one type is more general than the other" error. [1311]: https://github.com/libp2p/rust-libp2p/pull/1311
This commit is contained in:
24
src/lib.rs
24
src/lib.rs
@ -158,8 +158,6 @@ pub use futures;
|
||||
pub use multiaddr;
|
||||
#[doc(inline)]
|
||||
pub use multihash;
|
||||
pub use tokio_io;
|
||||
pub use tokio_codec;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use libp2p_core as core;
|
||||
@ -229,7 +227,7 @@ use std::{error, io, time::Duration};
|
||||
/// > **Note**: This `Transport` is not suitable for production usage, as its implementation
|
||||
/// > reserves the right to support additional protocols or remove deprecated protocols.
|
||||
pub fn build_development_transport(keypair: identity::Keypair)
|
||||
-> impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone
|
||||
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
|
||||
{
|
||||
build_tcp_ws_secio_mplex_yamux(keypair)
|
||||
}
|
||||
@ -241,14 +239,14 @@ pub fn build_development_transport(keypair: identity::Keypair)
|
||||
///
|
||||
/// > **Note**: If you ever need to express the type of this `Transport`.
|
||||
pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
|
||||
-> impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone
|
||||
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
|
||||
{
|
||||
CommonTransport::new()
|
||||
Ok(CommonTransport::new()?
|
||||
.upgrade(core::upgrade::Version::V1)
|
||||
.authenticate(secio::SecioConfig::new(keypair))
|
||||
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
|
||||
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
|
||||
.timeout(Duration::from_secs(20))
|
||||
.timeout(Duration::from_secs(20)))
|
||||
}
|
||||
|
||||
/// Implementation of `Transport` that supports the most common protocols.
|
||||
@ -276,27 +274,27 @@ struct CommonTransportInner {
|
||||
impl CommonTransport {
|
||||
/// Initializes the `CommonTransport`.
|
||||
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
|
||||
pub fn new() -> CommonTransport {
|
||||
pub fn new() -> io::Result<CommonTransport> {
|
||||
let tcp = tcp::TcpConfig::new().nodelay(true);
|
||||
let transport = dns::DnsConfig::new(tcp);
|
||||
let transport = dns::DnsConfig::new(tcp)?;
|
||||
#[cfg(feature = "libp2p-websocket")]
|
||||
let transport = {
|
||||
let trans_clone = transport.clone();
|
||||
transport.or_transport(websocket::WsConfig::new(trans_clone))
|
||||
};
|
||||
|
||||
CommonTransport {
|
||||
Ok(CommonTransport {
|
||||
inner: CommonTransportInner { inner: transport }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Initializes the `CommonTransport`.
|
||||
#[cfg(any(target_os = "emscripten", target_os = "unknown"))]
|
||||
pub fn new() -> CommonTransport {
|
||||
pub fn new() -> io::Result<CommonTransport> {
|
||||
let inner = core::transport::dummy::DummyTransport::new();
|
||||
CommonTransport {
|
||||
Ok(CommonTransport {
|
||||
inner: CommonTransportInner { inner }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user