From 9102266d7031c024e2fbce48198478edb0e40728 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 5 Dec 2018 17:04:25 +0100 Subject: [PATCH] Rename all the network behaviours to more basic names (#726) * Rename FloodsubBehaviour to Floodsub * Rename Ping behaviours * Rename identify --- examples/chat.rs | 2 +- misc/core-derive/tests/test.rs | 16 ++++++++-------- protocols/floodsub/src/layer.rs | 12 ++++++------ protocols/floodsub/src/lib.rs | 9 ++++----- protocols/identify/src/lib.rs | 11 ++++------- protocols/identify/src/listen_handler.rs | 2 +- protocols/identify/src/listen_layer.rs | 3 ++- protocols/identify/src/periodic_id_handler.rs | 2 +- protocols/identify/src/periodic_id_layer.rs | 3 ++- protocols/identify/src/protocol.rs | 2 +- protocols/ping/src/dial_layer.rs | 16 ++++++++-------- protocols/ping/src/lib.rs | 10 ++++------ protocols/ping/src/listen_layer.rs | 16 ++++++++-------- 13 files changed, 50 insertions(+), 54 deletions(-) diff --git a/examples/chat.rs b/examples/chat.rs index 14ba0359d5b..5218ea454b8 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -76,7 +76,7 @@ fn main() { // Create a Swarm to manage peers and events let mut swarm = { - let mut behaviour = libp2p::floodsub::FloodsubBehaviour::new(local_pub_key.clone().into_peer_id()); + let mut behaviour = libp2p::floodsub::Floodsub::new(local_pub_key.clone().into_peer_id()); behaviour.subscribe(floodsub_topic.clone()); libp2p::Swarm::new(transport, behaviour, libp2p::core::topology::MemoryTopology::empty(), local_pub_key) }; diff --git a/misc/core-derive/tests/test.rs b/misc/core-derive/tests/test.rs index 671888b9b50..e4a7c41e1b6 100644 --- a/misc/core-derive/tests/test.rs +++ b/misc/core-derive/tests/test.rs @@ -38,7 +38,7 @@ fn one_field() { #[allow(dead_code)] #[derive(NetworkBehaviour)] struct Foo { - ping: libp2p::ping::PeriodicPingBehaviour, + ping: libp2p::ping::PeriodicPing, } fn foo() { @@ -51,8 +51,8 @@ fn two_fields() { #[allow(dead_code)] #[derive(NetworkBehaviour)] struct Foo { - ping_dialer: libp2p::ping::PeriodicPingBehaviour, - ping_listener: libp2p::ping::PingListenBehaviour, + ping_dialer: libp2p::ping::PeriodicPing, + ping_listener: libp2p::ping::PingListen, } } @@ -61,8 +61,8 @@ fn three_fields() { #[allow(dead_code)] #[derive(NetworkBehaviour)] struct Foo { - ping_dialer: libp2p::ping::PeriodicPingBehaviour, - ping_listener: libp2p::ping::PingListenBehaviour, + ping_dialer: libp2p::ping::PeriodicPing, + ping_listener: libp2p::ping::PingListen, identify: libp2p::identify::PeriodicIdentifyBehaviour, #[behaviour(ignore)] foo: String, @@ -101,7 +101,7 @@ fn custom_polling() { #[derive(NetworkBehaviour)] #[behaviour(poll_method = "foo")] struct Foo { - ping: libp2p::ping::PeriodicPingBehaviour, + ping: libp2p::ping::PeriodicPing, identify: libp2p::identify::PeriodicIdentifyBehaviour, } @@ -120,7 +120,7 @@ fn custom_event_no_polling() { #[derive(NetworkBehaviour)] #[behaviour(out_event = "String")] struct Foo { - ping: libp2p::ping::PeriodicPingBehaviour, + ping: libp2p::ping::PeriodicPing, identify: libp2p::identify::PeriodicIdentifyBehaviour, } @@ -135,7 +135,7 @@ fn custom_event_and_polling() { #[derive(NetworkBehaviour)] #[behaviour(poll_method = "foo", out_event = "String")] struct Foo { - ping: libp2p::ping::PeriodicPingBehaviour, + ping: libp2p::ping::PeriodicPing, identify: libp2p::identify::PeriodicIdentifyBehaviour, } diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 9971aa97687..664be25a000 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -33,7 +33,7 @@ use topic::{Topic, TopicHash}; /// Network behaviour that automatically identifies nodes periodically, and returns information /// about them. -pub struct FloodsubBehaviour { +pub struct Floodsub { /// Events that need to be yielded to the outside when polling. events: VecDeque>, @@ -57,10 +57,10 @@ pub struct FloodsubBehaviour { marker: PhantomData, } -impl FloodsubBehaviour { - /// Creates a `FloodsubBehaviour`. +impl Floodsub { + /// Creates a `Floodsub`. pub fn new(local_peer_id: PeerId) -> Self { - FloodsubBehaviour { + Floodsub { events: VecDeque::new(), local_peer_id, connected_peers: HashMap::new(), @@ -71,7 +71,7 @@ impl FloodsubBehaviour { } } -impl FloodsubBehaviour { +impl Floodsub { /// Subscribes to a topic. /// /// Returns true if the subscription worked. Returns false if we were already subscribed. @@ -172,7 +172,7 @@ impl FloodsubBehaviour { } } -impl NetworkBehaviour for FloodsubBehaviour +impl NetworkBehaviour for Floodsub where TSubstream: AsyncRead + AsyncWrite, { diff --git a/protocols/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs index 57eb2d75cb2..67e5bade4e9 100644 --- a/protocols/floodsub/src/lib.rs +++ b/protocols/floodsub/src/lib.rs @@ -31,13 +31,12 @@ extern crate tokio_codec; extern crate tokio_io; extern crate unsigned_varint; -mod handler; +pub mod handler; +pub mod protocol; + mod layer; -mod protocol; mod rpc_proto; mod topic; -pub use self::handler::FloodsubHandler; -pub use self::layer::FloodsubBehaviour; -pub use self::protocol::*; // TODO: exact reexports +pub use self::layer::Floodsub; pub use self::topic::{Topic, TopicBuilder, TopicHash}; diff --git a/protocols/identify/src/lib.rs b/protocols/identify/src/lib.rs index ee50ddc0345..993fbb9709e 100644 --- a/protocols/identify/src/lib.rs +++ b/protocols/identify/src/lib.rs @@ -82,17 +82,14 @@ extern crate unsigned_varint; extern crate void; pub use self::id_transport::IdentifyTransport; -pub use self::listen_handler::IdentifyListenHandler; pub use self::listen_layer::IdentifyListen; -pub use self::periodic_id_handler::{PeriodicIdentification, PeriodicIdentificationEvent}; pub use self::periodic_id_layer::{PeriodicIdentifyBehaviour, PeriodicIdentifyBehaviourEvent}; -pub use self::protocol::{IdentifyInfo, RemoteInfo}; -pub use self::protocol::{IdentifyProtocolConfig, IdentifySender, IdentifySenderFuture}; + +pub mod listen_handler; +pub mod periodic_id_handler; +pub mod protocol; mod id_transport; -mod listen_handler; mod listen_layer; -mod periodic_id_handler; mod periodic_id_layer; -mod protocol; mod structs_proto; diff --git a/protocols/identify/src/listen_handler.rs b/protocols/identify/src/listen_handler.rs index 65f9f6cebb9..3f9684e2075 100644 --- a/protocols/identify/src/listen_handler.rs +++ b/protocols/identify/src/listen_handler.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::{IdentifySender, IdentifyProtocolConfig}; +use crate::protocol::{IdentifySender, IdentifyProtocolConfig}; use futures::prelude::*; use libp2p_core::{ protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent}, diff --git a/protocols/identify/src/listen_layer.rs b/protocols/identify/src/listen_layer.rs index ed8e5fbee8c..27fae73aa6c 100644 --- a/protocols/identify/src/listen_layer.rs +++ b/protocols/identify/src/listen_layer.rs @@ -18,6 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use crate::protocol::{IdentifyInfo, IdentifySenderFuture}; +use crate::listen_handler::IdentifyListenHandler; use futures::prelude::*; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; @@ -25,7 +27,6 @@ use smallvec::SmallVec; use std::collections::HashMap; use tokio_io::{AsyncRead, AsyncWrite}; use void::Void; -use {IdentifyListenHandler, IdentifyInfo, IdentifySenderFuture}; /// Network behaviour that automatically identifies nodes periodically, and returns information /// about them. diff --git a/protocols/identify/src/periodic_id_handler.rs b/protocols/identify/src/periodic_id_handler.rs index 76551fd0e93..5848f287147 100644 --- a/protocols/identify/src/periodic_id_handler.rs +++ b/protocols/identify/src/periodic_id_handler.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::{RemoteInfo, IdentifyProtocolConfig}; +use crate::protocol::{RemoteInfo, IdentifyProtocolConfig}; use futures::prelude::*; use libp2p_core::{ protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent}, diff --git a/protocols/identify/src/periodic_id_layer.rs b/protocols/identify/src/periodic_id_layer.rs index b3bf898f471..9291bb97e37 100644 --- a/protocols/identify/src/periodic_id_layer.rs +++ b/protocols/identify/src/periodic_id_layer.rs @@ -18,12 +18,13 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use crate::periodic_id_handler::{PeriodicIdentification, PeriodicIdentificationEvent}; +use crate::protocol::IdentifyInfo; use futures::prelude::*; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use std::{collections::VecDeque, marker::PhantomData}; use tokio_io::{AsyncRead, AsyncWrite}; -use {IdentifyInfo, PeriodicIdentification, PeriodicIdentificationEvent}; /// Network behaviour that automatically identifies nodes periodically, and returns information /// about them. diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index 9c62c1b864d..cf48c838360 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -256,13 +256,13 @@ mod tests { extern crate libp2p_tcp_transport; extern crate tokio; + use crate::protocol::{IdentifyInfo, RemoteInfo, IdentifyProtocolConfig}; use self::tokio::runtime::current_thread::Runtime; use self::libp2p_tcp_transport::TcpConfig; use futures::{Future, Stream}; use libp2p_core::{PublicKey, Transport, upgrade::{apply_outbound, apply_inbound}}; use std::sync::mpsc; use std::thread; - use {IdentifyInfo, RemoteInfo, IdentifyProtocolConfig}; #[test] fn correct_transfer() { diff --git a/protocols/ping/src/dial_layer.rs b/protocols/ping/src/dial_layer.rs index f922009f59d..c749904e908 100644 --- a/protocols/ping/src/dial_layer.rs +++ b/protocols/ping/src/dial_layer.rs @@ -18,37 +18,37 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use crate::dial_handler::PeriodicPingHandler; use futures::prelude::*; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use std::marker::PhantomData; use tokio_io::{AsyncRead, AsyncWrite}; use void::Void; -use PeriodicPingHandler; /// Network behaviour that handles receiving pings sent by other nodes. -pub struct PeriodicPingBehaviour { +pub struct PeriodicPing { /// Marker to pin the generics. marker: PhantomData, } -impl PeriodicPingBehaviour { - /// Creates a `PeriodicPingBehaviour`. +impl PeriodicPing { + /// Creates a `PeriodicPing`. pub fn new() -> Self { - PeriodicPingBehaviour { + PeriodicPing { marker: PhantomData, } } } -impl Default for PeriodicPingBehaviour { +impl Default for PeriodicPing { #[inline] fn default() -> Self { - PeriodicPingBehaviour::new() + PeriodicPing::new() } } -impl NetworkBehaviour for PeriodicPingBehaviour +impl NetworkBehaviour for PeriodicPing where TSubstream: AsyncRead + AsyncWrite, { diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index a8684c10305..4241071449a 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -94,14 +94,12 @@ extern crate tokio_io; extern crate tokio_timer; extern crate void; -pub use self::dial_handler::PeriodicPingHandler; -pub use self::dial_layer::PeriodicPingBehaviour; -pub use self::listen_handler::PingListenHandler; -pub use self::listen_layer::PingListenBehaviour; +pub use self::dial_layer::PeriodicPing; +pub use self::listen_layer::PingListen; +pub mod dial_handler; +pub mod listen_handler; pub mod protocol; -mod dial_handler; mod dial_layer; -mod listen_handler; mod listen_layer; diff --git a/protocols/ping/src/listen_layer.rs b/protocols/ping/src/listen_layer.rs index 32546cb7ad6..eafa4064001 100644 --- a/protocols/ping/src/listen_layer.rs +++ b/protocols/ping/src/listen_layer.rs @@ -18,37 +18,37 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use crate::listen_handler::PingListenHandler; use futures::prelude::*; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use std::marker::PhantomData; use tokio_io::{AsyncRead, AsyncWrite}; use void::Void; -use PingListenHandler; /// Network behaviour that handles receiving pings sent by other nodes. -pub struct PingListenBehaviour { +pub struct PingListen { /// Marker to pin the generics. marker: PhantomData, } -impl PingListenBehaviour { - /// Creates a `PingListenBehaviour`. +impl PingListen { + /// Creates a `PingListen`. pub fn new() -> Self { - PingListenBehaviour { + PingListen { marker: PhantomData, } } } -impl Default for PingListenBehaviour { +impl Default for PingListen { #[inline] fn default() -> Self { - PingListenBehaviour::new() + PingListen::new() } } -impl NetworkBehaviour for PingListenBehaviour +impl NetworkBehaviour for PingListen where TSubstream: AsyncRead + AsyncWrite, {