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 CompressionConfig
- 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) Migrate(resolver UDPResolver, address string) error
- 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 = 512 // Увеличено для быстрого старта MaxWindowSize = 2048 // Увеличено для гигабитных сетей InitialRTO = 100 * time.Millisecond // Уменьшено для быстрой реакции MinRTO = 10 * time.Millisecond // Минимальный RTO для локальных сетей MaxRTO = 5 * time.Second // Уменьшено для быстрого восстановления MaxRetransmissions = 8 // Уменьшено для быстрого отказа DuplicateACKThreshold = 2 // Уменьшено для быстрой детекции потерь // BBR parameters - more aggressive for high-speed BBRGain = 1.5 // Более агрессивный gain для высоких скоростей // FEC адаптивные параметры - optimized FECMinDataShards = 16 // Увеличено для лучшего соотношения FECMaxDataShards = 32 // Увеличено FECMinParityShards = 2 // Минимум parity FECMaxParityShards = 4 // Максимум parity // Delayed ACK parameters DelayedACKThreshold = 32 // Отправлять ACK после N полученных пакетов DelayedACKTimeout = 15 * time.Millisecond // Максимальная задержка ACK // Retransmission loop parameters MinRetransmitCheck = 5 * time.Millisecond // Минимальный интервал проверки ретрансмиссии )
ARQ engine constants - OPTIMIZED for high-speed networks (100 Mbps+)
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 FlagCompressed uint8 = 0x08 // Payload is compressed (applied BEFORE encryption) )
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 OPTIMIZED: split locks for better concurrency
func NewARQEngine ¶
func NewARQEngine(codec *PacketCodec, sendFunc func([]byte) error, deliverBufSize int) *ARQEngine
NewARQEngine creates a new ARQ engine with optimized parameters
func (*ARQEngine) Close ¶
func (a *ARQEngine) Close()
Close stops the ARQ engine OPTIMIZED: split locks for better concurrency
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 OPTIMIZED: split locks for better concurrency
func (*ARQEngine) HandlePacket ¶
HandlePacket processes a received packet OPTIMIZED: split locks for better concurrency
func (*ARQEngine) Send ¶
Send queues a DATA packet for reliable delivery with pacing OPTIMIZED: uses windowUpdate channel for instant wake-up on ACK
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 OPTIMIZED: split locks for better concurrency
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
Compression *CompressionConfig // Optional compression config
}
CodecConfig holds configuration for PacketCodec
type CompressionConfig ¶ added in v0.3.5
CompressionConfig holds compression configuration
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 по умолчанию
func (*FECConfig) GetAdjusted ¶ added in v0.3.9
GetAdjusted адаптирует параметры на основе потерь и возвращает новый конфиг OPTIMIZED: immutable to prevent data races
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 ListenWithConfig ¶ added in v0.3.5
func ListenWithConfig(address string, secret string, compression *CompressionConfig) (*Listener, error)
ListenWithConfig creates a new MTP listener with custom configuration
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 Uses protected dialer when running under Android VpnService.
func DialWithConfig ¶ added in v0.3.5
func DialWithConfig(resolver UDPResolver, address string, secret string, compression *CompressionConfig) (*MTPConn, error)
DialWithConfig creates a client-side MTPConn with custom configuration Uses protected dialer when running under Android VpnService.
func (*MTPConn) DispatchPacket ¶
DispatchPacket is called by the listener to route a raw datagram to this connection
func (*MTPConn) Migrate ¶ added in v0.3.9
func (c *MTPConn) Migrate(resolver UDPResolver, address string) error
Migrate performs session migration (seamless rotation) on an existing connection. It opens a new UDP socket, performs the MIGRATE handshake, and seamlessly swaps the underlying transport while preserving the ARQ engine and sequence numbers.
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)
func (*Pacer) Close ¶ added in v0.3.9
func (p *Pacer) Close()
Close stops the pacer, unblocking any Wait() calls
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 with optional compression (compression is applied BEFORE encryption)
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) Close ¶ added in v0.3.9
func (c *PacketCodec) Close()
Close stops background goroutines
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: Pipeline: Payload -> Compress (optional) -> Encrypt -> Add QUIC header [ 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)