Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use blockstore sessions #50

Merged
merged 9 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/interop/src/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('@helia/verified-fetch - json', () => {
await loadFixtureDataCar(controller, 'QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr-tokens.uniswap.org-2024-01-18.car')
verifiedFetch = await createVerifiedFetch({
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`]
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
allowInsecure: true,
allowLocal: true
})
})

Expand All @@ -31,7 +33,10 @@ describe('@helia/verified-fetch - json', () => {
})

it('handles UnixFS-chunked JSON file', async () => {
const resp = await verifiedFetch(CID.parse('QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr'))
const resp = await verifiedFetch(CID.parse('QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr'), {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const jsonObj = await resp.json()
expect(jsonObj).to.be.ok()
Expand Down
39 changes: 31 additions & 8 deletions packages/interop/src/unixfs-dir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('@helia/verified-fetch - unixfs directory', () => {

verifiedFetch = await createVerifiedFetch({
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`]
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
allowInsecure: true,
allowLocal: true
})
})

Expand All @@ -37,7 +39,11 @@ describe('@helia/verified-fetch - unixfs directory', () => {
'http://example.com/ipfs/bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q'
].forEach((url: string) => {
it(`request to unixfs directory with ${url} should return a 301 with a trailing slash`, async () => {
const response = await verifiedFetch(url, { redirect: 'manual' })
const response = await verifiedFetch(url, {
redirect: 'manual',
allowLocal: true,
allowInsecure: true
})
expect(response).to.be.ok()
expect(response.status).to.equal(301)
expect(response.headers.get('location')).to.equal(`${url}/`)
Expand All @@ -53,20 +59,29 @@ describe('@helia/verified-fetch - unixfs directory', () => {

it('fails to load when passed the root', async () => {
// The spec says we should generate HTML with directory listings, but we don't do that yet, so expect a failure
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR')
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
expect(resp.status).to.equal(501) // TODO: we should do a directory listing instead
})

it('can return a string for unixfs pathed data', async () => {
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1 - alt.txt')
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1 - alt.txt', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const text = await resp.text()
expect(text).to.equal('Don\'t we all.')
})

it('can return an image for unixfs pathed data', async () => {
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png')
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const imgData = await resp.blob()
expect(imgData).to.be.ok()
Expand All @@ -79,7 +94,9 @@ describe('@helia/verified-fetch - unixfs directory', () => {
await verifiedFetch.stop()
verifiedFetch = await createVerifiedFetch({
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`]
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
allowInsecure: true,
allowLocal: true
}, {
contentTypeParser: (bytes) => {
return filetypemime(bytes)?.[0]
Expand All @@ -88,7 +105,10 @@ describe('@helia/verified-fetch - unixfs directory', () => {
})

it('can return an image content-type for unixfs pathed data', async () => {
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png')
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png', {
allowLocal: true,
allowInsecure: true
})
// tediously this is actually a jpeg file with a .png extension
expect(resp.headers.get('content-type')).to.equal('image/jpeg')
})
Expand All @@ -101,7 +121,10 @@ describe('@helia/verified-fetch - unixfs directory', () => {
})

it('loads path /ipfs/bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt', async () => {
const resp = await verifiedFetch('ipfs://bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt')
const resp = await verifiedFetch('ipfs://bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const text = await resp.text()
// npx kubo@0.25.0 cat '/ipfs/bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt'
Expand Down
23 changes: 18 additions & 5 deletions packages/interop/src/websites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('@helia/verified-fetch - websites', () => {
await loadFixtureDataCar(controller, 'QmbxpRxwKXxnJQjnPqm1kzDJSJ8YgkLxH23mcZURwPHjGv-helia-identify-website.car')
verifiedFetch = await createVerifiedFetch({
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`]
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
allowInsecure: true,
allowLocal: true
})
})

Expand All @@ -27,15 +29,21 @@ describe('@helia/verified-fetch - websites', () => {
})

it('loads index.html when passed helia-identify.on.fleek.co root CID', async () => {
const resp = await verifiedFetch('ipfs://QmbxpRxwKXxnJQjnPqm1kzDJSJ8YgkLxH23mcZURwPHjGv')
const resp = await verifiedFetch('ipfs://QmbxpRxwKXxnJQjnPqm1kzDJSJ8YgkLxH23mcZURwPHjGv', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const html = await resp.text()
expect(html).to.be.ok()
expect(html).to.include('<title>Run Identify on a remote node with Helia</title>')
})

it('loads helia-identify.on.fleek.co index.html directly ', async () => {
const resp = await verifiedFetch('ipfs://QmbxpRxwKXxnJQjnPqm1kzDJSJ8YgkLxH23mcZURwPHjGv/index.html')
const resp = await verifiedFetch('ipfs://QmbxpRxwKXxnJQjnPqm1kzDJSJ8YgkLxH23mcZURwPHjGv/index.html', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const html = await resp.text()
expect(html).to.be.ok()
Expand Down Expand Up @@ -64,7 +72,9 @@ describe('@helia/verified-fetch - websites', () => {
await loadFixtureDataCar(controller, 'QmeiDMLtPUS3RT2xAcUwsNyZz169wPke2q7im9vZpVLSYw-fake-blog.libp2p.io.car')
verifiedFetch = await createVerifiedFetch({
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`]
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
allowInsecure: true,
allowLocal: true
})
})

Expand All @@ -74,7 +84,10 @@ describe('@helia/verified-fetch - websites', () => {
})

it('loads index.html when passed fake-blog.libp2p.io root CID', async () => {
const resp = await verifiedFetch('ipfs://QmeiDMLtPUS3RT2xAcUwsNyZz169wPke2q7im9vZpVLSYw')
const resp = await verifiedFetch('ipfs://QmeiDMLtPUS3RT2xAcUwsNyZz169wPke2q7im9vZpVLSYw', {
allowLocal: true,
allowInsecure: true
})
expect(resp).to.be.ok()
const html = await resp.text()
expect(html).to.be.ok()
Expand Down
11 changes: 7 additions & 4 deletions packages/verified-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ You can see variations of Helia and js-libp2p configuration options at <https://
```typescript
import { trustlessGateway } from '@helia/block-brokers'
import { createHeliaHTTP } from '@helia/http'
import { delegatedHTTPRouting } from '@helia/routers'
import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
import { createVerifiedFetch } from '@helia/verified-fetch'

const fetch = await createVerifiedFetch(
await createHeliaHTTP({
blockBrokers: [
trustlessGateway({
trustlessGateway()
],
routers: [
delegatedHTTPRouting('http://delegated-ipfs.dev'),
httpGatewayRouting({
gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
})
],
routers: ['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl))
]
})
)

Expand Down
26 changes: 13 additions & 13 deletions packages/verified-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
"release": "aegir release"
},
"dependencies": {
"@helia/block-brokers": "^2.1.0",
"@helia/car": "^3.1.3",
"@helia/http": "^1.0.4",
"@helia/interface": "^4.2.0",
"@helia/ipns": "^7.2.1",
"@helia/routers": "^1.0.3",
"@helia/block-brokers": "next",
"@helia/car": "next",
"@helia/http": "next",
"@helia/interface": "next",
"@helia/ipns": "next",
"@helia/routers": "next",
"@ipld/dag-cbor": "^9.2.0",
"@ipld/dag-json": "^10.2.0",
"@ipld/dag-pb": "^4.1.0",
Expand All @@ -79,17 +79,17 @@
"it-pipe": "^3.0.1",
"it-tar": "^6.0.5",
"it-to-browser-readablestream": "^2.0.6",
"lru-cache": "^10.2.0",
"multiformats": "^13.1.0",
"progress-events": "^1.0.0",
"uint8arrays": "^5.0.3"
},
"devDependencies": {
"@helia/car": "^3.1.3",
"@helia/dag-cbor": "^3.0.3",
"@helia/dag-json": "^3.0.3",
"@helia/json": "^3.0.3",
"@helia/unixfs": "^3.0.4",
"@helia/utils": "^0.2.0",
"@helia/dag-cbor": "next",
"@helia/dag-json": "next",
"@helia/json": "next",
"@helia/unixfs": "next",
"@helia/utils": "next",
"@ipld/car": "^5.3.0",
"@libp2p/interface-compliance-tests": "^5.3.4",
"@libp2p/logger": "^4.0.9",
Expand All @@ -100,7 +100,7 @@
"blockstore-core": "^4.4.1",
"browser-readablestream-to-it": "^2.0.5",
"datastore-core": "^9.2.9",
"helia": "^4.1.1",
"helia": "next",
"ipfs-unixfs-importer": "^15.2.5",
"ipns": "^9.1.0",
"it-all": "^3.0.4",
Expand Down
Loading
Loading