central

package
v0.0.0-...-a8acacb Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package central contains Central configuration for Nodes and CSes.

Index

Constants

View Source
const (
	DNone    = 0x0
	DNetwork = 0x1
	DIPs     = 0x2
	DKeys    = 0x8
	DPeer    = 0x4
	DSRVs    = 0x10
)

Variables

This section is empty.

Functions

func AllowedByAny

func AllowedByAny(sa SRVAllowable, a2s []SRVAllowance) bool

func IPNetSubsetOf

func IPNetSubsetOf(subset, superset net.IPNet) bool

func IPNetSubsetOfAny

func IPNetSubsetOfAny(subset net.IPNet, supersets []IPNet) bool

func Same

func Same(a []IPNet, b []IPNet) bool

func Same2

func Same2(a map[string]*Peer, b map[string]*Peer) bool

func ToIPNets

func ToIPNets(is2 []IPNet) []net.IPNet

ToIPNets converts IPNet slices.

Types

type CanSee

type CanSee struct {
	Only []string `yaml:"only"`
}

func (*CanSee) Same

func (c *CanSee) Same(c2 *CanSee) bool

type Config

type Config struct {
	Desynced int
	Networks map[string]*Network `yaml:"networks" json:"networks"`
}

Config is the root.

type Duration

type Duration time.Duration

Duration is a encoding-friendly time.Duration.

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements yaml.Marshaler.

func (*Duration) MarshalYAML

func (d *Duration) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

type IPNet

type IPNet net.IPNet

IPNet is a YAML- and JSON- friendly net.IPNet. TODO: move to package util

func FromIPNets

func FromIPNets(ipNets []net.IPNet) []IPNet

ToIPNets converts IPNet slices.

func (IPNet) MarshalJSON

func (i IPNet) MarshalJSON() ([]byte, error)

MarshalJSON implements yaml.Marshaler.

func (IPNet) MarshalYAML

func (i IPNet) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (*IPNet) UnmarshalJSON

func (i *IPNet) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*IPNet) UnmarshalYAML

func (i *IPNet) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

type Network

type Network struct {
	Desynced   int
	Name       string
	IPs        []IPNet          `yaml:"ips" json:"ips"`
	Peers      map[string]*Peer `yaml:"peers" json:"peers"`
	Me         string           `yaml:"me" json:"me"`
	Keepalive  Duration         `yaml:"keepalive" json:"keepalive"`
	ListenPort int              `yaml:"listenPort" json:"listenPort"`

	// lock is only for myPrivKey.
	MyPrivKey *wgtypes.Key `json:"myPrivKey"`
}

Network configures a CN.

func (*Network) AssignAddr

func (cn *Network) AssignAddr() (n net.IPNet, err error)

func (*Network) String

func (cn *Network) String() string

type Peer

type Peer struct {
	Desynced int
	// SyncedPeers is for internal use by the cs package.
	// In the cs package, it's used to track which peers have been synced with changes.
	SyncedPeers      []string
	Name             string   `yaml:"name" json:"name"`
	Host             string   `yaml:"host" json:"host"`
	AlternativeHosts []string `yaml:"hosts" json:"hosts"`
	AllowedIPs       []IPNet  `yaml:"allowedIPs" json:"allowedIPs"`
	CanForward       bool     `yaml:"canForward" json:"canForward"`
	// CanSee determines whether this Peer can see anything (nil) or specfic peers only (non-nil).
	CanSee      *CanSee        `yaml:"canSee" json:"canSee"`
	AllowedSRVs []SRVAllowance `yaml:"allowedSRVs" json:"allowedSRVs"`

	PubKey          wgtypes.Key
	ForwardingPeers []string
	SRVs            []SRV
}

Peer configures a peer.

func (*Peer) Same

func (p *Peer) Same(p2 *Peer) bool

func (*Peer) String

func (p *Peer) String() string

type SRV

type SRV struct {
	Service  string
	Protocol string
	Priority uint16
	Weight   uint16
	Port     uint16
}

func UpdateSRVs

func UpdateSRVs(target, updater []SRV) (target_ []SRV, updated bool)

func (SRV) AllowedBy

func (s SRV) AllowedBy(a2 SRVAllowance) error

type SRVAllowable

type SRVAllowable interface {
	// AllowedBy returns nil this is allowed by the SRVAllowance, and a non-nil error otherwise.
	AllowedBy(SRVAllowance) error
}

type SRVAllowance

type SRVAllowance struct {
	Service     string `yaml:"service"`
	ServiceAny  bool   `yaml:"serviceAny"`
	PriorityMin uint16 `yaml:"priorityMin"`
	PriorityMax uint16 `yaml:"priorityMax"`
	WeightMin   uint16 `yaml:"weightMin"`
	WeightMax   uint16 `yaml:"weightMax"`
}

func (SRVAllowance) AllowedBy

func (a SRVAllowance) AllowedBy(a2 SRVAllowance) error

Jump to

Keyboard shortcuts

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