1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-08-07 13:04:21 -04:00
v2fly/app/router/strategy_random.go

27 lines
572 B
Go
Raw Normal View History

package router
import (
2021-09-07 06:48:24 -04:00
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/dice"
)
// 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
}
func (s *RandomStrategy) PickOutbound(candidates []string) string {
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))
}