yuhan6665 2024-12-10 20:07:52 -05:00 committed by GitHub
parent a2b773135a
commit 0e2304c403
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 98 additions and 59 deletions

View file

@ -7,7 +7,6 @@ import (
"time"
"github.com/xtls/xray-core/app/observatory"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/dice"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/core"
@ -58,8 +57,11 @@ type node struct {
RTTDeviationCost time.Duration
}
func (l *LeastLoadStrategy) InjectContext(ctx context.Context) {
l.ctx = ctx
func (s *LeastLoadStrategy) InjectContext(ctx context.Context) {
s.ctx = ctx
core.RequireFeaturesAsync(s.ctx, func(observatory extension.Observatory) {
s.observer = observatory
})
}
func (s *LeastLoadStrategy) PickOutbound(candidates []string) string {
@ -136,10 +138,8 @@ func (s *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node {
func (s *LeastLoadStrategy) getNodes(candidates []string, maxRTT time.Duration) []*node {
if s.observer == nil {
common.Must(core.RequireFeatures(s.ctx, func(observatory extension.Observatory) error {
s.observer = observatory
return nil
}))
errors.LogError(s.ctx, "observer is nil")
return make([]*node, 0)
}
observeResult, err := s.observer.GetObservation(s.ctx)
if err != nil {