pub struct NodeConfigBuilder { /* private fields */ }Expand description
Builder for NodeConfig
Implementations§
Source§impl NodeConfigBuilder
impl NodeConfigBuilder
Sourcepub fn bind_addr(self, addr: impl Into<TransportAddr>) -> Self
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 toTransportAddr::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();Sourcepub fn known_peer(self, addr: impl Into<TransportAddr>) -> Self
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 toTransportAddr::UdpTransportAddr- 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();Sourcepub fn known_peers(
self,
addrs: impl IntoIterator<Item = impl Into<TransportAddr>>,
) -> Self
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();Sourcepub fn keypair(
self,
public_key: MlDsaPublicKey,
secret_key: MlDsaSecretKey,
) -> Self
pub fn keypair( self, public_key: MlDsaPublicKey, secret_key: MlDsaSecretKey, ) -> Self
Set the identity keypair (ML-DSA-65)
Sourcepub fn with_host_identity(
self,
host: &HostIdentity,
network_id: &[u8],
storage_dir: &Path,
) -> Result<Self, String>
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 derivationnetwork_id- Network identifier for per-network keypair isolationstorage_dir- Directory to store the encrypted keypair
§Errors
Returns an error if the keypair cannot be loaded or generated.
Sourcepub fn transport_provider(self, provider: Arc<dyn TransportProvider>) -> Self
pub fn transport_provider(self, provider: Arc<dyn TransportProvider>) -> Self
Add a transport provider
Transport providers are used for multi-transport P2P networking. UDP is always included, and constrained transports such as BLE are registered automatically when compiled in and available at runtime.
§Example
#[cfg(feature = "ble")]
let config = NodeConfig::builder()
.transport_provider(Arc::new(BleTransport::new().await?))
.build();Sourcepub fn transport_providers(
self,
providers: impl IntoIterator<Item = Arc<dyn TransportProvider>>,
) -> Self
pub fn transport_providers( self, providers: impl IntoIterator<Item = Arc<dyn TransportProvider>>, ) -> Self
Add multiple transport providers
Sourcepub fn data_channel_capacity(self, capacity: usize) -> Self
pub fn data_channel_capacity(self, capacity: usize) -> Self
Set the data channel capacity (bounded mpsc between reader tasks and recv).
Higher values reduce backpressure on reader tasks. Default: 256.
Sourcepub fn max_concurrent_uni_streams(self, count: u32) -> Self
pub fn max_concurrent_uni_streams(self, count: u32) -> Self
Set the maximum concurrent unidirectional QUIC streams per connection.
Each send() call opens a new unidirectional stream. Applications with
high message throughput should increase this. Default: 100.
Sourcepub fn max_message_size(self, bytes: usize) -> Self
pub fn max_message_size(self, bytes: usize) -> Self
Set the maximum bytes accepted for a single message read from a stream.
This mirrors crate::unified_config::P2pConfigBuilder::max_message_size
for applications using the simpler NodeConfig builder. Values must be
at least 1; crate::Node::with_config rejects zero with a configuration
error before constructing the endpoint.
Sourcepub fn port_mapping_enabled(self, enabled: bool) -> Self
pub fn port_mapping_enabled(self, enabled: bool) -> Self
Reviewer P2 #2: enable or disable the best-effort UPnP IGD
port-mapping task. Default (when not called) follows the global
ant-quic default — currently enabled. Use false on networks
without IGD support, or where operator policy prohibits unsolicited
router port mappings.
Sourcepub fn bootstrap_cache(self, config: BootstrapCacheConfig) -> Self
pub fn bootstrap_cache(self, config: BootstrapCacheConfig) -> Self
Configure the endpoint’s bootstrap peer cache (see
NodeConfig::bootstrap_cache)
Sourcepub fn build(self) -> NodeConfig
pub fn build(self) -> NodeConfig
Build the configuration