Compare commits

..
7 Commits
Author SHA1 Message Date
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
xtaci acf7a01922 adjust parameters based on improvements in kcp-go 2017-03-21 22:29:05 +08:00
xtaciandGitHub ee01d61266 Update README.md 2017-03-20 12:57:48 +08:00
xtaciandGitHub fd7ed8532e Update README.md 2017-03-20 12:56:23 +08:00
xtaci ff9e3d699b add SetWriteDelay func 2017-03-18 13:07:34 +08:00
6 changed files with 19 additions and 54 deletions
+1 -1
View File
@@ -3,6 +3,6 @@ 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
EXPOSE 29900/udp
EXPOSE 12948
+2 -3
View File
@@ -1,5 +1,7 @@
# <img src="logo.png" alt="kcptun" height="54px" />
[![Release][13]][14] [![Powered][17]][18] [![MIT licensed][11]][12] [![Build Status][3]][4] [![Go Report Card][5]][6] [![Downloads][15]][16] [![Docker][1]][2]
[1]: https://images.microbadger.com/badges/image/xtaci/kcptun.svg
[2]: https://microbadger.com/images/xtaci/kcptun
[3]: https://travis-ci.org/xtaci/kcptun.svg?branch=master
@@ -17,11 +19,8 @@
[17]: https://img.shields.io/badge/KCP-Powered-blue.svg
[18]: https://github.com/skywind3000/kcp
<img src="kcptun.png" alt="kcptun" height="300px"/>
-
### QuickStart
Download precompiled [Releases](https://github.com/xtaci/kcptun/releases).
+7 -25
View File
@@ -9,7 +9,6 @@ import (
"math/rand"
"net"
"os"
"sync"
"time"
"golang.org/x/crypto/pbkdf2"
@@ -28,11 +27,6 @@ var (
SALT = "kcp-go"
)
// global recycle buffer
var copyBuf sync.Pool
const bufSize = 4096
type compStream struct {
conn net.Conn
w *snappy.Writer
@@ -73,20 +67,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 +88,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)
@@ -290,13 +271,13 @@ func main() {
switch config.Mode {
case "normal":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 0, 50, 2, 1
case "fast":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 0, 40, 2, 1
case "fast":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 0, 30, 2, 1
case "fast2":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 1, 30, 2, 1
case "fast3":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 1, 20, 2, 1
case "fast3":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 1, 10, 2, 1
}
log.Println("version:", VERSION)
@@ -363,6 +344,7 @@ func main() {
return nil, errors.Wrap(err, "createConn()")
}
kcpconn.SetStreamMode(true)
kcpconn.SetWriteDelay(true)
kcpconn.SetNoDelay(config.NoDelay, config.Interval, config.Resend, config.NoCongestion)
kcpconn.SetWindowSize(config.SndWnd, config.RcvWnd)
kcpconn.SetMtu(config.MTU)
+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 {
+7 -25
View File
@@ -11,7 +11,6 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"sync"
"time"
"golang.org/x/crypto/pbkdf2"
@@ -29,11 +28,6 @@ var (
SALT = "kcp-go"
)
// global recycle buffer
var copyBuf sync.Pool
const bufSize = 4096
type compStream struct {
conn net.Conn
w *snappy.Writer
@@ -99,20 +93,10 @@ func handleClient(p1, p2 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 {
@@ -130,9 +114,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)
@@ -304,13 +285,13 @@ func main() {
switch config.Mode {
case "normal":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 0, 50, 2, 1
case "fast":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 0, 40, 2, 1
case "fast":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 0, 30, 2, 1
case "fast2":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 1, 30, 2, 1
case "fast3":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 1, 20, 2, 1
case "fast3":
config.NoDelay, config.Interval, config.Resend, config.NoCongestion = 1, 10, 2, 1
}
log.Println("version:", VERSION)
@@ -381,6 +362,7 @@ func main() {
if conn, err := lis.AcceptKCP(); err == nil {
log.Println("remote address:", conn.RemoteAddr())
conn.SetStreamMode(true)
conn.SetWriteDelay(true)
conn.SetNoDelay(config.NoDelay, config.Interval, config.Resend, config.NoCongestion)
conn.SetMtu(config.MTU)
conn.SetWindowSize(config.SndWnd, config.RcvWnd)
+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 {