Skip to content

fix(kubo): remove the address rewriter proxy that now degrades provider records - #263

Merged
Rinse12 merged 2 commits into
masterfrom
refactor/remove-address-rewriter-proxy-262
Aug 12, 2026
Merged

fix(kubo): remove the address rewriter proxy that now degrades provider records#263
Rinse12 merged 2 commits into
masterfrom
refactor/remove-address-rewriter-proxy-262

Conversation

@Rinse12

@Rinse12 Rinse12 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #262.

Why now

AddressesRewriterProxyServer existed to work around a Kubo bug: provider records PUT to a delegated HTTP router were missing the browser-dialable transports (AutoTLS /tls/ws, webrtc-direct), so a browser that found a node through a router had no address it could dial. We proxied every provider PUT and rewrote Addrs.

Kubo 0.43.0 fixed it (fix(http-routing): keep browser transports in provider records, ipfs/kubo#11394, closing the ipfs/kubo#11369 we filed). This repo already pins 0.43.0 and all production nodes run it.

Verified against production before writing any code. Querying /routing/v1/providers/<cid> for a live board on all six default routers from src/schema.ts:

router peers with /tls/ws webrtc+certhash bare webrtc (no certhash)
routerofbitsocial.xyz 6 6 6 0
bsotracker.online 6 6 6 0
routing.lol 10 7 7 3
peers.pleb.bot 10 7 7 3
peers.forumindex.com 10 7 7 3
peers.plebpubsub.xyz 9 0 6 3

Two things that survey showed:

  1. The proxy is now actively harmful. Three peers publish webrtc-direct and webtransport with no certhash, which no browser can dial. That is the proxy's signature: it rebuilds the addr set from kubo id + kubo swarm addrs, and self swarm addrs carry no certhash. Nodes announcing natively have complete records.
  2. peers.plebpubsub.xyz stores zero /dns* addrs while the same peer IDs have /dns4/.../tls/ws everywhere else. Stale router deploy, out of scope here, tracked in Remove the address rewriter proxy now that kubo 0.43.0 publishes browser transports to HTTP routers #262.

What changed

  • setup-kubo-address-rewriter-and-http-router.tssetup-kubo-http-routers.ts, returning void. Kubo's Routing.Routers now hold the router URLs verbatim. The typed config helpers, the merge logic, the Provide.DHT.SweepEnabled write and the capped retry are unchanged.
  • Deleted addresses-rewriter-proxy-server.ts, address-rewriter-db.ts and its SQLite request/reprovide logging, plus the browser stub.
  • Deleted the proxy port machinery: PKC_ADDRESSES_REWRITER_START_PORT, the free-port walk, the persisted httprouter_proxy_<url> storage mapping. tcp-port-used moves to devDependencies (the test server and tests still use it).
  • pkc.ts keeps one _httpRouterSetupPromise instead of the setup-promise/destroy-callback pair.
  • normalizeSelfAddrsForProvider moves to reprovide-on-address-change.ts, its only remaining caller, with its unit tests.
  • Docs: .address-rewriter/ is described as a legacy directory that can be deleted.

What replaces the 2-minute _retryFailedKeys loop

Nothing custom. It retried provider keys whose PUT had failed, it was not a general reprovide loop. Kubo owns provide and reprovide once it talks to the routers directly, and its reprovide cycle stays inside the routers' 24h record expiry. The browser-facing case that actually mattered is already independent of the proxy: reprovide-on-address-change.ts re-provides the connection-critical CIDs whenever the node's browser-dialable self-addresses change.

Tests

  • test/node/httprouter.test.ts now asserts Kubo is configured directly against the router (no proxy endpoint), that provider records reaching the router are usable, and that the config survives pkc.destroy().
  • test/node/httprouter-direct-kubo.test.ts gains the kubo#11369 regression test: the throwaway daemon now also listens on webrtc-direct, and the test asserts that addr survives into the record the router actually stored, not just into ipfs id. The two disagreeing is exactly what the bug looked like. Still runs with Provide.DHT.SweepEnabled both off and on.
  • Deleted address-rewriter-logging.unit.test.ts (tested the proxy's SQLite logging) and kubo-address-rewriter.unit.test.ts (its cases moved with the helper).

All green locally against the local test server: httprouter, httprouter-direct-kubo, reprovide-on-address-change.unit, rpc.auto-start-kubo-restart, pkc, datapath-retention.pkc. npm run build, npx tsc --project test/tsconfig.json --noEmit and knip are clean.

Out of scope

  • Redeploying peers.plebpubsub.xyz.
  • Provide.DHT.SweepEnabled=false and the legacy serial provider's throughput, unchanged here.

Summary by CodeRabbit

  • Improvements

    • Kubo now connects directly to configured HTTP routers, improving routing setup and reducing unnecessary proxy handling.
    • Provider records preserve usable direct addresses, including browser-dialable transports.
    • Router setup and shutdown are coordinated more reliably, including during automatic restarts and cleanup.
    • Address updates are normalized and deduplicated before being re-published.
  • Documentation

    • Clarified that legacy .address-rewriter/ directories are obsolete and may be safely deleted.
  • Bug Fixes

    • Improved provider-record and routing behavior across startup, restart, and shutdown scenarios.

Kubo 0.43.0 fixed the bug the proxy worked around: provider records PUT
to a delegated HTTP router no longer drop the browser-dialable transports
(AutoTLS /tls/ws, webrtc-direct). See ipfs/kubo#11394, closing the
ipfs/kubo#11369 we filed. Kubo's Routing.Routers now hold the router URLs
verbatim instead of loopback proxy URLs.

Keeping the proxy is worse than removing it. It rebuilds the addr set from
`kubo id` + `kubo swarm addrs`, and self swarm addrs carry no certhash, so
the webrtc-direct and webtransport addrs it publishes are ones no browser
can dial. A survey of the six production routers shows exactly that: nodes
still behind the proxy have certhash-less records while natively announcing
nodes have complete ones.

Removed:
- src/runtime/node/addresses-rewriter-proxy-server.ts (incl. the 2-minute
  failed-key retry loop; Kubo owns provide/reprovide now, and the
  browser-facing case is already covered by reprovide-on-address-change.ts)
- src/runtime/node/address-rewriter-db.ts and its SQLite request logging
- the proxy port machinery: PKC_ADDRESSES_REWRITER_START_PORT, the free-port
  walk, the persisted httprouter_proxy_<url> storage mapping
- tcp-port-used from dependencies (still a devDependency, the test server
  and tests use it)

setup-kubo-address-rewriter-and-http-router.ts is renamed to
setup-kubo-http-routers.ts and now returns void; pkc.ts keeps a single
_httpRouterSetupPromise in place of the setup/destroy pair.

normalizeSelfAddrsForProvider moves to reprovide-on-address-change.ts, its
only remaining caller, along with its unit tests.

Tests: httprouter.test.ts asserts the routers are configured directly and
that the records reaching them are usable. httprouter-direct-kubo.test.ts
gains a kubo#11369 regression test: the throwaway daemon now listens on
webrtc-direct, and the addr must survive into the record the router stored.
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

PKC now configures Kubo with HTTP routers directly. The address-rewriter proxy, database, persistence, and cleanup paths were removed. Provider address normalization moved to local-community reprovisioning, and tests now cover direct routing and reconciliation.

Changes

Direct HTTP-router migration

Layer / File(s) Summary
Direct router setup and lifecycle
src/pkc/pkc.ts, src/runtime/node/setup-kubo-http-routers.ts, src/runtime/browser/setup-kubo-http-routers.ts, src/runtime/node/address-rewriter-db.ts, src/runtime/node/addresses-rewriter-proxy-server.ts, package.json, docs/protocol/data-path-migration.md
PKC now tracks HTTP-router setup and awaits it during destruction. Kubo receives sorted router URLs directly. The address-rewriter proxy and database were removed.
Provider address normalization
src/runtime/node/community/local-community/reprovide-on-address-change.ts, test/node/community/reprovide-on-address-change.unit.test.ts
Address normalization now removes this node’s peer-ID suffix and deduplicates addresses before direct reprovisioning.
Direct-routing regression coverage
test/node/httprouter.test.ts, test/node/httprouter-direct-kubo.test.ts
Tests now verify direct router configuration, provider records, webrtc-direct address preservation, and destruction behavior.
RPC restart reconciliation
src/rpc/src/index.ts, src/rpc/test/node/rpc.auto-start-kubo-restart.test.ts
RPC auto-start tests now wait for _httpRouterSetupPromise during Kubo restart reconciliation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • pkcprotocol/pkc-js issue 262 — Directly covers removal of the address-rewriter proxy and direct Kubo HTTP-router configuration.

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant PKC
  participant HTTPRouterSetup
  participant Kubo
  participant HTTPRouters
  PKC->>HTTPRouterSetup: start reconciliation
  HTTPRouterSetup->>Kubo: set Routing.Routers
  Kubo->>HTTPRouters: submit provider records
  PKC->>HTTPRouterSetup: await setup during destroy
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: removing the Kubo address rewriter proxy because it degrades provider records.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/remove-address-rewriter-proxy-262

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pkc/pkc.ts`:
- Around line 408-429: Update _waitForHttpRoutersSetupToSettle and the
setupKuboHttpRouters completion flow so the promise remains pending after POST
/shutdown until the embedded Kubo accepts a lightweight RPC request again; poll
the appropriate readiness endpoint with the existing Kubo client utilities, then
resolve only once readiness is confirmed while preserving destroyed/error
handling. Adjust the regression test to simulate delayed Kubo readiness rather
than merely stubbing _httpRouterSetupPromise.

In `@src/runtime/node/community/local-community/reprovide-on-address-change.ts`:
- Around line 41-45: Update isBrowserDialableAddr() to return true for addresses
containing /webtransport in addition to the existing /webrtc and /ws checks, and
add a regression test covering a WebTransport address.

In `@src/runtime/node/setup-kubo-http-routers.ts`:
- Around line 194-200: Update the HTTP-router setup flow around
settingOptionRetryOption, setHttpRouterOnAllNodes, and PKC.destroy() so
destruction cancels the retry operation immediately and settles
_httpRouterSetupPromise without waiting for backoff retries. Pass the destroy
abort signal to every router-setup fetch, and ensure pending or scheduled
attempts observe cancellation rather than retrying against the destroyed PKC.

In `@test/node/httprouter.test.ts`:
- Around line 9-14: Add a concise comment immediately above the
describeSkipIfRpc call explaining that RPC clients cannot read or modify the
local Kubo Routing configuration, so this suite cannot run under RPC.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 877054cc-3fa0-4bb9-a1f9-dd2adfe4634c

📥 Commits

Reviewing files that changed from the base of the PR and between 0239e60 and 6a65e6d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json, !package-lock.json
📒 Files selected for processing (16)
  • docs/protocol/data-path-migration.md
  • package.json
  • src/pkc/pkc.ts
  • src/rpc/src/index.ts
  • src/rpc/test/node/rpc.auto-start-kubo-restart.test.ts
  • src/runtime/browser/setup-kubo-address-rewriter-and-http-router.ts
  • src/runtime/browser/setup-kubo-http-routers.ts
  • src/runtime/node/address-rewriter-db.ts
  • src/runtime/node/addresses-rewriter-proxy-server.ts
  • src/runtime/node/community/local-community/reprovide-on-address-change.ts
  • src/runtime/node/setup-kubo-http-routers.ts
  • test/node/address-rewriter-logging.unit.test.ts
  • test/node/community/reprovide-on-address-change.unit.test.ts
  • test/node/httprouter-direct-kubo.test.ts
  • test/node/httprouter.test.ts
  • test/node/kubo-address-rewriter.unit.test.ts
💤 Files with no reviewable changes (5)
  • src/runtime/browser/setup-kubo-address-rewriter-and-http-router.ts
  • test/node/address-rewriter-logging.unit.test.ts
  • test/node/kubo-address-rewriter.unit.test.ts
  • src/runtime/node/addresses-rewriter-proxy-server.ts
  • src/runtime/node/address-rewriter-db.ts

Comment thread src/pkc/pkc.ts
Comment thread src/runtime/node/setup-kubo-http-routers.ts
Comment thread test/node/httprouter.test.ts
The `pkc.destroyed` guard only runs at the top of a retry attempt, so a
destroy() landing inside a backoff window still had to wait out the
remaining delay (up to the 60s maxTimeout) on the setup promise it awaits.
Wire the destroy abort signal into the retry operation: stop() drops the
scheduled attempt and the promise resolves immediately. The same signal now
also aborts the in-flight config GET/POST and the /shutdown POST.

Regression test asserts destroy() returns in under 3s while the setup loop
sits in a 8s backoff against an unreachable kubo node (7s without the fix).

Also states why the http router suite is skipped under RPC, per AGENTS.md.
@Rinse12 Rinse12 changed the title refactor(kubo): remove the address rewriter proxy fix(kubo): remove the address rewriter proxy that now degrades provider records Aug 12, 2026
@Rinse12
Rinse12 merged commit 08ca094 into master Aug 12, 2026
16 of 17 checks passed
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.

Remove the address rewriter proxy now that kubo 0.43.0 publishes browser transports to HTTP routers

1 participant