account.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //go:build !confonly
  2. // +build !confonly
  3. package vless
  4. import (
  5. "github.com/v2fly/v2ray-core/v5/common/protocol"
  6. "github.com/v2fly/v2ray-core/v5/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, newError("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.
  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. }