1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-14 08:29:10 -04:00

accounts in protobuf

This commit is contained in:
Darien Raymond
2016-09-18 00:41:21 +02:00
parent 3423adaea4
commit d08cba000f
40 changed files with 790 additions and 224 deletions

View File

@@ -9,32 +9,10 @@ import (
"sync"
"time"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/signal"
)
type Account struct {
ID *protocol.ID
AlterIDs []*protocol.ID
}
func (this *Account) AnyValidID() *protocol.ID {
if len(this.AlterIDs) == 0 {
return this.ID
}
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
func (this *Account) Equals(account protocol.Account) bool {
vmessAccount, ok := account.(*Account)
if !ok {
return false
}
// TODO: handle AlterIds difference
return this.ID.Equals(vmessAccount.ID)
}
const (
updateIntervalSec = 10
cacheDurationSec = 120
@@ -140,7 +118,11 @@ L:
func (this *TimedUserValidator) Add(user *protocol.User) error {
idx := len(this.validUsers)
this.validUsers = append(this.validUsers, user)
account := user.Account.(*Account)
rawAccount, err := user.GetTypedAccount(&AccountPB{})
if err != nil {
return err
}
account := rawAccount.(*Account)
nowSec := time.Now().Unix()