Commit 732b9a7e authored by Jeromy's avatar Jeromy

fixing up some bitswap stuff after the PR

parent 54ff6ea4
......@@ -2,7 +2,6 @@ package blockservice
import (
"bytes"
"fmt"
"testing"
ds "github.com/jbenet/datastore.go"
......@@ -11,9 +10,8 @@ import (
)
func TestBlocks(t *testing.T) {
d := ds.NewMapDatastore()
bs, err := NewBlockService(d)
bs, err := NewBlockService(d, nil)
if err != nil {
t.Error("failed to construct block service", err)
return
......@@ -62,7 +60,4 @@ func TestBlocks(t *testing.T) {
if !bytes.Equal(b.Data, b2.Data) {
t.Error("Block data is not equal.")
}
fmt.Printf("key: %s\n", b.Key())
fmt.Printf("data: %v\n", b.Data)
}
......@@ -25,7 +25,7 @@ func NewBlockService(d ds.Datastore, rem *bitswap.BitSwap) (*BlockService, error
return nil, fmt.Errorf("BlockService requires valid datastore")
}
if rem == nil {
return nil, fmt.Errorf("BlockService requires a valid bitswap")
u.PErr("Caution: blockservice running in local (offline) mode.\n")
}
return &BlockService{Datastore: d, Remote: rem}, nil
}
......@@ -39,7 +39,9 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
if err != nil {
return k, err
}
err = s.Remote.HaveBlock(b.Key())
if s.Remote != nil {
err = s.Remote.HaveBlock(b.Key())
}
return k, err
}
......@@ -57,7 +59,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
Multihash: mh.Multihash(k),
Data: bdata,
}, nil
} else if err == ds.ErrNotFound {
} else if err == ds.ErrNotFound && s.Remote != nil {
blk, err := s.Remote.GetBlock(k, time.Second*5)
if err != nil {
return nil, err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment