Crate libp2p_swarm
source ·Expand description
High-level network manager.
A Swarm contains the state of the network as a whole. The entire
behaviour of a libp2p network can be controlled through the Swarm.
The Swarm struct contains all active and pending connections to
remotes and manages the state of all the substreams that have been
opened, and all the upgrades that were built upon these substreams.
Initializing a Swarm
Creating a Swarm requires three things:
- A network identity of the local node in form of a
PeerId. - An implementation of the
Transporttrait. This is the type that will be used in order to reach nodes on the network based on their address. See thetransportmodule for more information. - An implementation of the
NetworkBehaviourtrait. This is a state machine that defines how the swarm should behave once it is connected to a node.
Network Behaviour
The NetworkBehaviour trait is implemented on types that indicate to
the swarm how it should behave. This includes which protocols are supported
and which nodes to try to connect to. It is the NetworkBehaviour that
controls what happens on the network. Multiple types that implement
NetworkBehaviour can be composed into a single behaviour.
Protocols Handler
The ConnectionHandler trait defines how each active connection to a
remote should behave: how to handle incoming substreams, which protocols
are supported, when to open a new outbound substream, etc.
Re-exports
pub use behaviour::CloseConnection;pub use behaviour::NetworkBehaviour;pub use behaviour::NetworkBehaviourAction;pub use behaviour::NotifyHandler;pub use behaviour::PollParameters;pub use handler::ConnectionHandler;pub use handler::ConnectionHandlerEvent;pub use handler::ConnectionHandlerUpgrErr;pub use handler::IntoConnectionHandler;pub use handler::KeepAlive;pub use handler::SubstreamProtocol;Modules
ConnectionHandler negotiates
and handles one or more specific protocols on the connection.Structs
ConnectionHandler that combines two protocols into one.IntoConnectionHandler that combines two protocols into one.Swarm::network_info().ConnectionHandler that opens a new substream for each request.OneShotHandlerSwarmBuilder provides an API for configuring and constructing a Swarm.poll(), that the NetworkBehaviour has access to.Enums
Connection.Connection.Swarm.Traits
Future in the background.Type Definitions
Connection.Connection.Derive Macros
NetworkBehaviour implementation for the struct this is used for. See
the trait documentation for better description.