Commit 6db72127 authored by Brian Tiger Chow's avatar Brian Tiger Chow

style(bitswap/message) rename AppendWanted -> AddWanted

implementation will be patched to ensure bitswap messages cannot contain
duplicate blocks or keys
parent eb32931f
...@@ -78,7 +78,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error) ...@@ -78,7 +78,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
go func() { go func() {
message := bsmsg.New() message := bsmsg.New()
for _, wanted := range bs.wantlist.Keys() { for _, wanted := range bs.wantlist.Keys() {
message.AppendWanted(wanted) message.AddWanted(wanted)
} }
for peerToQuery := range peersToQuery { for peerToQuery := range peersToQuery {
log.Debugf("bitswap got peersToQuery: %s", peerToQuery) log.Debugf("bitswap got peersToQuery: %s", peerToQuery)
...@@ -167,7 +167,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm ...@@ -167,7 +167,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
message := bsmsg.New() message := bsmsg.New()
for _, wanted := range bs.wantlist.Keys() { for _, wanted := range bs.wantlist.Keys() {
message.AppendWanted(wanted) message.AddWanted(wanted)
} }
for _, key := range incoming.Wantlist() { for _, key := range incoming.Wantlist() {
// TODO: might be better to check if we have the block before checking // TODO: might be better to check if we have the block before checking
...@@ -208,7 +208,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block) ...@@ -208,7 +208,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
message := bsmsg.New() message := bsmsg.New()
message.AppendBlock(block) message.AppendBlock(block)
for _, wanted := range bs.wantlist.Keys() { for _, wanted := range bs.wantlist.Keys() {
message.AppendWanted(wanted) message.AddWanted(wanted)
} }
go bs.send(ctx, p, message) go bs.send(ctx, p, message)
} }
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
type BitSwapMessage interface { type BitSwapMessage interface {
Wantlist() []u.Key Wantlist() []u.Key
Blocks() []blocks.Block Blocks() []blocks.Block
AppendWanted(k u.Key) AddWanted(k u.Key)
AppendBlock(b blocks.Block) AppendBlock(b blocks.Block)
Exportable Exportable
} }
...@@ -39,7 +39,7 @@ func New() *message { ...@@ -39,7 +39,7 @@ func New() *message {
func newMessageFromProto(pbm pb.Message) BitSwapMessage { func newMessageFromProto(pbm pb.Message) BitSwapMessage {
m := New() m := New()
for _, s := range pbm.GetWantlist() { for _, s := range pbm.GetWantlist() {
m.AppendWanted(u.Key(s)) m.AddWanted(u.Key(s))
} }
for _, d := range pbm.GetBlocks() { for _, d := range pbm.GetBlocks() {
b := blocks.NewBlock(d) b := blocks.NewBlock(d)
...@@ -58,7 +58,7 @@ func (m *message) Blocks() []blocks.Block { ...@@ -58,7 +58,7 @@ func (m *message) Blocks() []blocks.Block {
return m.blocks return m.blocks
} }
func (m *message) AppendWanted(k u.Key) { func (m *message) AddWanted(k u.Key) {
m.wantlist = append(m.wantlist, k) m.wantlist = append(m.wantlist, k)
} }
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
func TestAppendWanted(t *testing.T) { func TestAppendWanted(t *testing.T) {
const str = "foo" const str = "foo"
m := New() m := New()
m.AppendWanted(u.Key(str)) m.AddWanted(u.Key(str))
if !contains(m.ToProto().GetWantlist(), str) { if !contains(m.ToProto().GetWantlist(), str) {
t.Fail() t.Fail()
...@@ -58,7 +58,7 @@ func TestWantlist(t *testing.T) { ...@@ -58,7 +58,7 @@ func TestWantlist(t *testing.T) {
keystrs := []string{"foo", "bar", "baz", "bat"} keystrs := []string{"foo", "bar", "baz", "bat"}
m := New() m := New()
for _, s := range keystrs { for _, s := range keystrs {
m.AppendWanted(u.Key(s)) m.AddWanted(u.Key(s))
} }
exported := m.Wantlist() exported := m.Wantlist()
...@@ -81,7 +81,7 @@ func TestCopyProtoByValue(t *testing.T) { ...@@ -81,7 +81,7 @@ func TestCopyProtoByValue(t *testing.T) {
const str = "foo" const str = "foo"
m := New() m := New()
protoBeforeAppend := m.ToProto() protoBeforeAppend := m.ToProto()
m.AppendWanted(u.Key(str)) m.AddWanted(u.Key(str))
if contains(protoBeforeAppend.GetWantlist(), str) { if contains(protoBeforeAppend.GetWantlist(), str) {
t.Fail() t.Fail()
} }
...@@ -101,11 +101,11 @@ func TestToNetMethodSetsPeer(t *testing.T) { ...@@ -101,11 +101,11 @@ func TestToNetMethodSetsPeer(t *testing.T) {
func TestToNetFromNetPreservesWantList(t *testing.T) { func TestToNetFromNetPreservesWantList(t *testing.T) {
original := New() original := New()
original.AppendWanted(u.Key("M")) original.AddWanted(u.Key("M"))
original.AppendWanted(u.Key("B")) original.AddWanted(u.Key("B"))
original.AppendWanted(u.Key("D")) original.AddWanted(u.Key("D"))
original.AppendWanted(u.Key("T")) original.AddWanted(u.Key("T"))
original.AppendWanted(u.Key("F")) original.AddWanted(u.Key("F"))
p := peer.WithIDString("X") p := peer.WithIDString("X")
netmsg, err := original.ToNet(p) netmsg, err := original.ToNet(p)
......
...@@ -60,7 +60,7 @@ func TestBlockRecordedAsWantedAfterMessageReceived(t *testing.T) { ...@@ -60,7 +60,7 @@ func TestBlockRecordedAsWantedAfterMessageReceived(t *testing.T) {
block := blocks.NewBlock([]byte("data wanted by beggar")) block := blocks.NewBlock([]byte("data wanted by beggar"))
messageFromBeggarToChooser := message.New() messageFromBeggarToChooser := message.New()
messageFromBeggarToChooser.AppendWanted(block.Key()) messageFromBeggarToChooser.AddWanted(block.Key())
chooser.MessageReceived(beggar.Peer, messageFromBeggarToChooser) chooser.MessageReceived(beggar.Peer, messageFromBeggarToChooser)
// for this test, doesn't matter if you record that beggar sent // for this test, doesn't matter if you record that beggar sent
......
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