1
0
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:
V2Ray 2015-09-14 22:00:03 +02:00
parent 7fef20258e
commit 3138960443

View File

@ -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 ++
}
}
}