1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-20 14:35:23 +00:00
v2fly/proxy/vmess/account.go

45 lines
1013 B
Go
Raw Normal View History

2016-09-17 22:41:21 +00:00
package vmess
import (
2017-02-01 20:35:40 +00:00
"v2ray.com/core/app/log"
2017-02-02 23:14:43 +00:00
"v2ray.com/core/common/dice"
2016-09-17 22:41:21 +00:00
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/uuid"
)
2016-10-12 16:43:55 +00:00
type InternalAccount struct {
2016-09-17 22:41:21 +00:00
ID *protocol.ID
AlterIDs []*protocol.ID
2016-12-07 20:43:41 +00:00
Security protocol.Security
2016-09-17 22:41:21 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *InternalAccount) AnyValidID() *protocol.ID {
if len(v.AlterIDs) == 0 {
return v.ID
2016-09-17 22:41:21 +00:00
}
2016-11-27 20:39:09 +00:00
return v.AlterIDs[dice.Roll(len(v.AlterIDs))]
2016-09-17 22:41:21 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *InternalAccount) Equals(account protocol.Account) bool {
2016-10-12 16:43:55 +00:00
vmessAccount, ok := account.(*InternalAccount)
2016-09-17 22:41:21 +00:00
if !ok {
return false
}
// TODO: handle AlterIds difference
2016-11-27 20:39:09 +00:00
return v.ID.Equals(vmessAccount.ID)
2016-09-17 22:41:21 +00:00
}
2016-11-27 20:39:09 +00:00
func (v *Account) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(v.Id)
2016-09-17 22:41:21 +00:00
if err != nil {
2017-04-08 23:43:25 +00:00
log.Trace(newError("failed to parse ID").Base(err).AtError())
2016-09-17 22:41:21 +00:00
return nil, err
}
2016-12-27 20:34:14 +00:00
protoID := protocol.NewID(id)
2016-10-12 16:43:55 +00:00
return &InternalAccount{
2016-12-27 20:34:14 +00:00
ID: protoID,
AlterIDs: protocol.NewAlterIDs(protoID, uint16(v.AlterId)),
2016-12-11 13:58:53 +00:00
Security: v.SecuritySettings.AsSecurity(),
2016-09-17 22:41:21 +00:00
}, nil
}