Skip to content

Commit

Permalink
style(bitswap/message) rename method -> AddBlock
Browse files Browse the repository at this point in the history
to emphasize idempotence
  • Loading branch information
Brian Tiger Chow committed Oct 27, 2014
1 parent 3dcf5ee commit 28db08d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions exchange/bitswap/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions exchange/bitswap/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions exchange/bitswap/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion exchange/bitswap/strategy/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions exchange/bitswap/testnet/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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
}))

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 {
Expand Down Expand Up @@ -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
}))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 28db08d

Please sign in to comment.