account.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package vmess
  2. import (
  3. "v2ray.com/core/common/dice"
  4. "v2ray.com/core/app/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. Security protocol.Security
  12. }
  13. func (v *InternalAccount) AnyValidID() *protocol.ID {
  14. if len(v.AlterIDs) == 0 {
  15. return v.ID
  16. }
  17. return v.AlterIDs[dice.Roll(len(v.AlterIDs))]
  18. }
  19. func (v *InternalAccount) Equals(account protocol.Account) bool {
  20. vmessAccount, ok := account.(*InternalAccount)
  21. if !ok {
  22. return false
  23. }
  24. // TODO: handle AlterIds difference
  25. return v.ID.Equals(vmessAccount.ID)
  26. }
  27. func (v *Account) AsAccount() (protocol.Account, error) {
  28. id, err := uuid.ParseString(v.Id)
  29. if err != nil {
  30. log.Error("VMess: Failed to parse ID: ", err)
  31. return nil, err
  32. }
  33. protoID := protocol.NewID(id)
  34. return &InternalAccount{
  35. ID: protoID,
  36. AlterIDs: protocol.NewAlterIDs(protoID, uint16(v.AlterId)),
  37. Security: v.SecuritySettings.AsSecurity(),
  38. }, nil
  39. }
  40. func (v *Account) GetMultiplexingSettings() *Multiplexing {
  41. if v.Mux == nil {
  42. return &Multiplexing{
  43. Enabled: false,
  44. }
  45. }
  46. return v.Mux
  47. }