2021-01-29 19:31:11 -05:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/dice"
|
2021-01-29 19:31:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// RandomStrategy represents a random balancing strategy
|
|
|
|
type RandomStrategy struct{}
|
|
|
|
|
2021-06-18 19:13:09 -04:00
|
|
|
func (s *RandomStrategy) GetPrincipleTarget(strings []string) []string {
|
|
|
|
return strings
|
|
|
|
}
|
|
|
|
|
2021-06-18 19:02:46 -04:00
|
|
|
func (s *RandomStrategy) PickOutbound(candidates []string) string {
|
2021-01-29 19:31:11 -05:00
|
|
|
count := len(candidates)
|
|
|
|
if count == 0 {
|
|
|
|
// goes to fallbackTag
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return candidates[dice.Roll(count)]
|
|
|
|
}
|
2021-09-07 06:48:24 -04:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
common.Must(common.RegisterConfig((*StrategyRandomConfig)(nil), nil))
|
|
|
|
}
|