pub struct Config {Show 23 fields
pub version: Version,
pub enable_monitor: bool,
pub access_control: Arc<dyn AccessControl>,
pub handshake_timeout: u64,
pub ping_interval: u64,
pub ping_timeout: u64,
pub max_connect_retries: usize,
pub bootstrap_peers: Vec<Endpoint>,
pub listen_endpoints: Vec<Endpoint>,
pub discovery_endpoints: Vec<Endpoint>,
pub dial_peers: Vec<Endpoint>,
pub public_ip: Option<IpAddr>,
pub inbound_slots: usize,
pub outbound_slots: usize,
pub seeding_interval: u64,
pub lookup_inbound_slots: usize,
pub lookup_outbound_slots: usize,
pub lookup_response_timeout: u64,
pub lookup_connection_lifespan: u64,
pub lookup_connect_retries: usize,
pub refresh_interval: u64,
pub refresh_response_timeout: u64,
pub refresh_connect_retries: usize,
}Expand description
Configuration for the p2p network.
dial_peers are static peers dialed directly (use for fixed
topologies). bootstrap_peers are seeds for the default Kademlia
discovery; the DHT grows the connection set from there. Custom
Discovery implementations may interpret bootstrap_peers
differently or ignore it. Pick one, or combine.
§Example
use karyon_p2p::Config;
let config = Config {
listen_endpoints: vec![
"tcp://0.0.0.0:8000".parse().unwrap(),
],
discovery_endpoints: vec![
"tcp://0.0.0.0:7000".parse().unwrap(),
"udp://0.0.0.0:7000".parse().unwrap(),
],
bootstrap_peers: vec![
"tcp://seed.example.com:7000".parse().unwrap(),
],
..Config::default()
};Fields§
§version: VersionRepresents the network version.
enable_monitor: boolEnable monitor
access_control: Arc<dyn AccessControl>Policy deciding who this node talks to. Defaults to AllowAll.
handshake_timeout: u64Timeout duration for the handshake with new peers, in seconds. Applied twice on an inbound connection: once for the transport handshake (TLS, or the first QUIC stream), then once for the protocol handshake.
ping_interval: u64Interval at which the ping protocol sends ping messages to a peer to maintain connections, in seconds.
ping_timeout: u64Timeout duration for receiving the pong message corresponding to the sent ping message, in seconds.
max_connect_retries: usizeThe maximum number of retries for outbound connection establishment.
bootstrap_peers: Vec<Endpoint>A list of bootstrap peers for the seeding process.
listen_endpoints: Vec<Endpoint>Endpoints to listen on for incoming peer connections. e.g. [tcp://0.0.0.0:8000, quic://0.0.0.0:9000]
discovery_endpoints: Vec<Endpoint>Endpoints used by the discovery service (Kademlia by default).
Kademlia needs two sockets that serve different roles:
- one stream endpoint for the lookup service
(
tcp://,tls://, orquic://when thequicfeature is on). Handles short-lived FIND_NODE / Ping queries from other peers. - one
udp://endpoint for the refresh service. Handles UDP liveness pings against routing-table entries.
Either provide both (one of each kind) or leave the vector empty
to disable Kademlia-style DHT discovery and rely on
dial_peers + bootstrap_peers for static peering.
e.g. [tcp://0.0.0.0:7000, udp://0.0.0.0:7000]
dial_peers: Vec<Endpoint>A list of endpoints representing peers that the Discovery will
manually connect to.
public_ip: Option<IpAddr>This node’s public IP, if known (e.g. learned with karyon_stun).
When set, discovery advertises it in place of the IP of every listen
and discovery endpoint of the same family. Ports are kept as
configured, so they must be reachable from outside (port
forwarding). None (the default) advertises endpoints as
configured.
inbound_slots: usizeThe number of available inbound slots for incoming connections.
outbound_slots: usizeThe number of available outbound slots for outgoing connections.
seeding_interval: u64Time interval, in seconds, at which the Discovery restarts the seeding process.
lookup_inbound_slots: usizeThe number of available inbound slots for incoming connections during the lookup process.
lookup_outbound_slots: usizeThe number of available outbound slots for outgoing connections during the lookup process.
lookup_response_timeout: u64Timeout duration for a peer response during the lookup process, in seconds.
lookup_connection_lifespan: u64Maximum allowable time for a live connection with a peer during the lookup process, in seconds.
lookup_connect_retries: usizeThe maximum number of retries for outbound connection establishment during the lookup process.
refresh_interval: u64Interval at which the table refreshes its entries, in seconds.
refresh_response_timeout: u64Timeout duration for a peer response during the table refresh process, in seconds.
refresh_connect_retries: usizeThe maximum number of retries for outbound connection establishment during the refresh process.