Skip to content

Commit 82e68ca

Browse files
committed
examples/unixfs-file-cid: use session for fetching blocks
1 parent 6c590b8 commit 82e68ca

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/unixfs-file-cid/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ func runClient(ctx context.Context, h host.Host, c cid.Cid, targetPeer string) (
209209
return nil, err
210210
}
211211

212-
dserv := merkledag.NewReadOnlyDagService(merkledag.NewSession(ctx, merkledag.NewDAGService(blockservice.New(blockstore.NewBlockstore(datastore.NewNullDatastore()), bswap))))
212+
bservice := blockservice.New(blockstore.NewBlockstore(datastore.NewNullDatastore()), bswap)
213+
// using a session allows bitswap to more easily corelate related block requests together
214+
// this would have significant impact if we were connected to more than one peers.
215+
ctx = blockservice.ContextWithSession(ctx, bservice)
216+
217+
dserv := merkledag.NewReadOnlyDagService(merkledag.NewSession(ctx, merkledag.NewDAGService(bservice)))
213218
nd, err := dserv.Get(ctx, c)
214219
if err != nil {
215220
return nil, err

0 commit comments

Comments
 (0)