diff --git a/common/pool/buffer.go b/common/pool/buffer.go deleted file mode 100644 index 18d14b8..0000000 --- a/common/pool/buffer.go +++ /dev/null @@ -1,17 +0,0 @@ -package pool - -import ( - "bytes" - "sync" -) - -var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} - -func GetBuffer() *bytes.Buffer { - return bufferPool.Get().(*bytes.Buffer) -} - -func PutBuffer(buf *bytes.Buffer) { - buf.Reset() - bufferPool.Put(buf) -} diff --git a/common/pool/alloc.go b/internal/pool/alloc.go similarity index 96% rename from common/pool/alloc.go rename to internal/pool/alloc.go index 80f320f..9a4cc10 100644 --- a/common/pool/alloc.go +++ b/internal/pool/alloc.go @@ -51,8 +51,7 @@ func (alloc *Allocator) Put(buf []byte) error { return errors.New("allocator Put() incorrect buffer size") } - //lint:ignore SA6002 ignore temporarily - //nolint + //nolint:staticcheck alloc.buffers[b].Put(buf) return nil } diff --git a/common/pool/alloc_test.go b/internal/pool/alloc_test.go similarity index 100% rename from common/pool/alloc_test.go rename to internal/pool/alloc_test.go diff --git a/internal/pool/buffer.go b/internal/pool/buffer.go new file mode 100644 index 0000000..9762b08 --- /dev/null +++ b/internal/pool/buffer.go @@ -0,0 +1,17 @@ +package pool + +import ( + "bytes" + "sync" +) + +var _bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} + +func GetBuffer() *bytes.Buffer { + return _bufferPool.Get().(*bytes.Buffer) +} + +func PutBuffer(buf *bytes.Buffer) { + buf.Reset() + _bufferPool.Put(buf) +} diff --git a/common/pool/pool.go b/internal/pool/pool.go similarity index 100% rename from common/pool/pool.go rename to internal/pool/pool.go diff --git a/proxy/relay.go b/proxy/relay.go index 2fba60a..87343e7 100644 --- a/proxy/relay.go +++ b/proxy/relay.go @@ -13,8 +13,8 @@ import ( "github.com/go-gost/relay" - "github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/dialer" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" M "github.com/xjasonlyu/tun2socks/v2/metadata" "github.com/xjasonlyu/tun2socks/v2/proxy/proto" ) diff --git a/transport/shadowsocks/shadowaead/packet.go b/transport/shadowsocks/shadowaead/packet.go index ecbb914..91b0bf4 100755 --- a/transport/shadowsocks/shadowaead/packet.go +++ b/transport/shadowsocks/shadowaead/packet.go @@ -6,7 +6,7 @@ import ( "io" "net" - "github.com/xjasonlyu/tun2socks/v2/common/pool" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" ) // ErrShortPacket means that the packet is too short for a valid encrypted packet. diff --git a/transport/shadowsocks/shadowaead/stream.go b/transport/shadowsocks/shadowaead/stream.go index a6b4d30..83cc641 100755 --- a/transport/shadowsocks/shadowaead/stream.go +++ b/transport/shadowsocks/shadowaead/stream.go @@ -7,7 +7,7 @@ import ( "io" "net" - "github.com/xjasonlyu/tun2socks/v2/common/pool" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" ) const ( diff --git a/transport/shadowsocks/shadowstream/packet.go b/transport/shadowsocks/shadowstream/packet.go index 54b5ece..082a6d5 100755 --- a/transport/shadowsocks/shadowstream/packet.go +++ b/transport/shadowsocks/shadowstream/packet.go @@ -6,7 +6,7 @@ import ( "io" "net" - "github.com/xjasonlyu/tun2socks/v2/common/pool" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" ) // ErrShortPacket means the packet is too short to be a valid encrypted packet. diff --git a/transport/simple-obfs/http.go b/transport/simple-obfs/http.go index f9a2ed1..bdae1a3 100644 --- a/transport/simple-obfs/http.go +++ b/transport/simple-obfs/http.go @@ -10,7 +10,7 @@ import ( "net" "net/http" - "github.com/xjasonlyu/tun2socks/v2/common/pool" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" ) // HTTPObfs is shadowsocks http simple-obfs implementation diff --git a/transport/simple-obfs/tls.go b/transport/simple-obfs/tls.go index b3d5d1c..a9a3926 100644 --- a/transport/simple-obfs/tls.go +++ b/transport/simple-obfs/tls.go @@ -8,7 +8,7 @@ import ( "net" "time" - "github.com/xjasonlyu/tun2socks/v2/common/pool" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" ) const ( diff --git a/tunnel/tcp.go b/tunnel/tcp.go index 45af37c..6ac563d 100644 --- a/tunnel/tcp.go +++ b/tunnel/tcp.go @@ -7,8 +7,8 @@ import ( "sync" "time" - "github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/core/adapter" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" "github.com/xjasonlyu/tun2socks/v2/log" M "github.com/xjasonlyu/tun2socks/v2/metadata" "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic" diff --git a/tunnel/udp.go b/tunnel/udp.go index 667a92b..03c5e3e 100644 --- a/tunnel/udp.go +++ b/tunnel/udp.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/core/adapter" + "github.com/xjasonlyu/tun2socks/v2/internal/pool" "github.com/xjasonlyu/tun2socks/v2/log" M "github.com/xjasonlyu/tun2socks/v2/metadata" "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"