diff --git a/services/http.go b/services/http.go index a9fb03c..043ae1c 100644 --- a/services/http.go +++ b/services/http.go @@ -239,7 +239,7 @@ func (s *HTTP) OutToTCP(useProxy bool, address string, inConn *net.Conn, req *ut log.Printf("conn %s - %s - %s - %s released [%s]", inAddr, inLocalAddr, outLocalAddr, outAddr, req.Host) utils.CloseConn(inConn) utils.CloseConn(&outConn) - }, func(n int, d bool) {}, 0) + }) log.Printf("conn %s - %s - %s - %s connected [%s]", inAddr, inLocalAddr, outLocalAddr, outAddr, req.Host) return diff --git a/services/tcp.go b/services/tcp.go index faf1db4..9b44671 100644 --- a/services/tcp.go +++ b/services/tcp.go @@ -109,7 +109,7 @@ func (s *TCP) OutToTCP(inConn *net.Conn) (err error) { log.Printf("conn %s - %s - %s - %s released", inAddr, inLocalAddr, outLocalAddr, outAddr) utils.CloseConn(inConn) utils.CloseConn(&outConn) - }, func(n int, d bool) {}, 0) + }) log.Printf("conn %s - %s - %s - %s connected", inAddr, inLocalAddr, outLocalAddr, outAddr) return } diff --git a/services/tunnel_bridge.go b/services/tunnel_bridge.go index e66138e..1bdd726 100644 --- a/services/tunnel_bridge.go +++ b/services/tunnel_bridge.go @@ -119,7 +119,7 @@ func (s *TunnelBridge) Start(args interface{}) (err error) { s.cmClient.RemoveOne(key, ID) s.cmServer.RemoveOne(serverID, ID) log.Printf("conn %s released", ID) - }, func(i int, b bool) {}, 0) + }) s.cmClient.Add(key, ID, &inConn) log.Printf("conn %s created", ID) diff --git a/services/tunnel_client.go b/services/tunnel_client.go index b48e507..61b1aa6 100644 --- a/services/tunnel_client.go +++ b/services/tunnel_client.go @@ -228,7 +228,7 @@ func (s *TunnelClient) ServeConn(localAddr, ID, serverID string) { utils.CloseConn(&inConn) utils.CloseConn(&outConn) s.cm.RemoveOne(*s.cfg.Key, ID) - }, func(i int, b bool) {}, 0) + }) s.cm.Add(*s.cfg.Key, ID, &inConn) log.Printf("conn %s created", ID) } diff --git a/services/tunnel_server.go b/services/tunnel_server.go index aa3c66f..e333106 100644 --- a/services/tunnel_server.go +++ b/services/tunnel_server.go @@ -244,7 +244,7 @@ func (s *TunnelServer) Start(args interface{}) (err error) { utils.CloseConn(&inConn) s.cfg.Mgr.cm.RemoveOne(s.cfg.Mgr.serverID, ID) log.Printf("%s conn %s released", *s.cfg.Key, ID) - }, func(i int, b bool) {}, 0) + }) //add conn s.cfg.Mgr.cm.Add(s.cfg.Mgr.serverID, ID, &inConn) log.Printf("%s conn %s created", *s.cfg.Key, ID) diff --git a/utils/functions.go b/utils/functions.go index 1de7cfd..58adac4 100755 --- a/utils/functions.go +++ b/utils/functions.go @@ -50,7 +50,7 @@ func IoBind0(dst io.ReadWriter, src io.ReadWriter, fn func(err error)) { }() }() } -func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error), cfn func(count int, isPositive bool), bytesPreSec float64) { +func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error)) { var one = &sync.Once{} go func() { defer func() { @@ -59,18 +59,7 @@ func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error), cfn func(c } }() var err error - if bytesPreSec > 0 { - newreader := NewReader(src) - newreader.SetRateLimit(bytesPreSec) - _, err = ioCopy(dst, newreader, func(c int) { - cfn(c, false) - }) - - } else { - _, err = ioCopy(dst, src, func(c int) { - cfn(c, false) - }) - } + _, err = ioCopy(dst, src) if err != nil { one.Do(func() { fn(err) @@ -84,17 +73,7 @@ func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error), cfn func(c } }() var err error - if bytesPreSec > 0 { - newReader := NewReader(dst) - newReader.SetRateLimit(bytesPreSec) - _, err = ioCopy(src, newReader, func(c int) { - cfn(c, true) - }) - } else { - _, err = ioCopy(src, dst, func(c int) { - cfn(c, true) - }) - } + _, err = ioCopy(src, dst) if err != nil { one.Do(func() { fn(err) @@ -102,31 +81,24 @@ func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error), cfn func(c } }() } -func ioCopy(dst io.Writer, src io.Reader, fn ...func(count int)) (written int64, err error) { +func ioCopy(dst io.Writer, src io.Reader) (written int64, err error) { buf := make([]byte, 32*1024) for { nr, er := src.Read(buf) - if nr > 0 { - nw, ew := dst.Write(buf[0:nr]) - if nw > 0 { - written += int64(nw) - if len(fn) == 1 { - fn[0](nw) - } - } - if ew != nil { - err = ew - break - } - if nr != nw { - err = io.ErrShortWrite - break - } - } if er != nil { err = er break } + nw, ew := dst.Write(buf[0:nr]) + if ew != nil { + err = ew + break + } + if nr != nw { + err = io.ErrShortWrite + break + } + written += int64(nw) } return written, err }