Move the Swarm in its own module (#681)

This commit is contained in:
Pierre Krieger
2018-11-27 11:22:55 +01:00
committed by GitHub
parent 95ebee5841
commit 45114aef46
10 changed files with 16 additions and 15 deletions

View File

@ -210,16 +210,17 @@ pub mod either;
pub mod muxing; pub mod muxing;
pub mod nodes; pub mod nodes;
pub mod protocols_handler; pub mod protocols_handler;
pub mod swarm;
pub mod topology; pub mod topology;
pub mod transport; pub mod transport;
pub mod upgrade; pub mod upgrade;
pub use self::multiaddr::Multiaddr; pub use self::multiaddr::Multiaddr;
pub use self::muxing::StreamMuxer; pub use self::muxing::StreamMuxer;
pub use self::nodes::Swarm;
pub use self::peer_id::PeerId; pub use self::peer_id::PeerId;
pub use self::protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent}; pub use self::protocols_handler::{ProtocolsHandler, ProtocolsHandlerEvent};
pub use self::public_key::PublicKey; pub use self::public_key::PublicKey;
pub use self::swarm::Swarm;
pub use self::transport::Transport; pub use self::transport::Transport;
pub use self::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, UpgradeError}; pub use self::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, UpgradeError};

View File

@ -24,9 +24,7 @@ pub mod handled_node_tasks;
pub mod listeners; pub mod listeners;
pub mod node; pub mod node;
pub mod raw_swarm; pub mod raw_swarm;
pub mod swarm;
pub use self::node::Substream; pub use self::node::Substream;
pub use self::handled_node::{NodeHandlerEvent, NodeHandlerEndpoint}; pub use self::handled_node::{NodeHandlerEvent, NodeHandlerEndpoint};
pub use self::raw_swarm::{ConnectedPoint, Peer, RawSwarm, RawSwarmEvent}; pub use self::raw_swarm::{ConnectedPoint, Peer, RawSwarm, RawSwarmEvent};
pub use self::swarm::{Swarm, NetworkBehaviour, NetworkBehaviourAction};

View File

@ -24,7 +24,7 @@ use crate::{
nodes::{ nodes::{
handled_node::NodeHandler, handled_node::NodeHandler,
node::Substream, node::Substream,
raw_swarm::{RawSwarm, RawSwarmEvent, ConnectedPoint} raw_swarm::{RawSwarm, RawSwarmEvent}
}, },
protocols_handler::{NodeHandlerWrapper, ProtocolsHandler}, protocols_handler::{NodeHandlerWrapper, ProtocolsHandler},
topology::Topology topology::Topology
@ -32,6 +32,8 @@ use crate::{
use futures::prelude::*; use futures::prelude::*;
use std::{fmt, io, ops::{Deref, DerefMut}}; use std::{fmt, io, ops::{Deref, DerefMut}};
pub use crate::nodes::raw_swarm::ConnectedPoint;
/// Contains the state of the network, plus the way it should behave. /// Contains the state of the network, plus the way it should behave.
pub struct Swarm<TTransport, TBehaviour, TTopology> pub struct Swarm<TTransport, TBehaviour, TTopology>
where TTransport: Transport, where TTransport: Transport,

View File

@ -49,13 +49,13 @@ fn build(ast: &DeriveInput) -> TokenStream {
fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
let name = &ast.ident; let name = &ast.ident;
let (_, ty_generics, where_clause) = ast.generics.split_for_impl(); let (_, ty_generics, where_clause) = ast.generics.split_for_impl();
let trait_to_impl = quote!{::libp2p::core::nodes::swarm::NetworkBehaviour}; let trait_to_impl = quote!{::libp2p::core::swarm::NetworkBehaviour};
let either_ident = quote!{::libp2p::core::either::EitherOutput}; let either_ident = quote!{::libp2p::core::either::EitherOutput};
let network_behaviour_action = quote!{::libp2p::core::nodes::swarm::NetworkBehaviourAction}; let network_behaviour_action = quote!{::libp2p::core::swarm::NetworkBehaviourAction};
let protocols_handler = quote!{::libp2p::core::protocols_handler::ProtocolsHandler}; let protocols_handler = quote!{::libp2p::core::protocols_handler::ProtocolsHandler};
let proto_select_ident = quote!{::libp2p::core::protocols_handler::ProtocolsHandlerSelect}; let proto_select_ident = quote!{::libp2p::core::protocols_handler::ProtocolsHandlerSelect};
let peer_id = quote!{::libp2p::core::PeerId}; let peer_id = quote!{::libp2p::core::PeerId};
let connected_point = quote!{::libp2p::core::nodes::ConnectedPoint}; let connected_point = quote!{::libp2p::core::swarm::ConnectedPoint};
// Name of the type parameter that represents the substream. // Name of the type parameter that represents the substream.
let substream_generic = { let substream_generic = {

View File

@ -74,7 +74,7 @@ fn event_handler() {
impl<TSubstream: libp2p::tokio_io::AsyncRead + libp2p::tokio_io::AsyncWrite + Send + Sync + 'static> Foo<TSubstream> { 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 // TODO: for some reason, the parameter cannot be `PeriodicIdentifyBehaviourEvent` or we
// get a compilation error ; figure out why or open an issue to Rust // 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::NetworkBehaviour>::OutEvent) { fn foo(&mut self, ev: <libp2p::identify::PeriodicIdentifyBehaviour<TSubstream> as libp2p::core::swarm::NetworkBehaviour>::OutEvent) {
let libp2p::identify::PeriodicIdentifyBehaviourEvent::Identified { .. } = ev; let libp2p::identify::PeriodicIdentifyBehaviourEvent::Identified { .. } = ev;
} }
} }
@ -91,7 +91,7 @@ fn custom_polling() {
} }
impl<TSubstream> Foo<TSubstream> { impl<TSubstream> Foo<TSubstream> {
fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::nodes::NetworkBehaviourAction<T, ()>> { libp2p::futures::Async::NotReady } fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::swarm::NetworkBehaviourAction<T, ()>> { libp2p::futures::Async::NotReady }
} }
} }
@ -117,6 +117,6 @@ fn custom_event_and_polling() {
} }
impl<TSubstream> Foo<TSubstream> { impl<TSubstream> Foo<TSubstream> {
fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::nodes::NetworkBehaviourAction<T, String>> { libp2p::futures::Async::NotReady } fn foo<T>(&mut self) -> libp2p::futures::Async<libp2p::core::swarm::NetworkBehaviourAction<T, String>> { libp2p::futures::Async::NotReady }
} }
} }

View File

@ -21,7 +21,7 @@
use cuckoofilter::CuckooFilter; use cuckoofilter::CuckooFilter;
use futures::prelude::*; use futures::prelude::*;
use handler::FloodsubHandler; use handler::FloodsubHandler;
use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId}; use libp2p_core::{protocols_handler::ProtocolsHandler, PeerId};
use protocol::{FloodsubMessage, FloodsubRpc, FloodsubSubscription, FloodsubSubscriptionAction}; use protocol::{FloodsubMessage, FloodsubRpc, FloodsubSubscription, FloodsubSubscriptionAction};
use rand; use rand;

View File

@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
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};

View File

@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
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};

View File

@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use futures::prelude::*; use futures::prelude::*;
use libp2p_core::nodes::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
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};