Commit e07d3418 authored by Brian Tiger Chow's avatar Brian Tiger Chow

refac(bitswap:message) accept block by value

parent 770cdebf
......@@ -157,7 +157,8 @@ func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
func (bs *BitSwap) SendBlock(p *peer.Peer, b *blocks.Block) {
message := bsmsg.New()
message.AppendBlock(b)
// TODO(brian): change interface to accept value instead of pointer
message.AppendBlock(*b)
bs.sender.SendMessage(context.Background(), p, message)
}
......
......@@ -15,7 +15,7 @@ type BitSwapMessage interface {
Wantlist() []u.Key
Blocks() []blocks.Block
AppendWanted(k u.Key)
AppendBlock(b *blocks.Block)
AppendBlock(b blocks.Block)
Exportable
}
......@@ -63,7 +63,7 @@ func (m *message) AppendWanted(k u.Key) {
m.pb.Wantlist = append(m.pb.Wantlist, string(k))
}
func (m *message) AppendBlock(b *blocks.Block) {
func (m *message) AppendBlock(b blocks.Block) {
m.pb.Blocks = append(m.pb.Blocks, b.Data)
}
......
......@@ -4,8 +4,8 @@ import (
"bytes"
"testing"
blocks "github.com/jbenet/go-ipfs/blocks"
u "github.com/jbenet/go-ipfs/util"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
func TestAppendWanted(t *testing.T) {
......@@ -39,10 +39,7 @@ func TestAppendBlock(t *testing.T) {
m := New()
for _, str := range strs {
block, err := blocks.NewBlock([]byte(str))
if err != nil {
t.Fail()
}
block := testutil.NewBlockOrFail(t, str)
m.AppendBlock(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