hive

package
v0.0.0-...-3b090a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package hive is Bee's native host: it prepares, before the runtime boots, the cluster configuration that joins every Bee node of this machine into the machine's hive once `bee hive init` created it. Everything after boot is Lua.

SPDX-License-Identifier: MIT

Index

Constants

View Source
const (
	RoleVariable = "BEE_ROLE"
	ClientRole   = "client"
)

RoleVariable tells the application what this process is. An in-memory client sets it to ClientRole: it displays another node and serves no node of its own.

View Source
const InviteLifetime = 10 * time.Minute

InviteLifetime is how long an invite stays redeemable.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir is this machine's hive directory.

func Help

func Help(out io.Writer)

Help writes the command overview.

func Init

func Init(dir string) error

Init creates the machine's hive. An existing hive is kept.

func Invite

func Invite(ctx context.Context, dir string, out, notes io.Writer) error

Invite creates the hive when this machine has none, prints an invite for another machine and serves it until it is redeemed, expires or ctx ends. The invite line goes to out; guidance goes to notes.

func Join

func Join(ctx context.Context, dir, token string, out io.Writer) error

Join redeems the invite token for this machine. The hive is created when the machine has none, and its secret is replaced by the hive's, so the machine's nodes join the hive the invite names when they start.

func Prepare

func Prepare(dir, state string, hive *Hive, members *Members) (boot.Config, string, error)

Prepare returns the boot configuration that runs this folder's node under its identity, joined into the hive when there is one, and the node's name.

func PrepareClient

func PrepareClient(dir string, hive Hive, members *Members) (boot.Config, string, error)

PrepareClient returns the boot configuration of an in-memory client node: a fresh identity that is never written to disk, joined into the hive.

func WriteHive

func WriteHive(dir string, hive Hive) error

WriteHive stores the machine's hive configuration.

Types

type Hive

type Hive struct {
	Secret string `json:"secret"`
	// Machine names this machine in invites.
	Machine string `json:"machine,omitempty"`
	// Port is the gossip port the first node of this machine binds, so other
	// machines know where to dial.
	Port int `json:"port,omitempty"`
	// Advertise is the address other machines reach this machine at. It is
	// set once the machine joined another, or another joined it; until then
	// nodes listen on loopback only.
	Advertise string `json:"advertise,omitempty"`
	// Seeds are gossip addresses of nodes on other machines.
	Seeds []string `json:"seeds,omitempty"`
}

Hive is the machine-wide hive configuration created by `bee hive init`.

func Ensure

func Ensure(dir string) (*Hive, error)

Ensure returns the machine's hive, creating it when there is none and completing a record that lacks its machine name or gossip port.

func ReadHive

func ReadHive(dir string) (*Hive, error)

ReadHive returns the machine's hive, or nil when none was initialized.

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host plans Bee launches and publishes the node's address once it runs.

func Component

func Component() *Host

Component returns the Bee native host.

func (*Host) DependsOn

func (h *Host) DependsOn() []string

DependsOn implements boot.Component: the address exists once the cluster runs.

func (*Host) Load

func (h *Host) Load(ctx context.Context) (context.Context, error)

Load implements boot.Component: the cluster created its membership, which resolves the keys of nodes on other machines.

func (*Host) Name

func (h *Host) Name() string

Name implements boot.Component.

func (*Host) Plan

func (h *Host) Plan(_ context.Context, launch app.Launch) (app.Plan, error)

Plan implements app.Host.

func (*Host) Start

func (h *Host) Start(ctx context.Context) error

Start records this node's membership address so other nodes can join it.

func (*Host) Stop

func (h *Host) Stop(context.Context) error

Stop withdraws this node's address, and a client node's key.

type Members

type Members struct {
	// contains filtered or unexported fields
}

Members resolves the identity keys of nodes on other machines from the membership the hive's gossip carries. The hive secret is the trust root across machines: a node of another machine is trusted under the key it advertises, while a node whose key this machine published locally is only trusted under that key.

type Node

type Node struct {
	Name string `json:"name"`
	Seed string `json:"seed"`
}

Node is one folder's node identity, kept in its state directory.

Directories

Path Synopsis
Package invite carries a Hive invite and the handshake that redeems it.
Package invite carries a Hive invite and the handshake that redeems it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL