SwarmBuilder

Struct 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§

Source§

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

Source

pub fn new( 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.

Source

pub fn executor(self, e: Box<dyn Executor + Send>) -> Self

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.

Source

pub fn notify_handler_buffer_size(self, n: NonZeroUsize) -> Self

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.

Source

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

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 ProtocolsHandlers 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 ProtocolsHandlers 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 connection_limits(self, limits: ConnectionLimits) -> Self

Configures the connection limits.

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 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, 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> ErasedDestructor for T
where T: 'static,