Skip to content

Commit

Permalink
chore: update anytls (#1863)
Browse files Browse the repository at this point in the history
Co-authored-by: anytls <anytls>
  • Loading branch information
anytls authored Feb 26, 2025
1 parent 8d783c6 commit e2140e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 14 additions & 7 deletions transport/anytls/session/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Client struct {
die context.Context
dieCancel context.CancelFunc

dialOut func(ctx context.Context) (net.Conn, error)
dialOut util.DialOutFunc

sessionCounter atomic.Uint64
idleSession *skiplist.SkipList[uint64, *Session]
Expand All @@ -31,7 +31,7 @@ type Client struct {
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{
dialOut: dialOut,
padding: _padding,
Expand Down Expand Up @@ -83,10 +83,16 @@ func (c *Client) CreateStream(ctx context.Context) (net.Conn, error) {
session.dieHook()
}
} else {
c.idleSessionLock.Lock()
session.idleSince = time.Now()
c.idleSession.Insert(math.MaxUint64-session.seq, session)
c.idleSessionLock.Unlock()
select {
case <-c.die.Done():
// Now client has been closed
go session.Close()
default:
c.idleSessionLock.Lock()
session.idleSince = time.Now()
c.idleSession.Insert(math.MaxUint64-session.seq, session)
c.idleSessionLock.Unlock()
}
}
}

Expand Down Expand Up @@ -131,7 +137,8 @@ func (c *Client) createSession(ctx context.Context) (*Session, error) {

func (c *Client) Close() error {
c.dieCancel()
go c.idleCleanupExpTime(time.Now())
c.minIdleSession = 0
go c.idleCleanupExpTime(time.Time{})
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions transport/anytls/util/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package util

import (
"context"
"net"
)

type DialOutFunc func(ctx context.Context) (net.Conn, error)

0 comments on commit e2140e6

Please # to comment.