mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-23 11:20:04 +08:00
chore: update anytls (#1863)
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 0s
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 0s
Co-authored-by: anytls <anytls>
This commit is contained in:
parent
8d783c65c1
commit
e2140e62ca
@ -19,7 +19,7 @@ type Client struct {
|
|||||||
die context.Context
|
die context.Context
|
||||||
dieCancel context.CancelFunc
|
dieCancel context.CancelFunc
|
||||||
|
|
||||||
dialOut func(ctx context.Context) (net.Conn, error)
|
dialOut util.DialOutFunc
|
||||||
|
|
||||||
sessionCounter atomic.Uint64
|
sessionCounter atomic.Uint64
|
||||||
idleSession *skiplist.SkipList[uint64, *Session]
|
idleSession *skiplist.SkipList[uint64, *Session]
|
||||||
@ -31,7 +31,7 @@ type Client struct {
|
|||||||
minIdleSession int
|
minIdleSession int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(ctx context.Context, dialOut func(ctx context.Context) (net.Conn, error), _padding *atomic.TypedValue[*padding.PaddingFactory], idleSessionCheckInterval, idleSessionTimeout time.Duration, minIdleSession int) *Client {
|
func NewClient(ctx context.Context, dialOut util.DialOutFunc, _padding *atomic.TypedValue[*padding.PaddingFactory], idleSessionCheckInterval, idleSessionTimeout time.Duration, minIdleSession int) *Client {
|
||||||
c := &Client{
|
c := &Client{
|
||||||
dialOut: dialOut,
|
dialOut: dialOut,
|
||||||
padding: _padding,
|
padding: _padding,
|
||||||
@ -83,10 +83,16 @@ func (c *Client) CreateStream(ctx context.Context) (net.Conn, error) {
|
|||||||
session.dieHook()
|
session.dieHook()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.idleSessionLock.Lock()
|
select {
|
||||||
session.idleSince = time.Now()
|
case <-c.die.Done():
|
||||||
c.idleSession.Insert(math.MaxUint64-session.seq, session)
|
// Now client has been closed
|
||||||
c.idleSessionLock.Unlock()
|
go session.Close()
|
||||||
|
default:
|
||||||
|
c.idleSessionLock.Lock()
|
||||||
|
session.idleSince = time.Now()
|
||||||
|
c.idleSession.Insert(math.MaxUint64-session.seq, session)
|
||||||
|
c.idleSessionLock.Unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +137,8 @@ func (c *Client) createSession(ctx context.Context) (*Session, error) {
|
|||||||
|
|
||||||
func (c *Client) Close() error {
|
func (c *Client) Close() error {
|
||||||
c.dieCancel()
|
c.dieCancel()
|
||||||
go c.idleCleanupExpTime(time.Now())
|
c.minIdleSession = 0
|
||||||
|
go c.idleCleanupExpTime(time.Time{})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
transport/anytls/util/type.go
Normal file
8
transport/anytls/util/type.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DialOutFunc func(ctx context.Context) (net.Conn, error)
|
||||||
Loading…
Reference in New Issue
Block a user