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
impl NetworkConfigBuilder
Sourcepub const fn max_connections(self, max: usize) -> Self
pub const fn max_connections(self, max: usize) -> Self
Set maximum concurrent connections
Sourcepub const fn connection_timeout_ms(self, timeout: u64) -> Self
pub const fn connection_timeout_ms(self, timeout: u64) -> Self
Set connection timeout
Sourcepub const fn request_timeout_ms(self, timeout: u64) -> Self
pub const fn request_timeout_ms(self, timeout: u64) -> Self
Set request timeout
Sourcepub const fn enable_relay(self, enable: bool) -> Self
pub const fn enable_relay(self, enable: bool) -> Self
Enable or disable relay mode
Sourcepub const fn enable_dht(self, enable: bool) -> Self
pub const fn enable_dht(self, enable: bool) -> Self
Enable or disable DHT
Sourcepub fn add_bootstrap_peer(self, addr: impl Into<String>) -> Self
pub fn add_bootstrap_peer(self, addr: impl Into<String>) -> Self
Add a bootstrap peer
Sourcepub fn bootstrap_peers(self, peers: Vec<String>) -> Self
pub fn bootstrap_peers(self, peers: Vec<String>) -> Self
Set bootstrap peers
Sourcepub fn add_listen_addr(self, addr: impl Into<String>) -> Self
pub fn add_listen_addr(self, addr: impl Into<String>) -> Self
Add a listen address
Sourcepub fn listen_addrs(self, addrs: Vec<String>) -> Self
pub fn listen_addrs(self, addrs: Vec<String>) -> Self
Set listen addresses
Sourcepub fn build(self) -> NetworkConfig
pub fn build(self) -> NetworkConfig
Build the configuration
Trait Implementations§
Source§impl Debug for NetworkConfigBuilder
impl Debug for NetworkConfigBuilder
Source§impl Default for NetworkConfigBuilder
impl Default for NetworkConfigBuilder
Source§fn default() -> NetworkConfigBuilder
fn default() -> NetworkConfigBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for NetworkConfigBuilder
impl RefUnwindSafe for NetworkConfigBuilder
impl Send for NetworkConfigBuilder
impl Sync for NetworkConfigBuilder
impl Unpin for NetworkConfigBuilder
impl UnwindSafe for NetworkConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more