func (this *TimedUserValidator) Add(user *protocol.User) error { idx := len(this.validUsers) this.validUsers = append(this.validUsers, user) rawAccount, err := user.GetTypedAccount() if err != nil { return err } account := rawAccount.(*InternalAccount) nowSec := time.Now().Unix() entry := &idEntry{ id: account.ID, userIdx: idx, lastSec: protocol.Timestamp(nowSec - cacheDurationSec), lastSecRemoval: protocol.Timestamp(nowSec - cacheDurationSec*3), } this.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), idx, entry) this.ids = append(this.ids, entry) for _, alterid := range account.AlterIDs { entry := &idEntry{ id: alterid, userIdx: idx, lastSec: protocol.Timestamp(nowSec - cacheDurationSec), lastSecRemoval: protocol.Timestamp(nowSec - cacheDurationSec*3), } this.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), idx, entry) this.ids = append(this.ids, entry) } return nil }
func (this *TimedUserValidator) updateUserHash(interval time.Duration) { L: for { select { case now := <-time.After(interval): nowSec := protocol.Timestamp(now.Unix() + cacheDurationSec) for _, entry := range this.ids { this.generateNewHashes(nowSec, entry.userIdx, entry) } case <-this.cancel.WaitForCancel(): break L } } this.cancel.Done() }
func (v *TimedUserValidator) updateUserHash(interval time.Duration) { v.cancel.WaitThread() defer v.cancel.FinishThread() for { select { case now := <-time.After(interval): nowSec := protocol.Timestamp(now.Unix() + cacheDurationSec) for _, entry := range v.ids { v.generateNewHashes(nowSec, entry.userIdx, entry) } case <-v.cancel.WaitForCancel(): return } } }