Xray-core/proxy/vless/account.go

53 lines
1.3 KiB
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package vless
import (
"google.golang.org/protobuf/proto"
"github.com/xtls/xray-core/common/errors"
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/uuid"
2020-11-25 11:01:53 +00:00
)
// AsAccount implements protocol.Account.AsAccount().
func (a *Account) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(a.Id)
if err != nil {
return nil, errors.New("failed to parse ID").Base(err).AtError()
2020-11-25 11:01:53 +00:00
}
return &MemoryAccount{
ID: protocol.NewID(id),
Flow: a.Flow, // needs parser here?
Encryption: a.Encryption, // needs parser here?
2024-04-13 18:55:05 +00:00
Seed: a.Seed,
2020-11-25 11:01:53 +00:00
}, nil
}
// MemoryAccount is an in-memory form of VLess account.
type MemoryAccount struct {
// ID of the account.
ID *protocol.ID
2023-03-04 10:39:26 +00:00
// Flow of the account. May be "xtls-rprx-vision".
2020-11-25 11:01:53 +00:00
Flow string
// Encryption of the account. Used for client connections, and only accepts "none" for now.
Encryption string
2024-04-13 18:55:05 +00:00
// Seed. Details TBD
Seed string
2020-11-25 11:01:53 +00:00
}
// Equals implements protocol.Account.Equals().
func (a *MemoryAccount) Equals(account protocol.Account) bool {
vlessAccount, ok := account.(*MemoryAccount)
if !ok {
return false
}
return a.ID.Equals(vlessAccount.ID)
}
func (a *MemoryAccount) ToProto() proto.Message {
return &Account{
2024-11-09 11:16:11 +00:00
Id: a.ID.String(),
Flow: a.Flow,
Encryption: a.Encryption,
}
}