diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 438f1b0d9bc..61b59f95a26 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -12,6 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" libp2p-core = { version = "0.14.0-alpha.1", path = "../core" } +log = "0.4" smallvec = "1.0" wasm-timer = "0.2" void = "1" diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 6dbf7b18bb5..7cd841bb921 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -77,7 +77,7 @@ pub use protocols_handler::{ SubstreamProtocol }; -use protocols_handler::{NodeHandlerWrapperBuilder, NodeHandlerWrapper, NodeHandlerWrapperError}; +use protocols_handler::{NodeHandlerWrapperBuilder, NodeHandlerWrapperError}; use futures::prelude::*; use libp2p_core::{ Transport, Multiaddr, Negotiated, PeerId, InboundUpgrade, OutboundUpgrade, UpgradeInfo, ProtocolName, @@ -85,7 +85,6 @@ use libp2p_core::{ nodes::{ ListenerId, collection::ConnectionInfo, - handled_node::NodeHandler, node::Substream, network::{self, Network, NetworkEvent} }, @@ -202,35 +201,33 @@ where impl ExpandedSwarm where TBehaviour: NetworkBehaviour, + TInEvent: Send + 'static, + TOutEvent: Send + 'static, + TConnInfo: ConnectionInfo + fmt::Debug + Clone + Send + 'static, TMuxer: StreamMuxer + Send + Sync + 'static, - ::OutboundSubstream: Send + 'static, - ::Substream: Send + 'static, + TMuxer::OutboundSubstream: Send + 'static, + TMuxer::Substream: Send + 'static, TTransport: Transport + Clone, TTransport::Error: Send + 'static, TTransport::Listener: Send + 'static, TTransport::ListenerUpgrade: Send + 'static, TTransport::Dial: Send + 'static, - THandlerErr: error::Error, + THandlerErr: error::Error + Send + 'static, THandler: IntoProtocolsHandler + Send + 'static, - ::Handler: ProtocolsHandler, Error = THandlerErr> + Send + 'static, - <::Handler as ProtocolsHandler>::InEvent: Send + 'static, - <::Handler as ProtocolsHandler>::OutEvent: Send + 'static, - <::Handler as ProtocolsHandler>::Error: Send + 'static, - <::Handler as ProtocolsHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary - <::Handler as ProtocolsHandler>::InboundProtocol: InboundUpgrade>> + Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::Info: Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, - <<<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Error: Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Future: Send + 'static, - <::Handler as ProtocolsHandler>::OutboundProtocol: OutboundUpgrade>> + Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::Info: Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, - <<<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Future: Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Error: Send + 'static, - ::Handler> as NodeHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary - TConnInfo: ConnectionInfo + fmt::Debug + Clone + Send + 'static, + THandler::Handler: ProtocolsHandler, Error = THandlerErr> + Send + 'static, + ::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary + ::InboundProtocol: InboundUpgrade>> + Send + 'static, + <::InboundProtocol as UpgradeInfo>::Info: Send + 'static, + <::InboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, + <<::InboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, + <::InboundProtocol as InboundUpgrade>>>::Error: Send + 'static, + <::InboundProtocol as InboundUpgrade>>>::Future: Send + 'static, + ::OutboundProtocol: OutboundUpgrade>> + Send + 'static, + <::OutboundProtocol as UpgradeInfo>::Info: Send + 'static, + <::OutboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, + <<::OutboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, + <::OutboundProtocol as OutboundUpgrade>>>::Future: Send + 'static, + <::OutboundProtocol as OutboundUpgrade>>>::Error: Send + 'static, { /// Builds a new `Swarm`. pub fn new(transport: TTransport, behaviour: TBehaviour, local_peer_id: PeerId) -> Self { @@ -383,7 +380,9 @@ where TBehaviour: NetworkBehaviour, return Poll::Ready(SwarmEvent::Connected(conn_info.peer_id().clone())); } }, - Poll::Ready(NetworkEvent::NodeClosed { conn_info, endpoint, .. }) => { + Poll::Ready(NetworkEvent::NodeClosed { conn_info, endpoint, error }) => { + log::trace!("Connection {:?} with endpoint {:?} closed by {:?}", + conn_info, endpoint, error); this.behaviour.inject_disconnected(conn_info.peer_id(), endpoint); return Poll::Ready(SwarmEvent::Disconnected(conn_info.peer_id().clone())); }, @@ -507,26 +506,24 @@ where TBehaviour: NetworkBehaviour, TTransport::Listener: Send + 'static, TTransport::ListenerUpgrade: Send + 'static, TTransport::Dial: Send + 'static, - THandlerErr: error::Error, + THandlerErr: error::Error + Send + 'static, THandler: IntoProtocolsHandler + Send + 'static, - ::Handler: ProtocolsHandler, Error = THandlerErr> + Send + 'static, - <::Handler as ProtocolsHandler>::InEvent: Send + 'static, - <::Handler as ProtocolsHandler>::OutEvent: Send + 'static, - <::Handler as ProtocolsHandler>::Error: Send + 'static, - <::Handler as ProtocolsHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary - <::Handler as ProtocolsHandler>::InboundProtocol: InboundUpgrade>> + Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Future: Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Error: Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::Info: Send + 'static, - <<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, - <<<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, - <::Handler as ProtocolsHandler>::OutboundProtocol: OutboundUpgrade>> + Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Future: Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Error: Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::Info: Send + 'static, - <<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, - <<<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, - ::Handler> as NodeHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary + TInEvent: Send + 'static, + TOutEvent: Send + 'static, + THandler::Handler: ProtocolsHandler, Error = THandlerErr> + Send + 'static, + ::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary + ::InboundProtocol: InboundUpgrade>> + Send + 'static, + <::InboundProtocol as InboundUpgrade>>>::Future: Send + 'static, + <::InboundProtocol as InboundUpgrade>>>::Error: Send + 'static, + <::InboundProtocol as UpgradeInfo>::Info: Send + 'static, + <::InboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, + <<::InboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, + ::OutboundProtocol: OutboundUpgrade>> + Send + 'static, + <::OutboundProtocol as OutboundUpgrade>>>::Future: Send + 'static, + <::OutboundProtocol as OutboundUpgrade>>>::Error: Send + 'static, + <::OutboundProtocol as UpgradeInfo>::Info: Send + 'static, + <::OutboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, + <<::OutboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, TConnInfo: ConnectionInfo + fmt::Debug + Clone + Send + 'static, { type Item = TBehaviour::OutEvent; @@ -589,25 +586,24 @@ where TBehaviour: NetworkBehaviour, TTransport::Listener: Send + 'static, TTransport::ListenerUpgrade: Send + 'static, TTransport::Dial: Send + 'static, - ::ProtocolsHandler: Send + 'static, - <::ProtocolsHandler as IntoProtocolsHandler>::Handler: ProtocolsHandler> + Send + 'static, - <<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent: Send + 'static, - <<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent: Send + 'static, - <<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::Error: Send + 'static, - <<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary - <<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InboundProtocol: InboundUpgrade>> + Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::Info: Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, - <<<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Error: Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Future: Send + 'static, - <<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundProtocol: OutboundUpgrade>> + Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::Info: Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, - <<<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Future: Send + 'static, - <<<::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Error: Send + 'static, - ::ProtocolsHandler as IntoProtocolsHandler>::Handler> as NodeHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary + TBehaviour::ProtocolsHandler: Send + 'static, + ::Handler: ProtocolsHandler> + Send + 'static, + <::Handler as ProtocolsHandler>::InEvent: Send + 'static, + <::Handler as ProtocolsHandler>::OutEvent: Send + 'static, + <::Handler as ProtocolsHandler>::Error: Send + 'static, + <::Handler as ProtocolsHandler>::OutboundOpenInfo: Send + 'static, // TODO: shouldn't be necessary + <::Handler as ProtocolsHandler>::InboundProtocol: InboundUpgrade>> + Send + 'static, + <<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::Info: Send + 'static, + <<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, + <<<::Handler as ProtocolsHandler>::InboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, + <<::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Error: Send + 'static, + <<::Handler as ProtocolsHandler>::InboundProtocol as InboundUpgrade>>>::Future: Send + 'static, + <::Handler as ProtocolsHandler>::OutboundProtocol: OutboundUpgrade>> + Send + 'static, + <<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::Info: Send + 'static, + <<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter: Send + 'static, + <<<::Handler as ProtocolsHandler>::OutboundProtocol as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send + 'static, + <<::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Future: Send + 'static, + <<::Handler as ProtocolsHandler>::OutboundProtocol as OutboundUpgrade>>>::Error: Send + 'static, TConnInfo: ConnectionInfo + fmt::Debug + Clone + Send + 'static, { pub fn new(transport: TTransport, behaviour: TBehaviour, local_peer_id: PeerId) -> Self {