|  | @@ -25,7 +25,6 @@ type idEntry struct {
 | 
											
												
													
														|  |  	id             *protocol.ID
 |  |  	id             *protocol.ID
 | 
											
												
													
														|  |  	userIdx        int
 |  |  	userIdx        int
 | 
											
												
													
														|  |  	lastSec        protocol.Timestamp
 |  |  	lastSec        protocol.Timestamp
 | 
											
												
													
														|  | -	lastSecRemoval protocol.Timestamp
 |  | 
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  type TimedUserValidator struct {
 |  |  type TimedUserValidator struct {
 | 
											
										
											
												
													
														|  | @@ -56,25 +55,26 @@ func NewTimedUserValidator(ctx context.Context, hasher protocol.IDHash) protocol
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, idx int, entry *idEntry) {
 |  |  func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, idx int, entry *idEntry) {
 | 
											
												
													
														|  |  	var hashValue [16]byte
 |  |  	var hashValue [16]byte
 | 
											
												
													
														|  | -	var hashValueRemoval [16]byte
 |  | 
 | 
											
												
													
														|  |  	idHash := v.hasher(entry.id.Bytes())
 |  |  	idHash := v.hasher(entry.id.Bytes())
 | 
											
												
													
														|  |  	for entry.lastSec <= nowSec {
 |  |  	for entry.lastSec <= nowSec {
 | 
											
												
													
														|  |  		common.Must2(idHash.Write(entry.lastSec.Bytes(nil)))
 |  |  		common.Must2(idHash.Write(entry.lastSec.Bytes(nil)))
 | 
											
												
													
														|  |  		idHash.Sum(hashValue[:0])
 |  |  		idHash.Sum(hashValue[:0])
 | 
											
												
													
														|  |  		idHash.Reset()
 |  |  		idHash.Reset()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -		common.Must2(idHash.Write(entry.lastSecRemoval.Bytes(nil)))
 |  | 
 | 
											
												
													
														|  | -		idHash.Sum(hashValueRemoval[:0])
 |  | 
 | 
											
												
													
														|  | -		idHash.Reset()
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -		delete(v.userHash, hashValueRemoval)
 |  | 
 | 
											
												
													
														|  |  		v.userHash[hashValue] = indexTimePair{
 |  |  		v.userHash[hashValue] = indexTimePair{
 | 
											
												
													
														|  |  			index:   idx,
 |  |  			index:   idx,
 | 
											
												
													
														|  |  			timeInc: uint32(entry.lastSec - v.baseTime),
 |  |  			timeInc: uint32(entry.lastSec - v.baseTime),
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		entry.lastSec++
 |  |  		entry.lastSec++
 | 
											
												
													
														|  | -		entry.lastSecRemoval++
 |  | 
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +func (v *TimedUserValidator) removeExpiredHashes(expire uint32) {
 | 
											
												
													
														|  | 
 |  | +	for key, pair := range v.userHash {
 | 
											
												
													
														|  | 
 |  | +		if pair.timeInc < expire {
 | 
											
												
													
														|  | 
 |  | +			delete(v.userHash, key)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -87,6 +87,11 @@ func (v *TimedUserValidator) updateUserHash(ctx context.Context, interval time.D
 | 
											
												
													
														|  |  			for _, entry := range v.ids {
 |  |  			for _, entry := range v.ids {
 | 
											
												
													
														|  |  				v.generateNewHashes(nowSec, entry.userIdx, entry)
 |  |  				v.generateNewHashes(nowSec, entry.userIdx, entry)
 | 
											
												
													
														|  |  			}
 |  |  			}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +			expire := protocol.Timestamp(now.Unix() - cacheDurationSec*3)
 | 
											
												
													
														|  | 
 |  | +			if expire > v.baseTime {
 | 
											
												
													
														|  | 
 |  | +				v.removeExpiredHashes(uint32(expire - v.baseTime))
 | 
											
												
													
														|  | 
 |  | +			}
 | 
											
												
													
														|  |  			v.Unlock()
 |  |  			v.Unlock()
 | 
											
												
													
														|  |  		case <-ctx.Done():
 |  |  		case <-ctx.Done():
 | 
											
												
													
														|  |  			return
 |  |  			return
 | 
											
										
											
												
													
														|  | @@ -112,7 +117,6 @@ func (v *TimedUserValidator) Add(user *protocol.User) error {
 | 
											
												
													
														|  |  		id:             account.ID,
 |  |  		id:             account.ID,
 | 
											
												
													
														|  |  		userIdx:        idx,
 |  |  		userIdx:        idx,
 | 
											
												
													
														|  |  		lastSec:        protocol.Timestamp(nowSec - cacheDurationSec),
 |  |  		lastSec:        protocol.Timestamp(nowSec - cacheDurationSec),
 | 
											
												
													
														|  | -		lastSecRemoval: protocol.Timestamp(nowSec - cacheDurationSec*3),
 |  | 
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	v.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), idx, entry)
 |  |  	v.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), idx, entry)
 | 
											
												
													
														|  |  	v.ids = append(v.ids, entry)
 |  |  	v.ids = append(v.ids, entry)
 | 
											
										
											
												
													
														|  | @@ -121,7 +125,6 @@ func (v *TimedUserValidator) Add(user *protocol.User) error {
 | 
											
												
													
														|  |  			id:             alterid,
 |  |  			id:             alterid,
 | 
											
												
													
														|  |  			userIdx:        idx,
 |  |  			userIdx:        idx,
 | 
											
												
													
														|  |  			lastSec:        protocol.Timestamp(nowSec - cacheDurationSec),
 |  |  			lastSec:        protocol.Timestamp(nowSec - cacheDurationSec),
 | 
											
												
													
														|  | -			lastSecRemoval: protocol.Timestamp(nowSec - cacheDurationSec*3),
 |  | 
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  		v.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), idx, entry)
 |  |  		v.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), idx, entry)
 | 
											
												
													
														|  |  		v.ids = append(v.ids, entry)
 |  |  		v.ids = append(v.ids, entry)
 |