From 56f8016d1e079ba70ad51e34ad509f31f64c37fa Mon Sep 17 00:00:00 2001 From: Mark Pashmfouroush Date: Mon, 15 Apr 2024 11:10:43 +0100 Subject: [PATCH] more tweaks Signed-off-by: Mark Pashmfouroush --- go.mod | 1 + go.sum | 2 ++ proxy/pkg/mixed/proxy.go | 2 +- proxy/pkg/socks5/server.go | 7 ++++--- wireguard/device/queueconstants_default.go | 2 +- wireguard/device/queueconstants_windows.go | 2 +- wiresocks/proxy.go | 3 +++ 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 24570eb22..87038ee71 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/quic-go/quic-go v0.40.1 github.com/refraction-networking/utls v1.3.3 github.com/rodaine/table v1.1.1 + github.com/things-go/go-socks5 v0.0.5 golang.org/x/crypto v0.21.0 golang.org/x/net v0.22.0 golang.org/x/sys v0.18.0 diff --git a/go.sum b/go.sum index 85422b980..6f07a00c5 100644 --- a/go.sum +++ b/go.sum @@ -204,6 +204,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/things-go/go-socks5 v0.0.5 h1:qvKaGcBkfDrUL33SchHN93srAmYGzb4CxSM2DPYufe8= +github.com/things-go/go-socks5 v0.0.5/go.mod h1:mtzInf8v5xmsBpHZVbIw2YQYhc4K0jRwzfsH64Uh0IQ= github.com/wader/filtertransport v0.0.0-20200316221534-bdd9e61eee78 h1:9sreu9e9KOihf2Y0NbpyfWhd1XFDcL4GTkPYL4IvMrg= github.com/wader/filtertransport v0.0.0-20200316221534-bdd9e61eee78/go.mod h1:HazXTRLhXFyq80TQp7PUXi6BKE6mS+ydEdzEqNBKopQ= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/proxy/pkg/mixed/proxy.go b/proxy/pkg/mixed/proxy.go index 3732c9fcd..d90eb4406 100644 --- a/proxy/pkg/mixed/proxy.go +++ b/proxy/pkg/mixed/proxy.go @@ -70,7 +70,7 @@ type SwitchConn struct { func NewSwitchConn(conn net.Conn) *SwitchConn { return &SwitchConn{ Conn: conn, - Reader: bufio.NewReader(conn), + Reader: bufio.NewReaderSize(conn, 1500), } } diff --git a/proxy/pkg/socks5/server.go b/proxy/pkg/socks5/server.go index ff6be811a..f36985441 100644 --- a/proxy/pkg/socks5/server.go +++ b/proxy/pkg/socks5/server.go @@ -7,6 +7,7 @@ import ( "io" "log/slog" "net" + "time" "github.com/bepass-org/warp-plus/proxy/pkg/statute" ) @@ -350,13 +351,12 @@ func (s *Server) handleAssociate(req *request) error { } func (s *Server) embedHandleAssociate(req *request, udpConn net.PacketConn) error { - defer func() { - _ = udpConn.Close() - }() + defer udpConn.Close() go func() { var buf [1]byte for { + req.Conn.SetReadDeadline(time.Now().Add(15 * time.Second)) _, err := req.Conn.Read(buf[:]) if err != nil { _ = udpConn.Close() @@ -375,6 +375,7 @@ func (s *Server) embedHandleAssociate(req *request, udpConn net.PacketConn) erro ) for { + udpConn.SetReadDeadline(time.Now().Add(15 * time.Second)) n, addr, err := udpConn.ReadFrom(buf[:]) if err != nil { return err diff --git a/wireguard/device/queueconstants_default.go b/wireguard/device/queueconstants_default.go index ae02b6387..4d03f9344 100644 --- a/wireguard/device/queueconstants_default.go +++ b/wireguard/device/queueconstants_default.go @@ -15,5 +15,5 @@ const ( QueueInboundSize = 1024 QueueHandshakeSize = 1024 MaxSegmentSize = (1 << 16) - 1 // largest possible UDP datagram - PreallocatedBuffersPerPool = 4096 // Disable and allow for infinite memory growth + PreallocatedBuffersPerPool = 2048 // Disable and allow for infinite memory growth ) diff --git a/wireguard/device/queueconstants_windows.go b/wireguard/device/queueconstants_windows.go index 3404afbf0..1eee32ba1 100644 --- a/wireguard/device/queueconstants_windows.go +++ b/wireguard/device/queueconstants_windows.go @@ -11,5 +11,5 @@ const ( QueueInboundSize = 1024 QueueHandshakeSize = 1024 MaxSegmentSize = 2048 - 32 // largest possible UDP datagram - PreallocatedBuffersPerPool = 4096 // Disable and allow for infinite memory growth + PreallocatedBuffersPerPool = 0 // Disable and allow for infinite memory growth ) diff --git a/wiresocks/proxy.go b/wiresocks/proxy.go index 7f43f8014..df7219690 100644 --- a/wiresocks/proxy.go +++ b/wiresocks/proxy.go @@ -11,6 +11,8 @@ import ( "github.com/bepass-org/warp-plus/proxy/pkg/statute" "github.com/bepass-org/warp-plus/wireguard/device" "github.com/bepass-org/warp-plus/wireguard/tun/netstack" + + "github.com/things-go/go-socks5/bufferpool" ) // VirtualTun stores a reference to netstack network and DNS configuration @@ -35,6 +37,7 @@ func (vt *VirtualTun) StartProxy(bindAddress netip.AddrPort) (netip.AddrPort, er mixed.WithUserHandler(func(request *statute.ProxyRequest) error { return vt.generalHandler(request) }), + mixed.WithBytesPool(bufferpool.NewPool(256*1024)), ) go func() { _ = proxy.ListenAndServe()