mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-28 14:56:33 -04:00
support principle target output
This commit is contained in:
parent
ea5bb04acf
commit
b122200c2a
@ -22,6 +22,15 @@ type LeastLoadStrategy struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LeastLoadStrategy) GetPrincipleTarget(strings []string) []string {
|
||||||
|
var ret []string
|
||||||
|
nodes := l.pickOutbounds(strings)
|
||||||
|
for _, v := range nodes {
|
||||||
|
ret = append(ret, v.Tag)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// NewLeastLoadStrategy creates a new LeastLoadStrategy with settings
|
// NewLeastLoadStrategy creates a new LeastLoadStrategy with settings
|
||||||
func NewLeastLoadStrategy(settings *StrategyLeastLoadConfig) *LeastLoadStrategy {
|
func NewLeastLoadStrategy(settings *StrategyLeastLoadConfig) *LeastLoadStrategy {
|
||||||
return &LeastLoadStrategy{
|
return &LeastLoadStrategy{
|
||||||
@ -56,8 +65,7 @@ func (l *LeastLoadStrategy) InjectContext(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *LeastLoadStrategy) PickOutbound(candidates []string) string {
|
func (s *LeastLoadStrategy) PickOutbound(candidates []string) string {
|
||||||
qualified := s.getNodes(candidates, time.Duration(s.settings.MaxRTT))
|
selects := s.pickOutbounds(candidates)
|
||||||
selects := s.selectLeastLoad(qualified)
|
|
||||||
count := len(selects)
|
count := len(selects)
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
// goes to fallbackTag
|
// goes to fallbackTag
|
||||||
@ -66,6 +74,12 @@ func (s *LeastLoadStrategy) PickOutbound(candidates []string) string {
|
|||||||
return selects[dice.Roll(count)].Tag
|
return selects[dice.Roll(count)].Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *LeastLoadStrategy) pickOutbounds(candidates []string) []*node {
|
||||||
|
qualified := s.getNodes(candidates, time.Duration(s.settings.MaxRTT))
|
||||||
|
selects := s.selectLeastLoad(qualified)
|
||||||
|
return selects
|
||||||
|
}
|
||||||
|
|
||||||
// selectLeastLoad selects nodes according to Baselines and Expected Count.
|
// selectLeastLoad selects nodes according to Baselines and Expected Count.
|
||||||
//
|
//
|
||||||
// The strategy always improves network response speed, not matter which mode below is configured.
|
// The strategy always improves network response speed, not matter which mode below is configured.
|
||||||
|
@ -17,6 +17,10 @@ type LeastPingStrategy struct {
|
|||||||
observatory extension.Observatory
|
observatory extension.Observatory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LeastPingStrategy) GetPrincipleTarget(strings []string) []string {
|
||||||
|
return []string{l.PickOutbound(strings)}
|
||||||
|
}
|
||||||
|
|
||||||
func (l *LeastPingStrategy) InjectContext(ctx context.Context) {
|
func (l *LeastPingStrategy) InjectContext(ctx context.Context) {
|
||||||
l.ctx = ctx
|
l.ctx = ctx
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,10 @@ import (
|
|||||||
// RandomStrategy represents a random balancing strategy
|
// RandomStrategy represents a random balancing strategy
|
||||||
type RandomStrategy struct{}
|
type RandomStrategy struct{}
|
||||||
|
|
||||||
|
func (s *RandomStrategy) GetPrincipleTarget(strings []string) []string {
|
||||||
|
return strings
|
||||||
|
}
|
||||||
|
|
||||||
func (s *RandomStrategy) PickOutbound(candidates []string) string {
|
func (s *RandomStrategy) PickOutbound(candidates []string) string {
|
||||||
count := len(candidates)
|
count := len(candidates)
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user