mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 17:03:58 +08:00
refac(bitswap:message) accept block by value
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user