Behavior -> Behaviour (#650)

This commit is contained in:
Pierre Krieger 2018-11-16 12:59:57 +01:00 committed by GitHub
parent 23bcd44f18
commit 37994b34e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 46 additions and 46 deletions

View File

@ -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};

View File

@ -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<TTransport, TBehaviour, TTopology>
where TTransport: Transport,
TBehaviour: NetworkBehavior,
TBehaviour: NetworkBehaviour,
{
raw_swarm: RawSwarm<
TTransport,
<<TBehaviour as NetworkBehavior>::ProtocolsHandler as ProtocolsHandler>::InEvent,
<<TBehaviour as NetworkBehavior>::ProtocolsHandler as ProtocolsHandler>::OutEvent,
<<TBehaviour as NetworkBehaviour>::ProtocolsHandler as ProtocolsHandler>::InEvent,
<<TBehaviour as NetworkBehaviour>::ProtocolsHandler as ProtocolsHandler>::OutEvent,
NodeHandlerWrapper<TBehaviour::ProtocolsHandler>,
>,
@ -55,7 +55,7 @@ where TTransport: Transport,
impl<TTransport, TBehaviour, TTopology> Deref for Swarm<TTransport, TBehaviour, TTopology>
where TTransport: Transport,
TBehaviour: NetworkBehavior,
TBehaviour: NetworkBehaviour,
{
type Target = TBehaviour;
@ -67,7 +67,7 @@ where TTransport: Transport,
impl<TTransport, TBehaviour, TTopology> DerefMut for Swarm<TTransport, TBehaviour, TTopology>
where TTransport: Transport,
TBehaviour: NetworkBehavior,
TBehaviour: NetworkBehaviour,
{
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
@ -76,7 +76,7 @@ where TTransport: Transport,
}
impl<TTransport, TBehaviour, TMuxer, TTopology> Swarm<TTransport, TBehaviour, TTopology>
where TBehaviour: NetworkBehavior,
where TBehaviour: NetworkBehaviour,
TMuxer: StreamMuxer + Send + Sync + 'static,
<TMuxer as StreamMuxer>::OutboundSubstream: Send + 'static,
<TMuxer as StreamMuxer>::Substream: Send + 'static,
@ -169,7 +169,7 @@ where TBehaviour: NetworkBehavior,
}
impl<TTransport, TBehaviour, TMuxer, TTopology> Stream for Swarm<TTransport, TBehaviour, TTopology>
where TBehaviour: NetworkBehavior,
where TBehaviour: NetworkBehaviour,
TMuxer: StreamMuxer + Send + Sync + 'static,
<TMuxer as StreamMuxer>::OutboundSubstream: Send + 'static,
<TMuxer as StreamMuxer>::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<NetworkBehaviorAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>;
fn poll(&mut self) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>;
}
/// Action to perform.
#[derive(Debug, Clone)]
pub enum NetworkBehaviorAction<TInEvent, TOutEvent> {
pub enum NetworkBehaviourAction<TInEvent, TOutEvent> {
/// Generate an event for the outside.
GenerateEvent(TOutEvent),

View File

@ -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,

View File

@ -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};

View File

@ -74,7 +74,7 @@ fn event_handler() {
impl<TSubstream: libp2p::tokio_io::AsyncRead + libp2p::tokio_io::AsyncWrite + Send + Sync + 'static> Foo<TSubstream> {
// 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: <libp2p::identify::PeriodicIdentifyBehaviour<TSubstream> as libp2p::core::nodes::NetworkBehavior>::OutEvent) {
fn foo(&mut self, ev: <libp2p::identify::PeriodicIdentifyBehaviour<TSubstream> as libp2p::core::nodes::NetworkBehaviour>::OutEvent) {
let libp2p::identify::PeriodicIdentifyBehaviourEvent::Identified { .. } = ev;
}
}
@ -91,7 +91,7 @@ fn custom_polling() {
}
impl<TSubstream> Foo<TSubstream> {
fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::nodes::NetworkBehaviorAction<T, ()>> { libp2p::futures::Async::NotReady }
fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::nodes::NetworkBehaviourAction<T, ()>> { libp2p::futures::Async::NotReady }
}
}
@ -117,6 +117,6 @@ fn custom_event_and_polling() {
}
impl<TSubstream> Foo<TSubstream> {
fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::nodes::NetworkBehaviorAction<T, String>> { libp2p::futures::Async::NotReady }
fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::nodes::NetworkBehaviourAction<T, String>> { libp2p::futures::Async::NotReady }
}
}

