mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
remove struct scoped context
This commit is contained in:
parent
9caa59c827
commit
9ff0dc7327
@ -30,7 +30,6 @@ type idEntry struct {
|
||||
|
||||
type TimedUserValidator struct {
|
||||
sync.RWMutex
|
||||
ctx context.Context
|
||||
validUsers []*protocol.User
|
||||
userHash map[[16]byte]indexTimePair
|
||||
ids []*idEntry
|
||||
@ -45,14 +44,13 @@ type indexTimePair struct {
|
||||
|
||||
func NewTimedUserValidator(ctx context.Context, hasher protocol.IDHash) protocol.UserValidator {
|
||||
tus := &TimedUserValidator{
|
||||
ctx: ctx,
|
||||
validUsers: make([]*protocol.User, 0, 16),
|
||||
userHash: make(map[[16]byte]indexTimePair, 512),
|
||||
ids: make([]*idEntry, 0, 512),
|
||||
hasher: hasher,
|
||||
baseTime: protocol.Timestamp(time.Now().Unix() - cacheDurationSec*3),
|
||||
}
|
||||
go tus.updateUserHash(updateIntervalSec * time.Second)
|
||||
go tus.updateUserHash(ctx, updateIntervalSec*time.Second)
|
||||
return tus
|
||||
}
|
||||
|
||||
@ -80,7 +78,7 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, idx in
|
||||
}
|
||||
}
|
||||
|
||||
func (v *TimedUserValidator) updateUserHash(interval time.Duration) {
|
||||
func (v *TimedUserValidator) updateUserHash(ctx context.Context, interval time.Duration) {
|
||||
for {
|
||||
select {
|
||||
case now := <-time.After(interval):
|
||||
@ -90,7 +88,7 @@ func (v *TimedUserValidator) updateUserHash(interval time.Duration) {
|
||||
v.generateNewHashes(nowSec, entry.userIdx, entry)
|
||||
}
|
||||
v.Unlock()
|
||||
case <-v.ctx.Done():
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
)
|
||||
|
||||
type TCPListener struct {
|
||||
ctx context.Context
|
||||
listener *net.TCPListener
|
||||
tlsConfig *gotls.Config
|
||||
authConfig internet.ConnectionAuthenticator
|
||||
@ -34,7 +33,6 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, addConn
|
||||
tcpSettings := networkSettings.(*Config)
|
||||
|
||||
l := &TCPListener{
|
||||
ctx: ctx,
|
||||
listener: listener,
|
||||
config: tcpSettings,
|
||||
addConn: addConn,
|
||||
@ -56,14 +54,14 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, addConn
|
||||
}
|
||||
l.authConfig = auth
|
||||
}
|
||||
go l.KeepAccepting()
|
||||
go l.KeepAccepting(ctx)
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func (v *TCPListener) KeepAccepting() {
|
||||
func (v *TCPListener) KeepAccepting(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case <-v.ctx.Done():
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user