Struct libp2p_swarm::SwarmBuilder
source · pub struct SwarmBuilder<TBehaviour> { /* private fields */ }
Expand description
A SwarmBuilder
provides an API for configuring and constructing a Swarm
.
Implementations§
source§impl<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
) -> Self
👎Deprecated since 0.41.0: Use SwarmBuilder::with_executor
or SwarmBuilder::without_executor
instead.
pub fn new(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
SwarmBuilder::with_executor
or SwarmBuilder::without_executor
instead.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 with_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId,
executor: impl Executor + Send + 'static
) -> Self
pub fn with_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId,
executor: impl Executor + Send + 'static
) -> Self
Creates a new SwarmBuilder
from the given transport, behaviour, local peer ID and
executor. The Swarm
with its underlying Network
is obtained via
SwarmBuilder::build
.
sourcepub fn with_tokio_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
Available on crate feature tokio
and neither Emscripten nor WASI nor target_os="unknown"
only.
pub fn with_tokio_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
tokio
and neither Emscripten nor WASI nor target_os="unknown"
only.Builds a new SwarmBuilder
from the given transport, behaviour, local peer ID and a
tokio
executor.
sourcepub fn with_async_std_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
Available on crate feature async-std
and neither Emscripten nor WASI nor target_os="unknown"
only.
pub fn with_async_std_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
async-std
and neither Emscripten nor WASI nor target_os="unknown"
only.Builds a new SwarmBuilder
from the given transport, behaviour, local peer ID and a
async-std
executor.
sourcepub fn without_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
pub fn without_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
Creates a new SwarmBuilder
from the given transport, behaviour and local peer ID. The
Swarm
with its underlying Network
is obtained via SwarmBuilder::build
.
⚠️ Performance warning
All connections will be polled on the current task, thus quite bad performance
characteristics should be expected. Whenever possible use an executor and
SwarmBuilder::with_executor
.
sourcepub fn executor(self, executor: Box<dyn Executor + Send>) -> Self
👎Deprecated since 0.41.0: Use SwarmBuilder::with_executor
instead.
pub fn executor(self, executor: Box<dyn Executor + Send>) -> Self
SwarmBuilder::with_executor
instead.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) -> Self
pub fn notify_handler_buffer_size(self, n: NonZeroUsize) -> Self
Configures the number of events from the NetworkBehaviour
in
destination to the ConnectionHandler
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) -> Self
pub fn connection_event_buffer_size(self, n: usize) -> Self
Configures the number of extra events from the ConnectionHandler
in
destination to the NetworkBehaviour
that can be buffered before
the ConnectionHandler
has to go to sleep.
There exists a buffer of events received from ConnectionHandler
s
that the NetworkBehaviour
has yet to process. This buffer is
shared between all instances of ConnectionHandler
. Each instance of
ConnectionHandler
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 ConnectionHandler
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 dial_concurrency_factor(self, factor: NonZeroU8) -> Self
pub fn dial_concurrency_factor(self, factor: NonZeroU8) -> Self
Number of addresses concurrently dialed for a single outbound connection attempt.
sourcepub fn connection_limits(self, limits: ConnectionLimits) -> Self
pub fn connection_limits(self, limits: ConnectionLimits) -> Self
Configures the connection limits.
sourcepub fn substream_upgrade_protocol_override(self, v: Version) -> Self
pub fn substream_upgrade_protocol_override(self, v: Version) -> Self
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 max_negotiating_inbound_streams(self, v: usize) -> Self
pub fn max_negotiating_inbound_streams(self, v: usize) -> Self
The maximum number of inbound streams concurrently negotiating on a connection. New inbound streams exceeding the limit are dropped and thus reset.
Note: This only enforces a limit on the number of concurrently
negotiating inbound streams. The total number of inbound streams on a
connection is the sum of negotiating and negotiated streams. A limit on
the total number of streams can be enforced at the
StreamMuxerBox
level.