Skip to content

feat(rule): weighted cascade chains with retry budgets - #456

Open
tobwen wants to merge 3 commits into
nadoo:mainfrom
tobwen:feat/cascade-weight-434
Open

tobwen wants to merge 3 commits into
nadoo:mainfrom
tobwen:feat/cascade-weight-434

Conversation

@tobwen

@tobwen tobwen commented Nov 8, 2026 •

Copy link
Copy Markdown

Closes #434

Summary

This adds weighted proxy chaining: main forwarders tagged with #cascade=N form ordered levels, and each request dials one weighted-random pick per level instead of a single forwarder. Budgets have two parts: per forwarder (#retries, #retrydelay) and global/per-level through the -cascade flag, which also carries the chain-level budget (attempts, attemptdelay).

  • pr/prs select main forwarders by relative weight (#weight=N) and dial complete cascade chains grouped by #cascade=N levels, in numeric order, 3proxy-style weighted parent groups.
  • Request-local budgets per level: retries/retrydelay repeat the selected forwarder, attempts/attemptdelay trigger new weighted draws. Both are configured through -cascade '[cascade=N&]retries=N&retrydelay=MS&attempts=N&attemptdelay=MS' with per-field precedence: specific cascade > global > forwarder, independent of order.
  • pr skips unavailable levels and falls back to direct after all chain attempts fail; prs requires every active level and never falls back to direct. Weight-0 forwarders never participate in pr/prs. Health checks alone disable cascade hops; dial failures and relay errors never do.
  • Framed UDP streams (Trojan/VLESS) reject raw direct fallback; PacketConn UDP keeps it.
  • Operational constraints: SSH/SMUX persist only in the first cascade level, KCP/Unix/VSOCK must be its first transport; health checks test standalone forwarders, not complete paths (check=disable enables everything immediately); cascades advance independently, the longest required pause applies, and there is no overall time limit.
  • Protocol fixes on the shared dial path: Trojan and UDP dial failures close their sockets, proxy servers no longer double-count dial failures. The first commit isolates an HTTP CONNECT handshake cleanup that overlaps fix(http): close failed CONNECT handshakes #449; drop it on rebase if that PR merges first.

Tests

  • config/examples/10.cascade_with_weight/glider.conf is a runnable example; the README feature section documents every switch in user terms.

  • In-process fake dialer schemes and real protocol servers cover complete-chain dialing, per-level budgets, redraw weights, override precedence, UDP restrictions and pr/prs fallback (rule/*_test.go).

  • Validation (Go 1.27, linux/amd64 and linux/386): go test ./... -count=1, go test -race ./rule, GOARCH=386 CGO_ENABLED=0 go test ./rule, go test ./rule -run TestCascade -count=20, go vet ./..., gofmt -l ..

@tobwen tobwen changed the title Weighted cascade chains with retry budgets feat(rule): weighted cascade chains with retry budgets Nov 8, 2026
@tobwen
tobwen force-pushed the feat/cascade-weight-434 branch 4 times, most recently from ae19810 to d414ea6 Compare November 8, 2026 20:00
The dialer left the upstream connection open after a write failure, an unreadable status line, or a rejected status, and ignored malformed response headers after 200 OK. Return header parsing errors and close the buffered connection on every failed handshake; successful tunnels keep buffered payload bytes.
pr/prs select by relative weight and dial complete chains per level. Budgets are request-local: retries/retrydelay per forwarder, attempts/attemptdelay per cascade via -cascade; precedence is level > global > forwarder. Weight-0 levels stay absent; pr falls back to direct, prs never does. Health checks alone disable hops; dial errors count once and diagnostics never echo URLs.

Also closes Trojan and UDP dial failures cleanly and removes the double failure count in proxy servers.
In-process fake dialers and real protocol servers cover complete-chain dialing, per-level budgets, override precedence, UDP restrictions, pr/prs fallback, rule routing and the health checkers. Package coverage 73 percent, stable under repeated runs.
@tobwen
tobwen force-pushed the feat/cascade-weight-434 branch from d414ea6 to 172aa10 Compare November 8, 2026 20:06
@tobwen
tobwen marked this pull request as ready for review November 8, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] proxy groups with weights like in 3proxy

1 participant