Compare commits

...
15 Commits
Author SHA1 Message Date
xtaci a04c959c9c add aes-128 aes-192 cipher 2016-08-16 16:46:27 +08:00
xtaci 4a79d26d35 upd README.md 2016-08-16 10:31:37 +08:00
xtaci 8104d18959 Revert "add manual GC support"
This reverts commit ae699f498c.
2016-08-15 21:34:43 +08:00
xtaci ae699f498c add manual GC support 2016-08-15 20:28:15 +08:00
xtaci dbdd79f1d6 upd 2016-08-15 14:04:45 +08:00
xtaciandGitHub 51bdedb1b3 Update README.md 2016-08-15 14:03:48 +08:00
xtaci 8ea071fa03 upd README 2016-08-15 10:23:47 +08:00
xtaciandGitHub f74201a410 Update ISSUE_TEMPLATE 2016-08-14 18:34:32 +08:00
xtaci 96622bcfc0 add issue template 2016-08-12 10:27:17 +08:00
xtaciandGitHub 29328b375a Update README.md 2016-08-11 21:02:21 +08:00
xtaciandGitHub db7f1def1b Update README.en.md 2016-08-11 20:50:48 +08:00
xtaciandGitHub 628e723167 Update README.md 2016-08-11 20:48:48 +08:00
xtaci ff393ccacb revert part of the PR 2016-08-11 14:47:43 +08:00
xtaciandGitHub 1bb61dbcfc Merge pull request #113 from buaazp/yamux-optimize
*: some optimizes for yamux cache and config
2016-08-11 14:38:05 +08:00
招牌疯子 0b1598d09f *: yamux optimizes for cache and config
and debug log flags when selfbuild.
2016-08-11 14:23:44 +08:00
7 changed files with 185 additions and 38 deletions
+12
View File
@@ -0,0 +1,12 @@
Before firing issue, make sure you figured out the following common questions.
PLEASE DO SEARCH FIRST.
1. Are you using the **latest release**?
2. Which **OS** do you use?
3. Which end for this issue related to, **client or server**?
4. Are you using the **same version** for both client & server
5. Did you correctly set the ***-target value, -t value target server address (default: "127.0.0.1:12948")*** on the server side?
6. Can ```telnet target port``` successful?
7. ```-nocomp, -datashard, -parityshard, -key, -crypt``` ***must be the same*** on both side.
8. Does your ***firewall allows UDP*** communications? (including your ISP Cable-Modem)
+77 -10
View File
@@ -29,8 +29,8 @@ A tool for converting tcp stream into kcp+udp stream, :zap: ***[download address
### *QuickStart* :lollipop:
```
Server Side: ./server_linux_amd64 -t "127.0.0.1:1080" -l ":554" -mode fast2 // forwarding to local port 1080
Client Side: ./client_darwin_amd64 -r "SERVERIP:554" -l ":1080" -mode fast2 // listening on port 1080
Server Side: ./server_linux_amd64 -t "127.0.0.1:1080" -l ":4000" -mode fast2 // forwarding to local port 1080
Client Side: ./client_darwin_amd64 -r "SERVERIP:4000" -l ":1080" -mode fast2 // listening on port 1080
```
### *Performance* :lollipop:
@@ -40,20 +40,83 @@ Client Side: ./client_darwin_amd64 -r "SERVERIP:554" -l ":1080" -mode fast2 //
* WIFI: 5GHz TL-WDR3320
### *Usage* :lollipop:
![client](client.png)
![server](server.png)
```
$ ./client_darwin_amd64 -h
NAME:
kcptun - kcptun client
USAGE:
client_darwin_amd64 [global options] command [command options] [arguments...]
VERSION:
20160811
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--localaddr value, -l value local listen address (default: ":12948")
--remoteaddr value, -r value kcp server address (default: "vps:29900")
--key value key for communcation, must be the same as kcptun server (default: "it's a secrect") [$KCPTUN_KEY]
--crypt value methods for encryption: aes, tea, xor, none (default: "aes")
--mode value mode for communication: fast3, fast2, fast, normal (default: "fast")
--conn value establish N physical connections as specified by 'conn' to server (default: 1)
--mtu value set MTU of UDP packets, suggest 'tracepath' to discover path mtu (default: 1350)
--sndwnd value set send window size(num of packets) (default: 128)
--rcvwnd value set receive window size(num of packets) (default: 1024)
--nocomp disable compression
--datashard value set reed-solomon erasure coding - datashard (default: 10)
--parityshard value set reed-solomon erasure coding - parityshard (default: 3)
--dscp value set DSCP(6bit) (default: 0)
--help, -h show help
--version, -v print the version
```
```
$ ./server_darwin_amd64 -h
NAME:
kcptun - kcptun server
USAGE:
server_darwin_amd64 [global options] command [command options] [arguments...]
VERSION:
20160811
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--listen value, -l value kcp server listen address (default: ":29900")
--target value, -t value target server address (default: "127.0.0.1:12948")
--key value key for communcation, must be the same as kcptun client (default: "it's a secrect") [$KCPTUN_KEY]
--crypt value methods for encryption: aes, tea, xor, none (default: "aes")
--mode value mode for communication: fast3, fast2, fast, normal (default: "fast")
--mtu value set MTU of UDP packets, suggest 'tracepath' to discover path mtu (default: 1350)
--sndwnd value set send window size(num of packets) (default: 1024)
--rcvwnd value set receive window size(num of packets) (default: 1024)
--nocomp disable compression
--datashard value set reed-solomon erasure coding - datashard (default: 10)
--parityshard value set reed-solomon erasure coding - parityshard (default: 3)
--dscp value set DSCP(6bit) (default: 0)
--help, -h show help
--version, -v print the version
```
### *Applications* :lollipop:
1. Real-time gaming.
2. Cross-ISP data exchange in PRC.
3. Other lossy network.
### *Parameters Recommended* :lollipop:
```
Test Environment: China Telecom 100M ADSL(100mbps up/8mbps down)
SERVER: -mtu 1400 -sndwnd 2048 -rcvwnd 2048 -mode fast2
CLIENT: -mtu 1400 -sndwnd 256 -rcvwnd 2048 -mode fast2 -dscp 46
```
### *Parameters* :lollipop:
***Both sides must agree on the following parameters:***
* datashard
* parityshard
* nocomp
* key
* crypt
other parameters can be set independently.
*How to optimize*
> Step 1Increase client rcvwnd & server sndwnd simultaneously & gradually。
@@ -61,6 +124,10 @@ CLIENT: -mtu 1400 -sndwnd 256 -rcvwnd 2048 -mode fast2 -dscp 46
***NOTICE: if too much retranmission happens, it's quite possible the windows are too large***
### *Memory Control* :lollipop:
Routers, mobile devices are sensitive to memory consumption; by setting GOGC environment(eg: GOGC=20) will lower memory consumption.
Reference: https://blog.golang.org/go15gc
### *Traffic Control* :lollipop:
***Intended audience : for those server's bandwidth is quite limited.***
+68 -14
View File
@@ -25,8 +25,8 @@
[English Readme](README.en.md)
### *快速设定* :lollipop:
```
服务器: ./server_linux_amd64 -t "127.0.0.1:8388" -l ":554" -mode fast2 // 转发到服务器的本地8388端口
客户端: ./client_darwin_amd64 -r "服务器IP地址:554" -l ":8388" -mode fast2 // 监听客户端的本地8388端口
服务器: ./server_linux_amd64 -t "127.0.0.1:8388" -l ":4000" -mode fast2 // 转发到服务器的本地8388端口
客户端: ./client_darwin_amd64 -r "服务器IP地址:4000" -l ":8388" -mode fast2 // 监听客户端的本地8388端口
注: 服务器端需要有服务监听8388端口
```
@@ -38,21 +38,71 @@
### *使用方法* :lollipop:
在Mac OS X El Capitan下的帮助输出:
![client](client.png)
![server](server.png)
### *推荐参数* :lollipop:
```
适用大部分ADSL接入(非对称上下行)的参数(实验环境电信100M ADSL)
其它带宽请按比例调整,比如 50M ADSL,把 CLIENT 的 -sndwnd -rcvwnd 减掉一半,SERVER 不变
$ ./client_darwin_amd64 -h
NAME:
kcptun - kcptun client
SERVER: -mtu 1400 -sndwnd 2048 -rcvwnd 2048 -mode fast2
CLIENT: -mtu 1400 -sndwnd 256 -rcvwnd 2048 -mode fast2 -dscp 46
*巭孬嫑乱动*
USAGE:
client_darwin_amd64 [global options] command [command options] [arguments...]
VERSION:
20160811
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--localaddr value, -l value local listen address (default: ":12948")
--remoteaddr value, -r value kcp server address (default: "vps:29900")
--key value key for communcation, must be the same as kcptun server (default: "it's a secrect") [$KCPTUN_KEY]
--crypt value methods for encryption: aes, tea, xor, none (default: "aes")
--mode value mode for communication: fast3, fast2, fast, normal (default: "fast")
--conn value establish N physical connections as specified by 'conn' to server (default: 1)
--mtu value set MTU of UDP packets, suggest 'tracepath' to discover path mtu (default: 1350)
--sndwnd value set send window size(num of packets) (default: 128)
--rcvwnd value set receive window size(num of packets) (default: 1024)
--nocomp disable compression
--datashard value set reed-solomon erasure coding - datashard (default: 10)
--parityshard value set reed-solomon erasure coding - parityshard (default: 3)
--dscp value set DSCP(6bit) (default: 0)
--help, -h show help
--version, -v print the version
```
两端参数必须一致的有:
```
$ ./server_darwin_amd64 -h
NAME:
kcptun - kcptun server
USAGE:
server_darwin_amd64 [global options] command [command options] [arguments...]
VERSION:
20160811
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--listen value, -l value kcp server listen address (default: ":29900")
--target value, -t value target server address (default: "127.0.0.1:12948")
--key value key for communcation, must be the same as kcptun client (default: "it's a secrect") [$KCPTUN_KEY]
--crypt value methods for encryption: aes, tea, xor, none (default: "aes")
--mode value mode for communication: fast3, fast2, fast, normal (default: "fast")
--mtu value set MTU of UDP packets, suggest 'tracepath' to discover path mtu (default: 1350)
--sndwnd value set send window size(num of packets) (default: 1024)
--rcvwnd value set receive window size(num of packets) (default: 1024)
--nocomp disable compression
--datashard value set reed-solomon erasure coding - datashard (default: 10)
--parityshard value set reed-solomon erasure coding - parityshard (default: 3)
--dscp value set DSCP(6bit) (default: 0)
--help, -h show help
--version, -v print the version
```
### *参数调整* :lollipop:
***两端参数必须一致的有:***
* datashard
* parityshard
* nocomp
@@ -92,6 +142,10 @@ CLIENT: -mtu 1400 -sndwnd 256 -rcvwnd 2048 -mode fast2 -dscp 46
max_bandwidth_fec = max_bandwidth * (10 + 3) /10 = 1.3*max_bandwidth 1.3 * 25Mbps = 32.5Mbps
```
### *内存控制* :lollipop:
路由器,手机等嵌入式设备通常对内存用量敏感,通过调节环境变量GOGC(例如GOGC=20)后启动client,可以降低内存使用。
参考:https://blog.golang.org/go15gc
### *流量控制* :lollipop:
***必要性: 针对流量敏感的服务器,做双保险。***
@@ -197,7 +251,7 @@ type Snmp struct {
对该项目的捐款将用于[gonet/2](http://gonet2.github.io/)游戏服务器框架的研发。
> 特别感谢: 郑H立, 南D风, Li, 七q, 凌J,昶,Les*ables, Ky*n等,名字已做特殊处理。
```特别感谢: 郑H立, 南D风, Li, 七q, 凌J,昶,Les*ables, Ky*n, 噼**啦, 等,名字已做特殊处理。```
### *参考资料* :paperclip:
1. https://github.com/skywind3000/kcp -- KCP - A Fast and Reliable ARQ Protocol.
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

+18 -10
View File
@@ -87,6 +87,10 @@ func checkError(err error) {
func main() {
rand.Seed(int64(time.Now().Nanosecond()))
if VERSION == "SELFBUILD" {
// add more log flags for debugging
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
myApp := cli.NewApp()
myApp.Name = "kcptun"
myApp.Usage = "kcptun client"
@@ -111,7 +115,7 @@ func main() {
cli.StringFlag{
Name: "crypt",
Value: "aes",
Usage: "methods for encryption: aes, tea, xor, none",
Usage: "methods for encryption: aes, aes-128, aes-192, tea, xor, none",
},
cli.StringFlag{
Name: "mode",
@@ -224,6 +228,10 @@ func main() {
block, _ = kcp.NewSimpleXORBlockCrypt(pass)
case "none":
block, _ = kcp.NewNoneBlockCrypt(pass)
case "aes-128":
block, _ = kcp.NewAESBlockCrypt(pass[:16])
case "aes-192":
block, _ = kcp.NewAESBlockCrypt(pass[:24])
default:
block, _ = kcp.NewAESBlockCrypt(pass)
}
@@ -248,6 +256,14 @@ func main() {
log.Println("keepalive:", keepalive)
log.Println("conn:", conn)
config := &yamux.Config{
AcceptBacklog: 256,
EnableKeepAlive: true,
KeepAliveInterval: 30 * time.Second,
ConnectionWriteTimeout: 30 * time.Second,
MaxStreamWindowSize: uint32(sockbuf),
LogOutput: os.Stderr,
}
createConn := func() *yamux.Session {
kcpconn, err := kcp.DialWithOptions(remoteaddr, block, datashard, parityshard)
checkError(err)
@@ -269,14 +285,6 @@ func main() {
}
// stream multiplex
config := &yamux.Config{
AcceptBacklog: 256,
EnableKeepAlive: true,
KeepAliveInterval: 30 * time.Second,
ConnectionWriteTimeout: 30 * time.Second,
MaxStreamWindowSize: uint32(sockbuf),
LogOutput: os.Stderr,
}
var session *yamux.Session
if nocomp {
session, err = yamux.Client(kcpconn, config)
@@ -302,8 +310,8 @@ func main() {
if err != nil { // yamux failure
log.Println(err)
p1.Close()
mux.Close()
muxes[rr%numconn] = createConn()
mux.Close()
continue
}
go handleClient(p1, p2)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

+10 -4
View File
@@ -55,13 +55,11 @@ func newCompStream(conn net.Conn) *compStream {
// handle multiplex-ed connection
func handleMux(conn io.ReadWriteCloser, target string, config *yamux.Config) {
// stream multiplex
var mux *yamux.Session
m, err := yamux.Server(conn, config)
mux, err := yamux.Server(conn, config)
if err != nil {
log.Println(err)
return
}
mux = m
defer mux.Close()
for {
@@ -107,6 +105,10 @@ func handleClient(p1, p2 io.ReadWriteCloser) {
func main() {
rand.Seed(int64(time.Now().Nanosecond()))
if VERSION == "SELFBUILD" {
// add more log flags for debugging
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
myApp := cli.NewApp()
myApp.Name = "kcptun"
myApp.Usage = "kcptun server"
@@ -131,7 +133,7 @@ func main() {
cli.StringFlag{
Name: "crypt",
Value: "aes",
Usage: "methods for encryption: aes, tea, xor, none",
Usage: "methods for encryption: aes, aes-128, aes-192, tea, xor, none",
},
cli.StringFlag{
Name: "mode",
@@ -232,6 +234,10 @@ func main() {
block, _ = kcp.NewSimpleXORBlockCrypt(pass)
case "none":
block, _ = kcp.NewNoneBlockCrypt(pass)
case "aes-128":
block, _ = kcp.NewAESBlockCrypt(pass[:16])
case "aes-192":
block, _ = kcp.NewAESBlockCrypt(pass[:24])
default:
block, _ = kcp.NewAESBlockCrypt(pass)
}