account.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package vmess
  2. import (
  3. "strings"
  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. // MemoryAccount is an in-memory form of VMess account.
  9. type MemoryAccount struct {
  10. // ID is the main ID of the account.
  11. ID *protocol.ID
  12. // Security type of the account. Used for client connections.
  13. Security protocol.SecurityType
  14. AuthenticatedLengthExperiment bool
  15. NoTerminationSignal bool
  16. }
  17. // Equals implements protocol.Account.
  18. func (a *MemoryAccount) Equals(account protocol.Account) bool {
  19. vmessAccount, ok := account.(*MemoryAccount)
  20. if !ok {
  21. return false
  22. }
  23. return a.ID.Equals(vmessAccount.ID)
  24. }
  25. // AsAccount implements protocol.Account.
  26. func (a *Account) AsAccount() (protocol.Account, error) {
  27. id, err := uuid.ParseString(a.Id)
  28. if err != nil {
  29. return nil, errors.New("failed to parse ID").Base(err).AtError()
  30. }
  31. protoID := protocol.NewID(id)
  32. var AuthenticatedLength, NoTerminationSignal bool
  33. if strings.Contains(a.TestsEnabled, "AuthenticatedLength") {
  34. AuthenticatedLength = true
  35. }
  36. if strings.Contains(a.TestsEnabled, "NoTerminationSignal") {
  37. NoTerminationSignal = true
  38. }
  39. return &MemoryAccount{
  40. ID: protoID,
  41. Security: a.SecuritySettings.GetSecurityType(),
  42. AuthenticatedLengthExperiment: AuthenticatedLength,
  43. NoTerminationSignal: NoTerminationSignal,
  44. }, nil
  45. }