account.go 1.0 KB

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