From c3604052ba7eaa3e8ebe44370b3e669aaa4d9170 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 22 Nov 2024 15:08:02 +0100 Subject: [PATCH] Restore a couple of changes that made it through from old prs. --- blockservice/providing_blockstore.go | 37 ---------------------------- gateway/backend_blocks.go | 6 +++++ 2 files changed, 6 insertions(+), 37 deletions(-) delete mode 100644 blockservice/providing_blockstore.go diff --git a/blockservice/providing_blockstore.go b/blockservice/providing_blockstore.go deleted file mode 100644 index 2ca91a908..000000000 --- a/blockservice/providing_blockstore.go +++ /dev/null @@ -1,37 +0,0 @@ -package blockservice - -import ( - "context" - - "github.com/ipfs/boxo/blockstore" - "github.com/ipfs/boxo/provider" - blocks "github.com/ipfs/go-block-format" -) - -var _ blockstore.Blockstore = providingBlockstore{} - -type providingBlockstore struct { - blockstore.Blockstore - provider provider.Provider -} - -func (pbs providingBlockstore) Put(ctx context.Context, b blocks.Block) error { - if err := pbs.Blockstore.Put(ctx, b); err != nil { - return err - } - - return pbs.provider.Provide(ctx, b.Cid(), true) -} - -func (pbs providingBlockstore) PutMany(ctx context.Context, b []blocks.Block) error { - if err := pbs.Blockstore.PutMany(ctx, b); err != nil { - return err // what are the semantics here, did some blocks were put ? assume PutMany is atomic - } - - for _, b := range b { - if err := pbs.provider.Provide(ctx, b.Cid(), true); err != nil { - return err // this can only error if the whole provider is done for - } - } - return nil -} diff --git a/gateway/backend_blocks.go b/gateway/backend_blocks.go index 3d4f98bf0..d62d3d876 100644 --- a/gateway/backend_blocks.go +++ b/gateway/backend_blocks.go @@ -624,6 +624,12 @@ func (bb *BlocksBackend) IsCached(ctx context.Context, p path.Path) bool { return has } +var _ WithContextHint = (*BlocksBackend)(nil) + +func (bb *BlocksBackend) WrapContextForRequest(ctx context.Context) context.Context { + return blockservice.ContextWithSession(ctx, bb.blockService) +} + func (bb *BlocksBackend) ResolvePath(ctx context.Context, path path.ImmutablePath) (ContentPathMetadata, error) { roots, lastSeg, remainder, err := bb.getPathRoots(ctx, path) if err != nil {