Rename all the network behaviours to more basic names (#726)

* Rename FloodsubBehaviour to Floodsub

* Rename Ping behaviours

* Rename identify
This commit is contained in:
Pierre Krieger
2018-12-05 17:04:25 +01:00
committed by GitHub
parent 4140047f34
commit 9102266d70
13 changed files with 50 additions and 54 deletions

View File

@ -76,7 +76,7 @@ fn main() {
// Create a Swarm to manage peers and events // Create a Swarm to manage peers and events
let mut swarm = { 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()); behaviour.subscribe(floodsub_topic.clone());
libp2p::Swarm::new(transport, behaviour, libp2p::core::topology::MemoryTopology::empty(), local_pub_key) libp2p::Swarm::new(transport, behaviour, libp2p::core::topology::MemoryTopology::empty(), local_pub_key)
}; };

View File

@ -38,7 +38,7 @@ fn one_field() {
#[allow(dead_code)] #[allow(dead_code)]
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
struct Foo<TSubstream> { struct Foo<TSubstream> {
ping: libp2p::ping::PeriodicPingBehaviour<TSubstream>, ping: libp2p::ping::PeriodicPing<TSubstream>,
} }
fn foo<TSubstream: libp2p::tokio_io::AsyncRead + libp2p::tokio_io::AsyncWrite>() { fn foo<TSubstream: libp2p::tokio_io::AsyncRead + libp2p::tokio_io::AsyncWrite>() {
@ -51,8 +51,8 @@ fn two_fields() {
#[allow(dead_code)] #[allow(dead_code)]
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
struct Foo<TSubstream> { struct Foo<TSubstream> {
ping_dialer: libp2p::ping::PeriodicPingBehaviour<TSubstream>, ping_dialer: libp2p::ping::PeriodicPing<TSubstream>,
ping_listener: libp2p::ping::PingListenBehaviour<TSubstream>, ping_listener: libp2p::ping::PingListen<TSubstream>,
} }
} }
@ -61,8 +61,8 @@ fn three_fields() {
#[allow(dead_code)] #[allow(dead_code)]
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
struct Foo<TSubstream> { struct Foo<TSubstream> {
ping_dialer: libp2p::ping::PeriodicPingBehaviour<TSubstream>, ping_dialer: libp2p::ping::PeriodicPing<TSubstream>,
ping_listener: libp2p::ping::PingListenBehaviour<TSubstream>, ping_listener: libp2p::ping::PingListen<TSubstream>,
identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>, identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>,
#[behaviour(ignore)] #[behaviour(ignore)]
foo: String, foo: String,
@ -101,7 +101,7 @@ fn custom_polling() {
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(poll_method = "foo")] #[behaviour(poll_method = "foo")]
struct Foo<TSubstream> { struct Foo<TSubstream> {
ping: libp2p::ping::PeriodicPingBehaviour<TSubstream>, ping: libp2p::ping::PeriodicPing<TSubstream>,
identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>, identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>,
} }
@ -120,7 +120,7 @@ fn custom_event_no_polling() {
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(out_event = "String")] #[behaviour(out_event = "String")]
struct Foo<TSubstream> { struct Foo<TSubstream> {
ping: libp2p::ping::PeriodicPingBehaviour<TSubstream>, ping: libp2p::ping::PeriodicPing<TSubstream>,
identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>, identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>,
} }
@ -135,7 +135,7 @@ fn custom_event_and_polling() {
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(poll_method = "foo", out_event = "String")] #[behaviour(poll_method = "foo", out_event = "String")]
struct Foo<TSubstream> { struct Foo<TSubstream> {
ping: libp2p::ping::PeriodicPingBehaviour<TSubstream>, ping: libp2p::ping::PeriodicPing<TSubstream>,
identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>, identify: libp2p::identify::PeriodicIdentifyBehaviour<TSubstream>,
} }

View File

@ -33,7 +33,7 @@ use topic::{Topic, TopicHash};
/// Network behaviour that automatically identifies nodes periodically, and returns information /// Network behaviour that automatically identifies nodes periodically, and returns information
/// about them. /// about them.
pub struct FloodsubBehaviour<TSubstream> { pub struct Floodsub<TSubstream> {
/// Events that need to be yielded to the outside when polling. /// Events that need to be yielded to the outside when polling.
events: VecDeque<NetworkBehaviourAction<FloodsubRpc, FloodsubMessage>>, events: VecDeque<NetworkBehaviourAction<FloodsubRpc, FloodsubMessage>>,
@ -57,10 +57,10 @@ pub struct FloodsubBehaviour<TSubstream> {
marker: PhantomData<TSubstream>, marker: PhantomData<TSubstream>,
} }
impl<TSubstream> FloodsubBehaviour<TSubstream> { impl<TSubstream> Floodsub<TSubstream> {
/// Creates a `FloodsubBehaviour`. /// Creates a `Floodsub`.
pub fn new(local_peer_id: PeerId) -> Self { pub fn new(local_peer_id: PeerId) -> Self {
FloodsubBehaviour { Floodsub {
events: VecDeque::new(), events: VecDeque::new(),
local_peer_id, local_peer_id,
connected_peers: HashMap::new(), connected_peers: HashMap::new(),
@ -71,7 +71,7 @@ impl<TSubstream> FloodsubBehaviour<TSubstream> {
} }
} }
impl<TSubstream> FloodsubBehaviour<TSubstream> { impl<TSubstream> Floodsub<TSubstream> {
/// Subscribes to a topic. /// Subscribes to a topic.
/// ///
/// Returns true if the subscription worked. Returns false if we were already subscribed. /// Returns true if the subscription worked. Returns false if we were already subscribed.
@ -172,7 +172,7 @@ impl<TSubstream> FloodsubBehaviour<TSubstream> {
} }
} }
impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for FloodsubBehaviour<TSubstream> impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for Floodsub<TSubstream>
where where
TSubstream: AsyncRead + AsyncWrite, TSubstream: AsyncRead + AsyncWrite,
{ {

View File

@ -31,13 +31,12 @@ extern crate tokio_codec;
extern crate tokio_io; extern crate tokio_io;
extern crate unsigned_varint; extern crate unsigned_varint;
mod handler; pub mod handler;
pub mod protocol;
mod layer; mod layer;
mod protocol;
mod rpc_proto; mod rpc_proto;
mod topic; mod topic;
pub use self::handler::FloodsubHandler; pub use self::layer::Floodsub;
pub use self::layer::FloodsubBehaviour;
pub use self::protocol::*; // TODO: exact reexports
pub use self::topic::{Topic, TopicBuilder, TopicHash}; pub use self::topic::{Topic, TopicBuilder, TopicHash};

View File

@ -82,17 +82,14 @@ extern crate unsigned_varint;
extern crate void; extern crate void;
pub use self::id_transport::IdentifyTransport; pub use self::id_transport::IdentifyTransport;
pub use self::listen_handler::IdentifyListenHandler;
pub use self::listen_layer::IdentifyListen; 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::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 id_transport;
mod listen_handler;
mod listen_layer; mod listen_layer;
mod periodic_id_handler;
mod periodic_id_layer; mod periodic_id_layer;
mod protocol;
mod structs_proto; mod structs_proto;

View File

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use crate::{IdentifySender, IdentifyProtocolConfig}; use crate::protocol::{IdentifySender, IdentifyProtocolConfig};
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::{ use libp2p_core::{
protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent}, protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent},

View File

@ -18,6 +18,8 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use crate::protocol::{IdentifyInfo, IdentifySenderFuture};
use crate::listen_handler::IdentifyListenHandler;
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId};
@ -25,7 +27,6 @@ use smallvec::SmallVec;
use std::collections::HashMap; use std::collections::HashMap;
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use void::Void; use void::Void;
use {IdentifyListenHandler, IdentifyInfo, IdentifySenderFuture};
/// Network behaviour that automatically identifies nodes periodically, and returns information /// Network behaviour that automatically identifies nodes periodically, and returns information
/// about them. /// about them.

View File

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use crate::{RemoteInfo, IdentifyProtocolConfig}; use crate::protocol::{RemoteInfo, IdentifyProtocolConfig};
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::{ use libp2p_core::{
protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent}, protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent},

View File

@ -18,12 +18,13 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use crate::periodic_id_handler::{PeriodicIdentification, PeriodicIdentificationEvent};
use crate::protocol::IdentifyInfo;
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId};
use std::{collections::VecDeque, marker::PhantomData}; use std::{collections::VecDeque, marker::PhantomData};
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use {IdentifyInfo, PeriodicIdentification, PeriodicIdentificationEvent};
/// Network behaviour that automatically identifies nodes periodically, and returns information /// Network behaviour that automatically identifies nodes periodically, and returns information
/// about them. /// about them.

View File

@ -256,13 +256,13 @@ mod tests {
extern crate libp2p_tcp_transport; extern crate libp2p_tcp_transport;
extern crate tokio; extern crate tokio;
use crate::protocol::{IdentifyInfo, RemoteInfo, IdentifyProtocolConfig};
use self::tokio::runtime::current_thread::Runtime; use self::tokio::runtime::current_thread::Runtime;
use self::libp2p_tcp_transport::TcpConfig; use self::libp2p_tcp_transport::TcpConfig;
use futures::{Future, Stream}; use futures::{Future, Stream};
use libp2p_core::{PublicKey, Transport, upgrade::{apply_outbound, apply_inbound}}; use libp2p_core::{PublicKey, Transport, upgrade::{apply_outbound, apply_inbound}};
use std::sync::mpsc; use std::sync::mpsc;
use std::thread; use std::thread;
use {IdentifyInfo, RemoteInfo, IdentifyProtocolConfig};
#[test] #[test]
fn correct_transfer() { fn correct_transfer() {

View File

@ -18,37 +18,37 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use crate::dial_handler::PeriodicPingHandler;
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId};
use std::marker::PhantomData; use std::marker::PhantomData;
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use void::Void; use void::Void;
use PeriodicPingHandler;
/// Network behaviour that handles receiving pings sent by other nodes. /// Network behaviour that handles receiving pings sent by other nodes.
pub struct PeriodicPingBehaviour<TSubstream> { pub struct PeriodicPing<TSubstream> {
/// Marker to pin the generics. /// Marker to pin the generics.
marker: PhantomData<TSubstream>, marker: PhantomData<TSubstream>,
} }
impl<TSubstream> PeriodicPingBehaviour<TSubstream> { impl<TSubstream> PeriodicPing<TSubstream> {
/// Creates a `PeriodicPingBehaviour`. /// Creates a `PeriodicPing`.
pub fn new() -> Self { pub fn new() -> Self {
PeriodicPingBehaviour { PeriodicPing {
marker: PhantomData, marker: PhantomData,
} }
} }
} }
impl<TSubstream> Default for PeriodicPingBehaviour<TSubstream> { impl<TSubstream> Default for PeriodicPing<TSubstream> {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
PeriodicPingBehaviour::new() PeriodicPing::new()
} }
} }
impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for PeriodicPingBehaviour<TSubstream> impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for PeriodicPing<TSubstream>
where where
TSubstream: AsyncRead + AsyncWrite, TSubstream: AsyncRead + AsyncWrite,
{ {

View File

@ -94,14 +94,12 @@ extern crate tokio_io;
extern crate tokio_timer; extern crate tokio_timer;
extern crate void; extern crate void;
pub use self::dial_handler::PeriodicPingHandler; pub use self::dial_layer::PeriodicPing;
pub use self::dial_layer::PeriodicPingBehaviour; pub use self::listen_layer::PingListen;
pub use self::listen_handler::PingListenHandler;
pub use self::listen_layer::PingListenBehaviour;
pub mod dial_handler;
pub mod listen_handler;
pub mod protocol; pub mod protocol;
mod dial_handler;
mod dial_layer; mod dial_layer;
mod listen_handler;
mod listen_layer; mod listen_layer;

View File

@ -18,37 +18,37 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use crate::listen_handler::PingListenHandler;
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId};
use std::marker::PhantomData; use std::marker::PhantomData;
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use void::Void; use void::Void;
use PingListenHandler;
/// Network behaviour that handles receiving pings sent by other nodes. /// Network behaviour that handles receiving pings sent by other nodes.
pub struct PingListenBehaviour<TSubstream> { pub struct PingListen<TSubstream> {
/// Marker to pin the generics. /// Marker to pin the generics.
marker: PhantomData<TSubstream>, marker: PhantomData<TSubstream>,
} }
impl<TSubstream> PingListenBehaviour<TSubstream> { impl<TSubstream> PingListen<TSubstream> {
/// Creates a `PingListenBehaviour`. /// Creates a `PingListen`.
pub fn new() -> Self { pub fn new() -> Self {
PingListenBehaviour { PingListen {
marker: PhantomData, marker: PhantomData,
} }
} }
} }
impl<TSubstream> Default for PingListenBehaviour<TSubstream> { impl<TSubstream> Default for PingListen<TSubstream> {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
PingListenBehaviour::new() PingListen::new()
} }
} }
impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for PingListenBehaviour<TSubstream> impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for PingListen<TSubstream>
where where
TSubstream: AsyncRead + AsyncWrite, TSubstream: AsyncRead + AsyncWrite,
{ {