You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/proxy/vmess/account.go

43 lines
979 B

package vmess
import (
"v2ray.com/core/common/dice"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/uuid"
)
8 years ago
type InternalAccount struct {
ID *protocol.ID
AlterIDs []*protocol.ID
Security protocol.SecurityType
}
7 years ago
func (a *InternalAccount) AnyValidID() *protocol.ID {
if len(a.AlterIDs) == 0 {
return a.ID
}
7 years ago
return a.AlterIDs[dice.Roll(len(a.AlterIDs))]
}
7 years ago
func (a *InternalAccount) Equals(account protocol.Account) bool {
8 years ago
vmessAccount, ok := account.(*InternalAccount)
if !ok {
return false
}
// TODO: handle AlterIds difference
7 years ago
return a.ID.Equals(vmessAccount.ID)
}
7 years ago
func (a *Account) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(a.Id)
if err != nil {
7 years ago
return nil, newError("failed to parse ID").Base(err).AtError()
}
protoID := protocol.NewID(id)
8 years ago
return &InternalAccount{
ID: protoID,
7 years ago
AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)),
Security: a.SecuritySettings.GetSecurityType(),
}, nil
}