udp

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 11 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewListener added in v0.0.3

func NewListener(conn net.PacketConn, cfg *ListenConfig) net.Listener

NewListener creates a net.Listener from a net.PacketConn by demultiplexing UDP datagrams into per-client net.Conn streams. Idle connections are cleaned up according to cfg.TTL.

When cfg.Stateless is true, the listener operates in raw datagram mode: no connPool, no listenLoop goroutine, no per-client session tracking. Each Accept call blocks on a ReadFrom and returns a lightweight datagramConn wrapping a single packet.

Types

type Conn

Conn is a net.PacketConn that also supports io.Reader, io.Writer, buffer sizing, syscall access, and remote address exposure.

type ListenConfig added in v0.0.3

type ListenConfig struct {
	Addr           net.Addr
	Backlog        int
	ReadQueueSize  int
	ReadBufferSize int
	TTL            time.Duration
	Keepalive      bool
	Stateless      bool
	Logger         logger.Logger
}

ListenConfig configures a UDP-to-TCP-stream listener.

type ReadUDP

type ReadUDP interface {
	ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
	ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error)
}

ReadUDP supports reading UDP datagrams with metadata.

type Relay

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

Relay copies UDP datagrams between two net.PacketConns bidirectionally.

func NewRelay

func NewRelay(pc1, pc2 net.PacketConn) *Relay

NewRelay creates a Relay that copies datagrams between pc1 and pc2.

func (*Relay) Run

func (r *Relay) Run(ctx context.Context) (err error)

Run starts the relay. It blocks until an error occurs or ctx is cancelled. Both packet conns are closed before returning so the underlying sockets are released and the pending read in either direction is unblocked.

func (*Relay) WithBufferSize added in v0.0.3

func (r *Relay) WithBufferSize(n int) *Relay

WithBufferSize sets the buffer size for copy operations.

func (*Relay) WithBypass

func (r *Relay) WithBypass(bp bypass.Bypass) *Relay

WithBypass sets the bypass matcher to skip certain addresses.

func (*Relay) WithLogger

func (r *Relay) WithLogger(logger logger.Logger) *Relay

WithLogger sets the logger.

func (*Relay) WithReadTimeout added in v0.28.1

func (r *Relay) WithReadTimeout(d time.Duration) *Relay

WithReadTimeout sets an idle read timeout for both relay directions. When a read blocks for longer than d the relay terminates and closes both packet conns. A value of 0 disables the timeout, relying on ctx cancellation to detect dead associations.

func (*Relay) WithService added in v0.28.1

func (r *Relay) WithService(service string) *Relay

WithService sets the service name for bypass matching.

type WriteUDP

type WriteUDP interface {
	WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)
	WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)
}

WriteUDP supports writing UDP datagrams with metadata.

Jump to

Keyboard shortcuts

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