Compare commits

...
5 Commits
Author SHA1 Message Date
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
3 changed files with 40 additions and 16 deletions
+4
View File
@@ -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
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 (
@@ -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
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"
@@ -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