81 lines
3.4 KiB
Diff
81 lines
3.4 KiB
Diff
--- a/protocol/group/urltest.go
|
|
+++ b/protocol/group/urltest.go
|
|
@@ -37,6 +37,7 @@
|
|
connection adapter.ConnectionManager
|
|
logger log.ContextLogger
|
|
tags []string
|
|
+ costs map[string]uint16 // OMV
|
|
link string
|
|
interval time.Duration
|
|
tolerance uint16
|
|
@@ -58,6 +59,7 @@
|
|
tolerance: options.Tolerance,
|
|
idleTimeout: time.Duration(options.IdleTimeout),
|
|
interruptExternalConnections: options.InterruptExistConnections,
|
|
+ costs: options.Costs, // OMV
|
|
}
|
|
if len(outbound.tags) == 0 {
|
|
return nil, E.New("missing tags")
|
|
@@ -74,7 +76,7 @@
|
|
}
|
|
outbounds = append(outbounds, detour)
|
|
}
|
|
- group, err := NewURLTestGroup(s.ctx, s.outbound, s.logger, outbounds, s.link, s.interval, s.tolerance, s.idleTimeout, s.interruptExternalConnections)
|
|
+ group, err := NewURLTestGroup(s.ctx, s.outbound, s.logger, outbounds, s.costs, s.link, s.interval, s.tolerance, s.idleTimeout, s.interruptExternalConnections) // OMV
|
|
if err != nil {
|
|
return err
|
|
}
|
|
@@ -175,6 +177,7 @@
|
|
pauseCallback *list.Element[pause.Callback]
|
|
logger log.Logger
|
|
outbounds []adapter.Outbound
|
|
+ costs map[string]uint16 // OMV
|
|
link string
|
|
interval time.Duration
|
|
tolerance uint16
|
|
@@ -192,7 +195,7 @@
|
|
lastActive common.TypedValue[time.Time]
|
|
}
|
|
|
|
-func NewURLTestGroup(ctx context.Context, outboundManager adapter.OutboundManager, logger log.Logger, outbounds []adapter.Outbound, link string, interval time.Duration, tolerance uint16, idleTimeout time.Duration, interruptExternalConnections bool) (*URLTestGroup, error) {
|
|
+func NewURLTestGroup(ctx context.Context, outboundManager adapter.OutboundManager, logger log.Logger, outbounds []adapter.Outbound, costs map[string]uint16, link string, interval time.Duration, tolerance uint16, idleTimeout time.Duration, interruptExternalConnections bool) (*URLTestGroup, error) { // OMV
|
|
if interval == 0 {
|
|
interval = C.DefaultURLTestInterval
|
|
}
|
|
@@ -202,6 +205,11 @@
|
|
if idleTimeout == 0 {
|
|
idleTimeout = C.DefaultURLTestIdleTimeout
|
|
}
|
|
+ // OMV start: initialize costs map
|
|
+ if costs == nil {
|
|
+ costs = map[string]uint16{}
|
|
+ }
|
|
+ // OMV end
|
|
if interval > idleTimeout {
|
|
return nil, E.New("interval must be less or equal than idle_timeout")
|
|
}
|
|
@@ -214,6 +222,7 @@
|
|
outbound: outboundManager,
|
|
logger: logger,
|
|
outbounds: outbounds,
|
|
+ costs: costs, // OMV
|
|
link: link,
|
|
interval: interval,
|
|
tolerance: tolerance,
|
|
@@ -374,7 +383,14 @@
|
|
g.logger.Debug("outbound ", tag, " unavailable: ", err)
|
|
g.history.DeleteURLTestHistory(realTag)
|
|
} else {
|
|
- g.logger.Debug("outbound ", tag, " available: ", t, "ms")
|
|
+ // OMV start: apply cost penalty to url test latency
|
|
+ add_latency, exist := g.costs[tag]
|
|
+ if !exist {
|
|
+ add_latency = 0
|
|
+ }
|
|
+ t = t + add_latency
|
|
+ g.logger.Debug("outbound ", tag, " available: ", t, "ms (add latency: ", add_latency, "ms)")
|
|
+ // OMV end
|
|
g.history.StoreURLTestHistory(realTag, &adapter.URLTestHistory{
|
|
Time: time.Now(),
|
|
Delay: t,
|