View File

@ -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<TSubstream> {
/// Events that need to be yielded to the outside when polling.
events: VecDeque<NetworkBehaviorAction<FloodsubRpc, FloodsubMessage>>,
events: VecDeque<NetworkBehaviourAction<FloodsubRpc, FloodsubMessage>>,
/// 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<TSubstream> FloodsubBehaviour<TSubstream> {
}
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<TSubstream> FloodsubBehaviour<TSubstream> {
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<TSubstream> FloodsubBehaviour<TSubstream> {
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<TSubstream> FloodsubBehaviour<TSubstream> {
}
}
impl<TSubstream> NetworkBehavior for FloodsubBehaviour<TSubstream>
impl<TSubstream> NetworkBehaviour for FloodsubBehaviour<TSubstream>
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<
<Self::ProtocolsHandler as ProtocolsHandler>::InEvent,
Self::OutEvent,
>,

View File

@ -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<TSubstream> IdentifyListen<TSubstream> {
}
}
impl<TSubstream> NetworkBehavior for IdentifyListen<TSubstream>
impl<TSubstream> NetworkBehaviour for IdentifyListen<TSubstream>
where
TSubstream: AsyncRead + AsyncWrite + Send + Sync + 'static,
{
@ -103,7 +103,7 @@ where
fn poll(
&mut self,
) -> Async<
NetworkBehaviorAction<
NetworkBehaviourAction<
<Self::ProtocolsHandler as ProtocolsHandler>::InEvent,
Self::OutEvent,
>,

View File

@ -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<TSubstream> PeriodicIdentifyBehaviour<TSubstream> {
}
}
impl<TSubstream> NetworkBehavior for PeriodicIdentifyBehaviour<TSubstream>
impl<TSubstream> NetworkBehaviour for PeriodicIdentifyBehaviour<TSubstream>
where
TSubstream: AsyncRead + AsyncWrite + Send + Sync + 'static,
{
@ -80,13 +80,13 @@ where
fn poll(
&mut self,
) -> Async<
NetworkBehaviorAction<
NetworkBehaviourAction<
<Self::ProtocolsHandler as ProtocolsHandler>::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

View File

@ -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<TSubstream> Default for PeriodicPingBehaviour<TSubstream> {
}
}
impl<TSubstream> NetworkBehavior for PeriodicPingBehaviour<TSubstream>
impl<TSubstream> NetworkBehaviour for PeriodicPingBehaviour<TSubstream>
where
TSubstream: AsyncRead + AsyncWrite,
{
@ -73,7 +73,7 @@ where
fn poll(
&mut self,
) -> Async<
NetworkBehaviorAction<
NetworkBehaviourAction<
<Self::ProtocolsHandler as ProtocolsHandler>::InEvent,
Self::OutEvent,
>,

View File

@ -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<TSubstream> Default for PingListenBehaviour<TSubstream> {
}
}
impl<TSubstream> NetworkBehavior for PingListenBehaviour<TSubstream>
impl<TSubstream> NetworkBehaviour for PingListenBehaviour<TSubstream>
where
TSubstream: AsyncRead + AsyncWrite,
{
@ -73,7 +73,7 @@ where
fn poll(
&mut self,
) -> Async<
NetworkBehaviorAction<
NetworkBehaviourAction<
<Self::ProtocolsHandler as ProtocolsHandler>::InEvent,
Self::OutEvent,
>,