mirror of
https://github.com/xtaci/kcptun.git
synced 2024-04-21 12:32:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f8d762742 | ||
|
|
e3ab00cf5b | ||
|
|
42bf13fb7a | ||
|
|
03f27ec53d | ||
|
|
b2390a5dd3 |
@@ -27,6 +27,10 @@
|
||||
|
||||
### QuickStart
|
||||
|
||||
Increase number of open files on your server, as:
|
||||
|
||||
`ulimit -n 65535`, or write it in `~/.bashrc`.
|
||||
|
||||
Download precompiled [Releases](https://github.com/xtaci/kcptun/releases).
|
||||
|
||||
```
|
||||
|
||||
+18
-8
@@ -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 (
|
||||
@@ -69,12 +70,18 @@ func handleClient(sess *smux.Session, p1 io.ReadWriteCloser, quiet bool) {
|
||||
}
|
||||
defer p2.Close()
|
||||
|
||||
// tunnel setup
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() { io.Copy(p1, p2); wg.Done() }()
|
||||
go func() { io.Copy(p2, p1); wg.Done() }()
|
||||
wg.Wait()
|
||||
// start tunnel
|
||||
p1die := make(chan struct{})
|
||||
go func() { io.Copy(p1, p2); close(p1die) }()
|
||||
|
||||
p2die := make(chan struct{})
|
||||
go func() { io.Copy(p2, p1); close(p2die) }()
|
||||
|
||||
// wait for tunnel termination
|
||||
select {
|
||||
case <-p1die:
|
||||
case <-p2die:
|
||||
}
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
@@ -471,7 +478,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
|
||||
|
||||
+18
-8
@@ -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"
|
||||
@@ -94,12 +95,18 @@ func handleClient(p1, p2 io.ReadWriteCloser, quiet bool) {
|
||||
defer p1.Close()
|
||||
defer p2.Close()
|
||||
|
||||
// tunnel setup
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() { io.Copy(p1, p2); wg.Done() }()
|
||||
go func() { io.Copy(p2, p1); wg.Done() }()
|
||||
wg.Wait()
|
||||
// start tunnel
|
||||
p1die := make(chan struct{})
|
||||
go func() { io.Copy(p1, p2); close(p1die) }()
|
||||
|
||||
p2die := make(chan struct{})
|
||||
go func() { io.Copy(p2, p1); close(p2die) }()
|
||||
|
||||
// wait for tunnel termination
|
||||
select {
|
||||
case <-p1die:
|
||||
case <-p2die:
|
||||
}
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
@@ -395,7 +402,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
|
||||
|
||||
Reference in New Issue
Block a user