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

45 lines
997 B

package vmess
import (
"v2ray.com/core/app/log"
"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.Security
}
8 years ago
func (v *InternalAccount) AnyValidID() *protocol.ID {
if len(v.AlterIDs) == 0 {
return v.ID
}
8 years ago
return v.AlterIDs[dice.Roll(len(v.AlterIDs))]
}
8 years ago
func (v *InternalAccount) Equals(account protocol.Account) bool {
8 years ago
vmessAccount, ok := account.(*InternalAccount)
if !ok {
return false
}
// TODO: handle AlterIds difference
8 years ago
return v.ID.Equals(vmessAccount.ID)
}
8 years ago
func (v *Account) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(v.Id)
if err != nil {
log.Error("VMess: Failed to parse ID: ", err)
return nil, err
}
protoID := protocol.NewID(id)
8 years ago
return &InternalAccount{
ID: protoID,
AlterIDs: protocol.NewAlterIDs(protoID, uint16(v.AlterId)),
Security: v.SecuritySettings.AsSecurity(),
}, nil
}