Commit 732b9a7e authored by Jeromy's avatar Jeromy

fixing up some bitswap stuff after the PR

parent 54ff6ea4
...@@ -2,7 +2,6 @@ package blockservice ...@@ -2,7 +2,6 @@ package blockservice
import ( import (
"bytes" "bytes"
"fmt"
"testing" "testing"
ds "github.com/jbenet/datastore.go" ds "github.com/jbenet/datastore.go"
...@@ -11,9 +10,8 @@ import ( ...@@ -11,9 +10,8 @@ import (
) )
func TestBlocks(t *testing.T) { func TestBlocks(t *testing.T) {
d := ds.NewMapDatastore() d := ds.NewMapDatastore()
bs, err := NewBlockService(d) bs, err := NewBlockService(d, nil)
if err != nil { if err != nil {
t.Error("failed to construct block service", err) t.Error("failed to construct block service", err)
return return
...@@ -62,7 +60,4 @@ func TestBlocks(t *testing.T) { ...@@ -62,7 +60,4 @@ func TestBlocks(t *testing.T) {
if !bytes.Equal(b.Data, b2.Data) { if !bytes.Equal(b.Data, b2.Data) {
t.Error("Block data is not equal.") 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 ...@@ -25,7 +25,7 @@ func NewBlockService(d ds.Datastore, rem *bitswap.BitSwap) (*BlockService, error
return nil, fmt.Errorf("BlockService requires valid datastore") return nil, fmt.Errorf("BlockService requires valid datastore")
} }
if rem == nil { 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 return &BlockService{Datastore: d, Remote: rem}, nil
} }
...@@ -39,7 +39,9 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) { ...@@ -39,7 +39,9 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
if err != nil { if err != nil {
return k, err return k, err
} }
err = s.Remote.HaveBlock(b.Key()) if s.Remote != nil {
err = s.Remote.HaveBlock(b.Key())
}
return k, err return k, err
} }
...@@ -57,7 +59,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) { ...@@ -57,7 +59,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
Multihash: mh.Multihash(k), Multihash: mh.Multihash(k),
Data: bdata, Data: bdata,
}, nil }, nil
} else if err == ds.ErrNotFound { } else if err == ds.ErrNotFound && s.Remote != nil {
blk, err := s.Remote.GetBlock(k, time.Second*5) blk, err := s.Remote.GetBlock(k, time.Second*5)
if err != nil { if err != nil {
return nil, err 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