generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 96
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
gateway: implement IPIP-0445 (skip-raw-blocks option) #502
Draft
Jorropo
wants to merge
1
commit into
main
Choose a base branch
from
ipip-0445
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,10 @@ | |
var emptyRoot = []cid.Cid{cid.MustParse("bafkqaaa")} | ||
|
||
func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, params CarParams) (ContentPathMetadata, io.ReadCloser, error) { | ||
if params.SkipRawBlocks.Bool() && p.RootCid().Prefix().Codec == cid.Raw { | ||
|
||
} | ||
|
||
pathMetadata, err := bb.ResolvePath(ctx, p) | ||
if err != nil { | ||
rootCid, err := cid.Decode(strings.Split(p.String(), "/")[2]) | ||
|
@@ -312,8 +316,9 @@ | |
blockGetter := merkledag.NewDAGService(bb.blockService).Session(ctx) | ||
|
||
blockGetter = &nodeGetterToCarExporer{ | ||
ng: blockGetter, | ||
cw: cw, | ||
ng: blockGetter, | ||
cw: cw, | ||
skipRawBlocks: params.SkipRawBlocks.Bool(), | ||
} | ||
|
||
// Setup the UnixFS resolver. | ||
|
@@ -352,8 +357,9 @@ | |
blockGetter := merkledag.NewDAGService(bb.blockService).Session(ctx) | ||
|
||
blockGetter = &nodeGetterToCarExporer{ | ||
ng: blockGetter, | ||
cw: cw, | ||
ng: blockGetter, | ||
cw: cw, | ||
skipRawBlocks: params.SkipRawBlocks.Bool(), | ||
} | ||
|
||
// Setup the UnixFS resolver. | ||
|
@@ -732,8 +738,9 @@ | |
} | ||
|
||
type nodeGetterToCarExporer struct { | ||
ng format.NodeGetter | ||
cw storage.WritableCar | ||
ng format.NodeGetter | ||
cw storage.WritableCar | ||
skipRawBlocks bool | ||
} | ||
|
||
func (n *nodeGetterToCarExporer) Get(ctx context.Context, c cid.Cid) (format.Node, error) { | ||
|
@@ -774,6 +781,19 @@ | |
} | ||
|
||
func (n *nodeGetterToCarExporer) trySendBlock(ctx context.Context, block blocks.Block) error { | ||
// FIXME(@Jorropo): this is very inneficient, we fetch all blocks even if we don't send them. | ||
// I've tried doing so using the ipld stack however the problem is that filtering on the | ||
// selector or traversal callback does not work because the unixfs reifier is ran before, | ||
// so trying to filter raw links do nothing because go-unixfsnode removed them already, | ||
// so we need to filter in a callback from unixfsnode but the reifier does not know a about | ||
// [traversal.SkipMe] making it a lost cause. I've looked into updating unixfsnode but this | ||
// much more work because there are no easy way to pass options or understand what the side | ||
// effects of this would be. | ||
// Abstractions everywhere yet a simple small behaviour change require rethinking everything :'(. | ||
// Will fix with boxo/unixfs. | ||
Comment on lines
+784
to
+793
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😞 |
||
if n.skipRawBlocks && block.Cid().Prefix().Codec == cid.Raw { | ||
return nil | ||
} | ||
return n.cw.Put(ctx, block.Cid().KeyString(), block.RawData()) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs 400: