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