mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
more readable for func generateNewHashes
in proxy/vmess/validator.go
This commit is contained in:
parent
41956e92a5
commit
65df107eac
@ -56,13 +56,14 @@ func NewTimedUserValidator(hasher protocol.IDHash) *TimedUserValidator {
|
||||
|
||||
func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *user) {
|
||||
var hashValue [16]byte
|
||||
genEndSec := nowSec + cacheDurationSec
|
||||
genHashForID := func(id *protocol.ID) {
|
||||
idHash := v.hasher(id.Bytes())
|
||||
lastSec := user.lastSec
|
||||
if lastSec < nowSec-cacheDurationSec*2 {
|
||||
lastSec = nowSec - cacheDurationSec*2
|
||||
genBeginSec := user.lastSec
|
||||
if genBeginSec < nowSec-cacheDurationSec {
|
||||
genBeginSec = nowSec - cacheDurationSec
|
||||
}
|
||||
for ts := lastSec; ts <= nowSec; ts++ {
|
||||
for ts := genBeginSec; ts <= genEndSec; ts++ {
|
||||
common.Must2(idHash.Write(ts.Bytes(nil)))
|
||||
idHash.Sum(hashValue[:0])
|
||||
idHash.Reset()
|
||||
@ -80,7 +81,7 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *
|
||||
for _, id := range account.AlterIDs {
|
||||
genHashForID(id)
|
||||
}
|
||||
user.lastSec = nowSec
|
||||
user.lastSec = genEndSec
|
||||
}
|
||||
|
||||
func (v *TimedUserValidator) removeExpiredHashes(expire uint32) {
|
||||
@ -93,7 +94,7 @@ func (v *TimedUserValidator) removeExpiredHashes(expire uint32) {
|
||||
|
||||
func (v *TimedUserValidator) updateUserHash() {
|
||||
now := time.Now()
|
||||
nowSec := protocol.Timestamp(now.Unix() + cacheDurationSec)
|
||||
nowSec := protocol.Timestamp(now.Unix())
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
|
||||
@ -118,7 +119,7 @@ func (v *TimedUserValidator) Add(u *protocol.MemoryUser) error {
|
||||
lastSec: protocol.Timestamp(nowSec - cacheDurationSec),
|
||||
}
|
||||
v.users = append(v.users, uu)
|
||||
v.generateNewHashes(protocol.Timestamp(nowSec+cacheDurationSec), uu)
|
||||
v.generateNewHashes(protocol.Timestamp(nowSec), uu)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user