NetworkConfigBuilder

Struct NetworkConfigBuilder 

Source
pub struct NetworkConfigBuilder { /* private fields */ }
Expand description

Builder for NetworkConfig

§Examples

Building a production configuration:

use chie_shared::NetworkConfigBuilder;

let config = NetworkConfigBuilder::new()
    .max_connections(200)
    .connection_timeout_ms(15_000)
    .request_timeout_ms(60_000)
    .enable_relay(true)
    .enable_dht(true)
    .add_bootstrap_peer("/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN")
    .add_listen_addr("/ip4/0.0.0.0/tcp/4001")
    .build();

assert_eq!(config.max_connections, 200);
assert!(config.validate().is_ok());

Implementations§

Source§

impl NetworkConfigBuilder

Source

pub fn new() -> Self

Create a new builder with default values

Source

pub const fn max_connections(self, max: usize) -> Self

Set maximum concurrent connections

Source

pub const fn connection_timeout_ms(self, timeout: u64) -> Self

Set connection timeout

Source

pub const fn request_timeout_ms(self, timeout: u64) -> Self

Set request timeout

Source

pub const fn enable_relay(self, enable: bool) -> Self

Enable or disable relay mode

Source

pub const fn enable_dht(self, enable: bool) -> Self

Enable or disable DHT

Source

pub fn add_bootstrap_peer(self, addr: impl Into<String>) -> Self

Add a bootstrap peer

Source

pub fn bootstrap_peers(self, peers: Vec<String>) -> Self

Set bootstrap peers

Source

pub fn add_listen_addr(self, addr: impl Into<String>) -> Self

Add a listen address

Source

pub fn listen_addrs(self, addrs: Vec<String>) -> Self

Set listen addresses

Source

pub fn build(self) -> NetworkConfig

Build the configuration

Trait Implementations§

Source§

impl Debug for NetworkConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NetworkConfigBuilder

Source§

fn default() -> NetworkConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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.