Skip to content

Commit 24e082f

Browse files
authored
Merge branch 'main' into ash/feat/add-did-document
2 parents 6e88033 + 7f8cea8 commit 24e082f

File tree

16 files changed

+257
-71
lines changed

16 files changed

+257
-71
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [2.34.0](https://github.com/storacha/freeway/compare/v2.33.0...v2.34.0) (2025-11-25)
4+
5+
6+
### Features
7+
8+
* add a stripped down server for debugging ([#196](https://github.com/storacha/freeway/issues/196)) ([bd7adb2](https://github.com/storacha/freeway/commit/bd7adb2fbe2a0780aeff8c6ed80dfd84552ce004))
9+
* bump egress tracking traffic to 5% ([#200](https://github.com/storacha/freeway/issues/200)) ([5b97f6f](https://github.com/storacha/freeway/commit/5b97f6f4945daf177daf73f2d2a7ada5598fc5a1))
10+
11+
12+
### Bug Fixes
13+
14+
* disable FF_TELEMETRY_ENABLED in wrangler.toml ([#197](https://github.com/storacha/freeway/issues/197)) ([b63d3c3](https://github.com/storacha/freeway/commit/b63d3c3bfdc24badce41b6f5f2517755ba98a153))
15+
* skip egress tracking if content found in multiple spaces ([#199](https://github.com/storacha/freeway/issues/199)) ([9a8089f](https://github.com/storacha/freeway/commit/9a8089f82214778a53de1f5891f25ebc51eca289))
16+
317
## [2.33.0](https://github.com/storacha/freeway/compare/v2.32.0...v2.33.0) (2025-11-20)
418

519

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "freeway",
3-
"version": "2.33.0",
3+
"version": "2.34.0",
44
"description": "An IPFS gateway for accessing UnixFS data via CAR CIDs",
55
"keywords": [
66
"IPFS",
@@ -85,7 +85,8 @@
8585
},
8686
"standard": {
8787
"ignore": [
88-
"*.ts"
88+
"*.ts",
89+
"src/middleware/withVersionHeader.js"
8990
]
9091
},
9192
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"

scripts/debug/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# freeway-debug
2+
3+
A stripped down freeway for debugging. Just run `npx wrangler dev` from this directory to start a freeway server that points to production on `http://localhost:8787`.

scripts/debug/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "freeway-debug",
3+
"version": "0.0.0",
4+
"description": "An IPFS gateway for accessing UnixFS data via CAR CIDs",
5+
"license": "Apache-2.0 OR MIT",
6+
"author": "Alan Shaw",
7+
"type": "module",
8+
"exports": {
9+
".": {
10+
"import": "./src/index.js",
11+
"types": "./dist/src/index.d.ts"
12+
}
13+
},
14+
"main": "src/index.js",
15+
"scripts": {
16+
"build": "esbuild --bundle src/index.js --format=esm --outfile=dist/worker.mjs",
17+
"build:tsc": "tsc --build"
18+
}
19+
}

scripts/debug/src/index.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-env worker */
2+
3+
// Stripped down freeway for debugging. It points at the production network.
4+
5+
import {
6+
withCdnCache,
7+
withContext,
8+
withCorsHeaders,
9+
withContentDispositionHeader,
10+
withErrorHandler,
11+
createWithHttpMethod as withHttpMethods,
12+
withParsedIpfsUrl,
13+
composeMiddleware
14+
} from '@web3-storage/gateway-lib/middleware'
15+
import { handleUnixfs } from '@web3-storage/gateway-lib/handlers'
16+
import {
17+
withContentClaimsDagula,
18+
withVersionHeader,
19+
withCarBlockHandler,
20+
withLocator,
21+
withOptionsRequest,
22+
withFormatRawHandler,
23+
withFormatCarHandler
24+
} from '../../../src/middleware/index.js'
25+
26+
/**
27+
* @import { Handler, Context } from '@web3-storage/gateway-lib'
28+
* @import { Environment } from '../../../src/bindings.js'
29+
*/
30+
31+
const middleware = composeMiddleware(
32+
withCdnCache,
33+
withContext,
34+
withOptionsRequest,
35+
withCorsHeaders,
36+
withVersionHeader,
37+
withErrorHandler,
38+
withHttpMethods('GET', 'HEAD'),
39+
withParsedIpfsUrl,
40+
withLocator,
41+
withCarBlockHandler,
42+
withContentClaimsDagula,
43+
withFormatRawHandler,
44+
withFormatCarHandler,
45+
withContentDispositionHeader
46+
)
47+
48+
const handler = {
49+
/** @type {Handler<Context, Environment>} */
50+
async fetch (request, env, ctx) {
51+
let status = 500
52+
let headers = new Headers()
53+
try {
54+
const handler = middleware(handleUnixfs)
55+
const response = await handler(request, env, ctx)
56+
status = response.status
57+
headers = response.headers
58+
return response
59+
} catch (/** @type {any} */ err) {
60+
console.error(err)
61+
return new Response(err.stack, { status })
62+
} finally {
63+
console.log(request.method, request.url, '→', status)
64+
for (const [k, v] of headers) {
65+
console.log(`\t${k}:`, v)
66+
}
67+
}
68+
}
69+
}
70+
71+
export default handler

scripts/debug/wrangler.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "freeway-debug"
2+
main = "./dist/worker.mjs"
3+
compatibility_flags = [ "nodejs_compat" ]
4+
compatibility_date = "2025-09-01"
5+
6+
[vars]
7+
FF_RAMP_UP_PROBABILITY = "100"
8+
9+
[build]
10+
command = "npm run build"

src/index.js

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
withFixedLengthStream,
1111
composeMiddleware
1212
} from '@web3-storage/gateway-lib/middleware'
13-
import {
14-
handleUnixfs,
15-
handleBlock,
16-
handleCar
17-
} from '@web3-storage/gateway-lib/handlers'
13+
import { handleUnixfs } from '@web3-storage/gateway-lib/handlers'
1814
import {
1915
withContentClaimsDagula,
2016
withVersionHeader,
@@ -31,21 +27,15 @@ import {
3127
withDelegationStubs,
3228
withOptionsRequest,
3329
withCarParkFetch,
34-
withDidDocumentHandler
30+
withDidDocumentHandler,
31+
withFormatRawHandler,
32+
withFormatCarHandler
3533
} from './middleware/index.js'
3634
import { instrument } from '@microlabs/otel-cf-workers'
3735
import { NoopSpanProcessor, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base'
3836

3937
/**
40-
* @import {
41-
* Handler,
42-
* Middleware,
43-
* Context,
44-
* IpfsUrlContext,
45-
* BlockContext,
46-
* DagContext,
47-
* UnixfsContext
48-
* } from '@web3-storage/gateway-lib'
38+
* @import { Handler, Context } from '@web3-storage/gateway-lib'
4939
* @import { Environment } from './bindings.js'
5040
*/
5141

@@ -181,39 +171,3 @@ const handler = {
181171
}
182172

183173
export default handler
184-
185-
/**
186-
* @type {Middleware<BlockContext & UnixfsContext & IpfsUrlContext, BlockContext & UnixfsContext & IpfsUrlContext, Environment>}
187-
*/
188-
export function withFormatRawHandler (handler) {
189-
return async (request, env, ctx) => {
190-
const { headers } = request
191-
const { searchParams } = ctx
192-
if (!searchParams) throw new Error('missing URL search params')
193-
if (
194-
searchParams.get('format') === 'raw' ||
195-
headers.get('Accept')?.includes('application/vnd.ipld.raw')
196-
) {
197-
return await handleBlock(request, env, ctx)
198-
}
199-
return handler(request, env, ctx) // pass to other handlers
200-
}
201-
}
202-
203-
/**
204-
* @type {Middleware<DagContext & IpfsUrlContext, DagContext & IpfsUrlContext, Environment>}
205-
*/
206-
export function withFormatCarHandler (handler) {
207-
return async (request, env, ctx) => {
208-
const { headers } = request
209-
const { searchParams } = ctx
210-
if (!searchParams) throw new Error('missing URL search params')
211-
if (
212-
searchParams.get('format') === 'car' ||
213-
headers.get('Accept')?.includes('application/vnd.ipld.car')
214-
) {
215-
return await handleCar(request, env, ctx)
216-
}
217-
return handler(request, env, ctx) // pass to other handlers
218-
}
219-
}

src/middleware/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ export { withVersionHeader } from './withVersionHeader.js'
66
export { withAuthorizedSpace } from './withAuthorizedSpace.js'
77
export { withLocator } from './withLocator.js'
88
export { withCarParkFetch } from './withCarParkFetch.js'
9-
export { withEgressTracker } from './withEgressTracker.js'
109
export { withEgressClient } from './withEgressClient.js'
10+
export { withEgressTracker } from './withEgressTracker.js'
11+
export { withFormatCarHandler } from './withFormatCarHandler.js'
12+
export { withFormatRawHandler } from './withFormatRawHandler.js'
1113
export { withDelegationStubs } from './withDelegationStubs.js'
1214
export { withDidDocumentHandler } from './withDidDocumentHandler.js'
1315
export { withGatewayIdentity } from './withGatewayIdentity.js'

src/middleware/withAuthorizedSpace.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ export function withAuthorizedSpace (handler) {
104104
.map((site) => extractSpaceDID(site.space))
105105
.filter((space) => space !== undefined)
106106

107+
// If content is found in multiple DIFFERENT spaces, skip egress tracking
108+
// by not setting ctx.space (security/billing concern - ambiguous ownership)
109+
const uniqueSpaces = [...new Set(spaces.map(s => s.toString()))]
110+
const skipEgressTracking = uniqueSpaces.length > 1
111+
if (skipEgressTracking && env.DEBUG === 'true') {
112+
console.log(`Content found in ${uniqueSpaces.length} different spaces - egress tracking will be skipped`)
113+
console.log(`Spaces: ${uniqueSpaces.join(', ')}`)
114+
}
115+
107116
try {
108117
// First space to successfully authorize is the one we'll use.
109118
const { space: selectedSpace, delegationProofs } = await Promise.any(
@@ -117,7 +126,8 @@ export function withAuthorizedSpace (handler) {
117126
)
118127
return handler(request, env, {
119128
...ctx,
120-
space: SpaceDID.from(selectedSpace.toString()),
129+
// Only set space if we're not skipping egress tracking
130+
space: skipEgressTracking ? undefined : SpaceDID.from(selectedSpace.toString()),
121131
delegationProofs,
122132
locator: locator.scopeToSpaces([selectedSpace])
123133
})

0 commit comments

Comments
 (0)