1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

refac(bitswap:message) accept block by value

This commit is contained in:
Brian Tiger Chow
2014-09-15 07:47:13 -07:00
parent 770cdebf7b
commit e07d3418c4
3 changed files with 6 additions and 8 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}