wireguard

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotStarted = errors.New("wireguard: device has not been started")

Functions

func GenerateKeypair

func GenerateKeypair() (privateKey, publicKey string, err error)

func GeneratePresharedKey

func GeneratePresharedKey() (string, error)

func GeneratePrivateKey

func GeneratePrivateKey() (string, error)

func PublicKey

func PublicKey(privateKey string) (string, error)

Types

type Client

type Client struct {
	Config Config
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) *Client

func (*Client) Runtime

func (c *Client) Runtime() (*Runtime, error)

func (*Client) Start

func (c *Client) Start(ctx context.Context) (*govpn.Session, error)

func (*Client) Status

func (c *Client) Status() (Status, error)

func (*Client) UAPIGet

func (c *Client) UAPIGet() (string, error)

func (*Client) UAPISet

func (c *Client) UAPISet(configuration string) error

type Config

type Config struct {
	PrivateKey   string
	Address      []string
	DNS          []string
	MTU          int
	ListenPort   int
	FirewallMark uint32
	Peers        []Peer
	Table        string
	PreUp        []string
	PostUp       []string
	PreDown      []string
	PostDown     []string
	SaveConfig   bool
	Logger       *log.Logger
}

func ParseConfig

func ParseConfig(r io.Reader) (*Config, error)

ParseConfig reads official wg and wg-quick configuration fields. Host route, DNS and lifecycle values are preserved in Config but are not executed.

func ParseConfigFile

func ParseConfigFile(path string) (*Config, error)

type EndpointPreference added in v0.0.2

type EndpointPreference string
const (
	EndpointPreferenceAuto EndpointPreference = "auto"
	EndpointPreferenceIPv4 EndpointPreference = "ipv4"
	EndpointPreferenceIPv6 EndpointPreference = "ipv6"
)

type Peer

type Peer struct {
	PublicKey          string             `json:"public-key"`
	PresharedKey       string             `json:"preshared-key,omitempty"`
	Endpoint           string             `json:"endpoint,omitempty"`
	EndpointPreference EndpointPreference `json:"endpoint-preference,omitempty"`
	AllowedIPs         []string           `json:"allowed-ips,omitempty"`
	Keepalive          int                `json:"persistent-keepalive,omitempty"`
	// contains filtered or unexported fields
}

type PeerStatus

type PeerStatus struct {
	PublicKey     string
	Endpoint      string
	AllowedIPs    []string
	Keepalive     int
	LastHandshake time.Time
	TransmitBytes uint64
	ReceiveBytes  uint64
}

type PeerUpdate

type PeerUpdate struct {
	PublicKey         string
	UpdateOnly        bool
	Remove            bool
	PresharedKey      *string
	Endpoint          *string
	Keepalive         *int
	ReplaceAllowedIPs bool
	AllowedIPs        []string
	RemoveAllowedIPs  []string
}

PeerUpdate describes an incremental update using the official WireGuard cross-platform UAPI semantics. Nil pointer fields are left unchanged. An empty PresharedKey clears the existing key, and a zero Keepalive disables persistent keepalives.

type Runtime

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

func (*Runtime) ClearPrivateKey

func (t *Runtime) ClearPrivateKey() error

func (*Runtime) Close

func (t *Runtime) Close() error

func (*Runtime) RemovePeer

func (t *Runtime) RemovePeer(publicKey string) error

func (*Runtime) ReplacePeers

func (t *Runtime) ReplacePeers(ctx context.Context, peers []Peer) error

func (*Runtime) SetFirewallMark

func (t *Runtime) SetFirewallMark(mark uint32) error

func (*Runtime) SetListenPort

func (t *Runtime) SetListenPort(port int) error

func (*Runtime) SetPrivateKey

func (t *Runtime) SetPrivateKey(privateKey string) error

func (*Runtime) Status

func (t *Runtime) Status() (Status, error)

func (*Runtime) UAPIGet

func (t *Runtime) UAPIGet() (string, error)

func (*Runtime) UAPISet

func (t *Runtime) UAPISet(configuration string) error

func (*Runtime) UpdatePeer

func (t *Runtime) UpdatePeer(ctx context.Context, update PeerUpdate) error

type Server

type Server struct {
	Config ServerConfig
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config ServerConfig) *Server

func (*Server) Runtime

func (s *Server) Runtime() (*Runtime, error)

func (*Server) Start

func (s *Server) Start(ctx context.Context) (*govpn.Session, error)

func (*Server) Status

func (s *Server) Status() (Status, error)

func (*Server) UAPIGet

func (s *Server) UAPIGet() (string, error)

func (*Server) UAPISet

func (s *Server) UAPISet(configuration string) error

type ServerConfig

type ServerConfig struct {
	PrivateKey string
	ListenPort int
	// ListenIP is retained for configuration compatibility. wireguard-go binds
	// both wildcard families; a specific bind address is not supported.
	ListenIP     string
	Address      string
	Address6     string
	Addresses    []string
	MTU          int
	FirewallMark uint32
	Peers        []ServerPeer
	Logger       *log.Logger
}

type ServerPeer

type ServerPeer = Peer

type Status

type Status struct {
	PublicKey    string
	ListenPort   int
	FirewallMark uint32
	Peers        []PeerStatus
}

Jump to

Keyboard shortcuts

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