Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into dp/chore/test-cor…
Browse files Browse the repository at this point in the history
…e-handled_node

* upstream/master:
  Add protocol to report external address view. (libp2p#566)
  Add a TransportExt trait (libp2p#533)
  libp2p#399 remove tokio_current_thread tests (libp2p#577)
  • Loading branch information
dvdplm committed Oct 29, 2018
2 parents e79e4f6 + 585c90a commit aaa0a46
Show file tree
Hide file tree
Showing 32 changed files with 396 additions and 88 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ libp2p-uds = { path = "./transports/uds" }
libp2p-websocket = { path = "./transports/websocket" }
libp2p-yamux = { path = "./muxers/yamux" }
tokio-codec = "0.1"
tokio-executor = "0.1"
tokio-io = "0.1"

[target.'cfg(not(target_os = "emscripten"))'.dependencies]
Expand All @@ -43,7 +44,7 @@ bigint = "4.2"
env_logger = "0.5.4"
rand = "0.4"
structopt = "0.2"
tokio-current-thread = "0.1"
tokio = "0.1"
tokio-io = "0.1"
tokio-stdin = "0.1"

Expand All @@ -59,6 +60,7 @@ members = [
"protocols/identify",
"protocols/kad",
"protocols/ping",
"protocols/observed",
"transports/relay",
"protocols/secio",
"muxers/mplex",
Expand Down
1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ libp2p-mplex = { path = "../muxers/mplex" }
rand = "0.5"
tokio = "0.1"
tokio-codec = "0.1"
tokio-current-thread = "0.1"
tokio-timer = "0.2"
assert_matches = "1.3"
tokio-mock-task = "0.1"
8 changes: 4 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@
//! extern crate libp2p_ping;
//! extern crate libp2p_core;
//! extern crate libp2p_tcp_transport;
//! extern crate tokio_current_thread;
//! extern crate tokio;
//!
//! use futures::{Future, Stream};
//! use libp2p_ping::{Ping, PingOutput};
//! use libp2p_core::Transport;
//! use tokio::runtime::current_thread::Runtime;
//!
//! # fn main() {
//! let ping_finished_future = libp2p_tcp_transport::TcpConfig::new()
Expand All @@ -154,7 +155,8 @@
//! });
//!
//! // Runs until the ping arrives.
//! tokio_current_thread::block_on_all(ping_finished_future).unwrap();
//! let mut rt = Runtime::new().unwrap();
//! let _ = rt.block_on(ping_finished_future).unwrap();
//! # }
//! ```
//!
Expand Down Expand Up @@ -191,8 +193,6 @@ extern crate tokio;
#[cfg(test)]
extern crate tokio_codec;
#[cfg(test)]
extern crate tokio_current_thread;
#[cfg(test)]
extern crate tokio_timer;
#[cfg(test)]
#[macro_use]
Expand Down
7 changes: 1 addition & 6 deletions core/src/upgrade/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,5 @@ pub trait ConnectionUpgrade<C> {
///
/// Because performing the upgrade may not be instantaneous (eg. it may require a handshake),
/// this function returns a future instead of the direct output.
fn upgrade(
self,
socket: C,
id: Self::UpgradeIdentifier,
ty: Endpoint,
) -> Self::Future;
fn upgrade(self, socket: C, id: Self::UpgradeIdentifier, ty: Endpoint) -> Self::Future;
}
2 changes: 1 addition & 1 deletion misc/multistream-select/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ tokio-io = "0.1"
unsigned-varint = { version = "0.2.1", features = ["codec"] }

[dev-dependencies]
tokio-current-thread = "0.1"
tokio = "0.1"
tokio-tcp = "0.1"
12 changes: 8 additions & 4 deletions misc/multistream-select/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
//! extern crate bytes;
//! extern crate futures;
//! extern crate multistream_select;
//! extern crate tokio_current_thread;
//! extern crate tokio;
//! extern crate tokio_tcp;
//!
//! # fn main() {
//! use bytes::Bytes;
//! use multistream_select::dialer_select_proto;
//! use futures::{Future, Sink, Stream};
//! use tokio_tcp::TcpStream;
//! use tokio::runtime::current_thread::Runtime;
//!
//! #[derive(Debug, Copy, Clone)]
//! enum MyProto { Echo, Hello }
Expand All @@ -68,7 +69,8 @@
//! dialer_select_proto(connec, protos).map(|r| r.0)
//! });
//!
//! let negotiated_protocol: MyProto = tokio_current_thread::block_on_all(client)
//! let mut rt = Runtime::new().unwrap();
//! let negotiated_protocol: MyProto = rt.block_on(client)
//! .expect("failed to find a protocol");
//! println!("negotiated: {:?}", negotiated_protocol);
//! # }
Expand All @@ -80,14 +82,15 @@
//! extern crate bytes;
//! extern crate futures;
//! extern crate multistream_select;
//! extern crate tokio_current_thread;
//! extern crate tokio;
//! extern crate tokio_tcp;
//!
//! # fn main() {
//! use bytes::Bytes;
//! use multistream_select::listener_select_proto;
//! use futures::{Future, Sink, Stream};
//! use tokio_tcp::TcpListener;
//! use tokio::runtime::current_thread::Runtime;
//!
//! #[derive(Debug, Copy, Clone)]
//! enum MyProto { Echo, Hello }
Expand All @@ -108,7 +111,8 @@
//! Ok(())
//! });
//!
//! tokio_current_thread::block_on_all(server).expect("failed to run server");
//! let mut rt = Runtime::new().unwrap();
//! let _ = rt.block_on(server).expect("failed to run server");
//! # }
//! ```

Expand Down
6 changes: 4 additions & 2 deletions misc/multistream-select/src/protocol/dialer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ impl<T: AsyncWrite> Future for DialerFuture<T> {

#[cfg(test)]
mod tests {
extern crate tokio_current_thread;
extern crate tokio;
extern crate tokio_tcp;
use self::tokio::runtime::current_thread::Runtime;
use self::tokio_tcp::{TcpListener, TcpStream};
use bytes::Bytes;
use futures::Future;
Expand All @@ -210,7 +211,8 @@ mod tests {
dialer.send(DialerToListenerMessage::ProtocolRequest { name: p })
});

match tokio_current_thread::block_on_all(server.join(client)) {
let mut rt = Runtime::new().unwrap();
match rt.block_on(server.join(client)) {
Err(MultistreamSelectError::WrongProtocolName) => (),
_ => panic!(),
}
Expand Down
6 changes: 4 additions & 2 deletions misc/multistream-select/src/protocol/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ impl<T: AsyncRead + AsyncWrite> Future for ListenerFuture<T> {

#[cfg(test)]
mod tests {
extern crate tokio_current_thread;
extern crate tokio;
extern crate tokio_tcp;
use self::tokio::runtime::current_thread::Runtime;
use self::tokio_tcp::{TcpListener, TcpStream};
use bytes::Bytes;
use futures::Future;
Expand All @@ -252,7 +253,8 @@ mod tests {
.from_err()
.and_then(move |stream| Dialer::new(stream));

match tokio_current_thread::block_on_all(server.join(client)) {
let mut rt = Runtime::new().unwrap();
match rt.block_on(server.join(client)) {
Err(MultistreamSelectError::WrongProtocolName) => (),
_ => panic!(),
}
Expand Down
21 changes: 12 additions & 9 deletions misc/multistream-select/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

#![cfg(test)]

extern crate tokio_current_thread;
extern crate tokio;
extern crate tokio_tcp;

use self::tokio::runtime::current_thread::Runtime;
use self::tokio_tcp::{TcpListener, TcpStream};
use bytes::Bytes;
use dialer_select::{dialer_select_proto_parallel, dialer_select_proto_serial};
Expand Down Expand Up @@ -69,8 +70,8 @@ fn negotiate_with_self_succeeds() {
assert_eq!(proto, "/hello/1.0.0");
Ok(())
});

tokio_current_thread::block_on_all(server.join(client)).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(server.join(client)).unwrap();
}

#[test]
Expand Down Expand Up @@ -100,9 +101,9 @@ fn select_proto_basic() {
].into_iter();
dialer_select_proto(connec, protos).map(|r| r.0)
});

let mut rt = Runtime::new().unwrap();
let (dialer_chosen, listener_chosen) =
tokio_current_thread::block_on_all(client.join(server)).unwrap();
rt.block_on(client.join(server)).unwrap();
assert_eq!(dialer_chosen, 3);
assert_eq!(listener_chosen, 1);
}
Expand Down Expand Up @@ -134,8 +135,8 @@ fn no_protocol_found() {
].into_iter();
dialer_select_proto(connec, protos).map(|r| r.0)
});

match tokio_current_thread::block_on_all(client.join(server)) {
let mut rt = Runtime::new().unwrap();
match rt.block_on(client.join(server)) {
Err(ProtocolChoiceError::NoProtocolFound) => (),
_ => panic!(),
}
Expand Down Expand Up @@ -169,8 +170,9 @@ fn select_proto_parallel() {
dialer_select_proto_parallel(connec, protos).map(|r| r.0)
});

let mut rt = Runtime::new().unwrap();
let (dialer_chosen, listener_chosen) =
tokio_current_thread::block_on_all(client.join(server)).unwrap();
rt.block_on(client.join(server)).unwrap();
assert_eq!(dialer_chosen, 3);
assert_eq!(listener_chosen, 1);
}
Expand Down Expand Up @@ -200,8 +202,9 @@ fn select_proto_serial() {
dialer_select_proto_serial(connec, protos).map(|r| r.0)
});

