datagram

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: 21 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 datagram owns WireGuard-facing UDP endpoint behavior.

Index

Constants

View Source
const (
	// MaximumBatchSize bounds opportunistic packet vectors throughout the relay data path.
	MaximumBatchSize = 16
)

Variables

View Source
var (
	// ErrNoLocalPeer indicates that no WireGuard process has sent a local datagram yet.
	ErrNoLocalPeer = errors.New("no local UDP peer")
	// ErrDatagramDropped indicates a per-datagram rejection or failure that does not invalidate the UDP endpoint.
	ErrDatagramDropped = errors.New("UDP datagram dropped")
)

Functions

func ReadBatch added in v0.2.0

func ReadBatch(ctx context.Context, endpoint Endpoint, packets []Packet) (int, error)

ReadBatch reads one or more packets while falling back to scalar endpoint I/O. It transfers ownership of the returned packet prefix to the caller even when it also returns an error.

func WriteBatch added in v0.2.0

func WriteBatch(ctx context.Context, endpoint Endpoint, payloads [][]byte, deadline time.Time) (int, error)

WriteBatch writes an ordered successful prefix and reports the first failed packet. A nil error means every payload was written.

Types

type Endpoint

type Endpoint interface {
	// Read returns one accepted packet with a caller-owned payload. Read calls on the same endpoint must not overlap.
	Read(context.Context) (Packet, error)
	// Write synchronously delivers one accepted WireGuard packet before deadline, or only the context deadline when
	// deadline is zero. It must not retain payload after returning.
	Write(context.Context, []byte, time.Time) error
	Close() error
}

Endpoint reads and writes one side of a WireGuard UDP data path.

func WithReservedTranslation

func WithReservedTranslation(endpoint Endpoint, reserved wgpacket.Reserved) Endpoint

WithReservedTranslation wraps endpoint when reserved translation is enabled.

type Local

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

Local is a UDP listener that tracks the latest valid local WireGuard source.

func ListenLocal

func ListenLocal(address netip.AddrPort) (*Local, error)

ListenLocal binds a local WireGuard UDP listener.

func NewLocal

func NewLocal(conn *net.UDPConn) *Local

NewLocal wraps an already bound local WireGuard UDP listener.

func (*Local) Close

func (e *Local) Close() error

Close closes the local WireGuard UDP listener.

func (*Local) LocalAddr

func (e *Local) LocalAddr() netip.AddrPort

LocalAddr returns the bound local WireGuard UDP listener endpoint.

func (*Local) Read

func (e *Local) Read(ctx context.Context) (Packet, error)

Read returns the next structurally valid local WireGuard datagram and remembers its source.

func (*Local) ReadBatch added in v0.2.0

func (e *Local) ReadBatch(ctx context.Context, packets []Packet) (int, error)

ReadBatch returns one blocking packet plus currently queued valid local WireGuard datagrams.

func (*Local) Write

func (e *Local) Write(ctx context.Context, payload []byte, deadline time.Time) error

Write writes one reply to the latest valid local WireGuard source by deadline.

func (*Local) WriteBatch added in v0.2.0

func (e *Local) WriteBatch(ctx context.Context, payloads [][]byte, deadline time.Time) (int, error)

WriteBatch writes an ordered packet prefix to the latest valid local WireGuard source.

type Packet

type Packet struct {
	Kind    wgpacket.Kind
	Payload []byte
	// contains filtered or unexported fields
}

Packet is one accepted WireGuard-looking UDP datagram.

func (*Packet) Release added in v0.2.0

func (p *Packet) Release()

Release relinquishes one ownership reference and clears p.

func (Packet) Retain added in v0.2.0

func (p Packet) Retain() Packet

Retain returns another ownership reference to p.

type Remote

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

Remote is an upstream logical target with DNS candidates and WireGuard index affinity.

func OpenRemote

func OpenRemote(parent context.Context, endpoint target.Endpoint, config RemoteConfig) (*Remote, error)

OpenRemote resolves target and opens its per-family UDP sockets. The context bounds preparation only. The caller must close a successful result to stop its readers and DNS refreshes.

func (*Remote) Close

func (e *Remote) Close() error

Close stops resolution and closes all target sockets.

func (*Remote) Read

func (e *Remote) Read(ctx context.Context) (Packet, error)

Read returns the next structurally valid WireGuard datagram from an accepted target candidate.

func (*Remote) ReadBatch added in v0.2.0

func (e *Remote) ReadBatch(ctx context.Context, packets []Packet) (int, error)

ReadBatch returns an accepted target packet vector from either address family.

func (*Remote) Write

func (e *Remote) Write(ctx context.Context, payload []byte, deadline time.Time) error

Write routes one WireGuard datagram to its indexed candidate or bounded handshake fan-out set.

func (*Remote) WriteBatch added in v0.2.0

func (e *Remote) WriteBatch(ctx context.Context, payloads [][]byte, deadline time.Time) (int, error)

WriteBatch writes an ordered packet prefix using vector I/O for single-candidate runs.

type RemoteConfig added in v0.2.0

type RemoteConfig struct {
	Resolver     target.Resolver
	ListenConfig net.ListenConfig
}

RemoteConfig defines target resolution and upstream UDP socket creation.

Jump to

Keyboard shortcuts

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