2016-09-17 18:41:21 -04:00
|
|
|
package vmess
|
|
|
|
|
|
|
|
import (
|
2017-02-02 18:14:43 -05:00
|
|
|
"v2ray.com/core/common/dice"
|
2016-09-17 18:41:21 -04:00
|
|
|
"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-12-07 15:43:41 -05:00
|
|
|
Security protocol.Security
|
2016-09-17 18:41:21 -04:00
|
|
|
}
|
|
|
|
|
2017-09-19 17:27:49 -04:00
|
|
|
func (a *InternalAccount) AnyValidID() *protocol.ID {
|
|
|
|
if len(a.AlterIDs) == 0 {
|
|
|
|
return a.ID
|
2016-09-17 18:41:21 -04:00
|
|
|
}
|
2017-09-19 17:27:49 -04:00
|
|
|
return a.AlterIDs[dice.Roll(len(a.AlterIDs))]
|
2016-09-17 18:41:21 -04:00
|
|
|
}
|
|
|
|
|
2017-09-19 17:27:49 -04:00
|
|
|
func (a *InternalAccount) Equals(account protocol.Account) bool {
|
2016-10-12 12:43:55 -04:00
|
|
|
vmessAccount, ok := account.(*InternalAccount)
|
2016-09-17 18:41:21 -04:00
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// TODO: handle AlterIds difference
|
2017-09-19 17:27:49 -04:00
|
|
|
return a.ID.Equals(vmessAccount.ID)
|
2016-09-17 18:41:21 -04:00
|
|
|
}
|
|
|
|
|
2017-09-19 17:27:49 -04:00
|
|
|
func (a *Account) AsAccount() (protocol.Account, error) {
|
|
|
|
id, err := uuid.ParseString(a.Id)
|
2016-09-17 18:41:21 -04:00
|
|
|
if err != nil {
|
2017-12-19 15:28:12 -05:00
|
|
|
newError("failed to parse ID").Base(err).AtError().WriteToLog()
|
2016-09-17 18:41:21 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2016-12-27 15:34:14 -05:00
|
|
|
protoID := protocol.NewID(id)
|
2016-10-12 12:43:55 -04:00
|
|
|
return &InternalAccount{
|
2016-12-27 15:34:14 -05:00
|
|
|
ID: protoID,
|
2017-09-19 17:27:49 -04:00
|
|
|
AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)),
|
|
|
|
Security: a.SecuritySettings.AsSecurity(),
|
2016-09-17 18:41:21 -04:00
|
|
|
}, nil
|
|
|
|
}
|