wg

package
v0.0.0-...-9adf2cc Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseKey

func ParseKey(key string) (wgtypes.Key, error)

ParseKey converts a base64 key into a WireGuard key.

Types

type Device

type Device interface {
	// SetKey sets the private key of the WireGuard interface.
	SetKey(privateKey wgtypes.Key) error

	// SetListenPort sets the listening port of the WireGuard interface.
	SetListenPort(port uint16) error

	// SetIP sets the IP of the WireGuard interface.
	SetIP(newIP *net.IPNet) error

	// SetState sets the state of the WireGuard interface to "up" (true) or
	// "down" (false).
	//
	// A "down" WireGuard interface will be unable to handle any traffic.
	SetState(up bool) error

	// AddPeer adds a new peer or updates existing peer information.
	//
	// A Peer already exists when a peer with the same key as publicKey has
	// been previously added to the interface.
	//
	// endpoint may be nil, and ip may be empty, but not at the same time.
	// publicKey must always be specified.
	AddPeer(ip *net.IPNet, endpoint *net.UDPAddr, publicKey wgtypes.Key) error

	// RemovePeer disconnects from the specified peer by their public key.
	//
	// If the public key is not found in an existing peer, this function
	// does nothing.
	RemovePeer(publicKey wgtypes.Key) error

	// Interface returns the underlying interface.
	Interface() ifctl.Interface

	// Close closes the WireGuard interface and cleans up.
	Close() error
}

Device implements an interface to a WireGuard device, whether it be an in-kernel implementation or based upon wireguard-go.

A Device is not thread-safe. Always use a mutex when using a device from multiple goroutines.

func New

func New(name string) (Device, error)

New creates a new WireGuard device.

Jump to

Keyboard shortcuts

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