account.go 543 B

123456789101112131415161718192021222324252627282930
  1. package protocol
  2. import (
  3. "github.com/v2ray/v2ray-core/common/dice"
  4. )
  5. type Account interface {
  6. Equals(Account) bool
  7. }
  8. type VMessAccount struct {
  9. ID *ID
  10. AlterIDs []*ID
  11. }
  12. func (this *VMessAccount) AnyValidID() *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 *VMessAccount) Equals(account Account) bool {
  19. vmessAccount, ok := account.(*VMessAccount)
  20. if !ok {
  21. return false
  22. }
  23. // TODO: handle AlterIds difference
  24. return this.ID.Equals(vmessAccount.ID)
  25. }