mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
bug fix to LeastPingStrategy
This commit is contained in:
parent
017a11cfd5
commit
304b4feff6
@ -6,7 +6,6 @@ package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
"github.com/v2fly/v2ray-core/v4/common"
|
||||
"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 {
|
||||
return err
|
||||
}
|
||||
balancer.InjectContext(ctx)
|
||||
r.balancers[rule.Tag] = balancer
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@ package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
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/app/observatory"
|
||||
"github.com/v2fly/v2ray-core/v4/features/extension"
|
||||
)
|
||||
|
||||
@ -15,14 +15,17 @@ type LeastPingStrategy struct {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
newError("cannot get observe report").Base(err).WriteToLog()
|
||||
|
Loading…
x
Reference in New Issue
Block a user