pub struct OverlayBootstrap { /* private fields */ }Expand description
Bootstrap manager for overlay network
Handles overlay network initialization, peer management, and overlay transport interface configuration.
Implementations§
Source§impl OverlayBootstrap
impl OverlayBootstrap
Sourcepub async fn init_leader(cidr: &str, port: u16, data_dir: &Path) -> Result<Self>
pub async fn init_leader(cidr: &str, port: u16, data_dir: &Path) -> Result<Self>
Initialize as cluster leader (first node in the overlay)
This generates a new overlay keypair, allocates the first IP in the CIDR range, and prepares the node as the overlay leader.
§Arguments
cidr- Overlay network CIDR (e.g., “10.200.0.0/16”)port- Overlay listen portdata_dir- Directory for persistent state
§Example
let bootstrap = OverlayBootstrap::init_leader(
"10.200.0.0/16",
51820,
Path::new("/var/lib/zlayer"),
).await?;§Errors
Returns an error if already initialized, key generation fails, or state cannot be saved.
Sourcepub async fn join(
leader_cidr: &str,
leader_endpoint: &str,
leader_public_key: &str,
leader_overlay_ip: IpAddr,
allocated_ip: IpAddr,
port: u16,
data_dir: &Path,
) -> Result<Self>
pub async fn join( leader_cidr: &str, leader_endpoint: &str, leader_public_key: &str, leader_overlay_ip: IpAddr, allocated_ip: IpAddr, port: u16, data_dir: &Path, ) -> Result<Self>
Join an existing overlay network
Generates a new overlay keypair and configures this node to connect to an existing overlay network.
§Arguments
leader_cidr- Leader’s overlay network CIDRleader_endpoint- Leader’s public endpoint (host:port)leader_public_key- Leader’s overlay public keyleader_overlay_ip- Leader’s overlay IP addressallocated_ip- IP address allocated for this node by the leaderport- Overlay listen port for this nodedata_dir- Directory for persistent state
§Errors
Returns an error if already initialized, key generation fails, or state cannot be saved.
Sourcepub async fn load(data_dir: &Path) -> Result<Self>
pub async fn load(data_dir: &Path) -> Result<Self>
Load existing bootstrap state from disk
§Errors
Returns an error if the state file is missing, unreadable, or invalid.
Sourcepub fn with_dns(self, zone: &str, port: u16) -> Result<Self>
pub fn with_dns(self, zone: &str, port: u16) -> Result<Self>
Enable DNS service discovery for the overlay network
When DNS is enabled, peers are automatically registered with both:
- An IP-based hostname:
node-X-Y.zone(e.g.,node-0-5.overlay.local) - A custom hostname if provided in
PeerConfig
The leader node additionally gets a leader.zone alias.
§Arguments
zone- DNS zone (e.g., “overlay.local.”)port- DNS server port (default: 15353 to avoid conflicts)
§Example
let bootstrap = OverlayBootstrap::init_leader(cidr, port, data_dir)
.await?
.with_dns("overlay.local.", 15353)?;
bootstrap.start().await?;§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub fn with_dns_default(self, zone: &str) -> Result<Self>
pub fn with_dns_default(self, zone: &str) -> Result<Self>
Enable DNS with default port (15353)
§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub fn dns_handle(&self) -> Option<&DnsHandle>
pub fn dns_handle(&self) -> Option<&DnsHandle>
Get the DNS handle for managing records
Returns None if DNS is not enabled or start() hasn’t been called yet.
Sourcepub fn dns_enabled(&self) -> bool
pub fn dns_enabled(&self) -> bool
Check if DNS is enabled
Sourcepub async fn start(&mut self) -> Result<()>
pub async fn start(&mut self) -> Result<()>
Start the overlay network (create and configure overlay transport)
This creates the boringtun TUN interface, assigns the overlay IP, configures all known peers, and starts the DNS server if enabled.
§Errors
Returns an error if interface creation, peer configuration, or DNS startup fails.
Sourcepub async fn stop(&mut self) -> Result<()>
pub async fn stop(&mut self) -> Result<()>
Stop the overlay network (shut down the boringtun transport)
§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub async fn add_peer(&mut self, peer: PeerConfig) -> Result<IpAddr>
pub async fn add_peer(&mut self, peer: PeerConfig) -> Result<IpAddr>
Add a new peer to the overlay network
For leader nodes, this also allocates an IP address for the peer.
§Errors
Returns an error if no IPs are available, DNS registration fails, or state cannot be saved.
Sourcepub async fn remove_peer(&mut self, public_key: &str) -> Result<()>
pub async fn remove_peer(&mut self, public_key: &str) -> Result<()>
Remove a peer from the overlay network
§Errors
Returns an error if the peer is not found, DNS removal fails, or state cannot be saved.
Sourcepub fn public_key(&self) -> &str
pub fn public_key(&self) -> &str
Get this node’s public key
Sourcepub fn peers(&self) -> &[PeerConfig]
pub fn peers(&self) -> &[PeerConfig]
Get configured peers
Sourcepub fn config(&self) -> &BootstrapConfig
pub fn config(&self) -> &BootstrapConfig
Get the bootstrap config
Sourcepub fn allocate_peer_ip(&mut self) -> Result<IpAddr>
pub fn allocate_peer_ip(&mut self) -> Result<IpAddr>
Allocate an IP for a new peer (leader only)
This is used by the control plane when processing join requests.
§Errors
Returns an error if this node is not a leader or no IPs are available.
Sourcepub fn allocation_stats(&self) -> Option<(u32, u32)>
pub fn allocation_stats(&self) -> Option<(u32, u32)>
Get IP allocation statistics (leader only)