-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
46 lines (40 loc) · 982 Bytes
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package vmess
import (
"v2ray.com/core/common/dice"
"v2ray.com/core/common/log"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/uuid"
)
type Account struct {
ID *protocol.ID
AlterIDs []*protocol.ID
}
func NewAccount() protocol.AsAccount {
return &AccountPB{}
}
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)
}
func (this *AccountPB) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(this.Id)
if err != nil {
log.Error("VMess: Failed to parse ID: ", err)
return nil, err
}
protoId := protocol.NewID(id)
return &Account{
ID: protoId,
AlterIDs: protocol.NewAlterIDs(protoId, uint16(this.AlterId)),
}, nil
}