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: serve CAR blocks #68

Merged
merged 3 commits into from
Jul 31, 2023
Merged

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Jul 24, 2023

This PR adds a new handler that allows freeway to serve CAR files directly from R2 (CARPARK).

Requesting a CID from the gateway with the CAR codec 0x0202 will invoke this new handler.

Obviously CARs are not served in the same way as regular IPFS data, since we can serve the data directly from an R2 bucket. To deal with this difference, there's a new middlewares that detects the CAR codec and calls the correct handler, passing through to the regular handlers if the CAR codec is not detected.

The handler supports HEAD requests, allowing you to get the file size of the item you're requesting. It also supports the HTTP Range header, allowing you to extract byte ranges from within a CAR, which you might do if you fetch the index for the CAR.

The idea is that we can use these handlers to build a system that runs on content-claims. The flow might be something like:

  1. Get partition claim for a given content CID
  2. Get inclusion claims for each CAR part in the partition claim
  3. Fetch each CARv2 index from the gateway for each includes CID specified in the inclusion claims (You must first fetch partition claims for each index CID to find out which CAR file they can be found in).
  4. Use HTTP Range requests to export the whole DAG or a sub-DAG directly from the parts, using the index data as a guide for which blocks to extract.

Note: if exporting a full DAG you might want to just stop after (1) and import all data in all CARs into IPFS.

@alanshaw alanshaw changed the title feat: serve CAR and CARv2 MultihashSortedIndex blocks feat: serve CAR blocks Jul 26, 2023
Copy link
Contributor

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM! ✨

}
}

const obj = await env.CARPARK.get(`${dataCid}/${dataCid}.car`, { range })
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be cool to try this with roundabout. I think it should work and let us redirect to presigned url.

Probably good to keep as is and track issue to attempt cost optimisation :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, yes but we probably don't want to give out those URLs to anyone via the gateway. Someone will try to use/abuse and they also expire...

Copy link
Contributor

Choose a reason for hiding this comment

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

So the usage would be the same as here? it would be a redirect that response will be read right away right? So, expiration would not be a problem, and if we perform request to roundabout within the worker and redirect to presigned URL then user will not even know how URL was created.

Use/abuse would be the same as via freeway no. So, rate limits is really the solution we seem to have to avoid abuse

test/helpers/builder.js Outdated Show resolved Hide resolved
@alanshaw alanshaw merged commit 0b95438 into main Jul 31, 2023
@alanshaw alanshaw deleted the feat/serve-car-and-car-index-blocks branch July 31, 2023 14:19
alanshaw pushed a commit that referenced this pull request Jul 31, 2023
🤖 I have created a release *beep* *boop*
---


##
[2.10.0](v2.9.2...v2.10.0)
(2023-07-31)


### Features

* serve CAR blocks
([#68](#68))
([0b95438](0b95438))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants