mirror of https://github.com/v2ray/v2ray-core
More accurate hash generation
parent
7fe9683f28
commit
d4f3fc0c0f
|
@ -72,14 +72,14 @@ func (queue *TimedQueue) RemovedEntries() <-chan interface{} {
|
||||||
|
|
||||||
func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
|
func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
|
||||||
for now := range tick {
|
for now := range tick {
|
||||||
queue.access.RLock()
|
|
||||||
queueLen := queue.queue.Len()
|
|
||||||
queue.access.RUnlock()
|
|
||||||
if queueLen == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
nowSec := now.UTC().Unix()
|
nowSec := now.UTC().Unix()
|
||||||
for {
|
for {
|
||||||
|
queue.access.RLock()
|
||||||
|
queueLen := queue.queue.Len()
|
||||||
|
queue.access.RUnlock()
|
||||||
|
if queueLen == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
queue.access.RLock()
|
queue.access.RLock()
|
||||||
entry := queue.queue[0]
|
entry := queue.queue[0]
|
||||||
queue.access.RUnlock()
|
queue.access.RUnlock()
|
||||||
|
|
|
@ -62,8 +62,7 @@ func (us *TimedUserSet) generateNewHashes(lastSec, nowSec int64, idx int, id ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
|
func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
|
||||||
now := time.Now().UTC()
|
lastSec := time.Now().UTC().Unix() - cacheDurationSec
|
||||||
lastSec := now.Unix()
|
|
||||||
|
|
||||||
for now := range tick {
|
for now := range tick {
|
||||||
nowSec := now.UTC().Unix() + cacheDurationSec
|
nowSec := now.UTC().Unix() + cacheDurationSec
|
||||||
|
@ -81,7 +80,7 @@ func (us *TimedUserSet) AddUser(user User) error {
|
||||||
|
|
||||||
nowSec := time.Now().UTC().Unix()
|
nowSec := time.Now().UTC().Unix()
|
||||||
lastSec := nowSec - cacheDurationSec
|
lastSec := nowSec - cacheDurationSec
|
||||||
us.generateNewHashes(lastSec, nowSec, idx, id)
|
us.generateNewHashes(lastSec, nowSec+cacheDurationSec, idx, id)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue