Skip to content

Commit

Permalink
examples/unixfs-file-cid: use session for fetching blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Jan 12, 2024
1 parent 8109917 commit c6ac1a3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/unixfs-file-cid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ func runClient(ctx context.Context, h host.Host, c cid.Cid, targetPeer string) (
return nil, err
}

dserv := merkledag.NewReadOnlyDagService(merkledag.NewSession(ctx, merkledag.NewDAGService(blockservice.New(blockstore.NewBlockstore(datastore.NewNullDatastore()), bswap))))
bservice := blockservice.New(blockstore.NewBlockstore(datastore.NewNullDatastore()), bswap)
// using a session allows bitswap to more orrelate related block requests together
// this would have more impact if we were connected to more than one peers.
ctx = blockservice.ContextWithSession(ctx, bservice)

dserv := merkledag.NewReadOnlyDagService(merkledag.NewSession(ctx, merkledag.NewDAGService(bservice)))
nd, err := dserv.Get(ctx, c)
if err != nil {
return nil, err
Expand Down

0 comments on commit c6ac1a3

Please sign in to comment.