account.go 979 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package vmess
  2. import (
  3. "v2ray.com/core/common/dice"
  4. "v2ray.com/core/common/protocol"
  5. "v2ray.com/core/common/uuid"
  6. )
  7. type InternalAccount struct {
  8. ID *protocol.ID
  9. AlterIDs []*protocol.ID
  10. Security protocol.SecurityType
  11. }
  12. func (a *InternalAccount) AnyValidID() *protocol.ID {
  13. if len(a.AlterIDs) == 0 {
  14. return a.ID
  15. }
  16. return a.AlterIDs[dice.Roll(len(a.AlterIDs))]
  17. }
  18. func (a *InternalAccount) Equals(account protocol.Account) bool {
  19. vmessAccount, ok := account.(*InternalAccount)
  20. if !ok {
  21. return false
  22. }
  23. // TODO: handle AlterIds difference
  24. return a.ID.Equals(vmessAccount.ID)
  25. }
  26. func (a *Account) AsAccount() (protocol.Account, error) {
  27. id, err := uuid.ParseString(a.Id)
  28. if err != nil {
  29. return nil, newError("failed to parse ID").Base(err).AtError()
  30. }
  31. protoID := protocol.NewID(id)
  32. return &InternalAccount{
  33. ID: protoID,
  34. AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)),
  35. Security: a.SecuritySettings.GetSecurityType(),
  36. }, nil
  37. }