1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-28 00:39:31 +08:00

refac(bitswap:exch) HasBlock(ptr) -> HasBlock(val)

This commit is contained in:
Brian Tiger Chow
2014-09-15 07:59:02 -07:00
parent e07d3418c4
commit 0ab86de407
5 changed files with 8 additions and 8 deletions

View File

@ -141,7 +141,7 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
// HasBlock announces the existance of a block to BitSwap, potentially sending
// it to peers (Partners) whose WantLists include it.
func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
func (bs *BitSwap) HasBlock(blk blocks.Block) error {
go func() {
for _, ledger := range bs.partners {
if ledger.WantListContains(blk.Key()) {
@ -155,10 +155,10 @@ func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
return bs.routing.Provide(blk.Key())
}
func (bs *BitSwap) SendBlock(p *peer.Peer, b *blocks.Block) {
func (bs *BitSwap) SendBlock(p *peer.Peer, b blocks.Block) {
message := bsmsg.New()
// TODO(brian): change interface to accept value instead of pointer
message.AppendBlock(*b)
message.AppendBlock(b)
bs.sender.SendMessage(context.Background(), p, message)
}
@ -190,7 +190,7 @@ func (bs *BitSwap) peerWantsBlock(p *peer.Peer, wanted u.Key) {
u.PErr("newBlock error: %v\n", err)
return
}
bs.SendBlock(p, bblk)
bs.SendBlock(p, *bblk)
ledger.SentBytes(len(blk))
} else {
u.DOut("Decided not to send block.")

View File

@ -18,5 +18,5 @@ type Exchange interface {
// TODO(brian): accept a value, not a pointer
// TODO(brian): remove error return value. Should callers be concerned with
// whether the block was made available on the network?
HasBlock(*blocks.Block) error
HasBlock(blocks.Block) error
}

View File

@ -25,6 +25,6 @@ func (_ *offlineExchange) Block(k u.Key, timeout time.Duration) (*blocks.Block,
}
// HasBlock always returns nil.
func (_ *offlineExchange) HasBlock(*blocks.Block) error {
func (_ *offlineExchange) HasBlock(blocks.Block) error {
return nil
}

View File

@ -20,7 +20,7 @@ func TestBlockReturnsErr(t *testing.T) {
func TestHasBlockReturnsNil(t *testing.T) {
off := NewOfflineExchange()
block := testutil.NewBlockOrFail(t, "data")
err := off.HasBlock(&block)
err := off.HasBlock(block)
if err != nil {
t.Fatal("")
}

View File

@ -42,7 +42,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
return k, err
}
if s.Remote != nil {
err = s.Remote.HasBlock(b)
err = s.Remote.HasBlock(*b)
}
return k, err
}