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) {
 | 
			
		||||
	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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue