Skip to content

Commit

Permalink
new: add url test delay to 65535 if node is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 10, 2024
1 parent 8dea444 commit 99f9e4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
12 changes: 7 additions & 5 deletions experimental/libbox/command_urltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ func (s *CommandServer) handleURLTest(conn net.Conn) error {
b.Go(outboundTag, func() (any, error) {
t, err := urltest.URLTest(serviceNow.ctx, "", outboundToTest)
if err != nil {
historyStorage.DeleteURLTestHistory(outboundTag)
// historyStorage.DeleteURLTestHistory(outboundTag)
t = 65535
} else {
historyStorage.StoreURLTestHistory(outboundTag, &urltest.History{
Time: time.Now(),
Delay: t,
})
}
historyStorage.StoreURLTestHistory(outboundTag, &urltest.History{
Time: time.Now(),
Delay: t,
})

return nil, nil
})
}
Expand Down
24 changes: 13 additions & 11 deletions outbound/urltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (g *URLTestGroup) Select(network string) (adapter.Outbound, bool) {
continue
}
history := g.history.LoadURLTestHistory(RealTag(detour))
if history == nil {
if history == nil || history.Delay == 65535 {
continue
}
if minDelay == 0 || minDelay > history.Delay+g.tolerance || minDelay > history.Delay-g.tolerance && minTime.Before(history.Time) {
Expand Down Expand Up @@ -375,19 +375,21 @@ func (g *URLTestGroup) urlTest(ctx context.Context, force bool) (map[string]uint
defer cancel()
t, err := urltest.URLTest(ctx, g.link, p)
if err != nil {
g.logger.Debug("outbound ", tag, " unavailable: ", err)
g.history.DeleteURLTestHistory(realTag)
g.logger.Debug("outbound ", tag, " unavailable (65535 ms): ", err)
// g.history.DeleteURLTestHistory(realTag)
t = 65535
} else {
g.logger.Debug("outbound ", tag, " available: ", t, "ms")
g.history.StoreURLTestHistory(realTag, &urltest.History{
Time: time.Now(),
Delay: t,
})
resultAccess.Lock()
result[tag] = t
g.performUpdateCheck()
resultAccess.Unlock()
}
g.history.StoreURLTestHistory(realTag, &urltest.History{
Time: time.Now(),
Delay: t,
})
resultAccess.Lock()
result[tag] = t
resultAccess.Unlock()
g.performUpdateCheck()

return nil, nil
})
}
Expand Down

0 comments on commit 99f9e4e

Please sign in to comment.