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