fix(warp): rotate exits on a live pool and size it to concurrency

The WARP pool could never rotate: its lifetime context was derived from the
startup deadline, so every standby registration and replacement died with
"context canceled" and requests stayed on the first egress forever. Give the
first registration the caller's deadline and the pool a context that only
Close cancels.

- warp.pool_size is an upper bound. The active ring follows concurrency (one
  exit per lease, one per queued request, plus a spare) and trims idle surplus
  after 60 seconds, so a burst expands it and quiet periods shrink it.
- An IPv6 exit is deduplicated and cooled by its /64 for 30 minutes (IPv4 by
  its /32), since the free quota is scoped to that block.
- 429/403 retires an exit immediately and re-registers right away; a free
  model request keeps switching exits and only returns the last 429 after
  retry.max_attempts, on both the anonymous and the Zen-key lane. 429s no
  longer trip the anonymous breaker or cool the key.
- Pin HTTP/1.1 ALPN and TLSNextProto on the WARP transport: a clone of
  DefaultTransport made after its first dial negotiated h2 and fed SETTINGS
  frames to the HTTP/1.x reader, breaking catalog refresh.
- Default to the IPv6 stack and, with warp.source_ipv6, let each exit bind its
  own outer source from a routed prefix via IPV6_FREEBIND. Endpoints try IPv6
  first and fall back to IPv4, so IPv4-only hosts keep working.
- WebUI, config example and all READMEs describe the new pool and rotation
  behaviour.
This commit is contained in:
Jason Xu committed 2026-10-25 06:49:00 +08:00
1 parent 953310117d
commit b8b1454a0e
17 files changed
+520 -146

No files matched your search

+2 -1
View File
@@ -29,9 +29,10 @@
## WARP 免费模型出口
WebUI「Proxy 节点」页底部新增 WARP 开关,对应配置 `warp.enabled`(默认关闭)、`warp.pool_size`(1–8,默认 2)和 `warp.stack`(`ipv4`、`ipv6` 或 `dual`)。开启后,匿名通道、免费模型的 Zen Key 回退、免费模型可用性探测和匿名模型目录刷新都通过用户态 Cloudflare WARP 出网,不再使用任何代理;Go 套餐 Key 与付费模型保持原有代理绑定。
WebUI「Proxy 节点」页底部新增 WARP 开关,对应配置 `warp.enabled`(默认关闭)、`warp.pool_size`(1–32,默认 2;出口数量上限,活跃出口按并发动态调整)、`warp.stack`(默认 `ipv6`,可选 `ipv4` 或 `dual`)和 `warp.source_ipv6`(外层 IPv6 源前缀,需配合 `stack = "ipv6"`)。开启后,匿名通道、免费模型的 Zen Key 回退、免费模型可用性探测和匿名模型目录刷新都通过用户态 Cloudflare WARP 出网,不再使用任何代理;Go 套餐 Key 与付费模型保持原有代理绑定。
- 主机或容器必须能向 Cloudflare 端点发送 UDP(端口 `2408`);不需要 TUN 设备、root、`NET_ADMIN` 或修改路由表。
- 出口第一次收到上游 429/403 即被淘汰并立刻在后台重新注册;免费模型请求会持续切换到其他出口,用完 `retry.max_attempts` 次后才把最后一个 429 返回客户端。活跃出口数按并发动态调整(每个在途请求一个,另留一个备用,上限为 `warp.pool_size`),空闲 60 秒的多余出口自动回收。免费额度按出口网段计算:IPv6 出口按 `/64`、IPv4 出口按 `/32` 去重并冷却 30 分钟。Cloudflare WARP 的共享 IPv4 出口通常已被用尽,`warp.stack` 默认 `ipv6`,配合 `warp.source_ipv6`(路由到本机的 `/64`,Linux 下通过 `IPV6_FREEBIND` 绑定)让每个出口使用独立源地址时,替换出口才会获得新的公网地址。
- WARP 无法初始化时启动直接失败;通过 WebUI 启用时参数错误会返回错误,旧运行时继续服务,不会静默回退到代理。
- `/healthz` 的 `warp` 块与 `/api/monitor` 的 `resources.warp` 显示堆栈、出口数量、活跃/备用/冷却数量和出口地址;启用 WARP 但无活跃出口时健康检查返回 503,此时若没有 Go Key,`no_healthy_proxies` 不再阻塞就绪。