Documentation
¶
Overview ¶
Package mesh owns the WireGuard overlay (ADR-0003). The Manager interface is consumed by the daemon wiring and the agent; implementations:
- device manager with wireguard-go / kernel WG (tasks T-18..T-21, T-57/58)
- Disabled (single-node mode, returned by NewDisabled)
- testutil fake (simcluster)
Index ¶
- func DiscoKey(pub wgtypes.Key, caHash []byte) []byte
- func EnsureNodeKey(path string) (string, error)
- func RunPeerSync(ctx context.Context, cfg PeerSyncConfig) error
- type DeviceManager
- func (dm *DeviceManager) ApplyPeers(_ context.Context, peers *clusterv1.PeerSet) error
- func (dm *DeviceManager) Down(_ context.Context) error
- func (dm *DeviceManager) LastHandshakes() (map[string]int64, error)
- func (dm *DeviceManager) PublicKey() (string, error)
- func (dm *DeviceManager) Status() Status
- func (dm *DeviceManager) Up(_ context.Context, cfg NodeConfig) error
- type Disabled
- type DiscoPinger
- type DiscoResponder
- type Manager
- type NodeConfig
- type PeerSyncConfig
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureNodeKey ¶
EnsureNodeKey loads or creates the WG private key at path and returns its public key (base64). A joining node calls this to advertise its public key in the join request before the device is brought up; Up reuses the same path so the advertised key matches the running device.
func RunPeerSync ¶
func RunPeerSync(ctx context.Context, cfg PeerSyncConfig) error
RunPeerSync keeps a WatchPeers stream open and applies every pushed PeerSet to the mesh device, reconnecting with backoff. Blocks until ctx is canceled.
Types ¶
type DeviceManager ¶
type DeviceManager struct {
// contains filtered or unexported fields
}
DeviceManager implements mesh.Manager over a real WireGuard device.
func NewDeviceManager ¶
func NewDeviceManager(log *slog.Logger) *DeviceManager
NewDeviceManager builds a mesh manager backed by a real WG device. The kernel-vs-userspace choice is made at Up time (kernel preferred on Linux).
func (*DeviceManager) ApplyPeers ¶
ApplyPeers reconciles the device's peer set to exactly `peers`.
func (*DeviceManager) Down ¶
func (dm *DeviceManager) Down(_ context.Context) error
Down tears the device down.
func (*DeviceManager) LastHandshakes ¶
func (dm *DeviceManager) LastHandshakes() (map[string]int64, error)
LastHandshakes returns the last-handshake time (unix seconds, 0 = never) per peer, keyed by hex public key. Useful for path diagnostics and integration tests.
func (*DeviceManager) PublicKey ¶
func (dm *DeviceManager) PublicKey() (string, error)
PublicKey returns the node's WG public key, generating the keypair on first use. Valid before Up (the key path is taken from the last Up config or, if Up has not run, this returns an error asking for a path).
func (*DeviceManager) Status ¶
func (dm *DeviceManager) Status() Status
Status reports the current device state.
func (*DeviceManager) Up ¶
func (dm *DeviceManager) Up(_ context.Context, cfg NodeConfig) error
Up creates and configures the WG device (idempotent). It requires root/CAP_NET_ADMIN.
type Disabled ¶
type Disabled struct{}
Disabled is the single-node no-mesh implementation: everything is a no-op and Status reports Enabled=false. The daemon then binds all internal services to 127.0.0.1.
func NewDisabled ¶
func NewDisabled() Disabled
type DiscoPinger ¶
type DiscoPinger struct {
NodeID string
Key []byte
Controls []string // control disco endpoints "ip:port"
Interval time.Duration
Clock clock.Clock
Report func(observedEndpoint string)
Logger *slog.Logger
// contains filtered or unexported fields
}
DiscoPinger is the node-side prober. It pings each control's disco endpoint and reports the reflexive address the control observed.
func (*DiscoPinger) Run ¶
func (p *DiscoPinger) Run(ctx context.Context)
Run probes every Interval until ctx is canceled.
type DiscoResponder ¶
type DiscoResponder struct {
// contains filtered or unexported fields
}
DiscoResponder is the control-side echo server. For each valid ping it returns a pong carrying the observed UDP source address.
func NewDiscoResponder ¶
func NewDiscoResponder(addr string, keyForNode func(string) ([]byte, bool), log *slog.Logger) (*DiscoResponder, error)
NewDiscoResponder binds a UDP listener on addr ("ip:port").
func (*DiscoResponder) Addr ¶
func (r *DiscoResponder) Addr() string
Addr is the bound listen address.
func (*DiscoResponder) Serve ¶
func (r *DiscoResponder) Serve(ctx context.Context)
Serve reads and answers pings until ctx is canceled.
type Manager ¶
type Manager interface {
// Up creates/configures the WG device. Idempotent.
Up(ctx context.Context, cfg NodeConfig) error
// ApplyPeers reconciles the device's peer set to exactly `peers`
// (declarative full set — implementations diff internally).
ApplyPeers(ctx context.Context, peers *clusterv1.PeerSet) error
// Down tears the device down.
Down(ctx context.Context) error
Status() Status
// PublicKey returns the node's WG public key (generating a keypair on
// first use), valid before Up.
PublicKey() (string, error)
}
Manager is the per-node mesh controller.
type NodeConfig ¶
type NodeConfig struct {
// PrivateKeyPath stores the WG private key (0600). Generated when absent.
PrivateKeyPath string
MeshIP netip.Addr
// ListenPort for WireGuard UDP (default 51820).
ListenPort uint16
// InterfaceName defaults to "zt0" (utunN chosen automatically on darwin).
InterfaceName string
}
NodeConfig is what a node needs to bring its mesh interface up.
type PeerSyncConfig ¶
type PeerSyncConfig struct {
NodeID string
Manager Manager
Clock clock.Clock
Logger *slog.Logger
// Dial opens a connection to a control node's MeshService. Called on every
// (re)connect; the returned closer is invoked when the stream ends.
Dial func(ctx context.Context) (grpc.ClientConnInterface, func() error, error)
}
PeerSyncConfig configures the node-side peer synchronizer.