From bcca92affcebccbd8f4d7a81797de5fecf7cd33b Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Tue, 23 Oct 2018 14:08:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86socks5=E7=9A=84U?= =?UTF-8?q?DP=E5=8A=9F=E8=83=BD=E5=8F=AF=E8=83=BD=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8=E8=BF=87=E5=A4=9A?= =?UTF-8?q?=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 1 + services/socks/udp.go | 4 ++-- services/sps/socksudp.go | 4 ++-- services/sps/ssudp.go | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 58eff61..d981466 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ proxy更新日志 v6.4 1.http(s)代理增加了--jumper参数,可以穿透外部代理连接上级. +2.优化了socks5代理UDP功能可能存在的内存占用过多问题. v6.3 1.fixed #156 diff --git a/services/socks/udp.go b/services/socks/udp.go index 5d9ebd1..582024b 100644 --- a/services/socks/udp.go +++ b/services/socks/udp.go @@ -174,9 +174,9 @@ func (s *Socks) proxyUDP(inConn *net.Conn, serverConn *socks.ServerConn) { } s.log.Printf("use proxy %v : udp %s", useProxy, serverConn.Target()) //relay + buf := utils.LeakyBuffer.Get() + defer utils.LeakyBuffer.Put(buf) for { - buf := utils.LeakyBuffer.Get() - defer utils.LeakyBuffer.Put(buf) n, srcAddr, err := udpListener.ReadFromUDP(buf) if err != nil { s.log.Printf("udp listener read fail, %s", err.Error()) diff --git a/services/sps/socksudp.go b/services/sps/socksudp.go index cc52f38..5a58eb4 100644 --- a/services/sps/socksudp.go +++ b/services/sps/socksudp.go @@ -126,9 +126,9 @@ func (s *SPS) proxyUDP(inConn *net.Conn, serverConn *socks.ServerConn) { //s.log.Printf("parent udp address %s", client.UDPAddr) destAddr, _ = net.ResolveUDPAddr("udp", client.UDPAddr) //relay + buf := utils.LeakyBuffer.Get() + defer utils.LeakyBuffer.Put(buf) for { - buf := utils.LeakyBuffer.Get() - defer utils.LeakyBuffer.Put(buf) n, srcAddr, err := udpListener.ReadFromUDP(buf) if err != nil { s.log.Printf("udp listener read fail, %s", err.Error()) diff --git a/services/sps/ssudp.go b/services/sps/ssudp.go index 9eccf1e..a3dd71a 100644 --- a/services/sps/ssudp.go +++ b/services/sps/ssudp.go @@ -27,9 +27,9 @@ func (s *SPS) RunSSUDP(addr string) (err error) { s.log.Printf("udp local->out io copy crashed:\n%s\n%s", e, string(debug.Stack())) } }() + buf := utils.LeakyBuffer.Get() + defer utils.LeakyBuffer.Put(buf) for { - buf := utils.LeakyBuffer.Get() - defer utils.LeakyBuffer.Put(buf) n, srcAddr, err := listener.ReadFrom(buf) if err != nil { s.log.Printf("read from client error %s", err) From f0389cdd5b09a6974186d620062163d5db6bf80c Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Fri, 26 Oct 2018 14:25:45 +0800 Subject: [PATCH 2/3] fix #164 --- services/mux/mux_client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/mux/mux_client.go b/services/mux/mux_client.go index 9e9ab6a..1cdcaf6 100644 --- a/services/mux/mux_client.go +++ b/services/mux/mux_client.go @@ -242,9 +242,9 @@ func (s *MuxClient) getParentConn() (conn net.Conn, err error) { conn = net.Conn(&_conn) } } else { - conf, err := utils.TlsConfig(s.cfg.CertBytes, s.cfg.KeyBytes, nil) - if err != nil { - return nil, err + conf, e := utils.TlsConfig(s.cfg.CertBytes, s.cfg.KeyBytes, nil) + if e != nil { + return nil, e } var _c net.Conn _c, err = s.jumper.Dial(*s.cfg.Parent, time.Millisecond*time.Duration(*s.cfg.Timeout)) From 9e496f246ce382af0d6d9b56edd148bfe6f6ba73 Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Wed, 31 Oct 2018 14:49:37 +0800 Subject: [PATCH 3/3] a --- CHANGELOG | 1 + VERSION | 2 +- utils/jumper/jumper.go | 19 ++++++++++--------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d981466..78b5640 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ proxy更新日志 v6.4 1.http(s)代理增加了--jumper参数,可以穿透外部代理连接上级. 2.优化了socks5代理UDP功能可能存在的内存占用过多问题. +3.优化了jumper,避免某些情况下不能正确返回错误的问题. v6.3 1.fixed #156 diff --git a/VERSION b/VERSION index 1f2be2a..124bfa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.3 \ No newline at end of file +6.4 \ No newline at end of file diff --git a/utils/jumper/jumper.go b/utils/jumper/jumper.go index 11fe4eb..4e26029 100644 --- a/utils/jumper/jumper.go +++ b/utils/jumper/jumper.go @@ -24,8 +24,9 @@ func (s socks5Dialer) Dial(network, addr string) (net.Conn, error) { } func New(proxyURL string, timeout time.Duration) (j Jumper, err error) { - u, err := url.Parse(proxyURL) - if err != nil { + u, e := url.Parse(proxyURL) + if e != nil { + err = e return } j = Jumper{ @@ -34,7 +35,7 @@ func New(proxyURL string, timeout time.Duration) (j Jumper, err error) { } return } -func (j *Jumper) Dial(address string, timeout time.Duration) (conn net.Conn, err error) { +func (j *Jumper) Dial(address string, timeout time.Duration) (net.Conn, error) { switch j.proxyURL.Scheme { case "https": return j.dialHTTPS(address, timeout) @@ -70,10 +71,10 @@ func (j *Jumper) dialHTTPS(address string, timeout time.Duration) (conn net.Conn } reply := make([]byte, 1024) conn.SetDeadline(time.Now().Add(timeout)) - n, err := conn.Read(reply) + n, e := conn.Read(reply) conn.SetDeadline(time.Time{}) - if err != nil { - err = fmt.Errorf("error read reply from proxy: %s", err) + if e != nil { + err = fmt.Errorf("error read reply from proxy: %s", e) conn.Close() conn = nil return @@ -94,9 +95,9 @@ func (j *Jumper) dialSOCKS5(address string, timeout time.Duration) (conn net.Con } else { auth = nil } - dialSocksProxy, err := proxy.SOCKS5("tcp", j.proxyURL.Host, auth, socks5Dialer{timeout: timeout}) - if err != nil { - err = fmt.Errorf("error connecting to proxy: %s", err) + dialSocksProxy, e := proxy.SOCKS5("tcp", j.proxyURL.Host, auth, socks5Dialer{timeout: timeout}) + if e != nil { + err = fmt.Errorf("error connecting to proxy: %s", e) return } return dialSocksProxy.Dial("tcp", address)