account.go 957 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package vmess
  2. import (
  3. "v2ray.com/core/common/dice"
  4. "v2ray.com/core/common/log"
  5. "v2ray.com/core/common/protocol"
  6. "v2ray.com/core/common/uuid"
  7. )
  8. type InternalAccount struct {
  9. ID *protocol.ID
  10. AlterIDs []*protocol.ID
  11. }
  12. func (this *InternalAccount) AnyValidID() *protocol.ID {
  13. if len(this.AlterIDs) == 0 {
  14. return this.ID
  15. }
  16. return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
  17. }
  18. func (this *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 this.ID.Equals(vmessAccount.ID)
  25. }
  26. func (this *Account) AsAccount() (protocol.Account, error) {
  27. id, err := uuid.ParseString(this.Id)
  28. if err != nil {
  29. log.Error("VMess: Failed to parse ID: ", err)
  30. return nil, err
  31. }
  32. protoId := protocol.NewID(id)
  33. return &InternalAccount{
  34. ID: protoId,
  35. AlterIDs: protocol.NewAlterIDs(protoId, uint16(this.AlterId)),
  36. }, nil
  37. }