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

Commit

Permalink
Merge pull request #29 from ipfs/feat/nil-exchange-is-okay
Browse files Browse the repository at this point in the history
nil exchange is okay
  • Loading branch information
whyrusleeping committed Jul 15, 2019
2 parents 67d4ac6 + 2ec77aa commit ccbef01
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ func (s *blockService) AddBlock(o blocks.Block) error {

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

if err := s.exchange.HasBlock(o); err != nil {
log.Errorf("HasBlock: %s", err.Error())
if s.exchange != nil {
if err := s.exchange.HasBlock(o); err != nil {
log.Errorf("HasBlock: %s", err.Error())
}
}

return nil
Expand Down Expand Up @@ -189,10 +191,12 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
return err
}

for _, o := range toput {
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
if err := s.exchange.HasBlock(o); err != nil {
log.Errorf("HasBlock: %s", err.Error())
if s.exchange != nil {
for _, o := range toput {
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
if err := s.exchange.HasBlock(o); err != nil {
log.Errorf("HasBlock: %s", err.Error())
}
}
}
return nil
Expand Down Expand Up @@ -255,7 +259,12 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
// the returned channel.
// NB: No guarantees are made about order.
func (s *blockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
return getBlocks(ctx, ks, s.blockstore, s.getExchange) // hash security
var f func() exchange.Fetcher
if s.exchange != nil {
f = s.getExchange
}

return getBlocks(ctx, ks, s.blockstore, f) // hash security
}

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

if len(misses) == 0 {
if len(misses) == 0 || fget == nil {
return
}

Expand Down

0 comments on commit ccbef01

Please sign in to comment.