target

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package target defines canonical WireGuard target identities and resolves their network addresses.

Index

Constants

View Source
const (
	// MaxHostnameSize is the longest supported DNS hostname without its terminating root label.
	MaxHostnameSize = 253
	// MaxTextSize is the longest canonical HOST:PORT representation.
	MaxTextSize = MaxHostnameSize + 1 + 5
	// MaxCandidates bounds handshake fan-out and retained DNS results for one target.
	MaxCandidates = 16
)

Variables

View Source
var (
	// ErrInvalid indicates a malformed or unsafe WireGuard target.
	ErrInvalid = errors.New("invalid UDP target")
	// ErrNoAddresses indicates that a target resolved to no usable unicast addresses.
	ErrNoAddresses = errors.New("target has no usable addresses")
)

Functions

func Resolve

func Resolve(ctx context.Context, resolver Resolver, endpoint Endpoint) ([]netip.AddrPort, error)

Resolve returns the bounded, deduplicated addresses currently represented by endpoint.

func ValidAddress

func ValidAddress(address netip.Addr) bool

ValidAddress reports whether address can identify a unicast WireGuard target without an IPv6 zone.

Types

type Endpoint

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

Endpoint is one canonical IP-literal or DNS WireGuard target with a numeric UDP port.

func FromAddrPort

func FromAddrPort(address netip.AddrPort) (Endpoint, error)

FromAddrPort returns a canonical target for address.

func MustParse

func MustParse(value string) Endpoint

MustParse parses value and panics on failure.

func Parse

func Parse(value string) (Endpoint, error)

Parse parses and canonicalizes an IP-literal or DNS target with an explicit, nonzero port.

func (Endpoint) Address

func (e Endpoint) Address() netip.Addr

Address returns the IP literal, or an invalid address for a DNS target.

func (Endpoint) IsDomain

func (e Endpoint) IsDomain() bool

IsDomain reports whether endpoint requires DNS resolution.

func (Endpoint) Port

func (e Endpoint) Port() uint16

Port returns the UDP port.

func (Endpoint) String

func (e Endpoint) String() string

String returns the canonical HOST:PORT representation.

func (Endpoint) Valid

func (e Endpoint) Valid() bool

Valid reports whether endpoint is canonical and usable.

type Resolver

type Resolver interface {
	LookupNetIP(context.Context, string, string) ([]netip.Addr, error)
}

Resolver resolves target hostnames through the owning process's name service.

Jump to

Keyboard shortcuts

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