SwarmBuilder

Struct SwarmBuilder 

Source
pub struct SwarmBuilder<TBehaviour> { /* private fields */ }
๐Ÿ‘ŽDeprecated: Use the new libp2p::SwarmBuilder instead of libp2p::swarm::SwarmBuilder or create a Swarm directly via Swarm::new.
Expand description

A SwarmBuilder provides an API for configuring and constructing a Swarm.

Implementationsยง

Sourceยง

impl<TBehaviour> SwarmBuilder<TBehaviour>
where TBehaviour: NetworkBehaviour,

Source

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.

Source

pub fn with_tokio_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId, ) -> Self

Builds a new SwarmBuilder from the given transport, behaviour, local peer ID and a tokio executor.

Source

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.

Source

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.

Source

pub fn per_connection_event_buffer_size(self, n: usize) -> Self

Configures the size of the buffer for events sent by a ConnectionHandler to the NetworkBehaviour.

Each connection has its own buffer.

The ideal value depends on the executor used, the CPU speed and the volume of events. If this value is too low, then the ConnectionHandlers 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.

Source

pub fn dial_concurrency_factor(self, factor: NonZeroU8) -> Self

Number of addresses concurrently dialed for a single outbound connection attempt.

Source

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 SubstreamProtocols emitted by the NetworkBehaviour are ignored.

Source

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.

Source

pub fn idle_connection_timeout(self, timeout: Duration) -> Self

How long to keep a connection alive once it is idling.

Defaults to 0.

Source

pub fn build(self) -> Swarm<TBehaviour>

Builds a Swarm with the current configuration.

Auto Trait Implementationsยง

ยง

impl<TBehaviour> Freeze for SwarmBuilder<TBehaviour>
where TBehaviour: Freeze,

ยง

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ยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self> โ“˜

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self> โ“˜

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self> โ“˜

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ“˜
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> โ“˜
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self> โ“˜

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more