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: helia supports additional byteProviders #276

Closed

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Oct 4, 2023

Work for addressing issues in #274.

The direction I'm thinking with this is:

  • We have ByteProvider and BlockProviders
  • Users are given a helper function to create trustless-http-gateway byte-providers
  • Users provide byteProviders array in helia instantiation (which will be used to construct BlockProviders that are passed a blockstore, and cannot be edited)
  • NetworkedStorage, which is what calls bitswap, was slightly refactored to call both bitswap & any given blockProviders, wrapping and listening to the given signal so that we can cancel any outstanding requests and prevent additional requests if any byteProvider returns quickly enough
  • Users have no control over BlockProvider instances (because a blockstore is required), but shouldn't need to (correct me if i'm wrong)

This is still a WIP, but confirmed it's working locally with:

import { createHelia } from 'helia'
import { CID } from 'multiformats/cid'

const node = await createHelia()

const blocks = await node.blockstore.get(CID.parse('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D'), {signal: AbortSignal.timeout(10000)})
console.log('done')

Output:

  helia:gateway-block-provider getting block for QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D from https://dweb.link +0ms
  helia:gateway-block-provider getting block for QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D from https://cf-ipfs.com +2ms
  helia:gateway-block-provider getting block for QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D from https://4everland.io +0ms
  helia:gateway-block-provider getting block for QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D from https://w3s.link +1ms
  helia:gateway-block-provider getting block for QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D from https://cloudflare-ipfs.com +1ms
  helia:gateway-block-provider got block for QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D from https://dweb.link +229ms

@SgtPooki SgtPooki changed the title feat: helia supports additional blockProviders feat: helia supports additional byteProviders Oct 4, 2023
@SgtPooki SgtPooki self-assigned this Oct 4, 2023
@SgtPooki SgtPooki marked this pull request as ready for review October 4, 2023 19:32
@SgtPooki SgtPooki requested a review from a team as a code owner October 4, 2023 19:32
try {
const block = await this.#provider.get(cid, options)

await this.blockstore.put(cid, block, options)
Copy link
Member Author

Choose a reason for hiding this comment

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

we could wrap the blockstore on put that re-hashes it to verify.

we don't need to parse the data.. we just need to verify that when we hash the block with the cid.multihash.code is the same.

add method to this class for verifying bytes. might be able to use util methods in blockstore classes/package

@achingbrain
Copy link
Member

This is great! I've taken some of the ideas here and opened #280 which I think is a bit simpler. Let me know what you think.

@SgtPooki
Copy link
Member Author

superseded by #280

@SgtPooki SgtPooki closed this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Update Helia to fallback to trustless HTTP gateways
2 participants