strategy_random.go 572 B

1234567891011121314151617181920212223242526
  1. package router
  2. import (
  3. "github.com/v2fly/v2ray-core/v4/common"
  4. "github.com/v2fly/v2ray-core/v4/common/dice"
  5. )
  6. // RandomStrategy represents a random balancing strategy
  7. type RandomStrategy struct{}
  8. func (s *RandomStrategy) GetPrincipleTarget(strings []string) []string {
  9. return strings
  10. }
  11. func (s *RandomStrategy) PickOutbound(candidates []string) string {
  12. count := len(candidates)
  13. if count == 0 {
  14. // goes to fallbackTag
  15. return ""
  16. }
  17. return candidates[dice.Roll(count)]
  18. }
  19. func init() {
  20. common.Must(common.RegisterConfig((*StrategyRandomConfig)(nil), nil))
  21. }