mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-24 13:38:05 +08:00
chore: using atomic.Pointer in anytls
This commit is contained in:
@@ -7,9 +7,9 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/metacubex/mihomo/adapter/inbound"
|
||||
"github.com/metacubex/mihomo/common/atomic"
|
||||
"github.com/metacubex/mihomo/common/buf"
|
||||
"github.com/metacubex/mihomo/component/ca"
|
||||
"github.com/metacubex/mihomo/component/ech"
|
||||
@@ -31,7 +31,7 @@ type Listener struct {
|
||||
listeners []net.Listener
|
||||
tlsConfig *tlsC.Config
|
||||
userMap map[[32]byte]string
|
||||
padding atomic.TypedValue[*padding.PaddingFactory]
|
||||
padding atomic.Pointer[padding.PaddingFactory]
|
||||
}
|
||||
|
||||
func New(config LC.AnyTLSServer, tunnel C.Tunnel, additions ...inbound.Addition) (sl *Listener, err error) {
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/common/atomic"
|
||||
"github.com/metacubex/mihomo/common/buf"
|
||||
"github.com/metacubex/mihomo/transport/anytls/padding"
|
||||
"github.com/metacubex/mihomo/transport/anytls/session"
|
||||
@@ -33,7 +33,7 @@ type Client struct {
|
||||
dialer N.Dialer
|
||||
server M.Socksaddr
|
||||
sessionClient *session.Client
|
||||
padding atomic.TypedValue[*padding.PaddingFactory]
|
||||
padding atomic.Pointer[padding.PaddingFactory]
|
||||
}
|
||||
|
||||
func NewClient(ctx context.Context, config ClientConfig) *Client {
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/metacubex/mihomo/common/atomic"
|
||||
"github.com/metacubex/mihomo/transport/anytls/util"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ type PaddingFactory struct {
|
||||
Md5 string
|
||||
}
|
||||
|
||||
func UpdatePaddingScheme(rawScheme []byte, to *atomic.TypedValue[*PaddingFactory]) bool {
|
||||
func UpdatePaddingScheme(rawScheme []byte, to *atomic.Pointer[PaddingFactory]) bool {
|
||||
if p := NewPaddingFactory(rawScheme); p != nil {
|
||||
to.Store(p)
|
||||
return true
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"math"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/common/atomic"
|
||||
"github.com/metacubex/mihomo/transport/anytls/padding"
|
||||
"github.com/metacubex/mihomo/transport/anytls/skiplist"
|
||||
"github.com/metacubex/mihomo/transport/anytls/util"
|
||||
@@ -29,13 +29,13 @@ type Client struct {
|
||||
sessions map[uint64]*Session
|
||||
sessionsLock sync.Mutex
|
||||
|
||||
padding *atomic.TypedValue[*padding.PaddingFactory]
|
||||
padding *atomic.Pointer[padding.PaddingFactory]
|
||||
|
||||
idleSessionTimeout time.Duration
|
||||
minIdleSession int
|
||||
}
|
||||
|
||||
func NewClient(ctx context.Context, dialOut util.DialOutFunc, _padding *atomic.TypedValue[*padding.PaddingFactory], idleSessionCheckInterval, idleSessionTimeout time.Duration, minIdleSession int) *Client {
|
||||
func NewClient(ctx context.Context, dialOut util.DialOutFunc, _padding *atomic.Pointer[padding.PaddingFactory], idleSessionCheckInterval, idleSessionTimeout time.Duration, minIdleSession int) *Client {
|
||||
c := &Client{
|
||||
sessions: make(map[uint64]*Session),
|
||||
dialOut: dialOut,
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/common/atomic"
|
||||
"github.com/metacubex/mihomo/common/buf"
|
||||
"github.com/metacubex/mihomo/common/pool"
|
||||
"github.com/metacubex/mihomo/constant"
|
||||
@@ -38,7 +38,7 @@ type Session struct {
|
||||
// pool
|
||||
seq uint64
|
||||
idleSince time.Time
|
||||
padding *atomic.TypedValue[*padding.PaddingFactory]
|
||||
padding *atomic.Pointer[padding.PaddingFactory]
|
||||
|
||||
peerVersion byte
|
||||
|
||||
@@ -53,7 +53,7 @@ type Session struct {
|
||||
onNewStream func(stream *Stream)
|
||||
}
|
||||
|
||||
func NewClientSession(conn net.Conn, _padding *atomic.TypedValue[*padding.PaddingFactory]) *Session {
|
||||
func NewClientSession(conn net.Conn, _padding *atomic.Pointer[padding.PaddingFactory]) *Session {
|
||||
s := &Session{
|
||||
conn: conn,
|
||||
isClient: true,
|
||||
@@ -65,7 +65,7 @@ func NewClientSession(conn net.Conn, _padding *atomic.TypedValue[*padding.Paddin
|
||||
return s
|
||||
}
|
||||
|
||||
func NewServerSession(conn net.Conn, onNewStream func(stream *Stream), _padding *atomic.TypedValue[*padding.PaddingFactory]) *Session {
|
||||
func NewServerSession(conn net.Conn, onNewStream func(stream *Stream), _padding *atomic.Pointer[padding.PaddingFactory]) *Session {
|
||||
s := &Session{
|
||||
conn: conn,
|
||||
onNewStream: onNewStream,
|
||||
|
||||
Reference in New Issue
Block a user