Documentation
¶
Index ¶
- Constants
- type ARQEngine
- func (a *ARQEngine) Close()
- func (a *ARQEngine) Delivered() <-chan *Packet
- func (a *ARQEngine) GetFECConfig() *FECConfig
- func (a *ARQEngine) GetLossRate() float64
- func (a *ARQEngine) HandlePacket(pkt *Packet)
- func (a *ARQEngine) Send(payload []byte) error
- func (a *ARQEngine) SendControl(pkt *Packet) error
- func (a *ARQEngine) SetFECConfig(config *FECConfig)
- func (a *ARQEngine) Stats() (sent, recv, retransmissions uint64, window int, rto time.Duration)
- type CodecConfig
- type FECConfig
- type FecDecoder
- type FecEncoder
- type FecGroup
- type Listener
- type MTPConn
- func (c *MTPConn) Close() error
- func (c *MTPConn) DispatchPacket(data []byte)
- func (c *MTPConn) LocalAddr() net.Addr
- func (c *MTPConn) Read(b []byte) (int, error)
- func (c *MTPConn) RemoteAddr() net.Addr
- func (c *MTPConn) SessionID() string
- func (c *MTPConn) SetDeadline(t time.Time) error
- func (c *MTPConn) SetReadDeadline(t time.Time) error
- func (c *MTPConn) SetWriteDeadline(t time.Time) error
- func (c *MTPConn) Write(b []byte) (int, error)
- type Pacer
- type Packet
- type PacketCodec
- type UDPResolver
Constants ¶
const ( DefaultWindowSize = 128 // Увеличено с 64 до 128 MaxWindowSize = 512 // Увеличено с 256 до 512 InitialRTO = 200 * time.Millisecond // Уменьшено с 500ms до 200ms MinRTO = 20 * time.Millisecond // Уменьшено с 100ms до 20ms (для плохих сетей) MaxRTO = 10 * time.Second MaxRetransmissions = 10 DuplicateACKThreshold = 3 // BBR parameters BBRGain = 1.25 // Более агрессивный gain (было 1.5) // FEC адаптивные параметры FECMinDataShards = 8 FECMaxDataShards = 16 FECMinParityShards = 2 FECMaxParityShards = 4 )
ARQ engine constants - OPTIMIZED for performance
const ( PacketDATA uint8 = 0x01 PacketACK uint8 = 0x02 PacketSYN uint8 = 0x03 PacketSYNACK uint8 = 0x04 PacketFIN uint8 = 0x05 PacketFINACK uint8 = 0x06 PacketPING uint8 = 0x07 PacketPONG uint8 = 0x08 PacketFEC uint8 = 0x09 )
Packet types
const ( FlagNone uint8 = 0x00 FlagMigrate uint8 = 0x01 // Session migration FlagSACK uint8 = 0x02 // Selective ACK FlagFragment uint8 = 0x04 // Fragmented payload )
Packet flags
const FECMaxPayload = MaxPayloadSize
FECMaxPayload is the maximum payload size for FEC shards
const MaxPayloadSize = 1200
MaxPayloadSize is the max payload per MTP packet (safe UDP MTU)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ARQEngine ¶
type ARQEngine struct {
// contains filtered or unexported fields
}
ARQEngine manages reliable delivery over unreliable UDP
func NewARQEngine ¶
func NewARQEngine(codec *PacketCodec, sendFunc func([]byte) error, deliverBufSize int) *ARQEngine
NewARQEngine creates a new ARQ engine with optimized parameters
func (*ARQEngine) GetFECConfig ¶ added in v0.3.4
GetFECConfig returns current FEC configuration
func (*ARQEngine) GetLossRate ¶ added in v0.3.4
GetLossRate returns current packet loss rate
func (*ARQEngine) HandlePacket ¶
HandlePacket processes a received packet
func (*ARQEngine) SendControl ¶
SendControl sends a control packet without ARQ tracking or pacing
func (*ARQEngine) SetFECConfig ¶ added in v0.3.4
SetFECConfig updates FEC configuration
type CodecConfig ¶ added in v0.3.4
type CodecConfig struct {
Secret string
EnableDCIDRot bool // Enable DCID rotation for security
DCIDRotInterval int // DCID rotation interval in seconds
}
CodecConfig holds configuration for PacketCodec
type FECConfig ¶ added in v0.3.4
type FECConfig struct {
DataShards int
ParityShards int
AutoAdjust bool
PacketLoss float64 // текущий уровень потерь
}
FECConfig - адаптивная конфигурация FEC
func NewFECConfig ¶ added in v0.3.4
func NewFECConfig() *FECConfig
NewFECConfig создает конфигурацию FEC по умолчанию
type FecDecoder ¶
type FecDecoder struct {
// contains filtered or unexported fields
}
FecDecoder collects incoming DATA and FEC packets, and recovers missing DATA packets
func NewFecDecoder ¶
func NewFecDecoder(onRecover func(uint32, []byte), config *FECConfig) (*FecDecoder, error)
NewFecDecoder creates a new FEC decoder
func (*FecDecoder) AddData ¶
func (f *FecDecoder) AddData(seq uint32, payload []byte)
AddData records a received DATA packet
func (*FecDecoder) AddParity ¶
func (f *FecDecoder) AddParity(startSeq uint32, parityIdx uint8, payload []byte)
AddParity records a received FEC packet
func (*FecDecoder) Reconfigure ¶ added in v0.3.4
func (f *FecDecoder) Reconfigure(config *FECConfig)
Reconfigure обновляет конфигурацию FEC
type FecEncoder ¶
type FecEncoder struct {
// contains filtered or unexported fields
}
FecEncoder collects outgoing DATA payloads and generates Parity packets
func NewFecEncoder ¶
NewFecEncoder creates a new FEC encoder with the given configuration
func (*FecEncoder) AddDataPacket ¶
func (f *FecEncoder) AddDataPacket(seq uint32, payload []byte)
AddDataPacket adds a DATA packet to the current FEC group
func (*FecEncoder) Reconfigure ¶ added in v0.3.4
func (f *FecEncoder) Reconfigure(config *FECConfig)
Reconfigure обновляет конфигурацию FEC
type FecGroup ¶ added in v0.3.4
type FecGroup struct {
// contains filtered or unexported fields
}
FecGroup represents a group of shards for Reed-Solomon decoding
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is an MTP server-side listener that accepts MTP connections over UDP. It implements a net.Listener-compatible interface.
func (*Listener) Accept ¶
Accept waits for and returns the next incoming connection. It implements net.Listener.Accept().
func (*Listener) GetSession ¶
GetSession returns the MTPConn for a given session ID (for VirtualConn swap)
func (*Listener) RemoveConnection ¶
RemoveConnection removes a connection from tracking (called on disconnect)
type MTPConn ¶
type MTPConn struct {
// Traffic stats
BytesSent atomic.Int64
BytesRecv atomic.Int64
PacketsSent atomic.Int64
PacketsRecv atomic.Int64
// contains filtered or unexported fields
}
MTPConn implements net.Conn over a reliable UDP transport using the MTP protocol. It provides ordered, reliable delivery with polymorphic packet encoding.
func Dial ¶
func Dial(resolver UDPResolver, address string, secret string) (*MTPConn, error)
Dial creates a client-side MTPConn to the given server address
func DialMigrate ¶
func DialMigrate(resolver UDPResolver, address string, secret string, sessionID string) (*MTPConn, error)
DialMigrate creates a new MTPConn for session migration (seamless rotation)
func (*MTPConn) DispatchPacket ¶
DispatchPacket is called by the listener to route a raw datagram to this connection
func (*MTPConn) Read ¶
Read implements net.Conn. Blocks until data is available, deadline expires, or conn closes.
func (*MTPConn) SetDeadline ¶
SetDeadline implements net.Conn
func (*MTPConn) SetReadDeadline ¶
SetReadDeadline implements net.Conn
func (*MTPConn) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn
type Pacer ¶ added in v0.3.4
type Pacer struct {
// contains filtered or unexported fields
}
Pacer implements token bucket rate limiting for smooth packet transmission This prevents burst loss and improves throughput on congested networks
func NewPacer ¶ added in v0.3.4
NewPacer creates a new pacer with the given rate limit rate: packets per second burst: maximum burst size (tokens)
type Packet ¶
type Packet struct {
Type uint8
SeqNum uint32
AckNum uint32
Flags uint8
Payload []byte
SACKBlocks []uint32
}
Packet represents a decoded MTP packet
type PacketCodec ¶
type PacketCodec struct {
// contains filtered or unexported fields
}
PacketCodec handles polymorphic encoding and decoding of MTP packets
func NewPacketCodec ¶
func NewPacketCodec(secret string) *PacketCodec
NewPacketCodec creates a new codec with the given shared secret
func NewPacketCodecWithConfig ¶ added in v0.3.4
func NewPacketCodecWithConfig(cfg CodecConfig) *PacketCodec
NewPacketCodecWithConfig creates a codec with custom configuration
func (*PacketCodec) Decode ¶
func (c *PacketCodec) Decode(wire []byte) (*Packet, error)
Decode decrypts and deserializes wire bytes into a Packet
func (*PacketCodec) Encode ¶
func (c *PacketCodec) Encode(pkt *Packet) ([]byte, error)
Encode serializes and encrypts a Packet into wire format: [ QUIC Short Header: 9 bytes ] [ padLen: 2 ] [ padding: N ] [ nonce: 24 ] [ ciphertext: M ]
func (*PacketCodec) GetDCID ¶ added in v0.3.4
func (c *PacketCodec) GetDCID() []byte
GetDCID returns current DCID (for debugging)