account.go 1.0 KB

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