spec

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAllEndpointsBad = errors.New("spec: all endpoints are bad")

Functions

func PingCommandScorer

func PingCommandScorer(endpoint string) (int, error)

PingCommandScorer gives a score of 0 for all reachable (see ping command below) hosts, and an error for unreachable ones. The command used is: ping -c 1 -w 4 -- <endpoint>

Types

type AccessControl

type AccessControl struct {
	AccessAll  bool
	AccessOnly []string
}

func (AccessControl) Clone

func (a AccessControl) Clone() AccessControl

func (AccessControl) Equal

func (a AccessControl) Equal(b AccessControl) bool

func (AccessControl) Validate

func (a AccessControl) Validate() error

type EndpointScorer

type EndpointScorer func(endpoint string) (int, error)

type Network

type Network struct {
	Name    string
	Devices []NetworkDevice
}

func (Network) CensorForDevice

func (n Network) CensorForDevice(censorFor string) NetworkCensored

func (Network) Clone

func (n Network) Clone() Network

func (Network) GetDevice

func (n Network) GetDevice(name string) (nd NetworkDevice, ok bool)

func (Network) GetDeviceIndex

func (n Network) GetDeviceIndex(name string) (i int, ok bool)

type NetworkCensored

type NetworkCensored struct {
	Name        string
	Devices     []NetworkDeviceCensored
	CensoredFor string
}

func (NetworkCensored) Equal

func (NetworkCensored) GetDevice

func (nc NetworkCensored) GetDevice(name string) (ndc NetworkDeviceCensored, ok bool)

func (NetworkCensored) GetDeviceIndex

func (nc NetworkCensored) GetDeviceIndex(name string) (i int, ok bool)

func (NetworkCensored) GetForwardersFor

func (nc NetworkCensored) GetForwardersFor(name string) []string

GetForwardersFor returns a list of device names that can forward for the given device, and has a chosen forwarder and endpoint.

type NetworkDevice

type NetworkDevice struct {
	NetworkDeviceCensored
	AccessControl
}

func (NetworkDevice) Clone

func (nd NetworkDevice) Clone() NetworkDevice

func (NetworkDevice) Equal

func (a NetworkDevice) Equal(b NetworkDevice) bool

func (*NetworkDevice) UnmarshalJSON

func (nd *NetworkDevice) UnmarshalJSON(data []byte) error

type NetworkDeviceCensored

type NetworkDeviceCensored struct {
	Name string
	// Endpoints is a unordered list of endpoints on which the peer is available on.
	Endpoints []string
	// EndpointChosen is whether the endpoint was chosen.
	// This value should always be false on the server.
	ForwarderAndEndpointChosen bool
	UsesForwarder              bool
	// EndpointChosenIndex is the index of the chosen endpoint.
	// This value should always be zero on the server.
	EndpointChosenIndex int
	// ForwarderChosenIndex is the name of the chosen forwarder.
	// This value should always be zero on the server.
	ForwarderChosenIndex int
	// Addresses is a list of IP networks that this peer represents.
	Addresses []goal.IPNet

	// ListenPort is the port that WireGuard will listen on.
	// Set to 0 to not specify a port.
	// This can be set by this peer.
	ListenPort int
	// This can be set by this peer.
	PublicKey goal.Key
	// This can be set by this peer.
	PresharedKey *goal.Key
	// PersistentKeepalive specifies how often a packet is sent to keep a connection alive.
	// Set to 0 to disable persistent keepalive.
	// This can be set by this peer.
	PersistentKeepalive goal.Duration
	// TODO: forwarding (keep this commented out for now)
	// ForwardsFor is the list of devices (in the same network) that this peer has access to, and can fowrard packets to.
	// Note that IPv6 forwarding is not supported yet.
	// This can be set by this peer.
	ForwardsFor []string
}

func (*NetworkDeviceCensored) ChooseEndpoint

func (ndc *NetworkDeviceCensored) ChooseEndpoint(score EndpointScorer) error

ChooseEndpoint chooses an endpoint and forwarder using the score function provided. If the score returned is tied, the first endpoint (in NetworkDeviceCensored.Endpoints) is chosen. The score function is run in separate goroutines for each endpoint. If all scorers return an error, a forwarder is chosen instead.

func (NetworkDeviceCensored) Clone

func (NetworkDeviceCensored) Equal

func (*NetworkDeviceCensored) UnmarshalJSON

func (ndc *NetworkDeviceCensored) UnmarshalJSON(data []byte) error

type Spec

type Spec struct {
	Networks []Network
}

func (Spec) Clone

func (s Spec) Clone() Spec

func (Spec) GetNetwork

func (s Spec) GetNetwork(name string) (n Network, ok bool)

func (Spec) GetNetworkIndex

func (s Spec) GetNetworkIndex(name string) (i int, ok bool)

type SpecCensored

type SpecCensored struct {
	Networks []NetworkCensored
}

func (SpecCensored) CompileMachine

func (sc SpecCensored) CompileMachine(name string, ignoreIncomplete bool) (goal.Machine, error)

func (SpecCensored) Equal

func (a SpecCensored) Equal(b SpecCensored) bool

func (SpecCensored) GetNetwork

func (s SpecCensored) GetNetwork(name string) (n NetworkCensored, ok bool)

func (SpecCensored) GetNetworkIndex

func (s SpecCensored) GetNetworkIndex(name string) (i int, ok bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