Compare commits

..
34 Commits
Author SHA1 Message Date
xtaci 561ee05818 make 'softfloat' for MIPS as the default when compiling 2018-09-17 16:12:58 +08:00
xtaci 65d8945050 hint before key stretching for low-end devices 2018-09-15 15:48:26 +08:00
xtaciandGitHub cdaff1bd72 Update README.md 2018-08-17 15:15:44 +08:00
xtaciandGitHub cb451a3a88 Update README.md 2018-08-16 17:12:18 +08:00
xtaci 8f8d762742 gofmt 2018-06-28 19:25:37 +08:00
xtaciandGitHub e3ab00cf5b Merge pull request #600 from mateomartin1998/master
snmplog: only format the log file name, not the whole path
2018-06-21 12:11:32 +08:00
mateomartin1998 42bf13fb7a snmplog: only format the log file name, not the whole path 2018-06-17 17:58:21 +08:00
xtaci 03f27ec53d Revert "passive tunnel termination"
This reverts commit bf1d0d6419.
2018-03-16 13:44:44 +08:00
xtaciandGitHub b2390a5dd3 Update README.md 2018-03-16 13:30:53 +08:00
xtaci bf1d0d6419 passive tunnel termination 2018-03-05 16:38:28 +08:00
xtaciandGitHub 834cc5d596 Update README.md 2017-12-03 21:59:22 +08:00
xtaciandGitHub 825ccca6ac Update README.md 2017-10-23 02:59:28 -05:00
xtaci 2845af3911 print quiet option 2017-10-21 19:34:26 +08:00
xtaciandGitHub 31a9d13871 Merge pull request #509 from jiangtiandao/master
reduce docker image size by using multi stage build
2017-10-21 19:16:01 +08:00
xtaci 43761f486c add '-quiet' option to suppress stream open/close messages 2017-10-21 19:11:14 +08:00
xtaci 030e39bf74 add encryption support for sm4 2017-10-09 22:58:44 +08:00
Rheinmetal e6a1d00758 reduce docker image size by using multi stage build 2017-09-23 10:26:17 +08:00
xtaci 9d5a5b9c0d upd travis 2017-09-04 11:06:21 +08:00
xtaci 4aaf974a0b add ethereum qrcode 2017-08-06 17:22:46 +08:00
xtaciandGitHub 1600d4d26f Update README.md 2017-08-02 19:26:33 +08:00
xtaciandGitHub c612e5e153 Update README.md 2017-07-30 18:48:11 +08:00
xtaciandGitHub 2fef48ce71 Update README.md 2017-07-30 18:47:19 +08:00
xtaciandGitHub 1d492accd6 Update README.md 2017-07-30 18:46:48 +08:00
xtaci d1beaf8383 update README.md 2017-07-02 00:14:39 +08:00
xtaciandGitHub ded53a9229 Update README.md 2017-05-20 19:35:17 +08:00
xtaciandGitHub 65751d535b Update README.md 2017-05-20 19:34:42 +08:00
xtaci 4b5f7c1405 add bitcoin donate 2017-05-20 18:48:05 +08:00
xtaciandGitHub 25bad3c03c Update README.md 2017-04-26 11:16:48 +08:00
xtaciandGitHub d2c4d04600 Update README.md 2017-04-26 11:07:24 +08:00
xtaci 0cb075b061 add a log for re-connecting 2017-04-08 10:38:51 +08:00
xtaciandGitHub ab7a8321a6 Update README.md 2017-03-29 21:08:16 +08:00
xtaci 6496672b61 Revert "use io.CopyBuffer instead of io.Copy for memory recycle"
This reverts commit ad8683d46c.
2017-03-28 15:34:23 +08:00
xtaci ae513e9af1 inject version in Dockerfile 2017-03-27 15:56:29 +08:00
xtaci 36763feca4 ignore sigpipe 2017-03-24 22:52:06 +08:00
11 changed files with 103 additions and 70 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
language: go
go:
- 1.6
- 1.9
before_install:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

