datagram

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: 13 Imported by: 0

Documentation

Overview

Package datagram owns WireGuard-facing UDP endpoint behavior.

Index

Constants

This section is empty.

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

This section is empty.

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 WireHop UDP relay session.

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 client UDP listener that tracks the latest valid local WireGuard source.

func ListenLocal

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

ListenLocal binds a client UDP listener.

func NewLocal

func NewLocal(conn *net.UDPConn) *Local

NewLocal wraps an already bound client UDP listener.

func (*Local) Close

func (e *Local) Close() error

Close closes the client UDP listener.

func (*Local) LocalAddr

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

LocalAddr returns the bound client 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) 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.

type Packet

type Packet struct {
	Kind    wgpacket.Kind
	Payload []byte
}

Packet is one accepted WireGuard-looking UDP datagram.

type Remote

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

Remote is a server-side logical target with DNS candidates and WireGuard index affinity.

func OpenRemote

func OpenRemote(parent context.Context, endpoint target.Endpoint, resolver target.Resolver) (*Remote, error)

OpenRemote resolves target and opens the required per-family UDP sockets.

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 authorized target candidate.

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.

Jump to

Keyboard shortcuts

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