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

Commit 2ec77aa

Browse files
committed
nil exchange is okay
1 parent ef3f60b commit 2ec77aa

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

blockservice.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ func (s *blockService) AddBlock(o blocks.Block) error {
148148

149149
log.Event(context.TODO(), "BlockService.BlockAdded", c)
150150

151-
if err := s.exchange.HasBlock(o); err != nil {
152-
log.Errorf("HasBlock: %s", err.Error())
151+
if s.exchange != nil {
152+
if err := s.exchange.HasBlock(o); err != nil {
153+
log.Errorf("HasBlock: %s", err.Error())
154+
}
153155
}
154156

155157
return nil
@@ -184,10 +186,12 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
184186
return err
185187
}
186188

187-
for _, o := range toput {
188-
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
189-
if err := s.exchange.HasBlock(o); err != nil {
190-
log.Errorf("HasBlock: %s", err.Error())
189+
if s.exchange != nil {
190+
for _, o := range toput {
191+
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
192+
if err := s.exchange.HasBlock(o); err != nil {
193+
log.Errorf("HasBlock: %s", err.Error())
194+
}
191195
}
192196
}
193197
return nil
@@ -250,7 +254,12 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
250254
// the returned channel.
251255
// NB: No guarantees are made about order.
252256
func (s *blockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
253-
return getBlocks(ctx, ks, s.blockstore, s.getExchange) // hash security
257+
var f func() exchange.Fetcher
258+
if s.exchange != nil {
259+
f = s.getExchange
260+
}
261+
262+
return getBlocks(ctx, ks, s.blockstore, f) // hash security
254263
}
255264

256265
func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget func() exchange.Fetcher) <-chan blocks.Block {
@@ -285,7 +294,7 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
285294
}
286295
}
287296

288-
if len(misses) == 0 {
297+
if len(misses) == 0 || fget == nil {
289298
return
290299
}
291300

0 commit comments

Comments
 (0)