Add logging to tcp-transport (#141)

This commit is contained in:
Pierre Krieger 2018-03-15 16:08:49 +01:00 committed by GitHub
parent fd9349d15a
commit f81cc08027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -5,6 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
libp2p-swarm = { path = "../libp2p-swarm" }
log = "0.4.1"
futures = "0.1"
multiaddr = "0.2.0"
tokio-core = "0.1"

View File

@ -51,6 +51,8 @@
extern crate futures;
extern crate libp2p_swarm as swarm;
#[macro_use]
extern crate log;
extern crate multiaddr;
extern crate tokio_core;
extern crate tokio_io;
@ -109,12 +111,15 @@ impl Transport for TcpConfig {
Err(_) => addr,
};
debug!(target: "libp2p-tcp-transport", "Now listening on {}", new_addr);
let future = future::result(listener)
.map(|listener| {
// Pull out a stream of sockets for incoming connections
listener.incoming().map(|(sock, addr)| {
let addr = addr.to_multiaddr()
.expect("generating a multiaddr from a socket addr never fails");
debug!(target: "libp2p-tcp-transport", "Incoming connection from {}", addr);
Ok((sock, addr)).into_future()
})
})
@ -130,6 +135,7 @@ impl Transport for TcpConfig {
/// or gives back the multiaddress.
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, (Self, Multiaddr)> {
if let Ok(socket_addr) = multiaddr_to_socketaddr(&addr) {
debug!(target: "libp2p-tcp-transport", "Dialing {}", addr);
let fut = TcpStream::connect(&socket_addr, &self.event_loop).map(|t| (t, addr));
Ok(Box::new(fut) as Box<_>)
} else {