$ account xtaci
kcp-go is a production-grade, high-performance reliable UDP library for Go, implementing the KCP (KCP Protocol) ARQ protocol. It provides a stream-based interface (net.Conn) over UDP with low latency, high throughput, and packet-level control. The library is widely used in gaming, streaming, and network acceleration (e.g., kcptun). Architecturally, it is layered: an application layer using net.Conn, a session layer (sess.go) managing encryption, FEC, and connection lifecycle, a pure protocol state machine (kcp.go) handling ARQ, retransmission, and congestion control, and a transport layer using raw UDP sockets. The data pipeline for outgoing packets is: App Write -> KCP Send -> KCP flush -> FEC Encode -> Encrypt -> UDP Socket. Incoming: UDP Socket -> Decrypt -> FEC Decode -> KCP Input -> App Read. Key features include: reliable ARQ with fast retransmit, Forward Error Correction (FEC) using Reed-Solomon codes, packet-level encryption (AES, TEA, Salsa20, etc., plus AEAD support), platform-specific optimizations (sendmmsg/recvmmsg on Linux), a global timer scheduler to avoid per-session goroutines, and a buffer pool to minimize GC pressure. The codebase demonstrates exceptional craftsmanship with hand-optimized CFB encryption (8x loop unrolling), a generic ring buffer with dynamic resizing, and an auto-tuning FEC decoder that adapts to peer parameters.