From bcca92affcebccbd8f4d7a81797de5fecf7cd33b Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Tue, 23 Oct 2018 14:08:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86socks5=E7=9A=84UDP?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=AF=E8=83=BD=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8=E8=BF=87=E5=A4=9A=E9=97=AE?= =?UTF-8?q?=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)