mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-09-26 16:46:38 +00:00
bug fix to LeastPingStrategy
This commit is contained in:
parent
017a11cfd5
commit
304b4feff6
@ -6,7 +6,6 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v4"
|
core "github.com/v2fly/v2ray-core/v4"
|
||||||
"github.com/v2fly/v2ray-core/v4/common"
|
"github.com/v2fly/v2ray-core/v4/common"
|
||||||
"github.com/v2fly/v2ray-core/v4/features/dns"
|
"github.com/v2fly/v2ray-core/v4/features/dns"
|
||||||
@ -41,6 +40,7 @@ func (r *Router) Init(ctx context.Context, config *Config, d dns.Client, ohm out
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
balancer.InjectContext(ctx)
|
||||||
r.balancers[rule.Tag] = balancer
|
r.balancers[rule.Tag] = balancer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v4"
|
core "github.com/v2fly/v2ray-core/v4"
|
||||||
"github.com/v2fly/v2ray-core/v4/app/observatory"
|
|
||||||
"github.com/v2fly/v2ray-core/v4/common"
|
"github.com/v2fly/v2ray-core/v4/common"
|
||||||
|
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/observatory"
|
||||||
"github.com/v2fly/v2ray-core/v4/features/extension"
|
"github.com/v2fly/v2ray-core/v4/features/extension"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,14 +15,17 @@ type LeastPingStrategy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *LeastPingStrategy) InjectContext(ctx context.Context) {
|
func (l *LeastPingStrategy) InjectContext(ctx context.Context) {
|
||||||
common.Must(core.RequireFeatures(ctx, func(observatory extension.Observatory) error {
|
|
||||||
l.observatory = observatory
|
|
||||||
return nil
|
|
||||||
}))
|
|
||||||
l.ctx = ctx
|
l.ctx = ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LeastPingStrategy) PickOutbound(strings []string) string {
|
func (l *LeastPingStrategy) PickOutbound(strings []string) string {
|
||||||
|
if l.observatory == nil {
|
||||||
|
common.Must(core.RequireFeatures(l.ctx, func(observatory extension.Observatory) error {
|
||||||
|
l.observatory = observatory
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
observeReport, err := l.observatory.GetObservation(l.ctx)
|
observeReport, err := l.observatory.GetObservation(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
newError("cannot get observe report").Base(err).WriteToLog()
|
newError("cannot get observe report").Base(err).WriteToLog()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user