Documentation
¶
Index ¶
- Constants
- type ARQEngine
- func (a *ARQEngine) Close()
- func (a *ARQEngine) Delivered() <-chan *Packet
- func (a *ARQEngine) HandlePacket(pkt *Packet)
- func (a *ARQEngine) Send(payload []byte) error
- func (a *ARQEngine) SendControl(pkt *Packet) error
- func (a *ARQEngine) Stats() (sent, recv, retransmissions uint64, window int, rto time.Duration)
- type FecDecoder
- type FecEncoder
- 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 Packet
- type PacketCodec
- type UDPResolver
Constants ¶
const ( DefaultWindowSize = 64 MaxWindowSize = 256 InitialRTO = 500 * time.Millisecond MinRTO = 100 * time.Millisecond MaxRTO = 10 * time.Second MaxRetransmissions = 10 DuplicateACKThreshold = 3 )
ARQ engine constants
const ( FECDataShards = 8 FECParityShards = 2 FECMaxPayload = MaxPayloadSize )
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 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
func (*ARQEngine) Close ¶
func (a *ARQEngine) Close()
Close stops the ARQ engine and cancels all pending retransmissions
func (*ARQEngine) HandlePacket ¶
HandlePacket processes a received packet (called from the recv loop)
func (*ARQEngine) Send ¶
Send queues a DATA packet for reliable delivery. It blocks if the congestion window is full.
func (*ARQEngine) SendControl ¶
SendControl sends a control packet (SYN, ACK, FIN, etc.) without ARQ tracking
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)) (*FecDecoder, error)
func (*FecDecoder) AddData ¶
func (f *FecDecoder) AddData(seq uint32, payload []byte)
AddData records a received DATA packet to aid in recovery of others
type FecEncoder ¶
type FecEncoder struct {
// contains filtered or unexported fields
}
FecEncoder collects outgoing DATA payloads and generates Parity packets
func NewFecEncoder ¶
func NewFecEncoder(onParity func(uint32, uint8, []byte)) (*FecEncoder, error)
func (*FecEncoder) AddDataPacket ¶
func (f *FecEncoder) AddDataPacket(seq uint32, payload []byte)
AddDataPacket adds a DATA packet to the current FEC group. It sends parity packets immediately when the group is full.
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 Packet ¶
type Packet struct {
Type uint8
SeqNum uint32
AckNum uint32
Flags uint8
Payload []byte
SACKBlocks []uint32 // For selective ACK: list of received sequence numbers
}
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