peer

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package peer handles the matching of data in this project.

Index

Constants

View Source
const (

	// HandshakeTimeout specifies the duration after a wireguard handshake is assumed out of date.
	HandshakeTimeout = 140 * time.Second
)

Variables

This section is empty.

Functions

func Merge added in v0.0.5

func Merge(peers []Peer, wgs []wgtypes.Peer, neighs map[string][]netip.AddrPort) error

Merge takes a list of wgpeers and a list of wgtypes peers, queries neighbour endpoint addresses from the kernel and combines the results into the instances. An error is returned if netlink access failed or information is inconsistent.

Types

type DNSResolver

type DNSResolver interface {
	LookupIP(context.Context, string, string) ([]net.IP, error)
}

DNSResolver is responsible for resolving a DNS record.

type Peer

type Peer struct {
	// Public is the base64 encoded WG public key.
	Public string `yaml:"public"`
	// DNSName is the name of the DNS AAAA RR that contains the global endpint of the peer.
	// Is refereshed continuously.
	DNSName string `yaml:"dnsName"`
	// MACs is the list of MAC addresses of the peer. This is used to determine if a link address
	// belongs to it. Multiple MACs may be specified in case the node connects with multiple network
	// cards (may it be with all at the same time or a single one out of the list).
	// If multiple peer addresses are found the one belonging belonging to the earlier specified MAC
	// is preferred.
	MACs []string `yaml:"macs"`
	// contains filtered or unexported fields
}

Peer defines a peer this nodes wants to connect to vai wireguard.

func (*Peer) WGConfig

func (p *Peer) WGConfig(ctx context.Context, log logr.Logger, resolver DNSResolver) *wgtypes.PeerConfig

WGConfig deducts a wireguard PeerConfig instance from a given peer container. It returns nil if not change needs to be performed.

It determines this by first checking if we have a recent handshake with the peer. If so no change is needed since the connection is working. It is then checked if we know a neighbouring endpoint address of the peer. If so and it is different from the current endpoint it is selected. If there are multiple endpoints known the next one in the list is tried out. If both of the previous are false and DNSName is set, try to resolve it and pick the next resolved address. Note that endpoints will be tried randomly if your DNS server returns RR in an randomized order.

Jump to

Keyboard shortcuts

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