Documentation
¶
Overview ¶
Package mesh contains the mesh store and related interfaces.
Index ¶
Constants ¶
const DefaultBootstrapListenAddress = "[::]:9001"
DefaultBootstrapListenAddress is the default listen address for the bootstrap transport.
const DefaultIPv4Network = "172.16.0.0/12"
DefaultIPv4Network is the default IPv4 network for the mesh.
const DefaultMeshAdmin = "admin"
DefaultMeshAdmin is the default mesh admin node ID.
const DefaultMeshDomain = "webmesh.internal"
DefaultMeshDomain is the default domain for the mesh network.
const DefaultNetworkPolicy = "accept"
DefaultNetworkPolicy is the default network policy for the mesh.
Variables ¶
var ( // ErrNotOpen is returned when attempting to close a store that is not open. ErrNotOpen = fmt.Errorf("not open") // ErrOpen is returned when a store is already open. ErrOpen = fmt.Errorf("already open") // ErrNoLeader is returned when there is no Raft leader. ErrNoLeader = fmt.Errorf("no leader") )
Functions ¶
This section is empty.
Types ¶
type BootstrapOptions ¶
type BootstrapOptions struct {
// Transport is the transport to use for bootstrapping the mesh.
Transport transport.BootstrapTransport
// IPv4Network is the IPv4 Network to use for the mesh. Defaults to
// DefaultIPv4Network.
IPv4Network string
// MeshDomain is the domain of the mesh network. Defaults to
// DefaultMeshDomain.
MeshDomain string
// Admin is the ID of the administrator node. Defaults to "admin".
Admin string
// Servers are other node IDs that were bootstrapped with the same
// transport.
Servers []string
// Voters are additional node IDs to assign voter permissions to.
Voters []string
// DisableRBAC disables RBAC for the mesh.
DisableRBAC bool
// DefaultNetworkPolicy is the default network policy for the mesh.
// If empty, DefaultNetworkPolicy will be used.
DefaultNetworkPolicy string
// Force is true if the node should force bootstrap.
Force bool
}
BootstrapOptions are options for bootstrapping the mesh when connecting for the first time.
type Config ¶ added in v0.3.1
type Config struct {
// NodeID is the node ID to use. If empty, the one from the raft
// instance will be used.
NodeID string
// Credentials are gRPC credentials to use when dialing the mesh.
Credentials []grpc.DialOption
// HeartbeatPurgeThreshold is the number of failed heartbeats before
// assuming a peer is offline. This is only applicable when currently
// the leader of the raft group.
HeartbeatPurgeThreshold int
// ZoneAwarenessID is an to use with zone-awareness to determine
// peers in the same LAN segment.
ZoneAwarenessID string
// UseMeshDNS will attempt to set the system DNS to any discovered
// DNS servers. This is only applicable when not serving MeshDNS
// ourselves.
UseMeshDNS bool
// LocalMeshDNSAddr is the address MeshDNS is listening on locally.
LocalMeshDNSAddr string
// WireGuardKeyFile is a location to store and reuse a WireGuard key.
// This is optional. If specified and the file does not exist, one will
// be generated and stored there.
WireGuardKeyFile string
// KeyRotationInterval is the interval to rotate WireGuard keys. This is
// only applicable when a WireguardKeyFile is specified. Otherwise a new
// one will be generated on each startup.
KeyRotationInterval time.Duration
// DisableIPv4 is true if IPv4 should be disabled.
DisableIPv4 bool
// DisableIPv6 is true if IPv6 should be disabled.
DisableIPv6 bool
}
Config contains the configurations for a new mesh connection.
type ConnectOptions ¶ added in v0.3.0
type ConnectOptions struct {
// Raft is the Raft instance. It should not be closed.
Raft raft.Raft
// Features are the features to broadcast to others in the mesh.
Features []v1.Feature
// Plugins is a map of plugins to use.
Plugins map[string]plugins.Plugin
// JoinRoundTripper is the round tripper to use for joining the mesh.
JoinRoundTripper transport.JoinRoundTripper
// NetworkOptions are options for the network manager
NetworkOptions net.Options
// Discovery are options for using peer discovery
Discovery *DiscoveryOptions
// MaxJoinRetries is the maximum number of join retries.
MaxJoinRetries int
// GRPCAdvertisePort is the port to advertise for gRPC connections.
GRPCAdvertisePort int
// MeshDNSAdvertisePort is the port to advertise for MeshDNS connections.
MeshDNSAdvertisePort int
// PrimaryEndpoint is a publicly accessible address to broadcast as the
// primary endpoint for this node. This is used for discovery and
// connection into the mesh. If left unset, the node will be assumed to be
// behind a NAT.
PrimaryEndpoint netip.Addr
// WireGuardEndpoints are endpoints to advertise for WireGuard connections.
WireGuardEndpoints []netip.AddrPort
// RequestVote requests a vote in Raft elections.
RequestVote bool
// RequestObserver requests to be an observer in Raft elections.
RequestObserver bool
// Routes are additional routes to broadcast to the mesh.
Routes []netip.Prefix
// DirectPeers are additional peers to connect to directly.
DirectPeers []string
// Bootstrap are options for bootstrapping the mesh when connecting for
// the first time.
Bootstrap *BootstrapOptions
// PreferIPv6 is true if IPv6 should be preferred over IPv4.
PreferIPv6 bool
}
ConnectOptions are options for opening the connection to the mesh.
type DiscoveryOptions ¶ added in v0.2.6
type DiscoveryOptions struct {
// BootstrapServers are bootstrap servers for the DHT.
BootstrapServers []string
// PSK is the pre-shared key to use as a rendezvous point for peer discovery.
PSK string
// DiscoveryTTL is the time-to-live for the discovery service.
DiscoveryTTL time.Duration
// Announce is a flag to announce this peer to the discovery service.
Announce bool
}
DiscoveryOptions are options for performing peer discovery.
type Mesh ¶
type Mesh interface {
// NodeDialer is the dialer for node connections.
transport.NodeDialer
// LeaderDialer is the dialer for leader connections.
transport.LeaderDialer
// ID returns the node ID.
ID() string
// Domain returns the domain of the mesh network.
Domain() string
// Connect opens the connection to the mesh. This must be called before
// other methods can be used.
Connect(ctx context.Context, opts ConnectOptions) error
// Ready returns a channel that will be closed when the mesh is ready.
// Ready is defined as having a leader and knowing its address.
Ready() <-chan struct{}
// Close closes the connection to the mesh and shuts down the storage.
Close() error
// Credentials returns the gRPC credentials to use for dialing the mesh.
Credentials() []grpc.DialOption
// LeaderID returns the current Raft leader ID.
LeaderID() (string, error)
// Storage returns a storage interface for use by the application.
Storage() storage.MeshStorage
// Raft returns the Raft interface. This will be nil if connect has not
// been called.
Raft() raft.Raft
// Network returns the Network manager.
Network() net.Manager
// Plugins returns the Plugin manager.
Plugins() plugins.Manager
// AnnounceDHT announces the peer discovery service via DHT.
AnnounceDHT(context.Context, DiscoveryOptions) error
// LeaveDHT leaves the peer discovery service for the given PSK.
LeaveDHT(ctx context.Context, psk string) error
}
Mesh is the connection to the Webmesh. It controls raft consensus, plugins, data storage, and WireGuard connections.
func NewTestMesh ¶
NewTestMesh creates a new test mesh and waits for it to be ready. The context is used to enforce startup timeouts.