udp

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const MTU = 9001

Variables

View Source
var ErrInvalidIPv6RemoteForSocket = errors.New("listener is IPv4, but writing to IPv6 remote")

Functions

func NewUDPStatsEmitter

func NewUDPStatsEmitter(udpConns []Conn) func()

Types

type Conn

type Conn interface {
	Rebind() error
	LocalAddr() (netip.AddrPort, error)
	ListenOut(r EncReader) error
	WriteTo(b []byte, addr netip.AddrPort) error
	ReloadConfig(c *config.C)
	SupportsMultipleReaders() bool
	Close() error
}

func NewListener

func NewListener(l *slog.Logger, ip netip.Addr, port int, multi bool, batch int) (Conn, error)

type EncReader

type EncReader func(
	addr netip.AddrPort,
	payload []byte,
)

type NetworkChangeMonitor added in v1.11.0

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

NetworkChangeMonitor rebinds the udp listener when the local network moves out from under it.

Detection lives here in the udp package, next to the socket it concerns and the platform matrix that already knows which sockets go stale. What to do about a change — updating the lighthouse, requerying tunnels — is not the udp package's business, so Start takes the reaction as a plain function. Passing it at Start rather than holding it keeps this package from referencing whatever owns the rebind.

On platforms whose sockets do not go stale, watchNetworkChanges hands back a nil channel and Start returns.

func NewNetworkChangeMonitor added in v1.11.0

func NewNetworkChangeMonitor(ctx context.Context, l *slog.Logger, c *config.C) *NetworkChangeMonitor

NewNetworkChangeMonitor builds a monitor for local network changes. The returned monitor is always usable: Start is safe to call unconditionally, it no-ops when disabled or on a platform that does not need it.

func (*NetworkChangeMonitor) Start added in v1.11.0

func (m *NetworkChangeMonitor) Start(rebind func())

Start watches for network changes until the context is cancelled, calling rebind once per settled change. It blocks, so callers run it in a goroutine, and it no-ops when disabled, unsupported, or with nothing to rebind.

type NoopConn added in v1.8.0

type NoopConn struct{}

func (NoopConn) Close added in v1.8.0

func (NoopConn) Close() error

func (NoopConn) ListenOut added in v1.8.0

func (NoopConn) ListenOut(_ EncReader) error

func (NoopConn) LocalAddr added in v1.8.0

func (NoopConn) LocalAddr() (netip.AddrPort, error)

func (NoopConn) Rebind added in v1.8.0

func (NoopConn) Rebind() error

func (NoopConn) ReloadConfig added in v1.8.0

func (NoopConn) ReloadConfig(_ *config.C)

func (NoopConn) SupportsMultipleReaders added in v1.10.0

func (NoopConn) SupportsMultipleReaders() bool

func (NoopConn) WriteTo added in v1.8.0

func (NoopConn) WriteTo(_ []byte, _ netip.AddrPort) error

type StdConn added in v1.8.0

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

func (*StdConn) Close added in v1.8.0

func (u *StdConn) Close() error

func (*StdConn) GetRecvBuffer added in v1.8.0

func (u *StdConn) GetRecvBuffer() (int, error)

func (*StdConn) GetSendBuffer added in v1.8.0

func (u *StdConn) GetSendBuffer() (int, error)

func (*StdConn) GetSoMark added in v1.10.0

func (u *StdConn) GetSoMark() (int, error)

func (*StdConn) ListenOut added in v1.8.0

func (u *StdConn) ListenOut(r EncReader) error

func (*StdConn) LocalAddr added in v1.8.0

func (u *StdConn) LocalAddr() (netip.AddrPort, error)

func (*StdConn) PrepareRawMessages added in v1.8.0

func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte)

func (*StdConn) Rebind added in v1.8.0

func (u *StdConn) Rebind() error

func (*StdConn) ReloadConfig added in v1.8.0

func (u *StdConn) ReloadConfig(c *config.C)

func (*StdConn) SetRecvBuffer added in v1.8.0

func (u *StdConn) SetRecvBuffer(n int) error

func (*StdConn) SetSendBuffer added in v1.8.0

func (u *StdConn) SetSendBuffer(n int) error

func (*StdConn) SetSoMark added in v1.10.0

func (u *StdConn) SetSoMark(mark int) error

func (*StdConn) SupportsMultipleReaders added in v1.10.0

func (u *StdConn) SupportsMultipleReaders() bool

func (*StdConn) WriteTo added in v1.8.0

func (u *StdConn) WriteTo(b []byte, ip netip.AddrPort) error

Jump to

Keyboard shortcuts

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