Crate swarm
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.
Modules§
- behaviour
- dial_opts 
- dummy
- handler
- Once a connection to a remote peer is established, a ConnectionHandlernegotiates and handles one or more specific protocols on the connection.
Structs§
- AddressChange 
- FromSwarmvariant that informs the behaviour that the- ConnectedPointof an existing connection has changed.
- Config
- ConnectionClosed 
- FromSwarmvariant that informs the behaviour about a closed connection to a peer.
- ConnectionCounters 
- Network connection information.
- ConnectionDenied 
- A connection was denied.
- ConnectionHandler Select 
- Implementation of ConnectionHandlerthat combines two protocols into one.
- ConnectionId 
- Connection identifier.
- DialFailure 
- FromSwarmvariant that informs the behaviour that the dial to a known or unknown node failed.
- ExpiredListen Addr 
- FromSwarmvariant that informs the behaviour that a multiaddr we were listening on has expired, which means that we are no longer listening on it.
- ExternalAddr Expired 
- FromSwarmvariant that informs the behaviour that an external address was removed.
- ExternalAddresses 
- Utility struct for tracking the external addresses of a Swarm.
- InvalidProtocol 
- ListenAddresses 
- Utility struct for tracking the addresses a Swarmis listening on.
- ListenFailure 
- FromSwarmvariant that informs the behaviour that an error happened on an incoming connection during its initial handshake.
- ListenOpts 
- ListenerClosed 
- FromSwarmvariant that informs the behaviour that a listener closed.
- ListenerError 
- FromSwarmvariant that informs the behaviour that a listener experienced an error.
- NetworkInfo 
- Information about the connections obtained by Swarm::network_info().
- NewExternalAddr Candidate 
- FromSwarmvariant that informs the behaviour about a new candidate for an external address for us.
- NewExternalAddr OfPeer 
- FromSwarmvariant that informs the behaviour that a new external address for a remote peer was detected.
- NewListenAddr 
- FromSwarmvariant that informs the behaviour that we have started listening on a new multiaddr.
- OneShotHandler 
- A ConnectionHandlerthat opens a new substream for each request.
- OneShotHandler Config 
- Configuration parameters for the OneShotHandler
- PeerAddresses 
- Struct for tracking peers’ external addresses of the Swarm.
- Stream
- StreamProtocol 
- Identifies a protocol for a stream.
- SubstreamProtocol 
- Configuration of inbound or outbound substream protocol(s)
for a ConnectionHandler.
- SupportedProtocols 
- Swarm
- Contains the state of the network, plus the way it should behave.
Enums§
- CloseConnection 
- The options which connections to close.
- ConnectionError 
- Errors that can occur in the context of an established Connection.
- ConnectionHandler Event 
- Event produced by a handler.
- DialError 
- Possible errors when trying to establish or upgrade an outbound connection.
- FromSwarm 
- Enumeration with the list of the possible events
to pass to on_swarm_event.
- ListenError 
- Possible errors when upgrading an inbound connection.
- NotifyHandler 
- The options w.r.t. which connection handler to notify of an event.
- StreamUpgrade Error 
- Error that can happen on an outbound substream opening attempt.
- SwarmEvent 
- Event generated by the Swarm.
- ToSwarm
- A command issued from a NetworkBehaviourfor theSwarm.
Traits§
- ConnectionHandler 
- A handler for a set of protocols used on a connection with a remote.
- Executor
- Implemented on objects that can run a Futurein the background.
- NetworkBehaviour 
- A NetworkBehaviourdefines the behaviour of the local node on the network.
Type Aliases§
- THandler
- ConnectionHandlerof the- NetworkBehaviourfor all the protocols the- NetworkBehavioursupports.
- THandlerInEvent 
- Custom event that can be received by the ConnectionHandlerof theNetworkBehaviour.
- THandlerOutEvent 
- Custom event that can be produced by the ConnectionHandlerof theNetworkBehaviour.
Derive Macros§
- NetworkBehaviour 
- Generates a delegating NetworkBehaviourimplementation for the struct this is used for. See the trait documentation for better description.