Add priority outbound group#4217
Open
Shooa wants to merge 112 commits into
Open
Conversation
`SecTrustEvaluateWithError` is serial
This reverts commit 62cb06c.
The URL test history update hook and the Clash mode update hook were single-slot: the API service's attached service overwrote the hook set by the daemon, so clients stopped receiving group updates. Replace both with multicast hook lists. Also share a single URL test history storage via context: Clash API looked it up under a key nobody registered and fell back to its own empty storage, so dashboards showed no delay once an API service was configured. Selector changes now notify through the shared storage, covering selections made from any API surface.
912a858 to
5348fd4
Compare
A priority group orders its members into tiers and holds the highest-priority tier that still has a healthy member, dropping to a lower tier only when the active tier has fully failed and climbing back up once a higher tier recovers (with configurable hysteresis via tier_up_checks / tier_down_checks). Within the active tier it selects the lowest-delay member, reusing the URLTest probing and health store.
5348fd4 to
adbbd02
Compare
f7ca395 to
f27d0e3
Compare
22fe3b6 to
b2d51f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new outbound group type,
priority, that picks an outbound by tiers instead of by latency.Why
I run a gateway with several exits in different locations. With
urltestthe group always lands on whatever has the lowest RTT, which isn't what I want there — I have a preferred exit (or a couple of preferred ones) and the rest are only meant as fallback.urltesthappily parks traffic on a far-away node just because it answered the probe a few ms faster, andtolerancedoesn't really solve it once the delta is large.What I actually want is "stay on tier 1 as long as anything in it works; if the whole tier dies, fall to tier 2; come back up when tier 1 is healthy again." That's the classic fallback behaviour from Clash/mihomo that sing-box doesn't have a direct equivalent for, so I wrote it as a small group on top of the existing urltest machinery.
Behaviour
{ "type": "priority", "tag": "proxy", "tiers": [ ["nl-reality", "nl-hy2"], ["de-reality", "de-hy2"], ["us-reality", "us-hy2"] ], "url": "https://www.gstatic.com/generate_204", "interval": "3m", "tier_up_checks": 2, "tier_down_checks": 1 }urltest(lowest delay +tolerance), so you can spread load across equivalent exits in the same tier.tier_down_checksconsecutive rounds (default 1).tier_up_checksconsecutive rounds (default 2) — the hysteresis keeps a flapping upstream from bouncing the selection every probe.Probing, the history store,
clash_apireporting and connection interruption are all reused from urltest, so it shows up in the dashboard/API like any other group with no extra wiring.Notes
protocol/group/priority.go) plus the usual registration touch-points and a docs page.priority_test.go) — cold start, drop, delayed drop, climb-back, flap suppression.clash_api. Drops and climb-back behave as expected.golangci-lint runis clean for linux/windows/android andgo test ./protocol/group/...passes.Happy to adjust naming/defaults if you'd prefer something different.