1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-06 01:05:35 -05:00

feat: RandomStrategy AliveOnly (#2850)

* feat: strategy_randomalive

* feat: RandomStrategy AliveOnly

* fix: unobserved candidate not alive

* fix: StrategySettings nil panic

* fix: TestRouterConfig

* fix: alive_only typo
This commit is contained in:
Mark Ma
2024-03-10 19:00:06 +08:00
committed by GitHub
parent 527a12d24e
commit a339721af8
6 changed files with 241 additions and 125 deletions

View File

@@ -164,10 +164,22 @@ func (br *BalancingRule) Build(ohm outbound.Manager, dispatcher routing.Dispatch
case "random":
fallthrough
case "":
var randomStrategy *RandomStrategy
if br.StrategySettings != nil {
i, err := serial.GetInstanceOf(br.StrategySettings)
if err != nil {
return nil, err
}
s, ok := i.(*StrategyRandomConfig)
if !ok {
return nil, newError("not a StrategyRandomConfig").AtError()
}
randomStrategy = NewRandomStrategy(s)
}
return &Balancer{
selectors: br.OutboundSelector,
ohm: ohm, fallbackTag: br.FallbackTag,
strategy: &RandomStrategy{},
strategy: randomStrategy,
}, nil
default:
return nil, newError("unrecognized balancer type")