mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-29 12:42:16 +00:00
Remove all target
s from log statements. (#195)
The default uses crate + module path anyway, so `target` has been redundant, causes more work when renaming crates and makes log lines longer.
This commit is contained in:
parent
cb800624f5
commit
86a21fc43e
@ -172,11 +172,11 @@ where
|
|||||||
let inner = self.inner;
|
let inner = self.inner;
|
||||||
let future = substream.and_then(move |outbound| {
|
let future = substream.and_then(move |outbound| {
|
||||||
if let Some(o) = outbound {
|
if let Some(o) = outbound {
|
||||||
debug!(target: "libp2p-core", "Using existing multiplexed connection to {}", addr);
|
debug!("Using existing multiplexed connection to {}", addr);
|
||||||
return Either::A(future::ok(o));
|
return Either::A(future::ok(o));
|
||||||
}
|
}
|
||||||
// The previous stream muxer did not yield a new substream => start new dial
|
// The previous stream muxer did not yield a new substream => start new dial
|
||||||
debug!(target: "libp2p-core", "No existing connection to {}; dialing", addr);
|
debug!("No existing connection to {}; dialing", addr);
|
||||||
match inner.dial(addr.clone()) {
|
match inner.dial(addr.clone()) {
|
||||||
Ok(dial) => {
|
Ok(dial) => {
|
||||||
let future = dial.and_then(move |(muxer, addr)| {
|
let future = dial.and_then(move |(muxer, addr)| {
|
||||||
@ -193,7 +193,7 @@ where
|
|||||||
));
|
));
|
||||||
Ok((s, addr))
|
Ok((s, addr))
|
||||||
} else {
|
} else {
|
||||||
error!(target: "libp2p-core", "failed to dial to {}", addr);
|
error!("failed to dial to {}", addr);
|
||||||
shared.lock().active_connections.remove(&addr);
|
shared.lock().active_connections.remove(&addr);
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "dial failed"))
|
Err(io::Error::new(io::ErrorKind::Other, "dial failed"))
|
||||||
}
|
}
|
||||||
@ -273,13 +273,13 @@ where
|
|||||||
}
|
}
|
||||||
Ok(Async::NotReady) => {}
|
Ok(Async::NotReady) => {}
|
||||||
Ok(Async::Ready(None)) => {
|
Ok(Async::Ready(None)) => {
|
||||||
debug!(target: "libp2p-core", "listener has been closed");
|
debug!("listener has been closed");
|
||||||
if self.connections.is_empty() && self.current_upgrades.is_empty() {
|
if self.connections.is_empty() && self.current_upgrades.is_empty() {
|
||||||
return Ok(Async::Ready(None));
|
return Ok(Async::Ready(None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-core", "error while polling listener: {:?}", err);
|
debug!("error while polling listener: {:?}", err);
|
||||||
if self.connections.is_empty() && self.current_upgrades.is_empty() {
|
if self.connections.is_empty() && self.current_upgrades.is_empty() {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
@ -296,8 +296,7 @@ where
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Insert the rest of the pending upgrades, but not the current one.
|
// Insert the rest of the pending upgrades, but not the current one.
|
||||||
debug!(target: "libp2p-core", "error while upgrading listener connection: \
|
debug!("error while upgrading listener connection: {:?}", err);
|
||||||
{:?}", err);
|
|
||||||
return Ok(Async::Ready(Some(future::err(err))));
|
return Ok(Async::Ready(Some(future::err(err))));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -309,7 +308,7 @@ where
|
|||||||
match next_incoming.poll() {
|
match next_incoming.poll() {
|
||||||
Ok(Async::Ready(None)) => {
|
Ok(Async::Ready(None)) => {
|
||||||
// stream muxer gave us a `None` => connection should be considered closed
|
// stream muxer gave us a `None` => connection should be considered closed
|
||||||
debug!(target: "libp2p-core", "no more inbound substreams on {}", client_addr);
|
debug!("no more inbound substreams on {}", client_addr);
|
||||||
self.shared.lock().active_connections.remove(&client_addr);
|
self.shared.lock().active_connections.remove(&client_addr);
|
||||||
}
|
}
|
||||||
Ok(Async::Ready(Some(incoming))) => {
|
Ok(Async::Ready(Some(incoming))) => {
|
||||||
@ -331,8 +330,7 @@ where
|
|||||||
self.connections.push((muxer, next_incoming, client_addr));
|
self.connections.push((muxer, next_incoming, client_addr));
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-core", "error while upgrading the \
|
debug!("error while upgrading the multiplexed incoming connection: {:?}", err);
|
||||||
multiplexed incoming connection: {:?}", err);
|
|
||||||
// Insert the rest of the pending connections, but not the current one.
|
// Insert the rest of the pending connections, but not the current one.
|
||||||
return Ok(Async::Ready(Some(future::err(err))));
|
return Ok(Async::Ready(Some(future::err(err))));
|
||||||
}
|
}
|
||||||
@ -384,13 +382,13 @@ where
|
|||||||
let (muxer, mut future, addr) = lock.next_incoming.swap_remove(n);
|
let (muxer, mut future, addr) = lock.next_incoming.swap_remove(n);
|
||||||
match future.poll() {
|
match future.poll() {
|
||||||
Ok(Async::Ready(None)) => {
|
Ok(Async::Ready(None)) => {
|
||||||
debug!(target: "libp2p-core", "no inbound substream for {}", addr);
|
debug!("no inbound substream for {}", addr);
|
||||||
lock.active_connections.remove(&addr);
|
lock.active_connections.remove(&addr);
|
||||||
}
|
}
|
||||||
Ok(Async::Ready(Some(value))) => {
|
Ok(Async::Ready(Some(value))) => {
|
||||||
// A substream is ready ; push back the muxer for the next time this function
|
// A substream is ready ; push back the muxer for the next time this function
|
||||||
// is called, then return.
|
// is called, then return.
|
||||||
debug!(target: "libp2p-core", "New incoming substream");
|
debug!("New incoming substream");
|
||||||
let next = muxer.clone().inbound();
|
let next = muxer.clone().inbound();
|
||||||
lock.next_incoming.push((muxer, next, addr.clone()));
|
lock.next_incoming.push((muxer, next, addr.clone()));
|
||||||
return Ok(Async::Ready(future::ok((value, addr))));
|
return Ok(Async::Ready(future::ok((value, addr))));
|
||||||
@ -400,9 +398,9 @@ where
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// In case of error, we just not push back the element, which drops it.
|
// In case of error, we just not push back the element, which drops it.
|
||||||
debug!(target: "libp2p-core", "ConnectionReuse incoming: one of the \
|
debug!("ConnectionReuse incoming: one of the \
|
||||||
multiplexed substreams produced an error: {:?}",
|
multiplexed substreams produced an error: {:?}",
|
||||||
err);
|
err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ where
|
|||||||
Du: Transport + 'static, // TODO: 'static :-/
|
Du: Transport + 'static, // TODO: 'static :-/
|
||||||
Du::Output: Into<T::Output>,
|
Du::Output: Into<T::Output>,
|
||||||
{
|
{
|
||||||
trace!(target: "libp2p-core", "Swarm dialing {}", multiaddr);
|
trace!("Swarm dialing {}", multiaddr);
|
||||||
|
|
||||||
match transport.dial(multiaddr.clone()) {
|
match transport.dial(multiaddr.clone()) {
|
||||||
Ok(dial) => {
|
Ok(dial) => {
|
||||||
@ -151,7 +151,7 @@ where
|
|||||||
Df: FnOnce(Du::Output, Multiaddr) -> Dfu + 'static, // TODO: 'static :-/
|
Df: FnOnce(Du::Output, Multiaddr) -> Dfu + 'static, // TODO: 'static :-/
|
||||||
Dfu: IntoFuture<Item = (), Error = IoError> + 'static, // TODO: 'static :-/
|
Dfu: IntoFuture<Item = (), Error = IoError> + 'static, // TODO: 'static :-/
|
||||||
{
|
{
|
||||||
trace!(target: "libp2p-core", "Swarm dialing {} with custom handler", multiaddr);
|
trace!("Swarm dialing {} with custom handler", multiaddr);
|
||||||
|
|
||||||
match transport.dial(multiaddr) {
|
match transport.dial(multiaddr) {
|
||||||
Ok(dial) => {
|
Ok(dial) => {
|
||||||
@ -170,7 +170,7 @@ where
|
|||||||
pub fn listen_on(&self, multiaddr: Multiaddr) -> Result<Multiaddr, Multiaddr> {
|
pub fn listen_on(&self, multiaddr: Multiaddr) -> Result<Multiaddr, Multiaddr> {
|
||||||
match self.transport.clone().listen_on(multiaddr) {
|
match self.transport.clone().listen_on(multiaddr) {
|
||||||
Ok((listener, new_addr)) => {
|
Ok((listener, new_addr)) => {
|
||||||
trace!(target: "libp2p-core", "Swarm listening on {}", new_addr);
|
trace!("Swarm listening on {}", new_addr);
|
||||||
// Ignoring errors if the receiver has been closed, because in that situation
|
// Ignoring errors if the receiver has been closed, because in that situation
|
||||||
// nothing is going to be processed anyway.
|
// nothing is going to be processed anyway.
|
||||||
let _ = self.new_listeners.unbounded_send(listener);
|
let _ = self.new_listeners.unbounded_send(listener);
|
||||||
@ -224,15 +224,13 @@ where
|
|||||||
|
|
||||||
match self.next_incoming.poll() {
|
match self.next_incoming.poll() {
|
||||||
Ok(Async::Ready(connec)) => {
|
Ok(Async::Ready(connec)) => {
|
||||||
debug!(target: "libp2p-core", "Swarm received new multiplexed \
|
debug!("Swarm received new multiplexed incoming connection");
|
||||||
incoming connection");
|
|
||||||
self.next_incoming = self.transport.clone().next_incoming();
|
self.next_incoming = self.transport.clone().next_incoming();
|
||||||
self.listeners_upgrade.push(Box::new(connec) as Box<_>);
|
self.listeners_upgrade.push(Box::new(connec) as Box<_>);
|
||||||
}
|
}
|
||||||
Ok(Async::NotReady) => {}
|
Ok(Async::NotReady) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-core", "Error in multiplexed incoming \
|
debug!("Error in multiplexed incoming connection: {:?}", err);
|
||||||
connection: {:?}", err);
|
|
||||||
self.next_incoming = self.transport.clone().next_incoming();
|
self.next_incoming = self.transport.clone().next_incoming();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -272,12 +270,12 @@ where
|
|||||||
|
|
||||||
match self.listeners.poll() {
|
match self.listeners.poll() {
|
||||||
Ok(Async::Ready(Some((Some(upgrade), remaining)))) => {
|
Ok(Async::Ready(Some((Some(upgrade), remaining)))) => {
|
||||||
trace!(target: "libp2p-core", "Swarm received new connection on listener socket");
|
trace!("Swarm received new connection on listener socket");
|
||||||
self.listeners_upgrade.push(upgrade);
|
self.listeners_upgrade.push(upgrade);
|
||||||
self.listeners.push(remaining.into_future());
|
self.listeners.push(remaining.into_future());
|
||||||
}
|
}
|
||||||
Err((err, _)) => {
|
Err((err, _)) => {
|
||||||
warn!(target: "libp2p-core", "Error in listener: {:?}", err);
|
warn!("Error in listener: {:?}", err);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -293,7 +291,7 @@ where
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(target: "libp2p-core", "Error in listener upgrade: {:?}", err);
|
warn!("Error in listener upgrade: {:?}", err);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -305,17 +303,17 @@ where
|
|||||||
.push(future::Either::A(handler(output, addr).into_future()));
|
.push(future::Either::A(handler(output, addr).into_future()));
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(target: "libp2p-core", "Error in dialer upgrade: {:?}", err);
|
warn!("Error in dialer upgrade: {:?}", err);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.to_process.poll() {
|
match self.to_process.poll() {
|
||||||
Ok(Async::Ready(Some(()))) => {
|
Ok(Async::Ready(Some(()))) => {
|
||||||
trace!(target: "libp2p-core", "Future returned by swarm handler driven to completion");
|
trace!("Future returned by swarm handler driven to completion");
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(target: "libp2p-core", "Error in processing: {:?}", err);
|
warn!("Error in processing: {:?}", err);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ where
|
|||||||
.protocol_names()
|
.protocol_names()
|
||||||
.map::<_, fn(_) -> _>(|(n, t)| (n, <Bytes as PartialEq>::eq, t));
|
.map::<_, fn(_) -> _>(|(n, t)| (n, <Bytes as PartialEq>::eq, t));
|
||||||
let remote_addr2 = remote_addr.clone();
|
let remote_addr2 = remote_addr.clone();
|
||||||
debug!(target: "libp2p-core", "Starting protocol negotiation");
|
debug!("Starting protocol negotiation");
|
||||||
|
|
||||||
let negotiation = match endpoint {
|
let negotiation = match endpoint {
|
||||||
Endpoint::Listener => multistream_select::listener_select_proto(connection, iter),
|
Endpoint::Listener => multistream_select::listener_select_proto(connection, iter),
|
||||||
@ -56,10 +56,8 @@ where
|
|||||||
.map_err(|err| IoError::new(IoErrorKind::Other, err))
|
.map_err(|err| IoError::new(IoErrorKind::Other, err))
|
||||||
.then(move |negotiated| {
|
.then(move |negotiated| {
|
||||||
match negotiated {
|
match negotiated {
|
||||||
Ok(_) => debug!(target: "libp2p-core", "Successfully negotiated \
|
Ok(_) => debug!("Successfully negotiated protocol upgrade with {}", remote_addr2),
|
||||||
protocol upgrade with {}", remote_addr2),
|
Err(ref err) => debug!("Error while negotiated protocol upgrade: {:?}", err),
|
||||||
Err(ref err) => debug!(target: "libp2p-core", "Error while negotiated \
|
|
||||||
protocol upgrade: {:?}", err),
|
|
||||||
};
|
};
|
||||||
negotiated
|
negotiated
|
||||||
})
|
})
|
||||||
@ -70,9 +68,8 @@ where
|
|||||||
.into_future()
|
.into_future()
|
||||||
.then(|val| {
|
.then(|val| {
|
||||||
match val {
|
match val {
|
||||||
Ok(_) => debug!(target: "libp2p-core", "Successfully applied negotiated \
|
Ok(_) => debug!("Successfully applied negotiated protocol"),
|
||||||
protocol"),
|
Err(_) => debug!("Failed to apply negotiated protocol"),
|
||||||
Err(_) => debug!(target: "libp2p-core", "Failed to apply negotiated protocol"),
|
|
||||||
}
|
}
|
||||||
val
|
val
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,7 @@ extern crate multiaddr;
|
|||||||
extern crate tokio_dns;
|
extern crate tokio_dns;
|
||||||
extern crate tokio_io;
|
extern crate tokio_io;
|
||||||
|
|
||||||
use futures::future::{self, Future, IntoFuture};
|
use futures::future::{self, Future};
|
||||||
use log::Level;
|
use log::Level;
|
||||||
use multiaddr::{AddrComponent, Multiaddr};
|
use multiaddr::{AddrComponent, Multiaddr};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -76,7 +76,7 @@ impl<T> DnsConfig<T> {
|
|||||||
/// Same as `new`, but allows specifying a number of threads for the resolving.
|
/// Same as `new`, but allows specifying a number of threads for the resolving.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_resolve_threads(inner: T, num_threads: usize) -> DnsConfig<T> {
|
pub fn with_resolve_threads(inner: T, num_threads: usize) -> DnsConfig<T> {
|
||||||
trace!(target: "libp2p-dns", "Created a CpuPoolResolver");
|
trace!("Created a CpuPoolResolver");
|
||||||
|
|
||||||
DnsConfig {
|
DnsConfig {
|
||||||
inner,
|
inner,
|
||||||
@ -126,7 +126,7 @@ where
|
|||||||
});
|
});
|
||||||
|
|
||||||
if !contains_dns {
|
if !contains_dns {
|
||||||
trace!(target: "libp2p-dns", "Pass-through address without DNS: {}", addr);
|
trace!("Pass-through address without DNS: {}", addr);
|
||||||
return match self.inner.dial(addr) {
|
return match self.inner.dial(addr) {
|
||||||
Ok(d) => Ok(Box::new(d) as Box<_>),
|
Ok(d) => Ok(Box::new(d) as Box<_>),
|
||||||
Err((inner, addr)) => Err((
|
Err((inner, addr)) => Err((
|
||||||
@ -141,7 +141,7 @@ where
|
|||||||
|
|
||||||
let resolver = self.resolver;
|
let resolver = self.resolver;
|
||||||
|
|
||||||
trace!(target: "libp2p-dns", "Dialing address with DNS: {}", addr);
|
trace!("Dialing address with DNS: {}", addr);
|
||||||
let resolve_iters = addr.iter()
|
let resolve_iters = addr.iter()
|
||||||
.map(move |cmp| match cmp {
|
.map(move |cmp| match cmp {
|
||||||
AddrComponent::DNS4(ref name) => {
|
AddrComponent::DNS4(ref name) => {
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
|
|
||||||
let new_addr = future::join_all(resolve_iters).map(move |outcome| {
|
let new_addr = future::join_all(resolve_iters).map(move |outcome| {
|
||||||
let outcome: Multiaddr = outcome.into_iter().collect();
|
let outcome: Multiaddr = outcome.into_iter().collect();
|
||||||
debug!(target: "libp2p-dns", "DNS resolution outcome: {} => {}", addr, outcome);
|
debug!("DNS resolution outcome: {} => {}", addr, outcome);
|
||||||
outcome
|
outcome
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -194,15 +194,15 @@ fn resolve_dns(
|
|||||||
resolver: CpuPoolResolver,
|
resolver: CpuPoolResolver,
|
||||||
ty: ResolveTy,
|
ty: ResolveTy,
|
||||||
) -> Box<Future<Item = AddrComponent, Error = IoError>> {
|
) -> Box<Future<Item = AddrComponent, Error = IoError>> {
|
||||||
let debug_name = if log_enabled!(target: "libp2p-dns", Level::Trace) {
|
let debug_name = if log_enabled!(Level::Trace) {
|
||||||
Some(name.to_owned())
|
Some(name.to_owned())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let future = resolver.resolve(name).and_then(move |addrs| {
|
let future = resolver.resolve(name).and_then(move |addrs| {
|
||||||
if log_enabled!(target: "libp2p-dns", Level::Trace) {
|
if log_enabled!(Level::Trace) {
|
||||||
trace!(target: "libp2p-dns", "DNS component resolution: {} => {:?}",
|
trace!("DNS component resolution: {} => {:?}",
|
||||||
debug_name.expect("trace log level was enabled"), addrs);
|
debug_name.expect("trace log level was enabled"), addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ where
|
|||||||
_: Endpoint,
|
_: Endpoint,
|
||||||
remote_addr: &Multiaddr,
|
remote_addr: &Multiaddr,
|
||||||
) -> Self::Future {
|
) -> Self::Future {
|
||||||
debug!(target: "libp2p-floodsub", "Upgrading connection to {} as floodsub", remote_addr);
|
debug!("Upgrading connection to {} as floodsub", remote_addr);
|
||||||
|
|
||||||
// Whenever a new node connects, we send to it a message containing the topics we are
|
// Whenever a new node connects, we send to it a message containing the topics we are
|
||||||
// already subscribed to.
|
// already subscribed to.
|
||||||
@ -192,8 +192,7 @@ where
|
|||||||
Some((bytes, MessageSource::FromChannel)) => {
|
Some((bytes, MessageSource::FromChannel)) => {
|
||||||
// Received a packet from the channel.
|
// Received a packet from the channel.
|
||||||
// Need to send a message to remote.
|
// Need to send a message to remote.
|
||||||
trace!(target: "libp2p-floodsub", "Effectively sending message \
|
trace!("Effectively sending message to remote");
|
||||||
to remote");
|
|
||||||
let future = floodsub_sink.send(bytes).map(|floodsub_sink| {
|
let future = floodsub_sink.send(bytes).map(|floodsub_sink| {
|
||||||
future::Loop::Continue((floodsub_sink, rest))
|
future::Loop::Continue((floodsub_sink, rest))
|
||||||
});
|
});
|
||||||
@ -203,7 +202,7 @@ where
|
|||||||
None => {
|
None => {
|
||||||
// Both the connection stream and `rx` are empty, so we break
|
// Both the connection stream and `rx` are empty, so we break
|
||||||
// the loop.
|
// the loop.
|
||||||
trace!(target: "libp2p-floodsub", "Pubsub future clean finish");
|
trace!("Pubsub future clean finish");
|
||||||
// TODO: what if multiple connections?
|
// TODO: what if multiple connections?
|
||||||
inner.remote_connections.write().remove(&remote_addr);
|
inner.remote_connections.write().remove(&remote_addr);
|
||||||
let future = future::ok(future::Loop::Break(()));
|
let future = future::ok(future::Loop::Break(()));
|
||||||
@ -341,9 +340,8 @@ impl FloodSubController {
|
|||||||
|
|
||||||
let topics = topics.into_iter();
|
let topics = topics.into_iter();
|
||||||
|
|
||||||
if log_enabled!(target: "libp2p-floodsub", Level::Debug) {
|
if log_enabled!(Level::Debug) {
|
||||||
debug!(target: "libp2p-floodsub", "Queuing sub/unsub message ; \
|
debug!("Queuing sub/unsub message ; sub = {:?} ; unsub = {:?}",
|
||||||
sub = {:?} ; unsub = {:?}",
|
|
||||||
topics.clone().filter(|t| t.1)
|
topics.clone().filter(|t| t.1)
|
||||||
.map(|t| t.0.hash().clone().into_string())
|
.map(|t| t.0.hash().clone().into_string())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
@ -387,8 +385,7 @@ impl FloodSubController {
|
|||||||
{
|
{
|
||||||
let topics = topics.into_iter().collect::<Vec<_>>();
|
let topics = topics.into_iter().collect::<Vec<_>>();
|
||||||
|
|
||||||
debug!(target: "libp2p-floodsub", "Queueing publish message ; \
|
debug!("Queueing publish message ; topics = {:?} ; data_len = {:?}",
|
||||||
topics = {:?} ; data_len = {:?}",
|
|
||||||
topics.iter().map(|t| t.hash().clone().into_string()).collect::<Vec<_>>(),
|
topics.iter().map(|t| t.hash().clone().into_string()).collect::<Vec<_>>(),
|
||||||
data.len());
|
data.len());
|
||||||
|
|
||||||
@ -457,8 +454,8 @@ impl FloodSubController {
|
|||||||
match remote.sender.unbounded_send(bytes.clone().into()) {
|
match remote.sender.unbounded_send(bytes.clone().into()) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
trace!(target: "libp2p-floodsub", "Failed to dispatch message to {} because \
|
trace!("Failed to dispatch message to {} because channel was closed",
|
||||||
channel was closed", remote_addr);
|
remote_addr);
|
||||||
failed_to_send.push(remote_addr.clone());
|
failed_to_send.push(remote_addr.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -474,7 +471,7 @@ impl FloodSubController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(target: "libp2p-floodsub", "Message queued for {} remotes", num_dispatched);
|
debug!("Message queued for {} remotes", num_dispatched);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,13 +543,13 @@ fn handle_packet_received(
|
|||||||
inner: Arc<Inner>,
|
inner: Arc<Inner>,
|
||||||
remote_addr: &Multiaddr,
|
remote_addr: &Multiaddr,
|
||||||
) -> Result<(), IoError> {
|
) -> Result<(), IoError> {
|
||||||
trace!(target: "libp2p-floodsub", "Received packet from {}", remote_addr);
|
trace!("Received packet from {}", remote_addr);
|
||||||
|
|
||||||
// Parsing attempt.
|
// Parsing attempt.
|
||||||
let mut input = match protobuf::parse_from_bytes::<rpc_proto::RPC>(&bytes) {
|
let mut input = match protobuf::parse_from_bytes::<rpc_proto::RPC>(&bytes) {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-floodsub", "Failed to parse protobuf message ; err = {:?}", err);
|
debug!("Failed to parse protobuf message ; err = {:?}", err);
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -567,12 +564,9 @@ fn handle_packet_received(
|
|||||||
let topic = TopicHash::from_raw(subscription.take_topicid());
|
let topic = TopicHash::from_raw(subscription.take_topicid());
|
||||||
let subscribe = subscription.get_subscribe();
|
let subscribe = subscription.get_subscribe();
|
||||||
if subscribe {
|
if subscribe {
|
||||||
trace!(target: "libp2p-floodsub", "Remote {} subscribed to {:?}",
|
trace!("Remote {} subscribed to {:?}", remote_addr, topic); topics.insert(topic);
|
||||||
remote_addr, topic);
|
|
||||||
topics.insert(topic);
|
|
||||||
} else {
|
} else {
|
||||||
trace!(target: "libp2p-floodsub", "Remote {} unsubscribed from {:?}",
|
trace!("Remote {} unsubscribed from {:?}", remote_addr, topic);
|
||||||
remote_addr, topic);
|
|
||||||
topics.remove(&topic);
|
topics.remove(&topic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -589,8 +583,7 @@ fn handle_packet_received(
|
|||||||
.lock()
|
.lock()
|
||||||
.insert(hash((from.clone(), publish.take_seqno())))
|
.insert(hash((from.clone(), publish.take_seqno())))
|
||||||
{
|
{
|
||||||
trace!(target: "libp2p-floodsub",
|
trace!("Skipping message because we had already received it ; payload = {} bytes",
|
||||||
"Skipping message because we had already received it ; payload = {} bytes",
|
|
||||||
publish.get_data().len());
|
publish.get_data().len());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -602,9 +595,9 @@ fn handle_packet_received(
|
|||||||
.map(|h| TopicHash::from_raw(h))
|
.map(|h| TopicHash::from_raw(h))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
trace!(target: "libp2p-floodsub",
|
trace!("Processing message for topics {:?} ; payload = {} bytes",
|
||||||
"Processing message for topics {:?} ; payload = {} bytes",
|
topics,
|
||||||
topics, publish.get_data().len());
|
publish.get_data().len());
|
||||||
|
|
||||||
// TODO: should check encryption/authentication of the message
|
// TODO: should check encryption/authentication of the message
|
||||||
|
|
||||||
@ -617,8 +610,7 @@ fn handle_packet_received(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// TODO: don't send back to the remote that just sent it
|
// TODO: don't send back to the remote that just sent it
|
||||||
trace!(target: "libp2p-floodsub",
|
trace!("Broadcasting received message to {}", addr);
|
||||||
"Broadcasting received message to {}", addr);
|
|
||||||
let _ = info.sender.unbounded_send(bytes.clone());
|
let _ = info.sender.unbounded_send(bytes.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -632,15 +624,14 @@ fn handle_packet_received(
|
|||||||
};
|
};
|
||||||
if dispatch_locally {
|
if dispatch_locally {
|
||||||
// Ignore if channel is closed.
|
// Ignore if channel is closed.
|
||||||
trace!(target: "libp2p-floodsub", "Dispatching message locally");
|
trace!("Dispatching message locally");
|
||||||
let _ = inner.output_tx.unbounded_send(Message {
|
let _ = inner.output_tx.unbounded_send(Message {
|
||||||
source: from,
|
source: from,
|
||||||
data: publish.take_data(),
|
data: publish.take_data(),
|
||||||
topics: topics,
|
topics: topics,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
trace!(target: "libp2p-floodsub",
|
trace!("Message not dispatched locally as we are not subscribed to any of the topics");
|
||||||
"Message not dispatched locally as we are not subscribed to any of the topics");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ where
|
|||||||
info: IdentifyInfo,
|
info: IdentifyInfo,
|
||||||
observed_addr: &Multiaddr,
|
observed_addr: &Multiaddr,
|
||||||
) -> Box<Future<Item = (), Error = IoError> + 'a> {
|
) -> Box<Future<Item = (), Error = IoError> + 'a> {
|
||||||
debug!(target: "libp2p-identify", "Sending identify info to client");
|
debug!("Sending identify info to client");
|
||||||
trace!(target: "libp2p-identify", "Sending: {:?}", info);
|
trace!("Sending: {:?}", info);
|
||||||
|
|
||||||
let listen_addrs = info.listen_addrs
|
let listen_addrs = info.listen_addrs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -128,11 +128,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade(self, socket: C, _: (), ty: Endpoint, observed_addr: &Multiaddr) -> Self::Future {
|
fn upgrade(self, socket: C, _: (), ty: Endpoint, observed_addr: &Multiaddr) -> Self::Future {
|
||||||
trace!(target: "libp2p-identify", "Upgrading connection with {:?} as {:?}",
|
trace!("Upgrading connection with {:?} as {:?}", observed_addr, ty);
|
||||||
observed_addr, ty);
|
|
||||||
|
|
||||||
let socket = socket.framed(VarintCodec::default());
|
let socket = socket.framed(VarintCodec::default());
|
||||||
let observed_addr_log = if log_enabled!(target: "libp2p-identify", Level::Debug) {
|
let observed_addr_log = if log_enabled!(Level::Debug) {
|
||||||
Some(observed_addr.clone())
|
Some(observed_addr.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -145,8 +144,8 @@ where
|
|||||||
.map(|(msg, _)| msg)
|
.map(|(msg, _)| msg)
|
||||||
.map_err(|(err, _)| err)
|
.map_err(|(err, _)| err)
|
||||||
.and_then(|msg| {
|
.and_then(|msg| {
|
||||||
if log_enabled!(target: "libp2p-identify", Level::Debug) {
|
if log_enabled!(Level::Debug) {
|
||||||
debug!(target: "libp2p-identify", "Received identify message from {:?}",
|
debug!("Received identify message from {:?}",
|
||||||
observed_addr_log
|
observed_addr_log
|
||||||
.expect("Programmer error: expected `observed_addr_log' to be \
|
.expect("Programmer error: expected `observed_addr_log' to be \
|
||||||
non-None since debug log level is enabled"));
|
non-None since debug log level is enabled"));
|
||||||
@ -156,23 +155,20 @@ where
|
|||||||
let (info, observed_addr) = match parse_proto_msg(msg) {
|
let (info, observed_addr) = match parse_proto_msg(msg) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-identify",
|
debug!("Failed to parse protobuf message ; error = {:?}", err);
|
||||||
"Failed to parse protobuf message ; error = {:?}", err);
|
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!(target: "libp2p-identify", "Remote observes us as {:?}",
|
trace!("Remote observes us as {:?}", observed_addr);
|
||||||
observed_addr);
|
trace!("Information received: {:?}", info);
|
||||||
trace!(target: "libp2p-identify", "Information received: {:?}", info);
|
|
||||||
|
|
||||||
Ok(IdentifyOutput::RemoteInfo {
|
Ok(IdentifyOutput::RemoteInfo {
|
||||||
info,
|
info,
|
||||||
observed_addr,
|
observed_addr,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
debug!(target: "libp2p-identify", "Identify protocol stream closed \
|
debug!("Identify protocol stream closed before receiving info");
|
||||||
before receiving info");
|
|
||||||
Err(IoErrorKind::InvalidData.into())
|
Err(IoErrorKind::InvalidData.into())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -101,17 +101,14 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
if peer.addrs().any(|addr| addr == client_addr) {
|
if peer.addrs().any(|addr| addr == client_addr) {
|
||||||
debug!(target: "libp2p-identify", "Incoming substream from {} \
|
debug!("Incoming substream from {} identified as {:?}", client_addr, peer_id);
|
||||||
identified as {:?}", client_addr,
|
|
||||||
peer_id);
|
|
||||||
let out = IdentifyTransportOutput { socket: connec, observed_addr: None };
|
let out = IdentifyTransportOutput { socket: connec, observed_addr: None };
|
||||||
let ret = (out, AddrComponent::P2P(peer_id.into_bytes()).into());
|
let ret = (out, AddrComponent::P2P(peer_id.into_bytes()).into());
|
||||||
return future::Either::A(future::ok(ret));
|
return future::Either::A(future::ok(ret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(target: "libp2p-identify", "Incoming connection from {}, dialing back \
|
debug!("Incoming connection from {}, dialing back in order to identify", client_addr);
|
||||||
in order to identify", client_addr);
|
|
||||||
// Dial the address that connected to us and try upgrade with the
|
// Dial the address that connected to us and try upgrade with the
|
||||||
// identify protocol.
|
// identify protocol.
|
||||||
let future = identify_upgrade
|
let future = identify_upgrade
|
||||||
@ -143,14 +140,12 @@ where
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(target: "libp2p-identify", "Identified {} as {}", original_addr,
|
debug!("Identified {} as {}", original_addr, real_addr);
|
||||||
real_addr);
|
|
||||||
let out = IdentifyTransportOutput { socket: connec, observed_addr: Some(observed) };
|
let out = IdentifyTransportOutput { socket: connec, observed_addr: Some(observed) };
|
||||||
Ok((out, real_addr))
|
Ok((out, real_addr))
|
||||||
})
|
})
|
||||||
.map_err(move |err| {
|
.map_err(move |err| {
|
||||||
warn!(target: "libp2p-identify", "Failed to identify incoming {}",
|
warn!("Failed to identify incoming {}", client_addr);
|
||||||
client_addr);
|
|
||||||
err
|
err
|
||||||
});
|
});
|
||||||
future::Either::B(future)
|
future::Either::B(future)
|
||||||
@ -176,8 +171,7 @@ where
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|
||||||
trace!(target: "libp2p-identify", "Try dialing peer ID {:?} ; {} multiaddrs \
|
trace!("Try dialing peer ID {:?} ; {} multiaddrs loaded from peerstore", peer_id, addrs.len());
|
||||||
loaded from peerstore", peer_id, addrs.len());
|
|
||||||
|
|
||||||
let transport = self.transport;
|
let transport = self.transport;
|
||||||
let future = stream::iter_ok(addrs)
|
let future = stream::iter_ok(addrs)
|
||||||
@ -186,8 +180,7 @@ where
|
|||||||
match transport.clone().dial(addr) {
|
match transport.clone().dial(addr) {
|
||||||
Ok(dial) => Some(dial),
|
Ok(dial) => Some(dial),
|
||||||
Err((_, addr)) => {
|
Err((_, addr)) => {
|
||||||
warn!(target: "libp2p-identify", "Address {} not supported by \
|
warn!("Address {} not supported by underlying transport", addr);
|
||||||
underlying transport", addr);
|
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -201,15 +194,12 @@ where
|
|||||||
.and_then(move |(val, _)| {
|
.and_then(move |(val, _)| {
|
||||||
match val {
|
match val {
|
||||||
Some((connec, inner_addr)) => {
|
Some((connec, inner_addr)) => {
|
||||||
debug!(target: "libp2p-identify", "Successfully dialed peer {:?} \
|
debug!("Successfully dialed peer {:?} through {}", peer_id, inner_addr);
|
||||||
through {}", peer_id,
|
|
||||||
inner_addr);
|
|
||||||
let out = IdentifyTransportOutput { socket: connec, observed_addr: None };
|
let out = IdentifyTransportOutput { socket: connec, observed_addr: None };
|
||||||
Ok((out, inner_addr))
|
Ok((out, inner_addr))
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
debug!(target: "libp2p-identify", "All multiaddresses failed when \
|
debug!("All multiaddresses failed when dialing peer {:?}", peer_id);
|
||||||
dialing peer {:?}", peer_id);
|
|
||||||
// TODO: wrong error
|
// TODO: wrong error
|
||||||
Err(IoErrorKind::InvalidData.into())
|
Err(IoErrorKind::InvalidData.into())
|
||||||
},
|
},
|
||||||
@ -227,7 +217,7 @@ where
|
|||||||
let transport = self.transport;
|
let transport = self.transport;
|
||||||
let identify_upgrade = transport.clone().with_upgrade(IdentifyProtocolConfig);
|
let identify_upgrade = transport.clone().with_upgrade(IdentifyProtocolConfig);
|
||||||
|
|
||||||
trace!(target: "libp2p-identify", "Pass through when dialing {}", addr);
|
trace!("Pass through when dialing {}", addr);
|
||||||
|
|
||||||
// We dial a first time the node and upgrade it to identify.
|
// We dial a first time the node and upgrade it to identify.
|
||||||
let dial = match identify_upgrade.dial(addr) {
|
let dial = match identify_upgrade.dial(addr) {
|
||||||
@ -311,9 +301,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
if peer.addrs().any(|addr| addr == client_addr) {
|
if peer.addrs().any(|addr| addr == client_addr) {
|
||||||
debug!(target: "libp2p-identify", "Incoming substream from {} \
|
debug!("Incoming substream from {} identified as {:?}", client_addr, peer_id);
|
||||||
identified as {:?}", client_addr,
|
|
||||||
peer_id);
|
|
||||||
let out = IdentifyTransportOutput { socket: connec, observed_addr: None };
|
let out = IdentifyTransportOutput { socket: connec, observed_addr: None };
|
||||||
let ret = (out, AddrComponent::P2P(peer_id.into_bytes()).into());
|
let ret = (out, AddrComponent::P2P(peer_id.into_bytes()).into());
|
||||||
return future::Either::A(future::ok(ret));
|
return future::Either::A(future::ok(ret));
|
||||||
|
@ -142,8 +142,7 @@ fn query<'a, I>(
|
|||||||
where
|
where
|
||||||
I: QueryInterface + 'a,
|
I: QueryInterface + 'a,
|
||||||
{
|
{
|
||||||
debug!(target: "libp2p-kad", "Start query for {:?} ; num results = {}", searched_key,
|
debug!("Start query for {:?} ; num results = {}", searched_key, num_results);
|
||||||
num_results);
|
|
||||||
|
|
||||||
// State of the current iterative process.
|
// State of the current iterative process.
|
||||||
struct State<'a> {
|
struct State<'a> {
|
||||||
@ -209,9 +208,9 @@ where
|
|||||||
to_contact
|
to_contact
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(target: "libp2p-kad", "New query round ; {} queries in progress ; contacting \
|
debug!("New query round ; {} queries in progress ; contacting {} new peers",
|
||||||
{} new peers", state.current_attempts_fut.len(),
|
state.current_attempts_fut.len(),
|
||||||
to_contact.len());
|
to_contact.len());
|
||||||
|
|
||||||
// For each node in `to_contact`, start an RPC query and a corresponding entry in the two
|
// For each node in `to_contact`, start an RPC query and a corresponding entry in the two
|
||||||
// `state.current_attempts_*` fields.
|
// `state.current_attempts_*` fields.
|
||||||
@ -262,7 +261,7 @@ where
|
|||||||
let closer_peers = match message {
|
let closer_peers = match message {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
trace!(target: "libp2p-kad", "RPC query failed for {:?}: {:?}", remote_id, err);
|
trace!("RPC query failed for {:?}: {:?}", remote_id, err);
|
||||||
state.failed_to_contact.insert(remote_id);
|
state.failed_to_contact.insert(remote_id);
|
||||||
return Ok(future::Loop::Continue(state));
|
return Ok(future::Loop::Continue(state));
|
||||||
}
|
}
|
||||||
@ -294,8 +293,7 @@ where
|
|||||||
// the remote.
|
// the remote.
|
||||||
{
|
{
|
||||||
let valid_multiaddrs = peer.multiaddrs.drain(..);
|
let valid_multiaddrs = peer.multiaddrs.drain(..);
|
||||||
trace!(target: "libp2p-kad", "Adding multiaddresses to {:?}: {:?}",
|
trace!("Adding multiaddresses to {:?}: {:?}", peer.node_id, valid_multiaddrs);
|
||||||
peer.node_id, valid_multiaddrs);
|
|
||||||
query_interface2.peer_add_addrs(
|
query_interface2.peer_add_addrs(
|
||||||
&peer.node_id,
|
&peer.node_id,
|
||||||
valid_multiaddrs,
|
valid_multiaddrs,
|
||||||
@ -334,7 +332,7 @@ where
|
|||||||
Ok(future::Loop::Break(state))
|
Ok(future::Loop::Break(state))
|
||||||
} else {
|
} else {
|
||||||
if !local_nearest_node_updated {
|
if !local_nearest_node_updated {
|
||||||
trace!(target: "libp2p-kad", "Loop didn't update closer node ; jumping to step 2");
|
trace!("Loop didn't update closer node ; jumping to step 2");
|
||||||
state.looking_for_closer = false;
|
state.looking_for_closer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +344,7 @@ where
|
|||||||
});
|
});
|
||||||
|
|
||||||
let stream = stream.map(|state| {
|
let stream = stream.map(|state| {
|
||||||
debug!(target: "libp2p-kad", "Query finished with {} results", state.result.len());
|
debug!("Query finished with {} results", state.result.len());
|
||||||
state.result
|
state.result
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ fn read_stream_internal<T: AsyncRead, Buf: Array<Item = u8>>(
|
|||||||
substream_id,
|
substream_id,
|
||||||
packet_type,
|
packet_type,
|
||||||
} = MultiplexHeader::parse(header).map_err(|err| {
|
} = MultiplexHeader::parse(header).map_err(|err| {
|
||||||
debug!(target: "libp2p-mplex", "failed to parse header: {}", err);
|
debug!("failed to parse header: {}", err);
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
format!("Error parsing header: {:?}", err),
|
format!("Error parsing header: {:?}", err),
|
||||||
@ -282,10 +282,10 @@ fn read_stream_internal<T: AsyncRead, Buf: Array<Item = u8>>(
|
|||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
return if let varint::Error(varint::ErrorKind::Io(inner), ..) = error {
|
return if let varint::Error(varint::ErrorKind::Io(inner), ..) = error {
|
||||||
debug!(target: "libp2p-mplex", "failed to read header: {}", inner);
|
debug!("failed to read header: {}", inner);
|
||||||
Err(inner)
|
Err(inner)
|
||||||
} else {
|
} else {
|
||||||
debug!(target: "libp2p-mplex", "failed to read header: {}", error);
|
debug!("failed to read header: {}", error);
|
||||||
Err(io::Error::new(io::ErrorKind::Other, error.description()))
|
Err(io::Error::new(io::ErrorKind::Other, error.description()))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -298,10 +298,7 @@ fn read_stream_internal<T: AsyncRead, Buf: Array<Item = u8>>(
|
|||||||
use self::NextMultiplexState::*;
|
use self::NextMultiplexState::*;
|
||||||
|
|
||||||
let body_len = varint_state.read(&mut lock.stream).map_err(|e| {
|
let body_len = varint_state.read(&mut lock.stream).map_err(|e| {
|
||||||
debug!(target: "libp2p-mplex",
|
debug!("substream {}: failed to read body length: {}", next.substream_id(), e);
|
||||||
"substream {}: failed to read body length: {}",
|
|
||||||
next.substream_id(),
|
|
||||||
e);
|
|
||||||
io::Error::new(io::ErrorKind::Other, "Error reading varint")
|
io::Error::new(io::ErrorKind::Other, "Error reading varint")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -401,8 +398,7 @@ fn read_stream_internal<T: AsyncRead, Buf: Array<Item = u8>>(
|
|||||||
return on_block;
|
return on_block;
|
||||||
}
|
}
|
||||||
Err(other) => {
|
Err(other) => {
|
||||||
debug!(target: "libp2p-mplex",
|
debug!("substream {}: failed to read new stream: {}",
|
||||||
"substream {}: failed to read new stream: {}",
|
|
||||||
substream_id,
|
substream_id,
|
||||||
other);
|
other);
|
||||||
lock.read_state = Some(NewStream {
|
lock.read_state = Some(NewStream {
|
||||||
@ -469,8 +465,7 @@ fn read_stream_internal<T: AsyncRead, Buf: Array<Item = u8>>(
|
|||||||
return on_block;
|
return on_block;
|
||||||
}
|
}
|
||||||
Err(other) => {
|
Err(other) => {
|
||||||
debug!(target: "libp2p-mplex",
|
debug!("substream {}: failed to read message body: {}",
|
||||||
"substream {}: failed to read message body: {}",
|
|
||||||
substream_id,
|
substream_id,
|
||||||
other);
|
other);
|
||||||
return Err(other);
|
return Err(other);
|
||||||
@ -520,8 +515,7 @@ fn read_stream_internal<T: AsyncRead, Buf: Array<Item = u8>>(
|
|||||||
return on_block;
|
return on_block;
|
||||||
}
|
}
|
||||||
Err(other) => {
|
Err(other) => {
|
||||||
debug!(target: "libp2p-mplex",
|
debug!("substream {}: failed to read ignore bytes: {}",
|
||||||
"substream {}: failed to read ignore bytes: {}",
|
|
||||||
substream_id,
|
substream_id,
|
||||||
other);
|
other);
|
||||||
lock.read_state = Some(Ignore {
|
lock.read_state = Some(Ignore {
|
||||||
|
@ -98,7 +98,7 @@ impl<T, Buf: Array> MultiplexShared<T, Buf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_stream(&mut self, id: u32) -> bool {
|
pub fn open_stream(&mut self, id: u32) -> bool {
|
||||||
trace!(target: "libp2p-mplex", "open stream {}", id);
|
trace!("open stream {}", id);
|
||||||
self.open_streams
|
self.open_streams
|
||||||
.entry(id)
|
.entry(id)
|
||||||
.or_insert(SubstreamMetadata::new_open())
|
.or_insert(SubstreamMetadata::new_open())
|
||||||
@ -106,7 +106,7 @@ impl<T, Buf: Array> MultiplexShared<T, Buf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_stream(&mut self, id: u32) {
|
pub fn close_stream(&mut self, id: u32) {
|
||||||
trace!(target: "libp2p-mplex", "close stream {}", id);
|
trace!("close stream {}", id);
|
||||||
self.open_streams.insert(id, SubstreamMetadata::Closed);
|
self.open_streams.insert(id, SubstreamMetadata::Closed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,10 +207,7 @@ pub fn write_stream<Buf: circular_buffer::Array, T: AsyncWrite>(
|
|||||||
Err(Some(Body { size }))
|
Err(Some(Body { size }))
|
||||||
}
|
}
|
||||||
Err(other) => {
|
Err(other) => {
|
||||||
debug!(target: "libp2p-mplex",
|
debug!("substream {}: failed to write body: {}", id, other);
|
||||||
"substream {}: failed to write body: {}",
|
|
||||||
id,
|
|
||||||
other);
|
|
||||||
return Err(other);
|
return Err(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ where
|
|||||||
let req = DialerToListenerMessage::ProtocolRequest {
|
let req = DialerToListenerMessage::ProtocolRequest {
|
||||||
name: proto_name.clone()
|
name: proto_name.clone()
|
||||||
};
|
};
|
||||||
trace!(target: "multistream-select", "sending {:?}", req);
|
trace!("sending {:?}", req);
|
||||||
dialer.send(req)
|
dialer.send(req)
|
||||||
.map(|d| (d, proto_name, proto_value))
|
.map(|d| (d, proto_name, proto_value))
|
||||||
.from_err()
|
.from_err()
|
||||||
@ -99,7 +99,7 @@ where
|
|||||||
})
|
})
|
||||||
// Once read, analyze the response.
|
// Once read, analyze the response.
|
||||||
.and_then(|(message, rest, proto_name, proto_value)| {
|
.and_then(|(message, rest, proto_name, proto_value)| {
|
||||||
trace!(target: "multistream-select", "received {:?}", message);
|
trace!("received {:?}", message);
|
||||||
let message = message.ok_or(ProtocolChoiceError::UnexpectedMessage)?;
|
let message = message.ok_or(ProtocolChoiceError::UnexpectedMessage)?;
|
||||||
|
|
||||||
match message {
|
match message {
|
||||||
@ -140,14 +140,14 @@ where
|
|||||||
let future = Dialer::new(inner)
|
let future = Dialer::new(inner)
|
||||||
.from_err()
|
.from_err()
|
||||||
.and_then(move |dialer| {
|
.and_then(move |dialer| {
|
||||||
trace!(target: "multistream-select", "requesting protocols list");
|
trace!("requesting protocols list");
|
||||||
dialer
|
dialer
|
||||||
.send(DialerToListenerMessage::ProtocolsListRequest)
|
.send(DialerToListenerMessage::ProtocolsListRequest)
|
||||||
.from_err()
|
.from_err()
|
||||||
})
|
})
|
||||||
.and_then(move |dialer| dialer.into_future().map_err(|(e, _)| e.into()))
|
.and_then(move |dialer| dialer.into_future().map_err(|(e, _)| e.into()))
|
||||||
.and_then(move |(msg, dialer)| {
|
.and_then(move |(msg, dialer)| {
|
||||||
trace!(target: "multistream-select", "protocols list response: {:?}", msg);
|
trace!("protocols list response: {:?}", msg);
|
||||||
let list = match msg {
|
let list = match msg {
|
||||||
Some(ListenerToDialerMessage::ProtocolsListResponse { list }) => list,
|
Some(ListenerToDialerMessage::ProtocolsListResponse { list }) => list,
|
||||||
_ => return Err(ProtocolChoiceError::UnexpectedMessage),
|
_ => return Err(ProtocolChoiceError::UnexpectedMessage),
|
||||||
@ -171,7 +171,7 @@ where
|
|||||||
Ok((proto_name, proto_val, dialer))
|
Ok((proto_name, proto_val, dialer))
|
||||||
})
|
})
|
||||||
.and_then(|(proto_name, proto_val, dialer)| {
|
.and_then(|(proto_name, proto_val, dialer)| {
|
||||||
trace!(target: "multistream-select", "sending {:?}", proto_name);
|
trace!("sending {:?}", proto_name);
|
||||||
dialer
|
dialer
|
||||||
.send(DialerToListenerMessage::ProtocolRequest {
|
.send(DialerToListenerMessage::ProtocolRequest {
|
||||||
name: proto_name.clone(),
|
name: proto_name.clone(),
|
||||||
@ -186,7 +186,7 @@ where
|
|||||||
.map_err(|(err, _)| err.into())
|
.map_err(|(err, _)| err.into())
|
||||||
})
|
})
|
||||||
.and_then(|(proto_name, proto_val, msg, dialer)| {
|
.and_then(|(proto_name, proto_val, msg, dialer)| {
|
||||||
trace!(target: "multistream-select", "received {:?}", msg);
|
trace!("received {:?}", msg);
|
||||||
match msg {
|
match msg {
|
||||||
Some(ListenerToDialerMessage::ProtocolAck { ref name }) if name == &proto_name => {
|
Some(ListenerToDialerMessage::ProtocolAck { ref name }) if name == &proto_name => {
|
||||||
Ok((proto_val, dialer.into_inner()))
|
Ok((proto_val, dialer.into_inner()))
|
||||||
|
@ -68,7 +68,7 @@ where
|
|||||||
let msg = ListenerToDialerMessage::ProtocolsListResponse {
|
let msg = ListenerToDialerMessage::ProtocolsListResponse {
|
||||||
list: protocols.map(|(p, _, _)| p).collect(),
|
list: protocols.map(|(p, _, _)| p).collect(),
|
||||||
};
|
};
|
||||||
trace!(target: "multistream-select", "protocols list response: {:?}", msg);
|
trace!("protocols list response: {:?}", msg);
|
||||||
let fut = listener
|
let fut = listener
|
||||||
.send(msg)
|
.send(msg)
|
||||||
.from_err()
|
.from_err()
|
||||||
@ -86,10 +86,7 @@ where
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trace!(target: "multistream-select",
|
trace!("requested: {:?}, response: {:?}", name, send_back);
|
||||||
"requested: {:?}, response: {:?}",
|
|
||||||
name,
|
|
||||||
send_back);
|
|
||||||
let fut = listener
|
let fut = listener
|
||||||
.send(send_back)
|
.send(send_back)
|
||||||
.from_err()
|
.from_err()
|
||||||
@ -97,7 +94,7 @@ where
|
|||||||
Box::new(fut) as Box<Future<Item = _, Error = ProtocolChoiceError>>
|
Box::new(fut) as Box<Future<Item = _, Error = ProtocolChoiceError>>
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
debug!(target: "multistream-select", "no protocol request received");
|
debug!("no protocol request received");
|
||||||
Box::new(err(ProtocolChoiceError::NoProtocolFound)) as Box<_>
|
Box::new(err(ProtocolChoiceError::NoProtocolFound)) as Box<_>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -58,7 +58,7 @@ where
|
|||||||
.map_err(|(e, _)| e.into())
|
.map_err(|(e, _)| e.into())
|
||||||
.and_then(|(msg, rest)| {
|
.and_then(|(msg, rest)| {
|
||||||
if msg.as_ref().map(|b| &b[..]) != Some(MULTISTREAM_PROTOCOL_WITH_LF) {
|
if msg.as_ref().map(|b| &b[..]) != Some(MULTISTREAM_PROTOCOL_WITH_LF) {
|
||||||
debug!(target: "multistream-select", "failed handshake; received: {:?}", msg);
|
debug!("failed handshake; received: {:?}", msg);
|
||||||
return Err(MultistreamSelectError::FailedHandshake);
|
return Err(MultistreamSelectError::FailedHandshake);
|
||||||
}
|
}
|
||||||
Ok(rest)
|
Ok(rest)
|
||||||
@ -93,7 +93,7 @@ where
|
|||||||
match item {
|
match item {
|
||||||
ListenerToDialerMessage::ProtocolAck { name } => {
|
ListenerToDialerMessage::ProtocolAck { name } => {
|
||||||
if !name.starts_with(b"/") {
|
if !name.starts_with(b"/") {
|
||||||
debug!(target: "multistream-select", "invalid protocol name {:?}", name);
|
debug!("invalid protocol name {:?}", name);
|
||||||
return Err(MultistreamSelectError::WrongProtocolName);
|
return Err(MultistreamSelectError::WrongProtocolName);
|
||||||
}
|
}
|
||||||
let mut protocol = BytesMut::from(name);
|
let mut protocol = BytesMut::from(name);
|
||||||
|
@ -165,7 +165,7 @@ where
|
|||||||
.map(|msg| Message::Received(msg.freeze()));
|
.map(|msg| Message::Received(msg.freeze()));
|
||||||
let (sink, stream) = sink_stream.split();
|
let (sink, stream) = sink_stream.split();
|
||||||
|
|
||||||
let remote_addr = if log_enabled!(target: "libp2p-ping", Level::Debug) {
|
let remote_addr = if log_enabled!(Level::Debug) {
|
||||||
Some(remote_addr.clone())
|
Some(remote_addr.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -185,9 +185,8 @@ where
|
|||||||
match message {
|
match message {
|
||||||
Message::Ping(payload, finished) => {
|
Message::Ping(payload, finished) => {
|
||||||
// Ping requested by the user through the `Pinger`.
|
// Ping requested by the user through the `Pinger`.
|
||||||
if log_enabled!(target: "libp2p-ping", Level::Debug) {
|
if log_enabled!(Level::Debug) {
|
||||||
debug!(target: "libp2p-ping", "Sending ping to {:?} with \
|
debug!("Sending ping to {:?} with payload {:?}",
|
||||||
payload {:?}",
|
|
||||||
remote_addr.expect("debug log level is enabled"),
|
remote_addr.expect("debug log level is enabled"),
|
||||||
payload);
|
payload);
|
||||||
}
|
}
|
||||||
@ -205,16 +204,14 @@ where
|
|||||||
// Payload was ours. Signalling future.
|
// Payload was ours. Signalling future.
|
||||||
// Errors can happen if the user closed the receiving end of
|
// Errors can happen if the user closed the receiving end of
|
||||||
// the future, which is fine to ignore.
|
// the future, which is fine to ignore.
|
||||||
debug!(target: "libp2p-ping", "Received pong from {:?} \
|
debug!("Received pong from {:?} (payload={:?}) ; ping fufilled",
|
||||||
(payload={:?}) ; ping fufilled",
|
|
||||||
remote_addr.expect("debug log level is enabled"), payload);
|
remote_addr.expect("debug log level is enabled"), payload);
|
||||||
let _ = fut.send(());
|
let _ = fut.send(());
|
||||||
Box::new(Ok(Loop::Continue((sink, stream))).into_future())
|
Box::new(Ok(Loop::Continue((sink, stream))).into_future())
|
||||||
as Box<Future<Item = _, Error = _>>
|
as Box<Future<Item = _, Error = _>>
|
||||||
} else {
|
} else {
|
||||||
// Payload was not ours. Sending it back.
|
// Payload was not ours. Sending it back.
|
||||||
debug!(target: "libp2p-ping", "Received ping from {:?} \
|
debug!("Received ping from {:?} (payload={:?}) ; sending back",
|
||||||
(payload={:?}) ; sending back",
|
|
||||||
remote_addr.expect("debug log level is enabled"), payload);
|
remote_addr.expect("debug log level is enabled"), payload);
|
||||||
Box::new(
|
Box::new(
|
||||||
sink.send(payload)
|
sink.send(payload)
|
||||||
@ -249,7 +246,7 @@ impl Pinger {
|
|||||||
pub fn ping(&mut self) -> Box<Future<Item = (), Error = Box<Error + Send + Sync>>> {
|
pub fn ping(&mut self) -> Box<Future<Item = (), Error = Box<Error + Send + Sync>>> {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
let payload: [u8; 32] = Rand::rand(&mut self.os_rng);
|
let payload: [u8; 32] = Rand::rand(&mut self.os_rng);
|
||||||
debug!(target: "libp2p-ping", "Preparing for ping with payload {:?}", payload);
|
debug!("Preparing for ping with payload {:?}", payload);
|
||||||
// Ignore errors if the ponger has been already destroyed. The returned future will never
|
// Ignore errors if the ponger has been already destroyed. The returned future will never
|
||||||
// be signalled.
|
// be signalled.
|
||||||
let fut = self.send
|
let fut = self.send
|
||||||
|
@ -51,11 +51,11 @@ impl<T> RateLimited<T> {
|
|||||||
Ok(RateLimited {
|
Ok(RateLimited {
|
||||||
value,
|
value,
|
||||||
rlimiter: Limiter::new(e, max_read).map_err(|e| {
|
rlimiter: Limiter::new(e, max_read).map_err(|e| {
|
||||||
error!(target: "libp2p-ratelimit", "failed to create read limiter: {}", e);
|
error!("failed to create read limiter: {}", e);
|
||||||
io::Error::new(io::ErrorKind::Other, e)
|
io::Error::new(io::ErrorKind::Other, e)
|
||||||
})?,
|
})?,
|
||||||
wlimiter: Limiter::new(e, max_write).map_err(|e| {
|
wlimiter: Limiter::new(e, max_write).map_err(|e| {
|
||||||
error!(target: "libp2p-ratelimit", "failed to create write limiter: {}", e);
|
error!("failed to create write limiter: {}", e);
|
||||||
io::Error::new(io::ErrorKind::Other, e)
|
io::Error::new(io::ErrorKind::Other, e)
|
||||||
})?,
|
})?,
|
||||||
})
|
})
|
||||||
@ -81,11 +81,11 @@ impl<C: AsyncRead + AsyncWrite> Connection<C> {
|
|||||||
let (r, w) = c.split();
|
let (r, w) = c.split();
|
||||||
Ok(Connection {
|
Ok(Connection {
|
||||||
reader: Limited::new(r, rlimiter).map_err(|e| {
|
reader: Limited::new(r, rlimiter).map_err(|e| {
|
||||||
error!(target: "libp2p-ratelimit", "failed to create limited reader: {}", e);
|
error!("failed to create limited reader: {}", e);
|
||||||
io::Error::new(io::ErrorKind::Other, e)
|
io::Error::new(io::ErrorKind::Other, e)
|
||||||
})?,
|
})?,
|
||||||
writer: Limited::new(w, wlimiter).map_err(|e| {
|
writer: Limited::new(w, wlimiter).map_err(|e| {
|
||||||
error!(target: "libp2p-ratelimit", "failed to create limited writer: {}", e);
|
error!("failed to create limited writer: {}", e);
|
||||||
io::Error::new(io::ErrorKind::Other, e)
|
io::Error::new(io::ErrorKind::Other, e)
|
||||||
})?,
|
})?,
|
||||||
})
|
})
|
||||||
|
@ -80,7 +80,7 @@ where
|
|||||||
let hmac_num_bytes = self.hmac_key.digest_algorithm().output_len;
|
let hmac_num_bytes = self.hmac_key.digest_algorithm().output_len;
|
||||||
|
|
||||||
if frame.len() < hmac_num_bytes {
|
if frame.len() < hmac_num_bytes {
|
||||||
debug!(target: "libp2p-secio", "frame too short when decoding secio frame");
|
debug!("frame too short when decoding secio frame");
|
||||||
return Err(SecioError::FrameTooShort);
|
return Err(SecioError::FrameTooShort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ where
|
|||||||
debug_assert_eq!(expected_hash.len(), hmac_num_bytes);
|
debug_assert_eq!(expected_hash.len(), hmac_num_bytes);
|
||||||
|
|
||||||
if let Err(_) = hmac::verify(&self.hmac_key, crypted_data, expected_hash) {
|
if let Err(_) = hmac::verify(&self.hmac_key, crypted_data, expected_hash) {
|
||||||
debug!(target: "libp2p-secio", "hmac mismatch when decoding secio frame");
|
debug!("hmac mismatch when decoding secio frame");
|
||||||
return Err(SecioError::HmacNotMatching);
|
return Err(SecioError::HmacNotMatching);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,7 @@ where
|
|||||||
.and_then(|mut context| {
|
.and_then(|mut context| {
|
||||||
context.rng.fill(&mut context.local_nonce)
|
context.rng.fill(&mut context.local_nonce)
|
||||||
.map_err(|_| SecioError::NonceGenerationFailed)?;
|
.map_err(|_| SecioError::NonceGenerationFailed)?;
|
||||||
trace!(target: "libp2p-secio", "starting handshake ; local pubkey = {:?} ; \
|
trace!("starting handshake ; local pubkey = {:?} ; local nonce = {:?}",
|
||||||
local nonce = {:?}",
|
|
||||||
context.local_public_key, context.local_nonce);
|
context.local_public_key, context.local_nonce);
|
||||||
Ok(context)
|
Ok(context)
|
||||||
})
|
})
|
||||||
@ -161,7 +160,7 @@ where
|
|||||||
let proposition_bytes = proposition.write_to_bytes().unwrap();
|
let proposition_bytes = proposition.write_to_bytes().unwrap();
|
||||||
context.local_proposition_bytes = proposition_bytes.clone();
|
context.local_proposition_bytes = proposition_bytes.clone();
|
||||||
|
|
||||||
trace!(target: "libp2p-secio", "sending proposition to remote");
|
trace!("sending proposition to remote");
|
||||||
|
|
||||||
socket.send(BytesMut::from(proposition_bytes.clone()))
|
socket.send(BytesMut::from(proposition_bytes.clone()))
|
||||||
.from_err()
|
.from_err()
|
||||||
@ -177,8 +176,7 @@ where
|
|||||||
Some(p) => context.remote_proposition_bytes = p,
|
Some(p) => context.remote_proposition_bytes = p,
|
||||||
None => {
|
None => {
|
||||||
let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof");
|
let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof");
|
||||||
debug!(target: "libp2p-secio", "unexpected eof while waiting for \
|
debug!("unexpected eof while waiting for remote's proposition");
|
||||||
remote's proposition");
|
|
||||||
return Err(err.into())
|
return Err(err.into())
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -188,8 +186,7 @@ where
|
|||||||
) {
|
) {
|
||||||
Ok(prop) => prop,
|
Ok(prop) => prop,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!(target: "libp2p-secio", "failed to parse remote's proposition \
|
debug!("failed to parse remote's proposition protobuf message");
|
||||||
protobuf message");
|
|
||||||
return Err(SecioError::HandshakeParsingFailure);
|
return Err(SecioError::HandshakeParsingFailure);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -199,8 +196,7 @@ where
|
|||||||
match protobuf_parse_from_bytes::<PublicKeyProtobuf>(bytes) {
|
match protobuf_parse_from_bytes::<PublicKeyProtobuf>(bytes) {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!(target: "libp2p-secio", "failed to parse remote's \
|
debug!("failed to parse remote's proposition's pubkey protobuf");
|
||||||
proposition's pubkey protobuf");
|
|
||||||
return Err(SecioError::HandshakeParsingFailure);
|
return Err(SecioError::HandshakeParsingFailure);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -212,15 +208,13 @@ where
|
|||||||
KeyTypeProtobuf::RSA => (),
|
KeyTypeProtobuf::RSA => (),
|
||||||
format => {
|
format => {
|
||||||
let err = IoError::new(IoErrorKind::Other, "unsupported protocol");
|
let err = IoError::new(IoErrorKind::Other, "unsupported protocol");
|
||||||
debug!(target: "libp2p-secio", "unsupported remote pubkey format {:?}",
|
debug!("unsupported remote pubkey format {:?}", format);
|
||||||
format);
|
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
context.remote_public_key = pubkey.take_Data();
|
context.remote_public_key = pubkey.take_Data();
|
||||||
context.remote_nonce = prop.take_rand();
|
context.remote_nonce = prop.take_rand();
|
||||||
trace!(target: "libp2p-secio", "received proposition from remote ; \
|
trace!("received proposition from remote ; pubkey = {:?} ; nonce = {:?}",
|
||||||
pubkey = {:?} ; nonce = {:?}",
|
|
||||||
context.remote_public_key, context.remote_nonce);
|
context.remote_public_key, context.remote_nonce);
|
||||||
Ok((prop, socket, context))
|
Ok((prop, socket, context))
|
||||||
})
|
})
|
||||||
@ -253,7 +247,7 @@ where
|
|||||||
Some(match algo_support::exchanges::select_best(context.hashes_ordering, list) {
|
Some(match algo_support::exchanges::select_best(context.hashes_ordering, list) {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-secio", "failed to select an exchange protocol");
|
debug!("failed to select an exchange protocol");
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -263,7 +257,7 @@ where
|
|||||||
Some(match algo_support::ciphers::select_best(context.hashes_ordering, list) {
|
Some(match algo_support::ciphers::select_best(context.hashes_ordering, list) {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-secio", "failed to select a cipher protocol");
|
debug!("failed to select a cipher protocol");
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -273,7 +267,7 @@ where
|
|||||||
Some(match algo_support::hashes::select_best(context.hashes_ordering, list) {
|
Some(match algo_support::hashes::select_best(context.hashes_ordering, list) {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-secio", "failed to select a hash protocol");
|
debug!("failed to select a hash protocol");
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -287,7 +281,7 @@ where
|
|||||||
match EphemeralPrivateKey::generate(&agreement::ECDH_P256, &context.rng) {
|
match EphemeralPrivateKey::generate(&agreement::ECDH_P256, &context.rng) {
|
||||||
Ok(tmp_priv_key) => Ok((socket, context, tmp_priv_key)),
|
Ok(tmp_priv_key) => Ok((socket, context, tmp_priv_key)),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!(target: "libp2p-secio", "failed to generate ECDH key");
|
debug!("failed to generate ECDH key");
|
||||||
Err(SecioError::EphemeralKeyGenerationFailed)
|
Err(SecioError::EphemeralKeyGenerationFailed)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -311,7 +305,7 @@ where
|
|||||||
let mut state = match RSASigningState::new(context.local_private_key.clone()) {
|
let mut state = match RSASigningState::new(context.local_private_key.clone()) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!(target: "libp2p-secio", "failed to sign local exchange");
|
debug!("failed to sign local exchange");
|
||||||
return Err(SecioError::SigningFailure);
|
return Err(SecioError::SigningFailure);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -321,7 +315,7 @@ where
|
|||||||
{
|
{
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!(target: "libp2p-secio", "failed to sign local exchange");
|
debug!("failed to sign local exchange");
|
||||||
return Err(SecioError::SigningFailure);
|
return Err(SecioError::SigningFailure);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -339,7 +333,7 @@ where
|
|||||||
|
|
||||||
// Send our local `Exchange`.
|
// Send our local `Exchange`.
|
||||||
.and_then(|(local_exch, socket, context)| {
|
.and_then(|(local_exch, socket, context)| {
|
||||||
trace!(target: "libp2p-secio", "sending exchange to remote");
|
trace!("sending exchange to remote");
|
||||||
socket.send(local_exch)
|
socket.send(local_exch)
|
||||||
.from_err()
|
.from_err()
|
||||||
.map(|s| (s, context))
|
.map(|s| (s, context))
|
||||||
@ -354,8 +348,7 @@ where
|
|||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => {
|
None => {
|
||||||
let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof");
|
let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof");
|
||||||
debug!(target: "libp2p-secio", "unexpected eof while waiting for \
|
debug!("unexpected eof while waiting for remote's exchange");
|
||||||
remote's exchange");
|
|
||||||
return Err(err.into())
|
return Err(err.into())
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -363,13 +356,12 @@ where
|
|||||||
let remote_exch = match protobuf_parse_from_bytes::<Exchange>(&raw) {
|
let remote_exch = match protobuf_parse_from_bytes::<Exchange>(&raw) {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-secio", "failed to parse remote's exchange \
|
debug!("failed to parse remote's exchange protobuf ; {:?}", err);
|
||||||
protobuf ; {:?}", err);
|
|
||||||
return Err(SecioError::HandshakeParsingFailure);
|
return Err(SecioError::HandshakeParsingFailure);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!(target: "libp2p-secio", "received and decoded the remote's exchange");
|
trace!("received and decoded the remote's exchange");
|
||||||
Ok((remote_exch, socket, context))
|
Ok((remote_exch, socket, context))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -392,12 +384,12 @@ where
|
|||||||
{
|
{
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
debug!(target: "libp2p-secio", "failed to verify the remote's signature");
|
debug!("failed to verify the remote's signature");
|
||||||
return Err(SecioError::SignatureVerificationFailed)
|
return Err(SecioError::SignatureVerificationFailed)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!(target: "libp2p-secio", "successfully verified the remote's signature");
|
trace!("successfully verified the remote's signature");
|
||||||
Ok((remote_exch, socket, context))
|
Ok((remote_exch, socket, context))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -455,7 +447,7 @@ where
|
|||||||
match codec {
|
match codec {
|
||||||
Ok(c) => Ok((c, context)),
|
Ok(c) => Ok((c, context)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(target: "libp2p-secio", "failed to generate shared secret with remote");
|
debug!("failed to generate shared secret with remote");
|
||||||
return Err(err);
|
return Err(err);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -464,7 +456,7 @@ where
|
|||||||
// We send back their nonce to check if the connection works.
|
// We send back their nonce to check if the connection works.
|
||||||
.and_then(|(codec, mut context)| {
|
.and_then(|(codec, mut context)| {
|
||||||
let remote_nonce = mem::replace(&mut context.remote_nonce, Vec::new());
|
let remote_nonce = mem::replace(&mut context.remote_nonce, Vec::new());
|
||||||
trace!(target: "libp2p-secio", "checking encryption by sending back remote's nonce");
|
trace!("checking encryption by sending back remote's nonce");
|
||||||
codec.send(BytesMut::from(remote_nonce))
|
codec.send(BytesMut::from(remote_nonce))
|
||||||
.map(|s| (s, context))
|
.map(|s| (s, context))
|
||||||
.from_err()
|
.from_err()
|
||||||
@ -477,15 +469,15 @@ where
|
|||||||
.and_then(move |(nonce, rest)| {
|
.and_then(move |(nonce, rest)| {
|
||||||
match nonce {
|
match nonce {
|
||||||
Some(ref n) if n == &context.local_nonce => {
|
Some(ref n) if n == &context.local_nonce => {
|
||||||
trace!(target: "libp2p-secio", "secio handshake success");
|
trace!("secio handshake success");
|
||||||
Ok((rest, context.remote_public_key))
|
Ok((rest, context.remote_public_key))
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
debug!(target: "libp2p-secio", "unexpected eof during nonce check");
|
debug!("unexpected eof during nonce check");
|
||||||
Err(IoError::new(IoErrorKind::BrokenPipe, "unexpected eof").into())
|
Err(IoError::new(IoErrorKind::BrokenPipe, "unexpected eof").into())
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
debug!(target: "libp2p-secio", "failed nonce verification with remote");
|
debug!("failed nonce verification with remote");
|
||||||
Err(SecioError::NonceVerificationFailed)
|
Err(SecioError::NonceVerificationFailed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ where
|
|||||||
_: libp2p_core::Endpoint,
|
_: libp2p_core::Endpoint,
|
||||||
remote_addr: &Multiaddr,
|
remote_addr: &Multiaddr,
|
||||||
) -> Self::Future {
|
) -> Self::Future {
|
||||||
info!(target: "libp2p-secio", "starting secio upgrade with {:?}", remote_addr);
|
info!("starting secio upgrade with {:?}", remote_addr);
|
||||||
|
|
||||||
let fut = SecioMiddleware::handshake(incoming, self.key);
|
let fut = SecioMiddleware::handshake(incoming, self.key);
|
||||||
let wrapped = fut.map(|(stream_sink, pubkey)| {
|
let wrapped = fut.map(|(stream_sink, pubkey)| {
|
||||||
@ -224,7 +224,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn map_err(err: SecioError) -> IoError {
|
fn map_err(err: SecioError) -> IoError {
|
||||||
debug!(target: "libp2p-secio", "error during secio handshake {:?}", err);
|
debug!("error during secio handshake {:?}", err);
|
||||||
IoError::new(IoErrorKind::InvalidData, err)
|
IoError::new(IoErrorKind::InvalidData, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ impl Transport for TcpConfig {
|
|||||||
Err(_) => addr,
|
Err(_) => addr,
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(target: "libp2p-tcp-transport", "Now listening on {}", new_addr);
|
debug!("Now listening on {}", new_addr);
|
||||||
|
|
||||||
let future = future::result(listener)
|
let future = future::result(listener)
|
||||||
.map(|listener| {
|
.map(|listener| {
|
||||||
@ -119,7 +119,7 @@ impl Transport for TcpConfig {
|
|||||||
listener.incoming().map(|(sock, addr)| {
|
listener.incoming().map(|(sock, addr)| {
|
||||||
let addr = addr.to_multiaddr()
|
let addr = addr.to_multiaddr()
|
||||||
.expect("generating a multiaddr from a socket addr never fails");
|
.expect("generating a multiaddr from a socket addr never fails");
|
||||||
debug!(target: "libp2p-tcp-transport", "Incoming connection from {}", addr);
|
debug!("Incoming connection from {}", addr);
|
||||||
Ok((sock, addr)).into_future()
|
Ok((sock, addr)).into_future()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -135,7 +135,7 @@ impl Transport for TcpConfig {
|
|||||||
/// or gives back the multiaddress.
|
/// or gives back the multiaddress.
|
||||||
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, (Self, Multiaddr)> {
|
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, (Self, Multiaddr)> {
|
||||||
if let Ok(socket_addr) = multiaddr_to_socketaddr(&addr) {
|
if let Ok(socket_addr) = multiaddr_to_socketaddr(&addr) {
|
||||||
debug!(target: "libp2p-tcp-transport", "Dialing {}", addr);
|
debug!("Dialing {}", addr);
|
||||||
let fut = TcpStream::connect(&socket_addr, &self.event_loop).map(|t| (t, addr));
|
let fut = TcpStream::connect(&socket_addr, &self.event_loop).map(|t| (t, addr));
|
||||||
Ok(Box::new(fut) as Box<_>)
|
Ok(Box::new(fut) as Box<_>)
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,7 +76,7 @@ impl Transport for BrowserWsConfig {
|
|||||||
Err(_) => return Err((self, original_addr)),
|
Err(_) => return Err((self, original_addr)),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(target: "libp2p-websocket", "Dialing {}", original_addr);
|
debug!("Dialing {}", original_addr);
|
||||||
|
|
||||||
// Create the JS `WebSocket` object.
|
// Create the JS `WebSocket` object.
|
||||||
let websocket = {
|
let websocket = {
|
||||||
|
@ -94,14 +94,14 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(target: "libp2p-websocket", "Listening on {}", new_addr);
|
debug!("Listening on {}", new_addr);
|
||||||
|
|
||||||
let listen = inner_listen.map::<_, fn(_) -> _>(|stream| {
|
let listen = inner_listen.map::<_, fn(_) -> _>(|stream| {
|
||||||
// Upgrade the listener to websockets like the websockets library requires us to do.
|
// Upgrade the listener to websockets like the websockets library requires us to do.
|
||||||
let upgraded = stream.and_then(|(stream, mut client_addr)| {
|
let upgraded = stream.and_then(|(stream, mut client_addr)| {
|
||||||
// Need to suffix `/ws` to each client address.
|
// Need to suffix `/ws` to each client address.
|
||||||
client_addr.append(AddrComponent::WS);
|
client_addr.append(AddrComponent::WS);
|
||||||
debug!(target: "libp2p-websocket", "Incoming connection from {}", client_addr);
|
debug!("Incoming connection from {}", client_addr);
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.into_ws()
|
.into_ws()
|
||||||
@ -112,8 +112,7 @@ where
|
|||||||
.accept()
|
.accept()
|
||||||
.map_err(|err| IoError::new(IoErrorKind::Other, err))
|
.map_err(|err| IoError::new(IoErrorKind::Other, err))
|
||||||
.map(|(client, _http_headers)| {
|
.map(|(client, _http_headers)| {
|
||||||
debug!(target: "libp2p-websocket", "Upgraded incoming connection \
|
debug!("Upgraded incoming connection to websockets");
|
||||||
to websockets");
|
|
||||||
|
|
||||||
// Plug our own API on top of the `websockets` API.
|
// Plug our own API on top of the `websockets` API.
|
||||||
let framed_data = client
|
let framed_data = client
|
||||||
@ -156,22 +155,22 @@ where
|
|||||||
Some(AddrComponent::WS) => false,
|
Some(AddrComponent::WS) => false,
|
||||||
Some(AddrComponent::WSS) => true,
|
Some(AddrComponent::WSS) => true,
|
||||||
_ => {
|
_ => {
|
||||||
trace!(target: "libp2p-websocket", "Ignoring dial attempt for {} because it is \
|
trace!("Ignoring dial attempt for {} because it is not a websocket multiaddr",
|
||||||
not a websocket multiaddr", original_addr);
|
original_addr);
|
||||||
return Err((self, original_addr));
|
return Err((self, original_addr));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(target: "libp2p-websocket", "Dialing {} through inner transport", inner_addr);
|
debug!("Dialing {} through inner transport", inner_addr);
|
||||||
|
|
||||||
let ws_addr = client_addr_to_ws(&inner_addr, is_wss);
|
let ws_addr = client_addr_to_ws(&inner_addr, is_wss);
|
||||||
|
|
||||||
let inner_dial = match self.transport.dial(inner_addr) {
|
let inner_dial = match self.transport.dial(inner_addr) {
|
||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err((transport, old_addr)) => {
|
Err((transport, old_addr)) => {
|
||||||
warn!(target: "libp2p-websocket", "Failed to dial {} because {} is not supported \
|
warn!("Failed to dial {} because {} is not supported by the underlying transport",
|
||||||
by the underlying transport", original_addr,
|
original_addr,
|
||||||
old_addr);
|
old_addr);
|
||||||
return Err((
|
return Err((
|
||||||
WsConfig {
|
WsConfig {
|
||||||
transport: transport,
|
transport: transport,
|
||||||
@ -189,8 +188,7 @@ where
|
|||||||
.async_connect_on(connec)
|
.async_connect_on(connec)
|
||||||
.map_err(|err| IoError::new(IoErrorKind::Other, err))
|
.map_err(|err| IoError::new(IoErrorKind::Other, err))
|
||||||
.map(|(client, _)| {
|
.map(|(client, _)| {
|
||||||
debug!(target: "libp2p-websocket", "Upgraded outgoing connection to \
|
debug!("Upgraded outgoing connection to websockets");
|
||||||
websockets");
|
|
||||||
|
|
||||||
// Plug our own API on top of the API of the websockets library.
|
// Plug our own API on top of the API of the websockets library.
|
||||||
let framed_data = client
|
let framed_data = client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user