Documentation
¶
Overview ¶
Package engine owns the WireGuard device and keeps it in sync with the netmap pushed by the coordinator. Path selection (direct or relayed) is delegated to magicsock.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
PrivateKey wgkey.Key
// ListenPort is the UDP port for WireGuard; 0 picks a random port.
ListenPort uint16
TUN tun.Device
// Conn carries WireGuard's packets; it must use the same PrivateKey.
Conn *magicsock.Conn
// Net configures the interface; nil skips OS configuration (tests).
Net NetConfigurator
Log *slog.Logger
}
Config configures an Engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine drives a WireGuard device.
func (*Engine) Close ¶
func (e *Engine) Close()
Close tears down the device (and with it the TUN interface).
func (*Engine) ListenPort ¶
ListenPort returns the UDP port WireGuard is bound to.
type NetConfigurator ¶
type NetConfigurator interface {
// SetAddress assigns the overlay address to the interface; its prefix
// length covers the whole mesh so the OS routes mesh traffic to it.
SetAddress(addr netip.Prefix) error
// SetRoutes makes the OS send traffic for these prefixes (outside the
// mesh prefix) into the interface.
SetRoutes(routes []netip.Prefix) error
}
NetConfigurator applies OS-level interface settings.
type Netmap ¶
type Netmap struct {
Self Node
Prefix netip.Prefix
Peers []Node
// Routes outside Prefix that the OS should send into the mesh: routes
// of peers (in their Addresses) and the MagicDNS address.
Routes []netip.Prefix
}
Netmap is the engine's view of the mesh.
type Node ¶
type Node struct {
ID string
Name string
Key wgkey.Key
// Addresses are the prefixes WireGuard routes to the node: its mesh
// address plus any of its routes this node uses.
Addresses []netip.Prefix
Endpoints []netip.AddrPort
Online bool
// Routes are the subnet routes the node offers, used or not.
Routes []netip.Prefix
}
Node is a mesh member as described by the coordinator.
type PeerStatus ¶
type PeerStatus struct {
ID string `json:"id"`
Name string `json:"name"`
Addresses []string `json:"addresses"`
PublicKey string `json:"publicKey"`
Online bool `json:"online"`
// Path is "direct", "relay" or "" when the peer is unreachable.
Path string `json:"path"`
Endpoint string `json:"endpoint,omitempty"`
LatencyMs float64 `json:"latencyMs,omitempty"`
Endpoints []string `json:"endpoints"`
LastHandshake time.Time `json:"lastHandshake,omitzero"`
RxBytes uint64 `json:"rxBytes"`
TxBytes uint64 `json:"txBytes"`
// Routes the peer offers (0.0.0.0/0 for an exit node).
Routes []string `json:"routes"`
}
PeerStatus describes one peer.
type Status ¶
type Status struct {
Name string `json:"name"`
Addresses []string `json:"addresses"`
PublicKey string `json:"publicKey"`
ListenPort uint16 `json:"listenPort"`
Prefix string `json:"networkPrefix"`
Connected bool `json:"connected"`
Endpoints []string `json:"endpoints"`
Peers []PeerStatus `json:"peers"`
}
Status is a snapshot for display.
Click to show internal directories.
Click to hide internal directories.