network

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeerStatusUnknown = "unknown"
	PeerStatusUp      = "up"
	PeerStatusDown    = "down"
)
View Source
const (
	WireGuardInterfaceName = "uncloud"
	WireGuardPort          = 51820
	// WireGuardKeepaliveInterval is sensible interval that works with a wide variety of firewalls.
	WireGuardKeepaliveInterval = 25 * time.Second
)

Variables

This section is empty.

Functions

func GetPublicIP

func GetPublicIP() (netip.Addr, error)

func ListRoutableIPs

func ListRoutableIPs() ([]netip.Addr, error)

ListRoutableIPs returns a list of routable unicast IP addresses.

func MachineIP

func MachineIP(subnet netip.Prefix) netip.Addr

MachineIP returns the IP address of the machine which is the first address in the subnet.

func ManagementIP

func ManagementIP(publicKey secret.Secret) netip.Addr

ManagementIP returns the IPv6 address of a peer derived from the first 14 bytes of its public key. This address always starts with fdcc: and is intended for cluster management traffic.

func NewMachineKeys

func NewMachineKeys() (privKey, pubKey secret.Secret, err error)

NewMachineKeys generates a new WireGuard private and public key pair.

Types

type Config

type Config struct {
	// Subnet is the IPv4 address range allocated to the machine. The machine's IP address is the first address
	// in the subnet. Other IP addresses are allocated to containers running on the machine.
	Subnet netip.Prefix
	// ManagementIP is the IPv6 address assigned to the machine within the WireGuard network. This address is used
	// for cluster management traffic, such as gRPC communication with the machine API server and Corrosion gossip.
	ManagementIP netip.Addr
	PrivateKey   secret.Secret
	PublicKey    secret.Secret
	Peers        []PeerConfig `json:",omitempty"`
}

func (Config) IsConfigured

func (c Config) IsConfigured() bool

IsConfigured returns true if the configuration is complete to establish a WireGuard network.

type EndpointChangeEvent

type EndpointChangeEvent struct {
	PublicKey secret.Secret
	// Endpoint is the new endpoint of the peer.
	Endpoint netip.AddrPort
}

type PeerConfig

type PeerConfig struct {
	Subnet *netip.Prefix `json:",omitempty"`
	// ManagementIP is the IPv6 address assigned to the peer within the WireGuard network. This address is used
	// for cluster management traffic, such as gRPC communication with the machine API server and Corrosion gossip.
	ManagementIP netip.Addr
	Endpoint     *netip.AddrPort  `json:",omitempty"`
	AllEndpoints []netip.AddrPort `json:",omitempty"`
	PublicKey    secret.Secret
}

type WireGuardNetwork

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

func NewWireGuardNetwork

func NewWireGuardNetwork() (*WireGuardNetwork, error)

func (*WireGuardNetwork) Cleanup added in v0.10.0

func (n *WireGuardNetwork) Cleanup() error

Cleanup deletes the WireGuard link. The network must not be running when this method is called.

func (*WireGuardNetwork) Configure

func (n *WireGuardNetwork) Configure(config Config) error

Configure applies the given configuration to the WireGuard network interface. It updates device and peers settings, subnet, and peer routes.

func (*WireGuardNetwork) Run

func (n *WireGuardNetwork) Run(ctx context.Context) error

func (*WireGuardNetwork) WatchEndpoints

func (n *WireGuardNetwork) WatchEndpoints() <-chan EndpointChangeEvent

WatchEndpoints returns a channel that receives endpoint change events for the WireGuard peers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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