mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
fix time based user hash
This commit is contained in:
parent
7fef20258e
commit
3138960443
18
userset.go
18
userset.go
@ -2,6 +2,8 @@ package core
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
_ "github.com/v2ray/v2ray-core/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -37,7 +39,7 @@ func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
|
||||
now := time.Now().UTC()
|
||||
lastSec := now.Unix() - cacheDurationSec
|
||||
|
||||
hash2Remove := make(chan hashEntry, updateIntervalSec*2)
|
||||
hash2Remove := make(chan hashEntry, cacheDurationSec*2)
|
||||
lastSec2Remove := now.Unix() + cacheDurationSec
|
||||
for {
|
||||
now := <-tick
|
||||
@ -51,14 +53,16 @@ func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
|
||||
delete(us.userHashes, entry.hash)
|
||||
}
|
||||
}
|
||||
|
||||
for i := lastSec + 1; i <= nowSec; i++ {
|
||||
for idx, id := range us.validUserIds {
|
||||
idHash := id.TimeHash(i)
|
||||
hash2Remove <- hashEntry{string(idHash), i}
|
||||
|
||||
for lastSec < nowSec + updateIntervalSec {
|
||||
for idx, id := range us.validUserIds {
|
||||
idHash := id.TimeHash(lastSec)
|
||||
hash2Remove <- hashEntry{string(idHash), lastSec}
|
||||
//log.Debug("Hash: %v", idHash)
|
||||
us.userHashes[string(idHash)] = idx
|
||||
}
|
||||
}
|
||||
lastSec ++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user