From 3138960443470610ee2617128b387cbc5c073afc Mon Sep 17 00:00:00 2001 From: V2Ray Date: Mon, 14 Sep 2015 22:00:03 +0200 Subject: [PATCH] fix time based user hash --- userset.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/userset.go b/userset.go index 4c466ed2..8ad5408a 100644 --- a/userset.go +++ b/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 ++ + } } }