1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-04 08:15:21 -05:00

incorporate changes in router implementation

This commit is contained in:
Shelikhoo
2021-06-19 00:02:46 +01:00
parent 24a5e34ce0
commit ea5bb04acf
16 changed files with 421 additions and 985 deletions

View File

@@ -2,33 +2,12 @@ package router
import (
"github.com/v2fly/v2ray-core/v4/common/dice"
"github.com/v2fly/v2ray-core/v4/features/routing"
)
// RandomStrategy represents a random balancing strategy
type RandomStrategy struct{}
// GetInformation implements the routing.BalancingStrategy.
func (s *RandomStrategy) GetInformation(tags []string) *routing.StrategyInfo {
items := make([]*routing.OutboundInfo, 0)
for _, tag := range tags {
items = append(items, &routing.OutboundInfo{Tag: tag})
}
return &routing.StrategyInfo{
Settings: []string{"random"},
ValueTitles: nil,
Selects: items,
Others: nil,
}
}
// SelectAndPick implements the routing.BalancingStrategy.
func (s *RandomStrategy) SelectAndPick(candidates []string) string {
return s.Pick(candidates)
}
// Pick implements the routing.BalancingStrategy.
func (s *RandomStrategy) Pick(candidates []string) string {
func (s *RandomStrategy) PickOutbound(candidates []string) string {
count := len(candidates)
if count == 0 {
// goes to fallbackTag