Skip to main content

NodeConfigBuilder

Struct NodeConfigBuilder 

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

Builder for NodeConfig

Implementations§

Source§

impl NodeConfigBuilder

Source

pub fn bind_addr(self, addr: impl Into<TransportAddr>) -> Self

Set the local address to bind to

Accepts any type implementing Into<TransportAddr>:

  • SocketAddr - Auto-converts to TransportAddr::Udp (backward compatible)
  • TransportAddr - Enables multi-transport support (BLE, LoRa, etc.)

If not specified, defaults to 0.0.0.0:0 (random ephemeral port).

§Examples
use ant_quic::NodeConfig;
use std::net::SocketAddr;

// Backward compatible: SocketAddr
let config = NodeConfig::builder()
    .bind_addr("0.0.0.0:9000".parse::<SocketAddr>().unwrap())
    .build();

// Multi-transport: Explicit TransportAddr
use ant_quic::transport::TransportAddr;
let config = NodeConfig::builder()
    .bind_addr(TransportAddr::Udp("0.0.0.0:0".parse().unwrap()))
    .build();
Source

pub fn known_peer(self, addr: impl Into<TransportAddr>) -> Self

Add a known peer for initial network connectivity

Known peers are used for initial discovery and connection establishment. The node will learn about additional peers through the network.

Accepts any type implementing Into<TransportAddr>:

  • SocketAddr - Auto-converts to TransportAddr::Udp
  • TransportAddr - Supports multiple transport types
§Examples
use ant_quic::NodeConfig;
use std::net::SocketAddr;

// Backward compatible: SocketAddr
let config = NodeConfig::builder()
    .known_peer("peer.example.com:9000".parse::<SocketAddr>().unwrap())
    .build();

// Multi-transport: Mix different transport types
use ant_quic::transport::TransportAddr;
let config = NodeConfig::builder()
    .known_peer(TransportAddr::Udp("192.168.1.1:9000".parse().unwrap()))
    .known_peer(TransportAddr::ble([0x11, 0x22, 0x33, 0x44, 0x55, 0x66], None))
    .build();
Source

pub fn known_peers( self, addrs: impl IntoIterator<Item = impl Into<TransportAddr>>, ) -> Self

Add multiple known peers at once

Convenient method to add a collection of peers. Each item is automatically converted via Into<TransportAddr>, supporting both SocketAddr and TransportAddr for backward compatibility and multi-transport scenarios.

§Examples
use ant_quic::NodeConfig;
use std::net::SocketAddr;

// Backward compatible: Vec<SocketAddr>
let peers: Vec<SocketAddr> = vec![
    "peer1.example.com:9000".parse().unwrap(),
    "peer2.example.com:9000".parse().unwrap(),
];
let config = NodeConfig::builder()
    .known_peers(peers)
    .build();

// Multi-transport: Heterogeneous transport list
use ant_quic::transport::TransportAddr;
let mixed = vec![
    TransportAddr::Udp("192.168.1.1:9000".parse().unwrap()),
    TransportAddr::ble([0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], None),
    TransportAddr::serial("/dev/ttyUSB0"),
];
let config = NodeConfig::builder()
    .known_peers(mixed)
    .build();
Source

pub fn keypair( self, public_key: MlDsaPublicKey, secret_key: MlDsaSecretKey, ) -> Self

Set the identity keypair (ML-DSA-65)

Source

pub fn with_host_identity( self, host: &HostIdentity, network_id: &[u8], storage_dir: &Path, ) -> Result<Self, String>

Set the identity from a HostIdentity with encrypted storage

This loads or generates a keypair using the HostIdentity for encryption. The keypair is stored encrypted at rest in the specified directory.

§Arguments
  • host - The HostIdentity for key derivation
  • network_id - Network identifier for per-network keypair isolation
  • storage_dir - Directory to store the encrypted keypair
§Errors

Returns an error if the keypair cannot be loaded or generated.

Source

pub fn transport_provider(self, provider: Arc<dyn TransportProvider>) -> Self

Add a transport provider

Transport providers are used for multi-transport P2P networking. The UDP transport is always included by default.

§Example
#[cfg(feature = "ble")]
let config = NodeConfig::builder()
    .transport_provider(Arc::new(BleTransport::new().await?))
    .build();
Source

pub fn transport_providers( self, providers: impl IntoIterator<Item = Arc<dyn TransportProvider>>, ) -> Self

Add multiple transport providers

Source

pub fn build(self) -> NodeConfig

Build the configuration

Trait Implementations§

Source§

impl Default for NodeConfigBuilder

Source§

fn default() -> NodeConfigBuilder

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