Commit a4fea7bb authored by Kevin Atkinson's avatar Kevin Atkinson

Make blocks.Block an interface.

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 364267d1
......@@ -41,7 +41,7 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) *BlockService {
// AddBlock adds a particular block to the service, Putting it into the datastore.
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func (s *BlockService) AddBlock(b *blocks.Block) (key.Key, error) {
func (s *BlockService) AddBlock(b blocks.Block) (key.Key, error) {
k := b.Key()
err := s.Blockstore.Put(b)
if err != nil {
......@@ -53,7 +53,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (key.Key, error) {
return k, nil
}
func (s *BlockService) AddBlocks(bs []*blocks.Block) ([]key.Key, error) {
func (s *BlockService) AddBlocks(bs []blocks.Block) ([]key.Key, error) {
err := s.Blockstore.PutMany(bs)
if err != nil {
return nil, err
......@@ -71,7 +71,7 @@ func (s *BlockService) AddBlocks(bs []*blocks.Block) ([]key.Key, error) {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block, error) {
func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (blocks.Block, error) {
log.Debugf("BlockService GetBlock: '%s'", k)
block, err := s.Blockstore.Get(k)
if err == nil {
......@@ -103,8 +103,8 @@ func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block,
// GetBlocks gets a list of blocks asynchronously and returns through
// the returned channel.
// NB: No guarantees are made about order.
func (s *BlockService) GetBlocks(ctx context.Context, ks []key.Key) <-chan *blocks.Block {
out := make(chan *blocks.Block, 0)
func (s *BlockService) GetBlocks(ctx context.Context, ks []key.Key) <-chan blocks.Block {
out := make(chan blocks.Block, 0)
go func() {
defer close(out)
var misses []key.Key
......
......@@ -24,7 +24,7 @@ func TestBlocks(t *testing.T) {
b := blocks.NewBlock([]byte("beep boop"))
h := u.Hash([]byte("beep boop"))
if !bytes.Equal(b.Multihash, h) {
if !bytes.Equal(b.Multihash(), h) {
t.Error("Block Multihash and data multihash not equal")
}
......@@ -54,7 +54,7 @@ func TestBlocks(t *testing.T) {
t.Error("Block keys not equal.")
}
if !bytes.Equal(b.Data, b2.Data) {
if !bytes.Equal(b.Data(), b2.Data()) {
t.Error("Block data is not equal.")
}
}
......@@ -79,7 +79,7 @@ func TestGetBlocksSequential(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*50)
defer cancel()
out := servs[i].GetBlocks(ctx, keys)
gotten := make(map[key.Key]*blocks.Block)
gotten := make(map[key.Key]blocks.Block)
for blk := range out {
if _, ok := gotten[blk.Key()]; ok {
t.Fatal("Got duplicate block!")
......
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