account.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package vless
  2. import (
  3. "google.golang.org/protobuf/proto"
  4. "github.com/xtls/xray-core/common/errors"
  5. "github.com/xtls/xray-core/common/protocol"
  6. "github.com/xtls/xray-core/common/uuid"
  7. )
  8. // AsAccount implements protocol.Account.AsAccount().
  9. func (a *Account) AsAccount() (protocol.Account, error) {
  10. id, err := uuid.ParseString(a.Id)
  11. if err != nil {
  12. return nil, errors.New("failed to parse ID").Base(err).AtError()
  13. }
  14. return &MemoryAccount{
  15. ID: protocol.NewID(id),
  16. Flow: a.Flow, // needs parser here?
  17. Encryption: a.Encryption, // needs parser here?
  18. }, nil
  19. }
  20. // MemoryAccount is an in-memory form of VLess account.
  21. type MemoryAccount struct {
  22. // ID of the account.
  23. ID *protocol.ID
  24. // Flow of the account. May be "xtls-rprx-vision".
  25. Flow string
  26. // Encryption of the account. Used for client connections, and only accepts "none" for now.
  27. Encryption string
  28. }
  29. // Equals implements protocol.Account.Equals().
  30. func (a *MemoryAccount) Equals(account protocol.Account) bool {
  31. vlessAccount, ok := account.(*MemoryAccount)
  32. if !ok {
  33. return false
  34. }
  35. return a.ID.Equals(vlessAccount.ID)
  36. }
  37. func (a *MemoryAccount) ToProto() proto.Message {
  38. return &Account{
  39. Id: a.ID.String(),
  40. Flow: a.Flow,
  41. Encryption: a.Encryption,
  42. }
  43. }