Versions in this module Expand all Collapse all v0 v0.1.0 Nov 2, 2026 Changes in this version + const DefaultBufferSize + const DefaultMaxConnections + const DefaultMaxIdleTimeout + const DefaultMetricsInterval + const DefaultSocketBufferSize + const DefaultWindowSize + const LevelTrace + var ErrAcceptTimedOut = errors.New("utp: timed out waiting for incoming connection") + var ErrConnRefused = errors.New("utp: connection refused") + var ErrDontFragmentUnsupported = errors.New("utp: per-packet don't-fragment is not supported on this platform") + var ErrNotConnected = errors.New("utp: not connected") + var ErrReadClosed = errors.New("utp: read side closed") + var ErrReset = errors.New("utp: connection reset by peer") + var ErrSocketClosed = fmt.Errorf("utp: socket closed: %w", net.ErrClosed) + var ErrTimedOut = errors.New("utp: connection timed out") + func IsPacket(b []byte) bool + type CongestionAlgorithm int + const AlgorithmLEDBAT + const AlgorithmLEDBATPP + func (a CongestionAlgorithm) String() string + type Conn interface + Close func() error + ReadFrom func(b []byte) (int, ConnectionPeer, error) + WriteTo func(b []byte, dst ConnectionPeer) (int, error) + type ConnectionConfig struct + BufferSize int + CongestionAlgorithm CongestionAlgorithm + DelayWindow time.Duration + InitialTimeout time.Duration + KeepAliveInterval time.Duration + MaxConnAttempts int + MaxIdleTimeout time.Duration + MaxPacketSize uint16 + MaxTimeout time.Duration + Metrics MetricsObserver + MetricsInterval time.Duration + MinTimeout time.Duration + NoDelay bool + RACK bool + TargetDelay time.Duration + WindowSize uint32 + ZeroWindowProbeInterval time.Duration + func NewConnectionConfig() *ConnectionConfig + type ConnectionID struct + Peer ConnectionPeer + Recv uint16 + Send uint16 + func NewConnectionID(peer ConnectionPeer, recvID uint16, sendID uint16) *ConnectionID + func (id *ConnectionID) Hash() string + func (id *ConnectionID) String() string + type ConnectionMetrics struct + AppLimitedSince time.Duration + At time.Time + BaseDelay time.Duration + BytesReceived uint64 + BytesRetransmitted uint64 + BytesSent uint64 + CID *ConnectionID + ClockDrift int64 + ClockDriftPenalty time.Duration + ClockSkewCorrection time.Duration + CurrentDelay time.Duration + CwndBytes uint32 + FastRetransmits uint64 + FineRTT time.Duration + InFlightBytes uint32 + LossProbes uint64 + MinCwndBytes uint32 + MtuCeiling uint32 + MtuCurrent uint32 + MtuFloor uint32 + MtuProbesLostToDuplicateAcks uint64 + PacketsReceived uint64 + PacketsRetransmitted uint64 + PacketsSent uint64 + PeerRecvWindow uint32 + PeerTimestampDiff time.Duration + PendingWrites int + RTT time.Duration + RTTVarianceMicros int64 + RackLosses uint64 + RackRelosts uint64 + RecvBufferDrops uint64 + RecvBufferPending int + RecvBufferReadable int + SendBufferPending int + SlowStart bool + State string + TargetDelayMicros uint32 + Timeout time.Duration + Timeouts uint64 + WindowReopenedAcks uint64 + func (m ConnectionMetrics) QueueingDelay() time.Duration + func (m ConnectionMetrics) RetransmitRate() float64 + type ConnectionPeer interface + Hash func() string + type DontFragmentWriter interface + WriteToDontFragment func(b []byte, dst ConnectionPeer) (int, error) + type MetricsObserver func(ConnectionMetrics) + type PathMTUProvider interface + PathMTU func(peer ConnectionPeer) (int, bool) + type QueuedReader interface + Queued func() int + type Socket struct + func Bind(ctx context.Context, network string, addr *net.UDPAddr, logger *slog.Logger, ...) (*Socket, error) + func NewSocket(ctx context.Context, socket Conn, logger *slog.Logger, opts ...SocketOption) *Socket + func (s *Socket) Accept(ctx context.Context, config *ConnectionConfig) (*Stream, error) + func (s *Socket) AcceptBacklog() int + func (s *Socket) AcceptWithCID(ctx context.Context, cid *ConnectionID, config *ConnectionConfig) (*Stream, error) + func (s *Socket) Close() error + func (s *Socket) Connect(ctx context.Context, peer ConnectionPeer, config *ConnectionConfig) (*Stream, error) + func (s *Socket) ConnectWithCID(ctx context.Context, cid *ConnectionID, config *ConnectionConfig) (*Stream, error) + func (s *Socket) ConnectionsRefusedAtCapacity() uint64 + func (s *Socket) ConnectionsRefusedByFirewall() uint64 + func (s *Socket) ConnectionsRefusedIDInUse() uint64 + func (s *Socket) LocalAddr() net.Addr + func (s *Socket) NumConnections() int + func (s *Socket) PacketsDroppedFullConnQueue() uint64 + func (s *Socket) PacketsResetSent() uint64 + func (s *Socket) ProcessICMPError(quoted []byte, peer ConnectionPeer) bool + func (s *Socket) ProcessICMPFragmentation(quoted []byte, peer ConnectionPeer, nextHopMTU uint16) bool + type SocketOption func(*Socket) + func WithAcceptConfig(config func() *ConnectionConfig) SocketOption + func WithFirewall(refuse func(peer ConnectionPeer) bool) SocketOption + func WithMaxConnections(n int) SocketOption + type Stream struct + func (s *Stream) CID() *ConnectionID + func (s *Stream) Close() error + func (s *Stream) CloseRead() error + func (s *Stream) CloseWrite() error + func (s *Stream) Done() <-chan struct{} + func (s *Stream) Read(ctx context.Context, buf []byte) (int, error) + func (s *Stream) ReadToEOF(ctx context.Context, buf *[]byte) (int, error) + func (s *Stream) SetWindowSize(bytes uint32) + func (s *Stream) WindowSize() uint32 + func (s *Stream) Write(ctx context.Context, buf []byte) (int, error) + func (s *Stream) WriteV(ctx context.Context, bufs [][]byte) (int, error) + type UDPPeer struct + func NewUDPPeer(addr *net.UDPAddr) *UDPPeer + func (p *UDPPeer) Addr() *net.UDPAddr + func (p *UDPPeer) Hash() string + func (p *UDPPeer) String() string