← Back to Pull requests

feat(route-rule): a proxy rule can pick its proxies by name (proxy_filter) #181

Open
unknown opened this pull request with 626 lines diff across 7 files
View on GitHub
unknown unknown commented on Nov 22, 2026 19:22 UTC
Author

Problem

A route rule can send traffic to the proxy, direct, or block, but "the proxy" is always the main one: whatever is picked in select. There is no way to say "these sites through a server in Germany, everything else as usual", which comes up for services that serve or price by country, or refuse some exits. Today the only way is to switch the main proxy by hand, or keep a second profile and switch profiles.

Other clients do this with a group filtered by name (mihomo's filter on a proxy group), and subscription names already carry the country, as a flag or a word ("🇩🇪 Germany [1]", "🇩🇪 Германия").

Change

  • proxy_filter in the app's Rule (v2/config/route_rule.proto, field 19, regenerated with the same protoc-gen-go v1.34.2). It is an RE2 expression, case-insensitive, on the names of the profile's proxies. It is empty by default, so nothing changes for current rules.

  • A proxy rule with a filter routes to a balancer of the proxies whose name matches: lowest-delay, with the same tolerance as lowest (proxyOutbound in v2/config/route_rules.go). Rules with the same filter share one balancer. The balancers are rule-proxies-N §hide§, a number past any tag the profile already has, so they don't show in the proxy list.

  • Names are matched as the proxy list shows them: the select group's members without lowest and balance, and without the § N that numbering adds or the §…§ markers. So ^🇩🇪 germany \[\d\]$ works on a numbered subscription.

  • The rule keeps the main proxy when the filter is empty, is not a valid expression, or matches no proxy, because the rule list is built without a way to fail (as with an unreadable CIDR today).

  • With the extra security chain the rule keeps the main proxy too, because the hop has to carry all proxied traffic. With the unblocker, every proxy already dials through the hop, so the balancer does too.

  • IPv6: the reject before the sniff rule checks only the main proxy. When the apps get IPv6, a filtered rule gets its own reject in front of it (ipv6_unavailable_via the balancer), so IPv6 the filter's proxies can't carry falls back to IPv4 at once, as it does for the main proxy.

  • Keep top: the filter's proxies are added to pinned (ApplyKeepTop). Otherwise, at rest, none of them answers and the balancer stays on its first, untested member.

  • Direct and block rules ignore the field. A filtered rule's domains resolve with the remote DNS through the main proxy, as for any proxy rule; the proto comment says so.

  • A test file and a line in HISTORY.md.
  • Tested

  • go vet and go test ./v2/config/ with the core tags. The new tests in v2/config/route_rule_proxy_filter_test.go build through BuildConfig and libbox.CheckConfigOptions. They check:

  • - matching: a flag filter picks two proxies of three; a word filter ignores case; ^germany$ matches the numbered repeats and not "Germany West"; a profile of one proxy works;
    - balancers: two rules with one filter share a balancer, and another filter gets its own;
    - fallbacks: no filter, no match, an invalid expression, only spaces and a missed anchor each go to select, with no balancer;
    - other outbounds: direct, direct with fragment and block rules ignore the filter;
    - tags: a profile proxy already tagged rule-proxies-1 §hide§ doesn't collide;
    - chains: extra security routes to the hop; with the unblocker, the members dial through the hop;
    - IPv6: the reject comes first with IPv6 on, and isn't added with IPv6 off;
    - keep top: it pins the filter's proxies;
    - app JSON: "proxy_filter": "🇩🇪" is read.

    With the matching, balancer, extra security, IPv6 and keep top parts of the change reverted, the tests that cover them fail.

  • Live on Linux with a real subscription of 75 proxies: HiddifyCli parse, then build with a claude.ai rule, then srun in proxy mode.

  • - With the filter 🇩🇪, the balancer got the five German proxies. With ^🇩🇪 germany \[\d\]$, it got the three numbered ones.
    - claude.ai/cdn-cgi/trace answered loc=DE every time. cloudflare.com/cdn-cgi/trace went through the main proxy (loc=RU).

    Unrelated, seen on main as it is now: dns_group_test.go, keep_top_test.go and inbound_ports_test.go in v2/config don't compile. Their helpers chainTestOptions, chainTestProfile, oneProxyProfile and selectorItems are in a file that isn't committed.

    For the app

    The rule editor needs a text field "Proxy filter" under the outbound when it is "proxy", with a hint such as "Only proxies whose name matches, e.g. 🇩🇪|germany", sent as proxy_filter. I can open that PR in hiddify-app once this one is in.

    Review

  • Confidence: High. The field is empty by default, the rule falls back to the main proxy on any doubt, and the change was checked live.

  • Complexity: Moderate. It adds one proto field and the balancer it builds, plus its keep top and IPv6 handling. Existing clients see no API change.
  • Diff: 626 lines (+469 / -157) across 7 files Reviewer: claude[bot] Review duration: 9m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.50) × (1 − Review Confidence (0.37)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 626 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 62% · Reviewer familiarity: 35%
    37%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.385
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #181"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 37.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 37.4% · Lower = rushed or shallow review
    37.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.5% · Safe to merge
    31.5%