target

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package target defines canonical WireGuard target identities and resolves their server-side 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 server-side 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 server's local name service.

Jump to

Keyboard shortcuts

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