1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-20 20:24:15 -04:00
v2fly/proxy/vmess/account.go

43 lines
957 B
Go
Raw Normal View History

2016-09-17 18:41:21 -04:00
package vmess
import (
"v2ray.com/core/common/dice"
"v2ray.com/core/common/log"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/uuid"
)
2016-10-12 12:43:55 -04:00
type InternalAccount struct {
2016-09-17 18:41:21 -04:00
ID *protocol.ID
AlterIDs []*protocol.ID
}
2016-10-12 12:43:55 -04:00
func (this *InternalAccount) AnyValidID() *protocol.ID {
2016-09-17 18:41:21 -04:00
if len(this.AlterIDs) == 0 {
return this.ID
}
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
2016-10-12 12:43:55 -04:00
func (this *InternalAccount) Equals(account protocol.Account) bool {
vmessAccount, ok := account.(*InternalAccount)
2016-09-17 18:41:21 -04:00
if !ok {
return false
}
// TODO: handle AlterIds difference
return this.ID.Equals(vmessAccount.ID)
}
2016-10-12 12:43:55 -04:00
func (this *Account) AsAccount() (protocol.Account, error) {
2016-09-17 18:41:21 -04:00
id, err := uuid.ParseString(this.Id)
if err != nil {
log.Error("VMess: Failed to parse ID: ", err)
return nil, err
}
protoId := protocol.NewID(id)
2016-10-12 12:43:55 -04:00
return &InternalAccount{
2016-09-17 18:41:21 -04:00
ID: protoId,
AlterIDs: protocol.NewAlterIDs(protoId, uint16(this.AlterId)),
}, nil
}