From 99235cc120519afe2bddcb6b1f7a6844ecc3707f Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 21 Oct 2021 10:16:30 -0700 Subject: [PATCH] add a fetcher constructor for the case where we already have a session --- impl/blockservice/fetcher.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/impl/blockservice/fetcher.go b/impl/blockservice/fetcher.go index 3327a4e..d203a15 100644 --- a/impl/blockservice/fetcher.go +++ b/impl/blockservice/fetcher.go @@ -39,11 +39,15 @@ func NewFetcherConfig(blockService blockservice.BlockService) FetcherConfig { // NewSession creates a session from which nodes may be retrieved. // The session ends when the provided context is canceled. func (fc FetcherConfig) NewSession(ctx context.Context) fetcher.Fetcher { + return fc.FetcherWithSession(ctx, blockservice.NewSession(ctx, fc.blockService)) +} + +func (fc FetcherConfig) FetcherWithSession(ctx context.Context, s *blockservice.Session) fetcher.Fetcher { ls := cidlink.DefaultLinkSystem() // while we may be loading blocks remotely, they are already hash verified by the time they load // into ipld-prime ls.TrustedStorage = true - ls.StorageReadOpener = blockOpener(ctx, blockservice.NewSession(ctx, fc.blockService)) + ls.StorageReadOpener = blockOpener(ctx, s) ls.NodeReifier = fc.NodeReifier protoChooser := fc.PrototypeChooser