Skip to content

feat(proxy): add keys_direct so keyed lanes can keep one stable exit IP - #113

Closed
WengeLiu101 wants to merge 1 commit into
jasonxu114514:mainfrom
WengeLiu101:feat/keys-direct-egress
Closed

WengeLiu101 wants to merge 1 commit into
jasonxu114514:mainfrom
WengeLiu101:feat/keys-direct-egress

Conversation

@WengeLiu101

Copy link
Copy Markdown
Contributor

Motivation

The keyed (Zen/Go) lanes share the proxy pool with the anonymous lane: newNodePool round-robins keys over
every transport. As soon as an operator configures more than one proxy, an account's egress IP changes from
request to request
. Upstream may read that as suspicious, and there is currently no way to opt out — short of
removing the proxies, which the anonymous lane needs for rotation.

The two lanes want opposite things:

lane wants
anonymous (public credential) rotation — the free tier rate-limits and region-gates by exit IP
keyed (Zen/Go) a stable address — the account, not the IP, is the identity

Change

New top-level config key, off by default so existing behaviour is unchanged:

{ "keys_direct": true }

When enabled, every key is pinned to the local egress:

  • config.EnsureDirect() appends a direct entry when the configured list has none. A config whose proxies all
    come from proxyfile has no direct transport, and without this the setting would silently degrade to
    "spread across the pool" — a no-op that looks like it worked.
  • newTransportPool records which entry is direct (transportPool.directIndex, proxyTransport.direct).
  • newNodePool(..., direct bool) pins every key to that index.
  • newAnonymousPool() skips the direct entry: the anonymous lane exists precisely to leave the local egress
    behind, and the free tier rejects/limits it by IP, so trying it there would burn an attempt on most requests.
  • Startup logs the resolved mode (event=keys_direct, with direct_index/transports), and warns instead
    of silently ignoring the setting if no direct egress could be arranged.

Verification

Built and run locally with proxies: [] + a proxyfile of two proxies (so the list contains no direct):

config startup log meaning
keys_direct: true event=keys_direct direct_index=2 transports=3 direct entry appended, keys pinned to it
key absent (default) (no such log) unchanged: keys spread over the pool

gofmt clean, go vet ./... clean, go build ./cmd/opencode2api clean, go test ./internal/... passes.

Notes

  • Orthogonal to the #pool rotating-entry feature: that one changes what a single entry is, this one changes
    which entries the keyed lanes may use.
  • Default false means no migration is needed and no existing deployment changes behaviour.

The keyed (Zen/Go) lanes share the proxy pool with the anonymous lane, so an
account's egress IP changes from request to request as soon as more than one
proxy is configured. Upstream may read that as suspicious, and an operator who
points the gateway at a large scraped pool has no way to opt out: the anonymous
lane needs rotation, the keyed lanes do not.

Add keys_direct, a top-level boolean (default false, so existing behaviour is
unchanged) that pins every key to the local egress.

- config.EnsureDirect appends a "direct" entry when the configured list has
  none, since a proxyfile-only config has no direct transport. Without it the
  setting would silently degrade to "spread across the pool".
- newTransportPool records which entry is direct (transportPool.directIndex,
  proxyTransport.direct).
- newNodePool pins every key to it when enabled.
- newAnonymousPool skips the direct entry: the anonymous lane exists to leave
  the local egress behind, and the free tier rate-limits it by IP.
- Startup logs the mode, and warns rather than silently ignoring keys_direct if
  no direct egress could be arranged.
@jasonxu114514

Copy link
Copy Markdown
Owner

已在 main 以 a0fbd6b 重新實作並驗證,本 PR 由該提交取代,將納入 v1.5.2。keys_direct 預設 false;明確 proxy_bindings(含 direct4/direct6)優先,未綁定手動 Key 固定直連且失敗不遷移。內部注入的直連不會加入匿名/自動 OAuth 路由,並修正混合部署的健康狀態判定。感謝提案;關閉舊分支而不直接合併。

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.

2 participants