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

Commit ccbef01

Browse files
Merge pull request #29 from ipfs/feat/nil-exchange-is-okay
nil exchange is okay
2 parents 67d4ac6 + 2ec77aa commit ccbef01

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
@@ -149,8 +149,10 @@ func (s *blockService) AddBlock(o blocks.Block) error {
149149

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

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

156158
return nil
@@ -189,10 +191,12 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
189191
return err
190192
}
191193

192-
for _, o := range toput {
193-
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
194-
if err := s.exchange.HasBlock(o); err != nil {
195-
log.Errorf("HasBlock: %s", err.Error())
194+
if s.exchange != nil {
195+
for _, o := range toput {
196+
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
197+
if err := s.exchange.HasBlock(o); err != nil {
198+
log.Errorf("HasBlock: %s", err.Error())
199+
}
196200
}
197201
}
198202
return nil
@@ -255,7 +259,12 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
255259
// the returned channel.
256260
// NB: No guarantees are made about order.
257261
func (s *blockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
258-
return getBlocks(ctx, ks, s.blockstore, s.getExchange) // hash security
262+
var f func() exchange.Fetcher
263+
if s.exchange != nil {
264+
f = s.getExchange
265+
}
266+
267+
return getBlocks(ctx, ks, s.blockstore, f) // hash security
259268
}
260269

261270
func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget func() exchange.Fetcher) <-chan blocks.Block {
@@ -290,7 +299,7 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
290299
}
291300
}
292301

293-
if len(misses) == 0 {
302+
if len(misses) == 0 || fget == nil {
294303
return
295304
}
296305

0 commit comments

Comments
 (0)