account.go 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.Security
  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. newError("failed to parse ID").Base(err).AtError().WriteToLog()
  30. return nil, err
  31. }
  32. protoID := protocol.NewID(id)
  33. return &InternalAccount{
  34. ID: protoID,
  35. AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)),
  36. Security: a.SecuritySettings.AsSecurity(),
  37. }, nil
  38. }