let mut rt = Runtime::new().unwrap();
let (dialer_chosen, listener_chosen) =
tokio_current_thread::block_on_all(client.join(server)).unwrap();
rt.block_on(client.join(server)).unwrap();
assert_eq!(dialer_chosen, 3);
assert_eq!(listener_chosen, 1);
}
2 changes: 1 addition & 1 deletion muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ unsigned-varint = { version = "0.2.1", features = ["codec"] }

[dev-dependencies]
libp2p-tcp-transport = { path = "../../transports/tcp" }
tokio-current-thread = "0.1"
tokio = "0.1"
15 changes: 10 additions & 5 deletions muxers/mplex/tests/two_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern crate futures;
extern crate libp2p_mplex as multiplex;
extern crate libp2p_core as swarm;
extern crate libp2p_tcp_transport as tcp;
extern crate tokio_current_thread;
extern crate tokio;
extern crate tokio_io;

use futures::future::Future;
Expand All @@ -33,6 +33,7 @@ use std::thread;
use swarm::{muxing, Transport};
use tcp::TcpConfig;
use tokio_io::codec::length_delimited::Framed;
use tokio::runtime::current_thread::Runtime;

#[test]
fn client_to_server_outbound() {
Expand Down Expand Up @@ -67,7 +68,8 @@ fn client_to_server_outbound() {
Ok(())
});

tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
});

let transport = TcpConfig::new().with_upgrade(multiplex::MplexConfig::new());
Expand All @@ -80,7 +82,8 @@ fn client_to_server_outbound() {
.and_then(|server| server.send("hello world".into()))
.map(|_| ());

tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
bg_thread.join().unwrap();
}

Expand Down Expand Up @@ -117,7 +120,8 @@ fn client_to_server_inbound() {
Ok(())
});

tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
});

let transport = TcpConfig::new().with_upgrade(multiplex::MplexConfig::new());
Expand All @@ -130,6 +134,7 @@ fn client_to_server_inbound() {
.and_then(|server| server.send("hello world".into()))
.map(|_| ());

tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
bg_thread.join().unwrap();
}
2 changes: 1 addition & 1 deletion protocols/identify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ void = "1.0"

[dev-dependencies]
libp2p-tcp-transport = { path = "../../transports/tcp" }
tokio-current-thread = "0.1"
tokio = "0.1"
11 changes: 6 additions & 5 deletions protocols/identify/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ fn parse_proto_msg(msg: BytesMut) -> Result<(IdentifyInfo, Multiaddr), IoError>
#[cfg(test)]
mod tests {
extern crate libp2p_tcp_transport;
extern crate tokio_current_thread;
extern crate tokio;

use self::tokio::runtime::current_thread::Runtime;
use self::libp2p_tcp_transport::TcpConfig;
use futures::{Future, Stream};
use libp2p_core::{PublicKey, Transport};
Expand Down Expand Up @@ -255,8 +256,8 @@ mod tests {
),
_ => panic!(),
});

let _ = tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
});

let transport = TcpConfig::new().with_upgrade(IdentifyProtocolConfig);
Expand Down Expand Up @@ -291,8 +292,8 @@ mod tests {
}
_ => panic!(),
});

let _ = tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
bg_thread.join().unwrap();
}
}
2 changes: 1 addition & 1 deletion protocols/kad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ unsigned-varint = { version = "0.2.1", features = ["codec"] }
[dev-dependencies]
libp2p-tcp-transport = { path = "../../transports/tcp" }
rand = "0.4.2"
tokio-current-thread = "0.1"
tokio = "0.1"
12 changes: 7 additions & 5 deletions protocols/kad/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn proto_to_msg(mut message: protobuf_structs::dht::Message) -> Result<KadMsg, I
#[cfg(test)]
mod tests {
extern crate libp2p_tcp_transport;
extern crate tokio_current_thread;
extern crate tokio;

use self::libp2p_tcp_transport::TcpConfig;
use futures::{Future, Sink, Stream};
Expand All @@ -418,6 +418,8 @@ mod tests {
use protocol::{KadConnectionType, KadMsg, KademliaProtocolConfig, KadPeer};
use std::sync::mpsc;
use std::thread;
use self::tokio::runtime::current_thread::Runtime;


#[test]
fn correct_transfer() {
Expand Down Expand Up @@ -494,8 +496,8 @@ mod tests {
assert_eq!(recv_msg.unwrap(), msg_server);
()
});

let _ = tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
});

let transport = TcpConfig::new().with_upgrade(KademliaProtocolConfig);
Expand All @@ -505,8 +507,8 @@ mod tests {
.unwrap_or_else(|_| panic!())
.and_then(|proto| proto.send(msg_client))
.map(|_| ());

let _ = tokio_current_thread::block_on_all(future).unwrap();
let mut rt = Runtime::new().unwrap();
let _ = rt.block_on(future).unwrap();
bg_thread.join().unwrap();
}
}
Expand Down
Loading

0 comments on commit aaa0a46

Please sign in to comment.