diff --git a/core/src/nodes/mod.rs b/core/src/nodes/mod.rs index b3a6b8ab..ba54ad5f 100644 --- a/core/src/nodes/mod.rs +++ b/core/src/nodes/mod.rs @@ -29,4 +29,4 @@ pub mod swarm; pub use self::node::Substream; pub use self::handled_node::{NodeHandlerEvent, NodeHandlerEndpoint}; pub use self::raw_swarm::{ConnectedPoint, Peer, RawSwarm, RawSwarmEvent}; -pub use self::swarm::{Swarm, NetworkBehavior, NetworkBehaviorAction}; +pub use self::swarm::{Swarm, NetworkBehaviour, NetworkBehaviourAction}; diff --git a/core/src/nodes/swarm.rs b/core/src/nodes/swarm.rs index e8eeb0aa..d7d51a54 100644 --- a/core/src/nodes/swarm.rs +++ b/core/src/nodes/swarm.rs @@ -35,12 +35,12 @@ use std::{fmt, io, ops::{Deref, DerefMut}}; /// Contains the state of the network, plus the way it should behave. pub struct Swarm where TTransport: Transport, - TBehaviour: NetworkBehavior, + TBehaviour: NetworkBehaviour, { raw_swarm: RawSwarm< TTransport, - <::ProtocolsHandler as ProtocolsHandler>::InEvent, - <::ProtocolsHandler as ProtocolsHandler>::OutEvent, + <::ProtocolsHandler as ProtocolsHandler>::InEvent, + <::ProtocolsHandler as ProtocolsHandler>::OutEvent, NodeHandlerWrapper, >, @@ -55,7 +55,7 @@ where TTransport: Transport, impl Deref for Swarm where TTransport: Transport, - TBehaviour: NetworkBehavior, + TBehaviour: NetworkBehaviour, { type Target = TBehaviour; @@ -67,7 +67,7 @@ where TTransport: Transport, impl DerefMut for Swarm where TTransport: Transport, - TBehaviour: NetworkBehavior, + TBehaviour: NetworkBehaviour, { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { @@ -76,7 +76,7 @@ where TTransport: Transport, } impl Swarm -where TBehaviour: NetworkBehavior, +where TBehaviour: NetworkBehaviour, TMuxer: StreamMuxer + Send + Sync + 'static, ::OutboundSubstream: Send + 'static, ::Substream: Send + 'static, @@ -169,7 +169,7 @@ where TBehaviour: NetworkBehavior, } impl Stream for Swarm -where TBehaviour: NetworkBehavior, +where TBehaviour: NetworkBehaviour, TMuxer: StreamMuxer + Send + Sync + 'static, ::OutboundSubstream: Send + 'static, ::Substream: Send + 'static, @@ -231,16 +231,16 @@ where TBehaviour: NetworkBehavior, match self.behaviour.poll() { Async::NotReady if raw_swarm_not_ready => return Ok(Async::NotReady), Async::NotReady => (), - Async::Ready(NetworkBehaviorAction::GenerateEvent(event)) => { + Async::Ready(NetworkBehaviourAction::GenerateEvent(event)) => { return Ok(Async::Ready(Some(event))); }, - Async::Ready(NetworkBehaviorAction::DialAddress { address }) => { + Async::Ready(NetworkBehaviourAction::DialAddress { address }) => { let _ = Swarm::dial_addr(self, address); }, - Async::Ready(NetworkBehaviorAction::DialPeer { peer_id }) => { + Async::Ready(NetworkBehaviourAction::DialPeer { peer_id }) => { Swarm::dial(self, peer_id) }, - Async::Ready(NetworkBehaviorAction::SendEvent { peer_id, event }) => { + Async::Ready(NetworkBehaviourAction::SendEvent { peer_id, event }) => { if let Some(mut peer) = self.raw_swarm.peer(peer_id).as_connected() { peer.send_event(event); } @@ -254,7 +254,7 @@ where TBehaviour: NetworkBehavior, /// /// This trait has been designed to be composable. Multiple implementations can be combined into /// one that handles all the behaviours at once. -pub trait NetworkBehavior { +pub trait NetworkBehaviour { /// Handler for all the protocols the network supports. type ProtocolsHandler: ProtocolsHandler; /// Event generated by the swarm. @@ -284,12 +284,12 @@ pub trait NetworkBehavior { /// Polls for things that swarm should do. /// /// This API mimics the API of the `Stream` trait. - fn poll(&mut self) -> Async::InEvent, Self::OutEvent>>; + fn poll(&mut self) -> Async::InEvent, Self::OutEvent>>; } /// Action to perform. #[derive(Debug, Clone)] -pub enum NetworkBehaviorAction { +pub enum NetworkBehaviourAction { /// Generate an event for the outside. GenerateEvent(TOutEvent), diff --git a/core/src/tests/dummy_muxer.rs b/core/src/tests/dummy_muxer.rs index 8eb1877b..7e5a41b7 100644 --- a/core/src/tests/dummy_muxer.rs +++ b/core/src/tests/dummy_muxer.rs @@ -47,7 +47,7 @@ struct DummyConnection { state: DummyConnectionState, } -/// `DummyMuxer` implements `StreamMuxer` and methods to control its behavior when used in tests +/// `DummyMuxer` implements `StreamMuxer` and methods to control its behaviour when used in tests #[derive(Debug, Clone)] pub struct DummyMuxer { in_connection: DummyConnection, diff --git a/misc/core-derive/src/lib.rs b/misc/core-derive/src/lib.rs index 4f6b503e..167b4c46 100644 --- a/misc/core-derive/src/lib.rs +++ b/misc/core-derive/src/lib.rs @@ -40,8 +40,8 @@ pub fn hello_macro_derive(input: TokenStream) -> TokenStream { fn build(ast: &DeriveInput) -> TokenStream { match ast.data { Data::Struct(ref s) => build_struct(ast, s), - Data::Enum(_) => unimplemented!("Deriving NetworkBehavior is not implemented for enums"), - Data::Union(_) => unimplemented!("Deriving NetworkBehavior is not implemented for unions"), + Data::Enum(_) => unimplemented!("Deriving NetworkBehaviour is not implemented for enums"), + Data::Union(_) => unimplemented!("Deriving NetworkBehaviour is not implemented for unions"), } } @@ -49,9 +49,9 @@ fn build(ast: &DeriveInput) -> TokenStream { fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let name = &ast.ident; let (_, ty_generics, where_clause) = ast.generics.split_for_impl(); - let trait_to_impl = quote!{::libp2p::core::nodes::swarm::NetworkBehavior}; + let trait_to_impl = quote!{::libp2p::core::nodes::swarm::NetworkBehaviour}; let either_ident = quote!{::libp2p::core::either::EitherOutput}; - let network_behaviour_action = quote!{::libp2p::core::nodes::swarm::NetworkBehaviorAction}; + let network_behaviour_action = quote!{::libp2p::core::nodes::swarm::NetworkBehaviourAction}; let protocols_handler = quote!{::libp2p::core::protocols_handler::ProtocolsHandler}; let proto_select_ident = quote!{::libp2p::core::protocols_handler::ProtocolsHandlerSelect}; let peer_id = quote!{::libp2p::core::PeerId}; diff --git a/misc/core-derive/tests/test.rs b/misc/core-derive/tests/test.rs index eb3ed0f2..9a68f7ed 100644 --- a/misc/core-derive/tests/test.rs +++ b/misc/core-derive/tests/test.rs @@ -74,7 +74,7 @@ fn event_handler() { impl Foo { // TODO: for some reason, the parameter cannot be `PeriodicIdentifyBehaviourEvent` or we // get a compilation error ; figure out why or open an issue to Rust - fn foo(&mut self, ev: as libp2p::core::nodes::NetworkBehavior>::OutEvent) { + fn foo(&mut self, ev: as libp2p::core::nodes::NetworkBehaviour>::OutEvent) { let libp2p::identify::PeriodicIdentifyBehaviourEvent::Identified { .. } = ev; } } @@ -91,7 +91,7 @@ fn custom_polling() { } impl Foo { - fn foo(&mut self) -> libp2p::futures::Async> { libp2p::futures::Async::NotReady } + fn foo(&mut self) -> libp2p::futures::Async> { libp2p::futures::Async::NotReady } } } @@ -117,6 +117,6 @@ fn custom_event_and_polling() { } impl Foo { - fn foo(&mut self) -> libp2p::futures::Async> { libp2p::futures::Async::NotReady } + fn foo(&mut self) -> libp2p::futures::Async> { libp2p::futures::Async::NotReady } } } diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 260dd3bd..40d2ea3d 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -21,7 +21,7 @@ use cuckoofilter::CuckooFilter; use futures::prelude::*; use handler::FloodsubHandler; -use libp2p_core::nodes::{ConnectedPoint, NetworkBehavior, NetworkBehaviorAction}; +use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use protocol::{FloodsubMessage, FloodsubRpc, FloodsubSubscription, FloodsubSubscriptionAction}; use rand; @@ -35,7 +35,7 @@ use topic::{Topic, TopicHash}; /// about them. pub struct FloodsubBehaviour { /// Events that need to be yielded to the outside when polling. - events: VecDeque>, + events: VecDeque>, /// Peer id of the local node. Used for the source of the messages that we publish. local_peer_id: PeerId, @@ -81,7 +81,7 @@ impl FloodsubBehaviour { } for peer in self.connected_peers.keys() { - self.events.push_back(NetworkBehaviorAction::SendEvent { + self.events.push_back(NetworkBehaviourAction::SendEvent { peer_id: peer.clone(), event: FloodsubRpc { messages: Vec::new(), @@ -112,7 +112,7 @@ impl FloodsubBehaviour { self.subscribed_topics.remove(pos); for peer in self.connected_peers.keys() { - self.events.push_back(NetworkBehaviorAction::SendEvent { + self.events.push_back(NetworkBehaviourAction::SendEvent { peer_id: peer.clone(), event: FloodsubRpc { messages: Vec::new(), @@ -161,7 +161,7 @@ impl FloodsubBehaviour { continue; } - self.events.push_back(NetworkBehaviorAction::SendEvent { + self.events.push_back(NetworkBehaviourAction::SendEvent { peer_id: peer_id.clone(), event: FloodsubRpc { subscriptions: Vec::new(), @@ -172,7 +172,7 @@ impl FloodsubBehaviour { } } -impl NetworkBehavior for FloodsubBehaviour +impl NetworkBehaviour for FloodsubBehaviour where TSubstream: AsyncRead + AsyncWrite, { @@ -186,7 +186,7 @@ where fn inject_connected(&mut self, id: PeerId, _: ConnectedPoint) { // We need to send our subscriptions to the newly-connected node. for topic in self.subscribed_topics.iter() { - self.events.push_back(NetworkBehaviorAction::SendEvent { + self.events.push_back(NetworkBehaviourAction::SendEvent { peer_id: id.clone(), event: FloodsubRpc { messages: Vec::new(), @@ -242,7 +242,7 @@ where // Add the message to be dispatched to the user. if self.subscribed_topics.iter().any(|t| message.topics.iter().any(|u| t.hash() == u)) { - self.events.push_back(NetworkBehaviorAction::GenerateEvent(message.clone())); + self.events.push_back(NetworkBehaviourAction::GenerateEvent(message.clone())); } // Propagate the message to everyone else who is subscribed to any of the topics. @@ -267,7 +267,7 @@ where } for (peer_id, rpc) in rpcs_to_dispatch { - self.events.push_back(NetworkBehaviorAction::SendEvent { + self.events.push_back(NetworkBehaviourAction::SendEvent { peer_id, event: rpc, }); @@ -277,7 +277,7 @@ where fn poll( &mut self, ) -> Async< - NetworkBehaviorAction< + NetworkBehaviourAction< ::InEvent, Self::OutEvent, >, diff --git a/protocols/identify/src/listen_layer.rs b/protocols/identify/src/listen_layer.rs index ace0d802..5942570e 100644 --- a/protocols/identify/src/listen_layer.rs +++ b/protocols/identify/src/listen_layer.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::nodes::{ConnectedPoint, NetworkBehavior, NetworkBehaviorAction}; +use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use smallvec::SmallVec; use std::{collections::HashMap, io, marker::PhantomData}; @@ -64,7 +64,7 @@ impl IdentifyListen { } } -impl NetworkBehavior for IdentifyListen +impl NetworkBehaviour for IdentifyListen where TSubstream: AsyncRead + AsyncWrite + Send + Sync + 'static, { @@ -103,7 +103,7 @@ where fn poll( &mut self, ) -> Async< - NetworkBehaviorAction< + NetworkBehaviourAction< ::InEvent, Self::OutEvent, >, diff --git a/protocols/identify/src/periodic_id_layer.rs b/protocols/identify/src/periodic_id_layer.rs index 32019eec..c4198b26 100644 --- a/protocols/identify/src/periodic_id_layer.rs +++ b/protocols/identify/src/periodic_id_layer.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::nodes::{ConnectedPoint, NetworkBehavior, NetworkBehaviorAction}; +use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use std::{collections::VecDeque, marker::PhantomData}; use tokio_io::{AsyncRead, AsyncWrite}; @@ -44,7 +44,7 @@ impl PeriodicIdentifyBehaviour { } } -impl NetworkBehavior for PeriodicIdentifyBehaviour +impl NetworkBehaviour for PeriodicIdentifyBehaviour where TSubstream: AsyncRead + AsyncWrite + Send + Sync + 'static, { @@ -80,13 +80,13 @@ where fn poll( &mut self, ) -> Async< - NetworkBehaviorAction< + NetworkBehaviourAction< ::InEvent, Self::OutEvent, >, > { if let Some(event) = self.events.pop_front() { - return Async::Ready(NetworkBehaviorAction::GenerateEvent(event)); + return Async::Ready(NetworkBehaviourAction::GenerateEvent(event)); } Async::NotReady diff --git a/protocols/ping/src/dial_layer.rs b/protocols/ping/src/dial_layer.rs index 8118cef8..b23b9677 100644 --- a/protocols/ping/src/dial_layer.rs +++ b/protocols/ping/src/dial_layer.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::nodes::{ConnectedPoint, NetworkBehavior, NetworkBehaviorAction}; +use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use std::marker::PhantomData; use tokio_io::{AsyncRead, AsyncWrite}; @@ -48,7 +48,7 @@ impl Default for PeriodicPingBehaviour { } } -impl NetworkBehavior for PeriodicPingBehaviour +impl NetworkBehaviour for PeriodicPingBehaviour where TSubstream: AsyncRead + AsyncWrite, { @@ -73,7 +73,7 @@ where fn poll( &mut self, ) -> Async< - NetworkBehaviorAction< + NetworkBehaviourAction< ::InEvent, Self::OutEvent, >, diff --git a/protocols/ping/src/listen_layer.rs b/protocols/ping/src/listen_layer.rs index b8da169b..f23f40e4 100644 --- a/protocols/ping/src/listen_layer.rs +++ b/protocols/ping/src/listen_layer.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::nodes::{ConnectedPoint, NetworkBehavior, NetworkBehaviorAction}; +use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use std::marker::PhantomData; use tokio_io::{AsyncRead, AsyncWrite}; @@ -48,7 +48,7 @@ impl Default for PingListenBehaviour { } } -impl NetworkBehavior for PingListenBehaviour +impl NetworkBehaviour for PingListenBehaviour where TSubstream: AsyncRead + AsyncWrite, { @@ -73,7 +73,7 @@ where fn poll( &mut self, ) -> Async< - NetworkBehaviorAction< + NetworkBehaviourAction< ::InEvent, Self::OutEvent, >,