Skip to content

Commit

Permalink
Refactor(pool): move to internal (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Aug 31, 2024
1 parent 978803c commit fc4c5c4
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 27 deletions.
17 changes: 0 additions & 17 deletions common/pool/buffer.go

This file was deleted.

3 changes: 1 addition & 2 deletions common/pool/alloc.go → internal/pool/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions internal/pool/buffer.go
Original file line number Diff line number Diff line change
@@ -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)
}
File renamed without changes.
2 changes: 1 addition & 1 deletion proxy/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion transport/shadowsocks/shadowaead/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion transport/shadowsocks/shadowaead/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net"

"github.com/xjasonlyu/tun2socks/v2/common/pool"
"github.com/xjasonlyu/tun2socks/v2/internal/pool"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion transport/shadowsocks/shadowstream/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion transport/simple-obfs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion transport/simple-obfs/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net"
"time"

"github.com/xjasonlyu/tun2socks/v2/common/pool"
"github.com/xjasonlyu/tun2socks/v2/internal/pool"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion tunnel/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tunnel/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fc4c5c4

Please sign in to comment.