@@ -3,6 +3,7 @@ package wiresocks
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "github.com/sagernet/sing/common/buf"
6
7
"io"
7
8
"log/slog"
8
9
"net"
@@ -14,7 +15,6 @@ import (
14
15
"github.com/bepass-org/warp-plus/proxy/pkg/statute"
15
16
"github.com/bepass-org/warp-plus/wireguard/device"
16
17
"github.com/bepass-org/warp-plus/wireguard/tun/netstack"
17
- "github.com/things-go/go-socks5/bufferpool"
18
18
)
19
19
20
20
// VirtualTun stores a reference to netstack network and DNS configuration
@@ -23,9 +23,12 @@ type VirtualTun struct {
23
23
Logger * slog.Logger
24
24
Dev * device.Device
25
25
Ctx context.Context
26
- pool bufferpool.BufPool
26
+ pool buf.Allocator
27
+ //pool bufferpool.BufPool
27
28
}
28
29
30
+ var BuffSize = 65536
31
+
29
32
// StartProxy spawns a socks5 server.
30
33
func StartProxy (ctx context.Context , l * slog.Logger , tnet * netstack.Net , bindAddress netip.AddrPort ) (netip.AddrPort , error ) {
31
34
ln , err := net .Listen ("tcp" , bindAddress .String ())
@@ -38,7 +41,7 @@ func StartProxy(ctx context.Context, l *slog.Logger, tnet *netstack.Net, bindAdd
38
41
Logger : l .With ("subsystem" , "vtun" ),
39
42
Dev : nil ,
40
43
Ctx : ctx ,
41
- pool : bufferpool . NewPool ( 256 * 1024 ) ,
44
+ pool : buf . DefaultAllocator ,
42
45
}
43
46
44
47
proxy := mixed .NewProxy (
@@ -80,9 +83,11 @@ func (vt *VirtualTun) generalHandler(req *statute.ProxyRequest) error {
80
83
done := make (chan error , 1 )
81
84
// Copy data from req.Conn to conn
82
85
go func () {
83
- buf1 := vt .pool .Get ()
84
- defer vt .pool .Put (buf1 )
85
- _ , err := copyConnTimeout (conn , req .Conn , buf1 [:cap (buf1 )], timeout )
86
+ buf1 := vt .pool .Get (BuffSize )
87
+ defer func (pool buf.Allocator , buf []byte ) {
88
+ _ = pool .Put (buf )
89
+ }(vt .pool , buf1 )
90
+ _ , err := copyConnTimeout (conn , req .Conn , buf1 , timeout )
86
91
if errors .Is (err , syscall .ECONNRESET ) {
87
92
done <- nil
88
93
return
@@ -91,9 +96,11 @@ func (vt *VirtualTun) generalHandler(req *statute.ProxyRequest) error {
91
96
}()
92
97
// Copy data from conn to req.Conn
93
98
go func () {
94
- buf2 := vt .pool .Get ()
95
- defer vt .pool .Put (buf2 )
96
- _ , err := copyConnTimeout (req .Conn , conn , buf2 [:cap (buf2 )], timeout )
99
+ buf2 := vt .pool .Get (BuffSize )
100
+ defer func (pool buf.Allocator , buf []byte ) {
101
+ _ = pool .Put (buf )
102
+ }(vt .pool , buf2 )
103
+ _ , err := copyConnTimeout (req .Conn , conn , buf2 , timeout )
97
104
done <- err
98
105
}()
99
106
// Wait for one of the copy operations to finish
0 commit comments