Struct libp2p::swarm::SwarmBuilder
source · [−]pub struct SwarmBuilder<TBehaviour> { /* private fields */ }
Expand description
A SwarmBuilder
provides an API for configuring and constructing a Swarm
,
including the underlying Network
.
Implementations
sourceimpl<TBehaviour> SwarmBuilder<TBehaviour> where
TBehaviour: NetworkBehaviour,
impl<TBehaviour> SwarmBuilder<TBehaviour> where
TBehaviour: NetworkBehaviour,
sourcepub fn new(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> SwarmBuilder<TBehaviour>
pub fn new(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> SwarmBuilder<TBehaviour>
Creates a new SwarmBuilder
from the given transport, behaviour and
local peer ID. The Swarm
with its underlying Network
is obtained
via SwarmBuilder::build
.
sourcepub fn executor(
self,
e: Box<dyn Executor + Send + 'static, Global>
) -> SwarmBuilder<TBehaviour>
pub fn executor(
self,
e: Box<dyn Executor + Send + 'static, Global>
) -> SwarmBuilder<TBehaviour>
Configures the Executor
to use for spawning background tasks.
By default, unless another executor has been configured,
SwarmBuilder::build
will try to set up a ThreadPool
.
sourcepub fn notify_handler_buffer_size(
self,
n: NonZeroUsize
) -> SwarmBuilder<TBehaviour>
pub fn notify_handler_buffer_size(
self,
n: NonZeroUsize
) -> SwarmBuilder<TBehaviour>
Configures the number of events from the NetworkBehaviour
in
destination to the ProtocolsHandler
that can be buffered before
the Swarm
has to wait. An individual buffer with this number of
events exists for each individual connection.
The ideal value depends on the executor used, the CPU speed, and the
volume of events. If this value is too low, then the Swarm
will
be sleeping more often than necessary. Increasing this value increases
the overall memory usage.
sourcepub fn connection_event_buffer_size(self, n: usize) -> SwarmBuilder<TBehaviour>
pub fn connection_event_buffer_size(self, n: usize) -> SwarmBuilder<TBehaviour>
Configures the number of extra events from the ProtocolsHandler
in
destination to the NetworkBehaviour
that can be buffered before
the ProtocolsHandler
has to go to sleep.
There exists a buffer of events received from ProtocolsHandler
s
that the NetworkBehaviour
has yet to process. This buffer is
shared between all instances of ProtocolsHandler
. Each instance of
ProtocolsHandler
is guaranteed one slot in this buffer, meaning
that delivering an event for the first time is guaranteed to be
instantaneous. Any extra event delivery, however, must wait for that
first event to be delivered or for an “extra slot” to be available.
This option configures the number of such “extra slots” in this shared buffer. These extra slots are assigned in a first-come, first-served basis.
The ideal value depends on the executor used, the CPU speed, the
average number of connections, and the volume of events. If this value
is too low, then the ProtocolsHandler
s will be sleeping more often
than necessary. Increasing this value increases the overall memory
usage, and more importantly the latency between the moment when an
event is emitted and the moment when it is received by the
NetworkBehaviour
.
sourcepub fn connection_limits(
self,
limits: ConnectionLimits
) -> SwarmBuilder<TBehaviour>
pub fn connection_limits(
self,
limits: ConnectionLimits
) -> SwarmBuilder<TBehaviour>
Configures the connection limits.
sourcepub fn substream_upgrade_protocol_override(
self,
v: Version
) -> SwarmBuilder<TBehaviour>
pub fn substream_upgrade_protocol_override(
self,
v: Version
) -> SwarmBuilder<TBehaviour>
Configures an override for the substream upgrade protocol to use.
The subtream upgrade protocol is the multistream-select protocol used for protocol negotiation on substreams. Since a listener supports all existing versions, the choice of upgrade protocol only effects the “dialer”, i.e. the peer opening a substream.
Note: If configured, specific upgrade protocols for individual
SubstreamProtocol
s emitted by theNetworkBehaviour
are ignored.
sourcepub fn build(
self
) -> ExpandedSwarm<TBehaviour, <<<TBehaviour as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, <<<TBehaviour as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent, <TBehaviour as NetworkBehaviour>::ProtocolsHandler>
pub fn build(
self
) -> ExpandedSwarm<TBehaviour, <<<TBehaviour as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, <<<TBehaviour as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent, <TBehaviour as NetworkBehaviour>::ProtocolsHandler>
Builds a Swarm
with the current configuration.
Auto Trait Implementations
impl<TBehaviour> !RefUnwindSafe for SwarmBuilder<TBehaviour>
impl<TBehaviour> Send for SwarmBuilder<TBehaviour> where
TBehaviour: Send,
impl<TBehaviour> !Sync for SwarmBuilder<TBehaviour>
impl<TBehaviour> Unpin for SwarmBuilder<TBehaviour> where
TBehaviour: Unpin,
impl<TBehaviour> !UnwindSafe for SwarmBuilder<TBehaviour>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more