1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 22:36:12 -04:00

More accurate hash generation

This commit is contained in:
V2Ray 2015-10-10 21:43:40 +02:00
parent 7fe9683f28
commit d4f3fc0c0f
2 changed files with 8 additions and 9 deletions

View File

@ -72,14 +72,14 @@ func (queue *TimedQueue) RemovedEntries() <-chan interface{} {
func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
for now := range tick {
queue.access.RLock()
queueLen := queue.queue.Len()
queue.access.RUnlock()
if queueLen == 0 {
continue
}
nowSec := now.UTC().Unix()
for {
queue.access.RLock()
queueLen := queue.queue.Len()
queue.access.RUnlock()
if queueLen == 0 {
break
}
queue.access.RLock()
entry := queue.queue[0]
queue.access.RUnlock()

View File

@ -62,8 +62,7 @@ func (us *TimedUserSet) generateNewHashes(lastSec, nowSec int64, idx int, id ID)
}
func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
now := time.Now().UTC()
lastSec := now.Unix()
lastSec := time.Now().UTC().Unix() - cacheDurationSec
for now := range tick {
nowSec := now.UTC().Unix() + cacheDurationSec
@ -81,7 +80,7 @@ func (us *TimedUserSet) AddUser(user User) error {
nowSec := time.Now().UTC().Unix()
lastSec := nowSec - cacheDurationSec
us.generateNewHashes(lastSec, nowSec, idx, id)
us.generateNewHashes(lastSec, nowSec+cacheDurationSec, idx, id)
return nil
}