Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

add a fetcher constructor for the case where we already have a session #26

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion impl/blockservice/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down