Skip to main content

OverlayBootstrap

Struct OverlayBootstrap 

Source
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

Source

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 port
  • data_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.

Source

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 CIDR
  • leader_endpoint - Leader’s public endpoint (host:port)
  • leader_public_key - Leader’s overlay public key
  • leader_overlay_ip - Leader’s overlay IP address
  • allocated_ip - IP address allocated for this node by the leader
  • port - Overlay listen port for this node
  • data_dir - Directory for persistent state
§Errors

Returns an error if already initialized, key generation fails, or state cannot be saved.

Source

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.

Source

pub async fn save(&self) -> Result<()>

Save bootstrap state to disk

§Errors

Returns an error if serialization or file writing fails.

Source

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.

Source

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.

Source

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.

Source

pub fn dns_enabled(&self) -> bool

Check if DNS is enabled

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn public_key(&self) -> &str

Get this node’s public key

Source

pub fn node_ip(&self) -> IpAddr

Get this node’s overlay IP (IPv4 or IPv6)

Source

pub fn cidr(&self) -> &str

Get the overlay CIDR

Source

pub fn interface(&self) -> &str

Get the overlay interface name

Source

pub fn port(&self) -> u16

Get the overlay listen port

Source

pub fn is_leader(&self) -> bool

Check if this node is the leader

Source

pub fn peers(&self) -> &[PeerConfig]

Get configured peers

Source

pub fn config(&self) -> &BootstrapConfig

Get the bootstrap config

Source

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.

Source

pub fn allocation_stats(&self) -> Option<(u32, u32)>

Get IP allocation statistics (leader only)

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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