+5 -2
View File
@@ -1,8 +1,11 @@
FROM golang:alpine
FROM golang:alpine as builder
MAINTAINER xtaci <daniel820313@gmail.com>
RUN apk update && \
apk upgrade && \
apk add git
RUN go get github.com/xtaci/kcptun/client && go get github.com/xtaci/kcptun/server
RUN go get -ldflags "-X main.VERSION=$(date -u +%Y%m%d) -s -w" github.com/xtaci/kcptun/client && go get -ldflags "-X main.VERSION=$(date -u +%Y%m%d) -s -w" github.com/xtaci/kcptun/server
FROM alpine:3.6
COPY --from=builder /go/bin /bin
EXPOSE 29900/udp
EXPOSE 12948
+39 -9
View File
@@ -21,23 +21,34 @@
<img src="kcptun.png" alt="kcptun" height="300px"/>
> *kcptun maintains a single website — [github.com/xtaci/kcptun](https://github.com/xtaci/kcptun). Any websites other than [github.com/xtaci/kcptun](https://github.com/xtaci/kcptun) are not endorsed by xtaci. kcptun won't publish anything on any social media.*
> *KCP discussion QQ group: 364933586, KCP integration, tuning, network transmission and related technical discussions.*
### QuickStart
Download precompiled [Releases](https://github.com/xtaci/kcptun/releases).
Increase the number of open files on your server, as:
`ulimit -n 65535`, or write it in `~/.bashrc`.
Download a corresponding precompiled [Releases](https://github.com/xtaci/kcptun/releases).
```
KCP Client: ./client_darwin_amd64 -r "KCP_SERVER_IP:4000" -l ":8388" -mode fast2
KCP Server: ./server_linux_amd64 -t "TARGET_IP:8388" -l ":4000" -mode fast2
```
The above commands will establish port forwarding for 8388/tcp as:
The above commands will establish port forwarding channel for 8388/tcp as:
Application -> KCP Client(8388/tcp) -> KCP Server(4000/udp) -> Server(8388/tcp)
> Application -> **KCP Client(8388/tcp) -> KCP Server(4000/udp)** -> Target Server(8388/tcp)
which tunnels the original connection:
> Application -> Target Server(8388/tcp)
### Install from source
```
$go get -u github.com/xtaci/kcptun/client
$go get -u github.com/xtaci/kcptun/server
$go get -u github.com/xtaci/kcptun/...
```
All precompiled releases are genereated from `build-release.sh` script.
@@ -52,7 +63,8 @@ All precompiled releases are genereated from `build-release.sh` script.
> **Q: I have a high speed network link, how to reach the maximum bandwidth?**
> **A:** Increase `-rcvwnd` on KCP Client and `-sndwnd` on KCP Server **simultaneously & gradually**, the mininum one decides the maximum transfer rate of the link, as `wnd * mtu / rtt`; Then try downloading something and to see if it meets your requirements.
> **A:** Increase `-rcvwnd` on KCP Client and `-sndwnd` on KCP Server **simultaneously & gradually**, the mininum one decides the maximum transfer rate of the link, as `wnd * mtu / rtt`; Then try downloading something and to see if it meets your requirements.
(mtu is adjustable by `-mtu`)
#### Improving Latency
@@ -154,7 +166,7 @@ It is able to detect and correct multiple symbol errors. By adding t check symbo
![reed-solomon](rs.png)
Setting parameters of RS-Code with ```-datashard m -parityshard n``` on both KCP Client & KCP Server.
Setting parameters of RS-Code with ```-datashard m -parityshard n``` on **BOTH** KCP Client & KCP Server **MUST** be **IDENTICAL**.
#### DSCP
@@ -194,7 +206,7 @@ BenchmarkSalsa20-4 300000 4998 ns/op
#### Memory Control
Routers, mobile devices are sensitive to memory consumption; by setting GOGC environment(eg: GOGC=20) will lower memory consumption.
Routers, mobile devices are susceptible to memory consumption; by setting GOGC environment(eg: GOGC=20) will make the garbage collector to recycle faster.
Reference: https://blog.golang.org/go15gc
#### Compression
@@ -212,7 +224,7 @@ kcptun has builtin snappy algorithms for compressing streams:
Compression may save bandwidth for **PLAINTEXT** data, such as HTTP data.
Compression is enabled by default, you can disable it by setting ```-nocomp``` on both KCP Client & KCP Server.
Compression is enabled by default, you can disable it by setting ```-nocomp``` on **BOTH** KCP Client & KCP Server **MUST** be **IDENTICAL**.
#### SNMP
@@ -254,6 +266,17 @@ https://github.com/skywind3000/kcp/blob/master/README.en.md#protocol-configurati
Low-level KCP configuration can be altered by using manual mode like above, make sure you really **UNDERSTAND** what these means before doing **ANY** manual settings.
### Identical Parmeters
The parameters below **MUST** be **IDENTICAL** on **BOTH** side:
1. -key
1. -crypt
1. -nocomp
1. -datashard
1. -parityshard
### References
1. https://github.com/skywind3000/kcp -- KCP - A Fast and Reliable ARQ Protocol.
@@ -271,3 +294,10 @@ Low-level KCP configuration can be altered by using manual mode like above, make
1. http://http2.github.io/ -- What is HTTP/2?
1. http://www.lartc.org/ -- Linux Advanced Routing & Traffic Control
1. https://en.wikipedia.org/wiki/Noisy-channel_coding_theorem -- Noisy channel coding theorem
1. https://play.google.com/store/apps/details?id=com.k17game.k3 -- Battle Zone - Earth 2048, an online strategy game using kcp.
### Donate via Ethereum(ETH)
Address: 0x2e4b43ab3d0983da282592571eef61ae5e60f726 , Or scan here:
<img src="0x2e4b43ab3d0983da282592571eef61ae5e60f726.png" alt="kcptun" height="100px" />
+4 -4
View File
@@ -47,10 +47,10 @@ tar -zcf kcptun-linux-arm-$VERSION.tar.gz client_linux_arm* server_linux_arm*
$sum kcptun-linux-arm-$VERSION.tar.gz
#MIPS32LE
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o client_linux_mipsle github.com/xtaci/kcptun/client
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o server_linux_mipsle github.com/xtaci/kcptun/server
env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o client_linux_mips github.com/xtaci/kcptun/client
env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o server_linux_mips github.com/xtaci/kcptun/server
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o client_linux_mipsle github.com/xtaci/kcptun/client
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o server_linux_mipsle github.com/xtaci/kcptun/server
env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o client_linux_mips github.com/xtaci/kcptun/client
env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o server_linux_mips github.com/xtaci/kcptun/server
if $UPX; then upx -9 client_linux_mips* server_linux_mips*;fi
tar -zcf kcptun-linux-mipsle-$VERSION.tar.gz client_linux_mipsle server_linux_mipsle
+1
View File
@@ -32,6 +32,7 @@ type Config struct {
Log string `json:"log"`
SnmpLog string `json:"snmplog"`
SnmpPeriod int `json:"snmpperiod"`
Quiet bool `json:"quiet"`
}
func parseJSONConfig(config *Config, path string) error {
+26 -27
View File
@@ -9,7 +9,6 @@ import (
"math/rand"
"net"
"os"
"sync"
"time"
"golang.org/x/crypto/pbkdf2"
@@ -19,6 +18,8 @@ import (
"github.com/urfave/cli"
kcp "github.com/xtaci/kcp-go"
"github.com/xtaci/smux"
"path/filepath"
)
var (
@@ -28,11 +29,6 @@ var (
SALT = "kcp-go"
)
// global recycle buffer
var copyBuf sync.Pool
const bufSize = 4096
type compStream struct {
conn net.Conn
w *snappy.Writer
@@ -61,9 +57,12 @@ func newCompStream(conn net.Conn) *compStream {
return c
}
func handleClient(sess *smux.Session, p1 io.ReadWriteCloser) {
log.Println("stream opened")
defer log.Println("stream closed")
func handleClient(sess *smux.Session, p1 io.ReadWriteCloser, quiet bool) {
if !quiet {
log.Println("stream opened")
defer log.Println("stream closed")
}
defer p1.Close()
p2, err := sess.OpenStream()
if err != nil {
@@ -73,20 +72,10 @@ func handleClient(sess *smux.Session, p1 io.ReadWriteCloser) {
// start tunnel
p1die := make(chan struct{})
go func() {
buf := copyBuf.Get().([]byte)
io.CopyBuffer(p1, p2, buf)
close(p1die)
copyBuf.Put(buf)
}()
go func() { io.Copy(p1, p2); close(p1die) }()
p2die := make(chan struct{})
go func() {
buf := copyBuf.Get().([]byte)
io.CopyBuffer(p2, p1, buf)
close(p2die)
copyBuf.Put(buf)
}()
go func() { io.Copy(p2, p1); close(p2die) }()
// wait for tunnel termination
select {
@@ -104,9 +93,6 @@ func checkError(err error) {
func main() {
rand.Seed(int64(time.Now().Nanosecond()))
copyBuf.New = func() interface{} {
return make([]byte, bufSize)
}
if VERSION == "SELFBUILD" {
// add more log flags for debugging
log.SetFlags(log.LstdFlags | log.Lshortfile)
@@ -135,7 +121,7 @@ func main() {
cli.StringFlag{
Name: "crypt",
Value: "aes",
Usage: "aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, none",
Usage: "aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, sm4, none",
},
cli.StringFlag{
Name: "mode",
@@ -241,6 +227,10 @@ func main() {
Value: "",
Usage: "specify a log file to output, default goes to stderr",
},
cli.BoolFlag{
Name: "quiet",
Usage: "to suppress the 'stream open/close' messages",
},
cli.StringFlag{
Name: "c",
Value: "", // when the value is not empty, the config path must exists
@@ -274,6 +264,7 @@ func main() {
config.Log = c.String("log")
config.SnmpLog = c.String("snmplog")
config.SnmpPeriod = c.Int("snmpperiod")
config.Quiet = c.Bool("quiet")
if c.String("c") != "" {
err := parseJSONConfig(&config, c.String("c"))
@@ -305,9 +296,12 @@ func main() {
listener, err := net.ListenTCP("tcp", addr)
checkError(err)
log.Println("initiating key derivation")
pass := pbkdf2.Key([]byte(config.Key), []byte(SALT), 4096, 32, sha1.New)
var block kcp.BlockCrypt
switch config.Crypt {
case "sm4":
block, _ = kcp.NewSM4BlockCrypt(pass[:16])
case "tea":
block, _ = kcp.NewTEABlockCrypt(pass[:16])
case "xor":
@@ -352,6 +346,7 @@ func main() {
log.Println("scavengettl:", config.ScavengeTTL)
log.Println("snmplog:", config.SnmpLog)
log.Println("snmpperiod:", config.SnmpPeriod)
log.Println("quiet:", config.Quiet)
smuxConfig := smux.DefaultConfig()
smuxConfig.MaxReceiveBuffer = config.SockBuf
@@ -399,6 +394,7 @@ func main() {
if session, err := createConn(); err == nil {
return session
} else {
log.Println("re-connecting:", err)
time.Sleep(time.Second)
}
}
@@ -434,7 +430,7 @@ func main() {
muxes[idx].ttl = time.Now().Add(time.Duration(config.AutoExpire) * time.Second)
}
go handleClient(muxes[idx].session, p1)
go handleClient(muxes[idx].session, p1, config.Quiet)
rr++
}
}
@@ -483,7 +479,10 @@ func snmpLogger(path string, interval int) {
for {
select {
case <-ticker.C:
f, err := os.OpenFile(time.Now().Format(path), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
// split path into dirname and filename
logdir, logfile := filepath.Split(path)
// only format logfile
f, err := os.OpenFile(logdir+time.Now().Format(logfile), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Println(err)
return
+1
View File
@@ -18,6 +18,7 @@ func init() {
func sigHandler() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGUSR1)
signal.Ignore(syscall.SIGPIPE)
for {
switch <-ch {
+1
View File
@@ -30,6 +30,7 @@ type Config struct {
SnmpLog string `json:"snmplog"`
SnmpPeriod int `json:"snmpperiod"`
Pprof bool `json:"pprof"`
Quiet bool `json:"quiet"`
}
func parseJSONConfig(config *Config, path string) error {
+24 -27
View File
@@ -11,11 +11,12 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"sync"
"time"
"golang.org/x/crypto/pbkdf2"
"path/filepath"
"github.com/golang/snappy"
"github.com/urfave/cli"
kcp "github.com/xtaci/kcp-go"
@@ -29,11 +30,6 @@ var (
SALT = "kcp-go"
)
// global recycle buffer
var copyBuf sync.Pool
const bufSize = 4096
type compStream struct {
conn net.Conn
w *snappy.Writer
@@ -87,32 +83,24 @@ func handleMux(conn io.ReadWriteCloser, config *Config) {
log.Println(err)
continue
}
go handleClient(p1, p2)
go handleClient(p1, p2, config.Quiet)
}
}
func handleClient(p1, p2 io.ReadWriteCloser) {
log.Println("stream opened")
defer log.Println("stream closed")
func handleClient(p1, p2 io.ReadWriteCloser, quiet bool) {
if !quiet {
log.Println("stream opened")
defer log.Println("stream closed")
}
defer p1.Close()
defer p2.Close()
// start tunnel
p1die := make(chan struct{})
go func() {
buf := copyBuf.Get().([]byte)
io.CopyBuffer(p1, p2, buf)
close(p1die)
copyBuf.Put(buf)
}()
go func() { io.Copy(p1, p2); close(p1die) }()
p2die := make(chan struct{})
go func() {
buf := copyBuf.Get().([]byte)
io.CopyBuffer(p2, p1, buf)
close(p2die)
copyBuf.Put(buf)
}()
go func() { io.Copy(p2, p1); close(p2die) }()
// wait for tunnel termination
select {
@@ -130,9 +118,6 @@ func checkError(err error) {
func main() {
rand.Seed(int64(time.Now().Nanosecond()))
copyBuf.New = func() interface{} {
return make([]byte, bufSize)
}
if VERSION == "SELFBUILD" {
// add more log flags for debugging
log.SetFlags(log.LstdFlags | log.Lshortfile)
@@ -161,7 +146,7 @@ func main() {
cli.StringFlag{
Name: "crypt",
Value: "aes",
Usage: "aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, none",
Usage: "aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, sm4, none",
},
cli.StringFlag{
Name: "mode",
@@ -256,6 +241,10 @@ func main() {
Value: "",
Usage: "specify a log file to output, default goes to stderr",
},
cli.BoolFlag{
Name: "quiet",
Usage: "to suppress the 'stream open/close' messages",
},
cli.StringFlag{
Name: "c",
Value: "", // when the value is not empty, the config path must exists
@@ -287,6 +276,7 @@ func main() {
config.SnmpLog = c.String("snmplog")
config.SnmpPeriod = c.Int("snmpperiod")
config.Pprof = c.Bool("pprof")
config.Quiet = c.Bool("quiet")
if c.String("c") != "" {
//Now only support json config file
@@ -314,9 +304,12 @@ func main() {
}
log.Println("version:", VERSION)
log.Println("initiating key derivation")
pass := pbkdf2.Key([]byte(config.Key), []byte(SALT), 4096, 32, sha1.New)
var block kcp.BlockCrypt
switch config.Crypt {
case "sm4":
block, _ = kcp.NewSM4BlockCrypt(pass[:16])
case "tea":
block, _ = kcp.NewTEABlockCrypt(pass[:16])
case "xor":
@@ -361,6 +354,7 @@ func main() {
log.Println("snmplog:", config.SnmpLog)
log.Println("snmpperiod:", config.SnmpPeriod)
log.Println("pprof:", config.Pprof)
log.Println("quiet:", config.Quiet)
if err := lis.SetDSCP(config.DSCP); err != nil {
log.Println("SetDSCP:", err)
@@ -409,7 +403,10 @@ func snmpLogger(path string, interval int) {
for {
select {
case <-ticker.C:
f, err := os.OpenFile(time.Now().Format(path), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
// split path into dirname and filename
logdir, logfile := filepath.Split(path)
// only format logfile
f, err := os.OpenFile(logdir+time.Now().Format(logfile), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Println(err)
return
+1
View File
@@ -18,6 +18,7 @@ func init() {
func sigHandler() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGUSR1)
signal.Ignore(syscall.SIGPIPE)
for {
switch <-ch {