@cryptotaxi247 / kubo / commits / cebeff43b

style(bitswap/message) rename method -> AddBlock

to emphasize idempotence

Brian Tiger Chow committed Oct 27, 2014 at 06:18 UTC cebeff43b9c686666e1508724893d5c242dbcf45
5 files changed +15 -15
exchange/bitswap/bitswap.go
+2 -2
@@ -176,7 +176,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
176 if block, errBlockNotFound := bs.blockstore.Get(key); errBlockNotFound != nil {
177 continue
178 } else {
179 - message.AppendBlock(*block)
179 + message.AddBlock(*block)
180 }
181 }
182 }
@@ -206,7 +206,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
206 log.Debugf("%v wants %v", p, block.Key())
207 if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
208 message := bsmsg.New()
209 - message.AppendBlock(block)
209 + message.AddBlock(block)
210 for _, wanted := range bs.wantlist.Keys() {
211 message.AddWanted(wanted)
212 }
exchange/bitswap/message/message.go
+3 -3
@@ -17,7 +17,7 @@ type BitSwapMessage interface {
17 Wantlist() []u.Key
18 Blocks() []blocks.Block
19 AddWanted(k u.Key)
20 - AppendBlock(b blocks.Block)
20 + AddBlock(b blocks.Block)
21 Exportable
22 }
23
@@ -45,7 +45,7 @@ func newMessageFromProto(pbm pb.Message) BitSwapMessage {
45 }
46 for _, d := range pbm.GetBlocks() {
47 b := blocks.NewBlock(d)
48 - m.AppendBlock(*b)
48 + m.AddBlock(*b)
49 }
50 return m
51 }
@@ -72,7 +72,7 @@ func (m *impl) AddWanted(k u.Key) {
72 m.wantlist[k] = struct{}{}
73 }
74
75 -func (m *impl) AppendBlock(b blocks.Block) {
75 +func (m *impl) AddBlock(b blocks.Block) {
76 m.blocks[b.Key()] = b
77 }
78
exchange/bitswap/message/message_test.go
+5 -5
@@ -42,7 +42,7 @@ func TestAppendBlock(t *testing.T) {
42 m := New()
43 for _, str := range strs {
44 block := blocks.NewBlock([]byte(str))
45 - m.AppendBlock(*block)
45 + m.AddBlock(*block)
46 }
47
48 // assert strings are in proto message
@@ -133,10 +133,10 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
133 func TestToAndFromNetMessage(t *testing.T) {
134
135 original := New()
136 - original.AppendBlock(*blocks.NewBlock([]byte("W")))
137 - original.AppendBlock(*blocks.NewBlock([]byte("E")))
138 - original.AppendBlock(*blocks.NewBlock([]byte("F")))
139 - original.AppendBlock(*blocks.NewBlock([]byte("M")))
136 + original.AddBlock(*blocks.NewBlock([]byte("W")))
137 + original.AddBlock(*blocks.NewBlock([]byte("E")))
138 + original.AddBlock(*blocks.NewBlock([]byte("F")))
139 + original.AddBlock(*blocks.NewBlock([]byte("M")))
140
141 p := peer.WithIDString("X")
142 netmsg, err := original.ToNet(p)
exchange/bitswap/strategy/strategy_test.go
+1 -1
@@ -30,7 +30,7 @@ func TestConsistentAccounting(t *testing.T) {
30
31 m := message.New()
32 content := []string{"this", "is", "message", "i"}
33 - m.AppendBlock(*blocks.NewBlock([]byte(strings.Join(content, " "))))
33 + m.AddBlock(*blocks.NewBlock([]byte(strings.Join(content, " "))))
34
35 sender.MessageSent(receiver.Peer, m)
36 receiver.MessageReceived(sender.Peer, m)
exchange/bitswap/testnet/network_test.go
+4 -4
@@ -33,7 +33,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
33 // TODO test contents of incoming message
34
35 m := bsmsg.New()
36 - m.AppendBlock(*blocks.NewBlock([]byte(expectedStr)))
36 + m.AddBlock(*blocks.NewBlock([]byte(expectedStr)))
37
38 return from, m
39 }))
@@ -41,7 +41,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
41 t.Log("Build a message and send a synchronous request to recipient")
42
43 message := bsmsg.New()
44 - message.AppendBlock(*blocks.NewBlock([]byte("data")))
44 + message.AddBlock(*blocks.NewBlock([]byte("data")))
45 response, err := initiator.SendRequest(
46 context.Background(), peer.WithID(idOfRecipient), message)
47 if err != nil {
@@ -77,7 +77,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
77 peer.Peer, bsmsg.BitSwapMessage) {
78
79 msgToWaiter := bsmsg.New()
80 - msgToWaiter.AppendBlock(*blocks.NewBlock([]byte(expectedStr)))
80 + msgToWaiter.AddBlock(*blocks.NewBlock([]byte(expectedStr)))
81
82 return fromWaiter, msgToWaiter
83 }))
@@ -105,7 +105,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
105 }))
106
107 messageSentAsync := bsmsg.New()
108 - messageSentAsync.AppendBlock(*blocks.NewBlock([]byte("data")))
108 + messageSentAsync.AddBlock(*blocks.NewBlock([]byte("data")))
109 errSending := waiter.SendMessage(
110 context.Background(), peer.WithID(idOfResponder), messageSentAsync)
111 if errSending != nil {