Commit 8cd17e8d authored by Brian Tiger Chow's avatar Brian Tiger Chow

style(bitswap/message) rename method -> AddBlock

to emphasize idempotence
parent 9cebc05a
......@@ -176,7 +176,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
if block, errBlockNotFound := bs.blockstore.Get(key); errBlockNotFound != nil {
continue
} else {
message.AppendBlock(*block)
message.AddBlock(*block)
}
}
}
......@@ -206,7 +206,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
log.Debugf("%v wants %v", p, block.Key())
if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
message := bsmsg.New()
message.AppendBlock(block)
message.AddBlock(block)
for _, wanted := range bs.wantlist.Keys() {
message.AddWanted(wanted)
}
......
......@@ -17,7 +17,7 @@ type BitSwapMessage interface {
Wantlist() []u.Key
Blocks() []blocks.Block
AddWanted(k u.Key)
AppendBlock(b blocks.Block)
AddBlock(b blocks.Block)
Exportable
}
......@@ -45,7 +45,7 @@ func newMessageFromProto(pbm pb.Message) BitSwapMessage {
}
for _, d := range pbm.GetBlocks() {
b := blocks.NewBlock(d)
m.AppendBlock(*b)
m.AddBlock(*b)
}
return m
}
......@@ -72,7 +72,7 @@ func (m *impl) AddWanted(k u.Key) {
m.wantlist[k] = struct{}{}
}
func (m *impl) AppendBlock(b blocks.Block) {
func (m *impl) AddBlock(b blocks.Block) {
m.blocks[b.Key()] = b
}
......
......@@ -42,7 +42,7 @@ func TestAppendBlock(t *testing.T) {
m := New()
for _, str := range strs {
block := blocks.NewBlock([]byte(str))
m.AppendBlock(*block)
m.AddBlock(*block)
}
// assert strings are in proto message
......@@ -133,10 +133,10 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
func TestToAndFromNetMessage(t *testing.T) {
original := New()
original.AppendBlock(*blocks.NewBlock([]byte("W")))
original.AppendBlock(*blocks.NewBlock([]byte("E")))
original.AppendBlock(*blocks.NewBlock([]byte("F")))
original.AppendBlock(*blocks.NewBlock([]byte("M")))
original.AddBlock(*blocks.NewBlock([]byte("W")))
original.AddBlock(*blocks.NewBlock([]byte("E")))
original.AddBlock(*blocks.NewBlock([]byte("F")))
original.AddBlock(*blocks.NewBlock([]byte("M")))
p := peer.WithIDString("X")
netmsg, err := original.ToNet(p)
......
......@@ -30,7 +30,7 @@ func TestConsistentAccounting(t *testing.T) {
m := message.New()
content := []string{"this", "is", "message", "i"}
m.AppendBlock(*blocks.NewBlock([]byte(strings.Join(content, " "))))
m.AddBlock(*blocks.NewBlock([]byte(strings.Join(content, " "))))
sender.MessageSent(receiver.Peer, m)
receiver.MessageReceived(sender.Peer, m)
......
......@@ -33,7 +33,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
// TODO test contents of incoming message
m := bsmsg.New()
m.AppendBlock(*blocks.NewBlock([]byte(expectedStr)))
m.AddBlock(*blocks.NewBlock([]byte(expectedStr)))
return from, m
}))
......@@ -41,7 +41,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
t.Log("Build a message and send a synchronous request to recipient")
message := bsmsg.New()
message.AppendBlock(*blocks.NewBlock([]byte("data")))
message.AddBlock(*blocks.NewBlock([]byte("data")))
response, err := initiator.SendRequest(
context.Background(), peer.WithID(idOfRecipient), message)
if err != nil {
......@@ -77,7 +77,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
peer.Peer, bsmsg.BitSwapMessage) {
msgToWaiter := bsmsg.New()
msgToWaiter.AppendBlock(*blocks.NewBlock([]byte(expectedStr)))
msgToWaiter.AddBlock(*blocks.NewBlock([]byte(expectedStr)))
return fromWaiter, msgToWaiter
}))
......@@ -105,7 +105,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
}))
messageSentAsync := bsmsg.New()
messageSentAsync.AppendBlock(*blocks.NewBlock([]byte("data")))
messageSentAsync.AddBlock(*blocks.NewBlock([]byte("data")))
errSending := waiter.SendMessage(
context.Background(), peer.WithID(idOfResponder), messageSentAsync)
if errSending != nil {
......
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