1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-07 13:09:13 -04:00

introduce in-memory user

This commit is contained in:
Darien Raymond
2018-08-27 00:11:32 +02:00
parent b4d065610a
commit 54e1bb96cc
22 changed files with 212 additions and 167 deletions

View File

@@ -23,8 +23,7 @@ const (
)
type user struct {
user *protocol.User
account *InternalAccount
user *protocol.MemoryUser
lastSec protocol.Timestamp
}
@@ -80,8 +79,10 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *
}
}
genHashForID(user.account.ID)
for _, id := range user.account.AlterIDs {
account := user.user.Account.(*InternalAccount)
genHashForID(account.ID)
for _, id := range account.AlterIDs {
genHashForID(id)
}
user.lastSec = nowSec
@@ -111,21 +112,14 @@ func (v *TimedUserValidator) updateUserHash() {
}
}
func (v *TimedUserValidator) Add(u *protocol.User) error {
func (v *TimedUserValidator) Add(u *protocol.MemoryUser) error {
v.Lock()
defer v.Unlock()
rawAccount, err := u.GetTypedAccount()
if err != nil {
return err
}
account := rawAccount.(*InternalAccount)
nowSec := time.Now().Unix()
uu := &user{
user: u,
account: account,
lastSec: protocol.Timestamp(nowSec - cacheDurationSec),
}
v.users = append(v.users, uu)
@@ -134,7 +128,7 @@ func (v *TimedUserValidator) Add(u *protocol.User) error {
return nil
}
func (v *TimedUserValidator) Get(userHash []byte) (*protocol.User, protocol.Timestamp, bool) {
func (v *TimedUserValidator) Get(userHash []byte) (*protocol.MemoryUser, protocol.Timestamp, bool) {
defer v.RUnlock()
v.RLock()