Repository navigation
feat(cli): decdn gateway --public-url serves anyone from its own pool - #2608
Merged
Merged
Conversation
thiras
added a commit
that referenced
this pull request
Oct 24, 2026
Co-Authored-By: Claude Fable 5.1 <[email protected]>
thiras
force-pushed
the
feat/gateway-public
branch
3 times, most recently
from
October 24, 2026 14:58
0d2efe9 to
aaa717d
Compare
thiras
force-pushed
the
feat/gateway-sites
branch
from
October 24, 2026 15:07
c748f37 to
6021ca8
Compare
thiras
force-pushed
the
feat/gateway-public
branch
from
October 24, 2026 15:18
aaa717d to
3453643
Compare
thiras
marked this pull request as ready for review
October 24, 2026 15:18
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 7 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🟡 Changes recommended
Allowance enforcement and concurrent pool-funding defects can permit unintended operator spending or disrupt service.
9 open issues
Concurrent fetches race funding transaction serialization · New Concurrent fetches prematurely clear the payer recovery marker · New Queued pulls bypass allowance checks before paid work · New Generated indexes bypass allowance checks · New Manifest reads continue after allowance exhaustion · New Cancellation skips accounting for read-ahead pulls · New Data directory override misresolves the default keystore path · New HEAD fails URI decoding and root directory resolution · New Shared test log causes nondeterministic size-cap assertions · New
What changed in this PR
Adds a hosted public mode to the existing CLI gateway, letting ordinary HTTP clients retrieve deCDN content using the operator’s payment pool while retaining loopback mode.
Changes:
- Adds public-domain routing, per-bundle sites, and metadata-only HEAD responses.
- Introduces shared pool payment, persistent buyer storage, and daily allowance accounting.
- Adds gateway regression tests, an anvil-backed integration test, and deployment documentation.
| File | Description |
|---|---|
Dockerfile |
Clarifies port publishing for public gateways in comments. |
docker/README.decdn.md |
Documents container deployment and operator funding. |
crates/e2e/tests/gateway_public.rs |
Adds a funded public-gateway integration journey. |
crates/e2e/Cargo.toml |
Adds BLAKE3 for integration-test hashing. |
crates/common/src/cli/mod.rs |
Updates gateway command help. |
crates/common/src/cli/gateway/tests.rs |
Tests public URL and allowance arguments. |
crates/common/src/cli/gateway.rs |
Defines public-mode CLI options. |
crates/cli/src/commands/gateway/worker/tests.rs |
Tests shared payers, replacement, and startup failures. |
crates/cli/src/commands/gateway/worker.rs |
Adds pool-backed jobs and payer retirement. |
crates/cli/src/commands/gateway/tests.rs |
Covers public routing, HEAD, refusals, and accounting. |
crates/cli/src/commands/gateway/site/tests.rs |
Tests public hosts, schemes, ports, and content policy. |
crates/cli/src/commands/gateway/site.rs |
Generalizes site routing to public domains. |
crates/cli/src/commands/gateway/allowance/tests.rs |
Tests allowance charging and daily reset. |
crates/cli/src/commands/gateway/allowance.rs |
Implements in-memory daily byte accounting. |
crates/cli/src/commands/gateway.rs |
Integrates public serving, allowance checks, and HEAD handling. |
crates/cli/src/commands/fetch/tests.rs |
Tests declared-size cap behavior. |
crates/cli/src/commands/fetch.rs |
Adds shared pool payers, early unlocking, and pull limits. |
crates/cli/README.md |
Introduces public gateway usage. |
CHANGELOG.md |
Records the public gateway feature. |
Cargo.lock |
Records the integration-test dependency. |
Review effort: Balanced
6 tasks done
A public gateway serves a domain to anyone, behind a proxy that terminates TLS: `<origin>/<hash>[/<path>]`, every bundle as a site at `[<ns>.]<hash32>.<host>`, and a namespace host (`<ns>.<host>`) that answers 404 until it has a pointer. There is no token and no capability: every request pays from the keystore's own pool, through one payer the pull worker builds with its host and every pool pull shares (one set of funding facts, so no two pulls send a `topUp` at once, and no pull clears a replacement a sibling still runs on), and a daily allowance (`--allowance-bytes-per-day`) bounds the bytes the gateway delivers. A request past it, or an entry whose size does not fit what is left, answers 402 before any pull; a stream of unknown size is cut when the allowance runs out; a pool that cannot pay answers 503. Each carries the canonical `decdn:` URI in a `Link` header and a JSON body so a paying client continues on its own. The namespace hint buys no bucket of its own: it is the client's to set. Every byte a pull lands is charged, a manifest that does not parse included, and a manifest read stops where the allowance does; a generated listing is admitted by its length; a pull is admitted again once it has its slot, and a request dropped at any point, its first byte still awaited included, is charged the pull's read-ahead bound; an entry's pull is capped at the size its manifest declares, so a manifest cannot make the gateway pay for more than it says, and an entry declared empty is answered empty with no pull; a public pull runs a small read-ahead, and a response that does not end whole (a client that drops it, a cut, a fault) is charged what the pull may have paid past the frames it delivered, so a client that connects and drops spends no more than it is charged. `HEAD` is answered from the bundle manifest at no pull of the entry. An upstream failure answers a bare 502 with the detail in the log. The buyer store lives under the data dir, so the pool and its lanes survive a restart. A `/_decdn/` request with no `Sec-Fetch-Mode` is a navigation: another bundle's pages never run on a site's origin. Sites are separate origins; they are separate sites only when the public host is on the Public Suffix List. Part of #2593. Co-Authored-By: Claude Fable 5.1 <[email protected]>
thiras
force-pushed
the
feat/gateway-public
branch
from
October 24, 2026 16:37
3453643 to
7ac2af5
Compare
6 tasks done
Open
7 of 11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What
decdn gateway --public-url <origin>turns the gateway into a hosted public HTTP gateway (#2593): it serves a domain to anyone, behind a proxy that terminates TLS, and pays for every request from its own pool.gateway/site.rs,SiteDomain/Route):<origin>/<hash>[/<path>]on the bare host (a blob streams, a bundle or entry redirects to its site over the public scheme), every bundle as a site at<scheme>://[<ns>.]<hash32>.<host>/(the gateway: serve bundles as websites, one browser origin per bundle, no extension needed #2457 origins on the real domain), and a namespace host<ns>.<host>that answers 404 until it has a pointer (next PR). Every otherHostis 403; the listen address's loopback names still reach the bare host for health checks.Sec-Fetch-*decides nothing (the operator pays, within the allowance;curlsends none).worker.rs,fetch.rs):Payment::{Held, Pool}; the worker builds onePayer::poolwith its host (keystore unlocked at startup, so a wrong password fails before the gateway listens) and every pool pull shares it; a pull that ends withPoolReplacedretires it so the next pull's ledgers know only the new pool. Pool open and low-water top-up happen inside the existing fetch path, so there is no keeper. The buyer store lives in<data-dir>/storeso the pool and lanes survive a restart.gateway/allowance.rs):--allowance-bytes-per-day(default 1 GiB) bounds the bytes the gateway delivers per UTC day, over every request, metered in memory on delivered bytes (entries, manifests, index pages). A request past it answers402before any pull; an entry whose manifest size does not fit what is left is refused before its pull too; a stream of unknown size is cut (body error, never a quiet short file) once the bound is reached, so delivery is bounded by the allowance plus the frames in flight.402and the503for a pool that cannot pay both carryRetry-After,Link: <decdn:…>; rel="alternate"and a JSON body, so a paying client continues on its own. The namespace hint (?ns=, the<ns>.site label) buys no bucket of its own: it is the client's to set (ADR 002), so a per-namespace allowance only makes sense for a namespace served through its owner-signed pointer, which is the next PR along with--allowance <ns>=<bytes>.PUBLIC_READ_AHEAD_BYTES, via a newBlobFetch.read_ahead), and a response that does not end whole (a client that drops it, a cut, a fault) is charged the pull's maximum paid-but-undelivered bound (DROP_PENALTY_BYTES= read-ahead + pipe + one frame), so a connect-and-drop loop spends no more than it is charged. A body with a declared length that hyper stops polling once that length is out counts as whole (Streaming::drop), and that declared length is safe to trust because an entry pull is capped at it (BlobFetch.size_cap→ the fetch'smax_blob_bytes): a manifest that understates an entry cannot make the gateway pay for the rest, and an entry declared empty is answered empty with no pull at all (a zero size never lifts the cap:held_cap).RunFundingper pool payer so concurrent pulls never race atopUp;leave_carriedonly for sequential payers; aJob.admitre-check once a pull has its slot; the listing admitted by its length; the manifest read stops at the allowance; aPullGuardarmed before the worker has the job (a request dropped while waiting for its first byte is charged); the resolved keystore pinned before the store dir replaces the data dir (the e2e now runs without--keystore);HEADresolving paths through the same URI parsing asGET; per-gateway test logs.502on a public gateway, with the detail (node ids, addresses, chain errors) in the log; loopback keeps showing its own user the detail./_decdn/withoutSec-Fetch-*is a navigation on a public site (redirect to the other bundle's own origin, or a download for a blob), so a browser that sends noSec-Fetch-Modecan never have another bundle's page run on this origin. Loopback was already covered bymay_spendrefusing header-less requests.github.iois). The docs say to register it.Content-Length,ETag= entry hash) at no pull of the entry; a raw blob's HEAD has no length. NoAccept-Rangesyet (Range is the next PR; advertising it now would makehuggingface_hubresume with aRangeand restart on the 200).Loopback mode is unchanged: same token, capabilities,
Sec-Fetch-*rules, 405 on HEAD, and its store still dies with the process.Rebased onto
mainafter #2590 and #2607 merged. Part of #2593; the next PRs add Range, metrics, the namespace pointer and theHF_ENDPOINTresolve shim.Reviewer notes
Read
site.rsfirst (SiteDomain::routeis the whole host policy), thenworker.rs(Payment,PayerId,pool_payer,rebuild_pool_payer), thengateway.rs(mode,paid→allowance_refusal/serve/pull_failed,head_site).fetch.rsonly lifts the keystore-load closure intoPayer::keyssounlockcan run it at startup;fetch_oncalls the same code.Design calls worth a look: scheme comes from
--public-url, notX-Forwarded-Proto; the allowance is operator-set, in memory and one bucket (two automated security passes on the pushed commits flagged: a client-chosen?ns=bucket defeats the cap, a finished-after-exhaustion response is unbounded,HEADskipped the check, manifest bytes went uncharged when the blob was no manifest, a dropped response left the read-ahead uncharged, a manifest-declared size was trusted for "delivered whole", a zero declared size lifted the cap, a header-less/_decdn/request was served as site content, and the shared registrable domain; all are fixed or documented here, each with a test); a--capabilityis allowed in public mode (the gateway then delegates for that pool, and cannot top it up).Verification
Always:
pre-commit runon commit (all hooks passed;cargo denyfindings are the known warn-only advisories)CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features: cleancargo nextest run -p decdn-cli -p decdn-common -p decdn-e2e: 1507 passed (decdn-clientuntouched)Only if touched:
cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(gateway_public)'passes (pool opened by the gateway, site entry byte-exact, HEAD from the manifest, bare blob, four concurrent pulls with zerodecdn_serve_stream_voucher_rejected_total, 402 before any pull once the entry no longer fits the allowance, 403 for an unknown host)CHANGELOG.mdentry added by hand, one per PR🤖 Generated with Claude Code