{"id":13413615,"url":"https://github.com/xtaci/kcp-go","last_synced_at":"2025-12-30T12:59:33.269Z","repository":{"id":4098604,"uuid":"37511821","full_name":"xtaci/kcp-go","owner":"xtaci","description":" A Crypto-Secure Reliable-UDP Library for golang with FEC ","archived":false,"fork":false,"pushed_at":"2025-04-15T02:40:48.000Z","size":879,"stargazers_count":4243,"open_issues_count":62,"forks_count":751,"subscribers_count":144,"default_branch":"master","last_synced_at":"2025-05-05T22:16:08.252Z","etag":null,"topics":["automatic-repeat-request","forward-error-correction","kcp","reed-solomon-codes","reliable-udp-library","symmetric-key-cryptography"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtaci.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-06-16T06:15:55.000Z","updated_at":"2025-05-05T08:03:08.000Z","dependencies_parsed_at":"2024-06-18T10:56:06.280Z","dependency_job_id":"ba634f58-9966-4c6a-8358-cdafde8ef142","html_url":"https://github.com/xtaci/kcp-go","commit_stats":{"total_commits":687,"total_committers":20,"mean_commits":34.35,"dds":"0.11644832605531297","last_synced_commit":"e026777b9cb8afa9ce8a963f3e54ffccaf03f6a1"},"previous_names":[],"tags_count":148,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fkcp-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fkcp-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fkcp-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtaci%2Fkcp-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtaci","download_url":"https://codeload.github.com/xtaci/kcp-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253968041,"owners_count":21992252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic-repeat-request","forward-error-correction","kcp","reed-solomon-codes","reliable-udp-library","symmetric-key-cryptography"],"created_at":"2024-07-30T20:01:44.594Z","updated_at":"2025-12-28T07:33:32.914Z","avatar_url":"https://github.com/xtaci.png","language":"Go","funding_links":[],"categories":["Misc","Networking","开源类库","Go","网络","网络相关库","Open source library","others","Quic \u0026\u0026 KCP \u0026\u0026 KTP \u0026\u0026 PCC \u0026\u0026 SRT 学习资料快速链接","\u003cspan id=\"网络-networking\"\u003e网络 Networking\u003c/span\u003e","Program","Relational Databases"],"sub_categories":["Transliteration","Strings","网络","音译","暂未分类","The Internet","暂未分类这些库被放在这里是因为其他类别似乎都不适合。","Advanced Console UIs","Uncategorized","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Go","交流"],"readme":"\u003cimg src=\"assets/kcp-go.png\" alt=\"kcp-go\" height=\"100px\" /\u003e\n\n\n[![GoDoc][1]][2] [![Powered][9]][10] [![MIT licensed][11]][12] [![Build Status][3]][4] [![Go Report Card][5]][6] [![Coverage Status][7]][8] [![Sourcegraph][13]][14]\n\n[1]: https://godoc.org/github.com/xtaci/kcp-go?status.svg\n[2]: https://pkg.go.dev/github.com/xtaci/kcp-go/v5\n[3]: https://img.shields.io/github/created-at/xtaci/kcp-go\n[4]: https://img.shields.io/github/created-at/xtaci/kcp-go\n[5]: https://goreportcard.com/badge/github.com/xtaci/kcp-go\n[6]: https://goreportcard.com/report/github.com/xtaci/kcp-go\n[7]: https://codecov.io/gh/xtaci/kcp-go/branch/master/graph/badge.svg\n[8]: https://codecov.io/gh/xtaci/kcp-go\n[9]: https://img.shields.io/badge/KCP-Powered-blue.svg\n[10]: https://github.com/skywind3000/kcp\n[11]: https://img.shields.io/badge/license-MIT-blue.svg\n[12]: LICENSE\n[13]: https://sourcegraph.com/github.com/xtaci/kcp-go/-/badge.svg\n[14]: https://sourcegraph.com/github.com/xtaci/kcp-go?badge\n \n[English](README.md) | [中文](README_zh.md)\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Documentation](#documentation)\n- [Layer-Model of KCP-GO](#layer-model-of-kcp-go)\n- [Key Design Considerations](#key-design-considerations)\n- [Specification](#specification)\n- [Performance](#performance)\n- [Typical Flame Graph](#typical-flame-graph)\n- [Connection Termination](#connection-termination)\n- [FAQ](#faq)\n- [Who is using this?](#who-is-using-this)\n- [Examples](#examples)\n- [Links](#links)\n\n## Introduction\n\n**kcp-go** is a **Reliable-UDP** library for [golang](https://golang.org/).\n\nThis library provides **smooth, resilient, ordered, error-checked, and anonymous** stream delivery over **UDP** packets. Battle-tested with the open-source project [kcptun](https://github.com/xtaci/kcptun), millions of devices—from low-end MIPS routers to high-end servers—have deployed kcp-go-powered programs across various applications, including **online games, live broadcasting, file synchronization, and network acceleration**.\n\n[Latest Release](https://github.com/xtaci/kcp-go/releases)\n\n## Features\n\n1. Designed for **latency-sensitive** scenarios.\n2. **Cache-friendly** and **memory-optimized** design, offering an extremely **high-performance** core.\n3. Handles **\u003e5K concurrent connections** on a single commodity server.\n4. Compatible with [net.Conn](https://golang.org/pkg/net/#Conn) and [net.Listener](https://golang.org/pkg/net/#Listener), serving as a drop-in replacement for [net.TCPConn](https://golang.org/pkg/net/#TCPConn).\n5. [FEC (Forward Error Correction)](https://en.wikipedia.org/wiki/Forward_error_correction) support using [Reed-Solomon Codes](https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction).\n6. Packet-level encryption support for [AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard), [TEA](https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm), [3DES](https://en.wikipedia.org/wiki/Triple_DES), [Blowfish](https://en.wikipedia.org/wiki/Blowfish_(cipher)), [Cast5](https://en.wikipedia.org/wiki/CAST-128), [Salsa20](https://en.wikipedia.org/wiki/Salsa20), etc., in [CFB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Feedback_(CFB)) mode, generating completely anonymous packets.\n7. [AEAD](https://en.wikipedia.org/wiki/Authenticated_encryption) packet encryption support.\n8. Only **a fixed number of goroutines** are created for the entire server application, with **context switching** costs between goroutines taken into consideration.\n9. Compatible with [skywind3000's](https://github.com/skywind3000) C version, with various improvements.\n10. Platform-specific optimizations: [sendmmsg](http://man7.org/linux/man-pages/man2/sendmmsg.2.html) and [recvmmsg](http://man7.org/linux/man-pages/man2/recvmmsg.2.html) for Linux.\n\n## Documentation\n\nFor complete documentation, see the associated [Godoc](https://pkg.go.dev/github.com/xtaci/kcp-go/v5).\n\n\n### Layer-Model of KCP-GO\n\n\u003cimg src=\"assets/layermodel.jpg\" alt=\"layer-model\" /\u003e\n\n## Key Design Considerations\n\n### 1. Slice vs. Container/List\n\n`kcp.flush()` loops through the send queue for retransmission checking every 20 ms.\n\nI wrote a benchmark comparing sequential loops through a *slice* and a *container/list* [here](https://github.com/xtaci/notes/blob/master/golang/benchmark2/cachemiss_test.go):\n\n```\nBenchmarkLoopSlice-4   \t2000000000\t         0.39 ns/op\nBenchmarkLoopList-4    \t100000000\t        54.6 ns/op\n```\n\nThe list structure introduces **heavy cache misses** compared to the slice, which offers better **locality**. For 5,000 connections with a 32-window size and a 20 ms interval, using a slice costs 6 μs (0.03% CPU) per `kcp.flush()`, whereas using a list costs 8.7 ms (43.5% CPU).\n\n### 2. Timing Accuracy vs. Syscall clock_gettime\n\nTiming is **critical** for the **RTT estimator**. Inaccurate timing leads to false retransmissions in KCP, but calling `time.Now()` costs 42 cycles (10.5 ns on a 4 GHz CPU, 15.6 ns on my MacBook Pro 2.7 GHz).\n\nThe benchmark for `time.Now()` is [here](https://github.com/xtaci/notes/blob/master/golang/benchmark2/syscall_test.go):\n\n```\nBenchmarkNow-4         \t100000000\t        15.6 ns/op\n```\n\nIn kcp-go, after each `kcp.output()` function call, the current clock time is updated upon return. For a single `kcp.flush()` operation, the current time is queried from the system once. For 5,000 connections, this costs 5000 × 15.6 ns = 78 μs (a fixed cost when no packets need to be sent). For 10 MB/s data transfer with a 1400 MTU, `kcp.output()` is called approximately 7,500 times, costing 117 μs for `time.Now()` per second.\n\n### 3. Memory Management\n\nPrimary memory allocation is performed from a global buffer pool, `xmit.Buf`. In kcp-go, when bytes need to be allocated, they are obtained from this pool, which returns a fixed-capacity 1500 bytes (mtuLimit). The rx queue, tx queue, and FEC queue all receive bytes from this pool and return them after use to prevent unnecessary zeroing of bytes. The pool mechanism maintains a high watermark for slice objects, allowing these in-flight objects to survive periodic garbage collection while also being able to return memory to the runtime when idle.\n\n### 4. Information Security\n\nkcp-go ships with built-in packet encryption powered by various block encryption algorithms and operates in [Cipher Feedback Mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Feedback_(CFB)). For each packet to be sent, the encryption process begins by encrypting a [nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce) from the [system entropy](https://en.wikipedia.org/wiki//dev/random), ensuring that encryption of the same plaintext never produces the same ciphertext.\n\nThe contents of packets are completely anonymous with encryption, including the headers (FEC, KCP), checksums, and payload. Note that regardless of which encryption method you choose at the upper layer, if you disable encryption, the transmission will be insecure because the header is ***plaintext*** and susceptible to tampering, such as jamming the *sliding window size*, *round-trip time*, *FEC properties*, and *checksums*. `AES-128` is recommended for minimal encryption, as modern CPUs feature [AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set) instructions and perform better than `salsa20` (see the table above).\n\nOther possible attacks on kcp-go include:\n\n- **[Traffic analysis](https://en.wikipedia.org/wiki/Traffic_analysis):** Data flow on specific websites may exhibit patterns during data exchange. This type of eavesdropping has been mitigated by adopting [smux](https://github.com/xtaci/smux) to mix data streams and introduce noise. While a perfect solution has not yet emerged, theoretically, shuffling/mixing messages on a larger-scale network may mitigate this problem.\n- **[Replay attack](https://en.wikipedia.org/wiki/Replay_attack):** Since asymmetric encryption has not been introduced into kcp-go, capturing packets and replaying them on a different machine is possible. Note that hijacking the session and decrypting the contents is still *impossible*. Upper layers should use an asymmetric encryption system to guarantee the authenticity of each message (to process each message exactly once), such as HTTPS/OpenSSL/LibreSSL. Signing requests with private keys can eliminate this type of attack.\n\n### 5. Packet Clocking\n\n1. **Immediate FastACK**: Send immediately after `fastack` is triggered, without waiting for the fixed `interval`.\n2. **Immediate ACK**: Send immediately after accumulating ACKs that fill a full MTU packet, also without waiting for the `interval`.\n   In high-speed networks, this acts as a higher-frequency \"clock signal,\" potentially boosting unidirectional transmission speed by approximately 6x. For instance, if a batch takes only 1.5ms to process on a high-speed link but still adheres to a fixed 10ms transmission cycle, the actual throughput would be limited to 1/6 of the potential.\n3. **Pacing Mechanism**: Introduced a pacing clock to prevent burst congestion where data piles up in the kernel when `snd_wnd` is large, causing the kernel to drop packets. While difficult to implement in user space, a usable version has been achieved, allowing user-space echo to stabilize above 100MB/s.\n4. **Data Structure Optimization**: Optimized data structures (e.g., `snd_buf` ringbuffer) to ensure good cache coherency. Queues must not be too long; otherwise, traversal costs introduce extra latency. In high-speed networks, the buffer corresponding to BDP should be kept smaller to minimize latency from data structures. Note that the current KCP structure has O(n) complexity for RTO; changing it to O(1) would require significant refactoring.\n\nUltimately, nothing is more critical in a transmission system than the clock (real-time performance).\n\n### 6. FEC Design Characteristics\n\n- Reed-Solomon based encoder/decoder lives in the `postProcess`/`packetInput` path, so parity shards are generated and consumed without extra goroutines or lock contention.\n- Data/parity ratios are configurable per session, letting operators trade ~20–30% bandwidth overhead for lower tail latency on lossy or long-haul links.\n- Parity shards are produced from buffer-pool-backed slices, which avoids repeated allocations and keeps GC pressure flat even during multi-Gbps transfers.\n- Decoding favors single-pass recovery: as soon as enough shards arrive, the original packets are reconstructed and pushed into `KCP.Input`, minimizing reordering and retransmission storms.\n- When combined with encryption, FEC headers stay protected, preventing traffic shapers from inferring recovery patterns or downgrading throughput.\n\n## Specification\n\n\u003cimg src=\"assets/frame.png\" alt=\"Frame Format\" height=\"109px\" /\u003e\n\n```\nNONCE:\n  16bytes cryptographically secure random number, nonce changes for every packet.\n  \nCRC32:\n  CRC-32 checksum of data using the IEEE polynomial\n \nFEC TYPE:\n  typeData = 0xF1\n  typeParity = 0xF2\n  \nFEC SEQID:\n  monotonically increasing in range: [0, (0xffffffff/shardSize) * shardSize - 1]\n  \nSIZE:\n  The size of KCP frame plus 2\n\nKCP Header\n+------------------------------+\n|           conv (u32)         |\n+-------+-------+--------------+\n|  cmd  |  frag |     wnd      |\n|  u8   |  u8   |     u16      |\n+------------------------------+\n|           ts   (u32)         |\n+------------------------------+\n|           sn   (u32)         |\n+------------------------------+\n|           una  (u32)         |\n+------------------------------+\n|           data (bytes)       |\n+------------------------------+\n```\n\n## Performance\n```\n2025/11/26 11:12:51 beginning tests, encryption:salsa20, fec:10/3\ngoos: linux\ngoarch: amd64\npkg: github.com/xtaci/kcp-go/v5\ncpu: AMD Ryzen 9 5950X 16-Core Processor\nBenchmarkSM4\nBenchmarkSM4-32                            56077             21672 ns/op         138.43 MB/s           0 B/op          0 allocs/op\nBenchmarkAES128\nBenchmarkAES128-32                        525854              2228 ns/op        1346.69 MB/s           0 B/op          0 allocs/op\nBenchmarkAES192\nBenchmarkAES192-32                        473692              2429 ns/op        1234.95 MB/s           0 B/op          0 allocs/op\nBenchmarkAES256\nBenchmarkAES256-32                        427497              2725 ns/op        1101.06 MB/s           0 B/op          0 allocs/op\nBenchmarkTEA\nBenchmarkTEA-32                           149976              8085 ns/op         371.06 MB/s           0 B/op          0 allocs/op\nBenchmarkXOR\nBenchmarkXOR-32                         12333190                92.35 ns/op     32485.16 MB/s          0 B/op          0 allocs/op\nBenchmarkBlowfish\nBenchmarkBlowfish-32                       70762             16983 ns/op         176.65 MB/s           0 B/op          0 allocs/op\nBenchmarkNone\nBenchmarkNone-32                        47325206                24.49 ns/op     122482.39 MB/s         0 B/op          0 allocs/op\nBenchmarkCast5\nBenchmarkCast5-32                          66837             18035 ns/op         166.35 MB/s           0 B/op          0 allocs/op\nBenchmark3DES\nBenchmark3DES-32                           18402             64349 ns/op          46.62 MB/s           0 B/op          0 allocs/op\nBenchmarkTwofish\nBenchmarkTwofish-32                        56440             21380 ns/op         140.32 MB/s           0 B/op          0 allocs/op\nBenchmarkXTEA\nBenchmarkXTEA-32                           45616             26124 ns/op         114.84 MB/s           0 B/op          0 allocs/op\nBenchmarkSalsa20\nBenchmarkSalsa20-32                       525685              2199 ns/op        1363.97 MB/s           0 B/op          0 allocs/op\nBenchmarkCRC32\nBenchmarkCRC32-32                       19418395                59.05 ns/op     17341.83 MB/s\nBenchmarkCsprngSystem\nBenchmarkCsprngSystem-32                 2912889               404.3 ns/op        39.58 MB/s\nBenchmarkCsprngMD5\nBenchmarkCsprngMD5-32                   15063580                79.23 ns/op      201.95 MB/s\nBenchmarkCsprngSHA1\nBenchmarkCsprngSHA1-32                  20186407                60.04 ns/op      333.08 MB/s\nBenchmarkCsprngNonceMD5\nBenchmarkCsprngNonceMD5-32              13863704                85.11 ns/op      187.98 MB/s\nBenchmarkCsprngNonceAES128\nBenchmarkCsprngNonceAES128-32           97239751                12.56 ns/op     1274.09 MB/s\nBenchmarkFECDecode\nBenchmarkFECDecode-32                    1808791               679.1 ns/op      2208.94 MB/s        1641 B/op          3 allocs/op\nBenchmarkFECEncode\nBenchmarkFECEncode-32                    6671982               181.4 ns/op      8270.76 MB/s           2 B/op          0 allocs/op\nBenchmarkFlush\nBenchmarkFlush-32                         322982              3809 ns/op               0 B/op          0 allocs/op\nBenchmarkDebugLog\nBenchmarkDebugLog-32                    1000000000               0.2146 ns/op\nBenchmarkEchoSpeed4K\nBenchmarkEchoSpeed4K-32                    35583             32875 ns/op         124.59 MB/s       18223 B/op        148 allocs/op\nBenchmarkEchoSpeed64K\nBenchmarkEchoSpeed64K-32                    1995            510301 ns/op         128.43 MB/s      284233 B/op       2297 allocs/op\nBenchmarkEchoSpeed512K\nBenchmarkEchoSpeed512K-32                    259           4058131 ns/op         129.19 MB/s     2243058 B/op      18148 allocs/op\nBenchmarkEchoSpeed1M\nBenchmarkEchoSpeed1M-32                      145           8561996 ns/op         122.47 MB/s     4464227 B/op      36009 allocs/op\nBenchmarkSinkSpeed4K\nBenchmarkSinkSpeed4K-32                   194648             42136 ns/op          97.21 MB/s        2073 B/op         50 allocs/op\nBenchmarkSinkSpeed64K\nBenchmarkSinkSpeed64K-32                   10000            113038 ns/op         579.77 MB/s       29242 B/op        741 allocs/op\nBenchmarkSinkSpeed256K\nBenchmarkSinkSpeed256K-32                   1555            843724 ns/op         621.40 MB/s      229558 B/op       5850 allocs/op\nBenchmarkSinkSpeed1M\nBenchmarkSinkSpeed1M-32                      667           1783214 ns/op         588.03 MB/s      462691 B/op      11694 allocs/op\nPASS\nok      github.com/xtaci/kcp-go/v5      49.978s\n```\n\n```\n===\nModel Name:\tMacBook Pro\nModel Identifier:\tMacBookPro14,1\nProcessor Name:\tIntel Core i5\nProcessor Speed:\t3.1 GHz\nNumber of Processors:\t1\nTotal Number of Cores:\t2\nL2 Cache (per Core):\t256 KB\nL3 Cache:\t4 MB\nMemory:\t8 GB\n===\n\n$ go test -v -run=^$ -bench .\nbeginning tests, encryption:salsa20, fec:10/3\ngoos: darwin\ngoarch: amd64\npkg: github.com/xtaci/kcp-go\nBenchmarkSM4-4                 \t   50000\t     32180 ns/op\t  93.23 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkAES128-4              \t  500000\t      3285 ns/op\t 913.21 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkAES192-4              \t  300000\t      3623 ns/op\t 827.85 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkAES256-4              \t  300000\t      3874 ns/op\t 774.20 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkTEA-4                 \t  100000\t     15384 ns/op\t 195.00 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkXOR-4                 \t20000000\t        89.9 ns/op\t33372.00 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkBlowfish-4            \t   50000\t     26927 ns/op\t 111.41 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkNone-4                \t30000000\t        45.7 ns/op\t65597.94 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkCast5-4               \t   50000\t     34258 ns/op\t  87.57 MB/s\t       0 B/op\t       0 allocs/op\nBenchmark3DES-4                \t   10000\t    117149 ns/op\t  25.61 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkTwofish-4             \t   50000\t     33538 ns/op\t  89.45 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkXTEA-4                \t   30000\t     45666 ns/op\t  65.69 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkSalsa20-4             \t  500000\t      3308 ns/op\t 906.76 MB/s\t       0 B/op\t       0 allocs/op\nBenchmarkCRC32-4               \t20000000\t        65.2 ns/op\t15712.43 MB/s\nBenchmarkCsprngSystem-4        \t 1000000\t      1150 ns/op\t  13.91 MB/s\nBenchmarkCsprngMD5-4           \t10000000\t       145 ns/op\t 110.26 MB/s\nBenchmarkCsprngSHA1-4          \t10000000\t       158 ns/op\t 126.54 MB/s\nBenchmarkCsprngNonceMD5-4      \t10000000\t       153 ns/op\t 104.22 MB/s\nBenchmarkCsprngNonceAES128-4   \t100000000\t        19.1 ns/op\t 837.81 MB/s\nBenchmarkFECDecode-4           \t 1000000\t      1119 ns/op\t1339.61 MB/s\t    1606 B/op\t       2 allocs/op\nBenchmarkFECEncode-4           \t 2000000\t       832 ns/op\t1801.83 MB/s\t      17 B/op\t       0 allocs/op\nBenchmarkFlush-4               \t 5000000\t       272 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkEchoSpeed4K-4         \t    5000\t    259617 ns/op\t  15.78 MB/s\t    5451 B/op\t     149 allocs/op\nBenchmarkEchoSpeed64K-4        \t    1000\t   1706084 ns/op\t  38.41 MB/s\t   56002 B/op\t    1604 allocs/op\nBenchmarkEchoSpeed512K-4       \t     100\t  14345505 ns/op\t  36.55 MB/s\t  482597 B/op\t   13045 allocs/op\nBenchmarkEchoSpeed1M-4         \t      30\t  34859104 ns/op\t  30.08 MB/s\t 1143773 B/op\t   27186 allocs/op\nBenchmarkSinkSpeed4K-4         \t   50000\t     31369 ns/op\t 130.57 MB/s\t    1566 B/op\t      30 allocs/op\nBenchmarkSinkSpeed64K-4        \t    5000\t    329065 ns/op\t 199.16 MB/s\t   21529 B/op\t     453 allocs/op\nBenchmarkSinkSpeed256K-4       \t     500\t   2373354 ns/op\t 220.91 MB/s\t  166332 B/op\t    3554 allocs/op\nBenchmarkSinkSpeed1M-4         \t     300\t   5117927 ns/op\t 204.88 MB/s\t  310378 B/op\t    6988 allocs/op\nPASS\nok  \tgithub.com/xtaci/kcp-go\t50.349s\n```\n\n```\n=== Raspberry Pi 4 ===\n\n➜  kcp-go git:(master) cat /proc/cpuinfo\nprocessor\t: 0\nmodel name\t: ARMv7 Processor rev 3 (v7l)\nBogoMIPS\t: 108.00\nFeatures\t: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32\nCPU implementer\t: 0x41\nCPU architecture: 7\nCPU variant\t: 0x0\nCPU part\t: 0xd08\nCPU revision\t: 3\n\n➜  kcp-go git:(master)  go test -run=^$ -bench .\n2020/01/05 19:25:13 beginning tests, encryption:salsa20, fec:10/3\ngoos: linux\ngoarch: arm\npkg: github.com/xtaci/kcp-go/v5\nBenchmarkSM4-4                     20000             86475 ns/op          34.69 MB/s           0 B/op          0 allocs/op\nBenchmarkAES128-4                  20000             62254 ns/op          48.19 MB/s           0 B/op          0 allocs/op\nBenchmarkAES192-4                  20000             71802 ns/op          41.78 MB/s           0 B/op          0 allocs/op\nBenchmarkAES256-4                  20000             80570 ns/op          37.23 MB/s           0 B/op          0 allocs/op\nBenchmarkTEA-4                     50000             37343 ns/op          80.34 MB/s           0 B/op          0 allocs/op\nBenchmarkXOR-4                    100000             22266 ns/op         134.73 MB/s           0 B/op          0 allocs/op\nBenchmarkBlowfish-4                20000             66123 ns/op          45.37 MB/s           0 B/op          0 allocs/op\nBenchmarkNone-4                  3000000               518 ns/op        5786.77 MB/s           0 B/op          0 allocs/op\nBenchmarkCast5-4                   20000             76705 ns/op          39.11 MB/s           0 B/op          0 allocs/op\nBenchmark3DES-4                     5000            418868 ns/op           7.16 MB/s           0 B/op          0 allocs/op\nBenchmarkTwofish-4                  5000            326896 ns/op           9.18 MB/s           0 B/op          0 allocs/op\nBenchmarkXTEA-4                    10000            114418 ns/op          26.22 MB/s           0 B/op          0 allocs/op\nBenchmarkSalsa20-4                 50000             36736 ns/op          81.66 MB/s           0 B/op          0 allocs/op\nBenchmarkCRC32-4                 1000000              1735 ns/op         589.98 MB/s\nBenchmarkCsprngSystem-4          1000000              2179 ns/op           7.34 MB/s\nBenchmarkCsprngMD5-4             2000000               811 ns/op          19.71 MB/s\nBenchmarkCsprngSHA1-4            2000000               862 ns/op          23.19 MB/s\nBenchmarkCsprngNonceMD5-4        2000000               878 ns/op          18.22 MB/s\nBenchmarkCsprngNonceAES128-4     5000000               326 ns/op          48.97 MB/s\nBenchmarkFECDecode-4              200000              9081 ns/op         165.16 MB/s         140 B/op          1 allocs/op\nBenchmarkFECEncode-4              100000             12039 ns/op         124.59 MB/s          11 B/op          0 allocs/op\nBenchmarkFlush-4                  100000             21704 ns/op               0 B/op          0 allocs/op\nBenchmarkEchoSpeed4K-4              2000            981182 ns/op           4.17 MB/s       12384 B/op        424 allocs/op\nBenchmarkEchoSpeed64K-4              100          10503324 ns/op           6.24 MB/s      123616 B/op       3779 allocs/op\nBenchmarkEchoSpeed512K-4              20         138633802 ns/op           3.78 MB/s     1606584 B/op      29233 allocs/op\nBenchmarkEchoSpeed1M-4                 5         372903568 ns/op           2.81 MB/s     4080504 B/op      63600 allocs/op\nBenchmarkSinkSpeed4K-4             10000            121239 ns/op          33.78 MB/s        4647 B/op        104 allocs/op\nBenchmarkSinkSpeed64K-4             1000           1587906 ns/op          41.27 MB/s       50914 B/op       1115 allocs/op\nBenchmarkSinkSpeed256K-4             100          16277830 ns/op          32.21 MB/s      453027 B/op       9296 allocs/op\nBenchmarkSinkSpeed1M-4               100          31040703 ns/op          33.78 MB/s      898097 B/op      18932 allocs/op\nPASS\nok      github.com/xtaci/kcp-go/v5      64.151s\n```\n\n\n## Typical Flame Graph\n![Flame Graph in kcptun](assets/flame.png)\n\n\n\n## Connection Termination\n\nControl messages like **SYN/FIN/RST** in TCP **are not defined** in KCP. You need a **keepalive/heartbeat mechanism** at the application level. A practical example is to use a **multiplexing** protocol over the session, such as [smux](https://github.com/xtaci/smux) (which has an embedded keepalive mechanism). See [kcptun](https://github.com/xtaci/kcptun) for a reference implementation.\n\n## FAQ\n\n**Q: I'm handling \u003e5K connections on my server, and the CPU utilization is very high.**\n\n**A:** A standalone `agent` or `gate` server for running kcp-go is recommended, not only to reduce CPU utilization but also to improve the **precision** of RTT measurements (timing), which indirectly affects retransmission. Increasing the update `interval` with `SetNoDelay`, such as `conn.SetNoDelay(1, 40, 1, 1)`, will dramatically reduce system load but may lower performance.\n\n**Q: When should I enable FEC?**\n\n**A:** Forward error correction is critical for long-distance transmission because packet loss incurs a significant time penalty. In the complex packet routing networks of the modern world, round-trip time-based loss checks are not always efficient. The significant deviation of RTT samples over long distances typically leads to a larger RTO value in typical RTT estimators, which slows down transmission.\n\n**Q: Should I enable encryption?**\n\n**A:** Yes, for the security of the protocol, even if the upper layer has encryption.\n\n## Who is using this?\n\n1. https://github.com/xtaci/kcptun -- A Secure Tunnel Based on KCP over UDP.\n2. https://github.com/getlantern/lantern -- Lantern delivers fast access to the open Internet.\n3. https://github.com/smallnest/rpcx -- An RPC service framework based on net/rpc, similar to Alibaba Dubbo and Weibo Motan.\n4. https://github.com/gonet2/agent -- A gateway for games with stream multiplexing.\n5. https://github.com/syncthing/syncthing -- Open Source Continuous File Synchronization.\n\n### Looking for a C++ client?\n1. https://github.com/xtaci/libkcp -- FEC enhanced KCP session library for iOS/Android in C++\n\n## Examples\n\n1. [simple examples](https://github.com/xtaci/kcp-go/tree/master/examples)\n2. [kcptun client](https://github.com/xtaci/kcptun/blob/master/client/main.go)\n3. [kcptun server](https://github.com/xtaci/kcptun/blob/master/server/main.go)\n\n## Links\n\n1. https://github.com/xtaci/smux/ -- A Stream Multiplexing Library for golang with least memory\n1. **https://github.com/xtaci/libkcp -- FEC enhanced KCP session library for iOS/Android in C++**\n1. https://github.com/skywind3000/kcp -- A Fast and Reliable ARQ Protocol\n1. https://github.com/klauspost/reedsolomon -- Reed-Solomon Erasure Coding in Go\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtaci%2Fkcp-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtaci%2Fkcp-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtaci%2Fkcp-go/lists"}