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 index claim #10

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@
"dependencies": {
"@ucanto/interface": "^10.0.1",
"@web3-storage/blob-index": "^1.0.2",
"@web3-storage/content-claims": "^5.0.0",
"@web3-storage/content-claims": "^5.1.0",
"multiformats": "^13.1.0",
"multipart-byte-range": "^3.0.1",
"p-defer": "^4.0.1",
"p-queue": "^8.0.1"
},
"devDependencies": {
"@ipld/unixfs": "^3.0.0",
"@web3-storage/public-bucket": "^1.0.0",
"@ucanto/principal": "^9.0.1",
"@web3-storage/public-bucket": "^1.1.0",
"c8": "^9.1.0",
"carstream": "^2.1.0",
"carstream": "^2.2.0",
"entail": "^2.1.2",
"ipfs-unixfs-exporter": "^13.5.0",
"standard": "^17.1.0",
Expand Down
56 changes: 20 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/fetcher/batching.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { resolveRange } from './lib.js'
* @typedef {Map<RangeKey, PendingBlobRequest[]>} RangedRequests
*/

const MAX_BATCH_SIZE = 12
const MAX_BATCH_SIZE = 16

/** @implements {API.Fetcher} */
class BatchingFetcher {
Expand Down
42 changes: 41 additions & 1 deletion src/locator/content-claims.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// eslint-disable-next-line
import * as API from '../api.js'
import * as Claims from '@web3-storage/content-claims/client'
import { DigestMap } from '@web3-storage/blob-index'
import { DigestMap, ShardedDAGIndex } from '@web3-storage/blob-index'
import { fetchBlob } from '../fetcher/simple.js'
import { NotFoundError } from '../lib.js'

/**
Expand Down Expand Up @@ -85,6 +86,45 @@ export class ContentClaimsLocator {
})
}
}

if (claim.type === 'assert/index') {
await this.#readClaims(claim.index.multihash)
const location = this.#cache.get(claim.index.multihash)
if (!location) continue

const fetchRes = await fetchBlob(location)
if (fetchRes.error) {
console.warn('failed to fetch index', fetchRes.error)
continue
}

const indexBytes = await fetchRes.ok.bytes()
const decodeRes = ShardedDAGIndex.extract(indexBytes)
if (decodeRes.error) {
console.warn('failed to decode index', decodeRes.error)
continue
}

const index = decodeRes.ok
await Promise.all([...index.shards].map(async ([shard, slices]) => {
await this.#readClaims(shard)
const location = this.#cache.get(shard)
if (!location) return

for (const [slice, pos] of slices) {
this.#cache.set(slice, {
digest: slice,
site: location.site.map(s => ({
location: s.location,
range: {
offset: s.range.offset + pos[0],
length: s.range.offset + pos[1]
}
}))
})
}
}))
}
}
this.#claimFetched.set(digest, true)
}
Expand Down
Loading
Loading