initial
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
--- /data/projects/arknights/omv-dijiang/works/sing-box/protocol/group/urltest.go 2026-03-05 11:39:22.630699577 +0800
|
||||
+++ /data/projects/arknights/omv-dijiang/works/core/protocol/group/urltest.go 2026-03-05 13:17:32.300369913 +0800
|
||||
@@ -39,6 +39,7 @@
|
||||
connection adapter.ConnectionManager
|
||||
logger log.ContextLogger
|
||||
tags []string
|
||||
+ costs map[string]uint16 // OMV
|
||||
link string
|
||||
interval time.Duration
|
||||
tolerance uint16
|
||||
@@ -61,6 +62,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")
|
||||
@@ -77,7 +79,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
|
||||
}
|
||||
@@ -194,6 +196,7 @@
|
||||
pauseCallback *list.Element[pause.Callback]
|
||||
logger log.Logger
|
||||
outbounds []adapter.Outbound
|
||||
+ costs map[string]uint16 // OMV
|
||||
link string
|
||||
interval time.Duration
|
||||
tolerance uint16
|
||||
@@ -211,7 +214,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
|
||||
}
|
||||
@@ -221,6 +224,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")
|
||||
}
|
||||
@@ -237,6 +245,7 @@
|
||||
outbound: outboundManager,
|
||||
logger: logger,
|
||||
outbounds: outbounds,
|
||||
+ costs: costs, // OMV
|
||||
link: link,
|
||||
interval: interval,
|
||||
tolerance: tolerance,
|
||||
@@ -392,7 +401,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,
|
||||
Reference in New Issue
Block a user