mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 08:47:42 +08:00
refac(bitswap:exch) HasBlock(ptr) -> HasBlock(val)
This commit is contained in:
@ -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
|
// HasBlock announces the existance of a block to BitSwap, potentially sending
|
||||||
// it to peers (Partners) whose WantLists include it.
|
// 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() {
|
go func() {
|
||||||
for _, ledger := range bs.partners {
|
for _, ledger := range bs.partners {
|
||||||
if ledger.WantListContains(blk.Key()) {
|
if ledger.WantListContains(blk.Key()) {
|
||||||
@ -155,10 +155,10 @@ func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
|
|||||||
return bs.routing.Provide(blk.Key())
|
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()
|
message := bsmsg.New()
|
||||||
// TODO(brian): change interface to accept value instead of pointer
|
// TODO(brian): change interface to accept value instead of pointer
|
||||||
message.AppendBlock(*b)
|
message.AppendBlock(b)
|
||||||
bs.sender.SendMessage(context.Background(), p, message)
|
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)
|
u.PErr("newBlock error: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bs.SendBlock(p, bblk)
|
bs.SendBlock(p, *bblk)
|
||||||
ledger.SentBytes(len(blk))
|
ledger.SentBytes(len(blk))
|
||||||
} else {
|
} else {
|
||||||
u.DOut("Decided not to send block.")
|
u.DOut("Decided not to send block.")
|
||||||
|
@ -18,5 +18,5 @@ type Exchange interface {
|
|||||||
// TODO(brian): accept a value, not a pointer
|
// TODO(brian): accept a value, not a pointer
|
||||||
// TODO(brian): remove error return value. Should callers be concerned with
|
// TODO(brian): remove error return value. Should callers be concerned with
|
||||||
// whether the block was made available on the network?
|
// whether the block was made available on the network?
|
||||||
HasBlock(*blocks.Block) error
|
HasBlock(blocks.Block) error
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ func (_ *offlineExchange) Block(k u.Key, timeout time.Duration) (*blocks.Block,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasBlock always returns nil.
|
// HasBlock always returns nil.
|
||||||
func (_ *offlineExchange) HasBlock(*blocks.Block) error {
|
func (_ *offlineExchange) HasBlock(blocks.Block) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func TestBlockReturnsErr(t *testing.T) {
|
|||||||
func TestHasBlockReturnsNil(t *testing.T) {
|
func TestHasBlockReturnsNil(t *testing.T) {
|
||||||
off := NewOfflineExchange()
|
off := NewOfflineExchange()
|
||||||
block := testutil.NewBlockOrFail(t, "data")
|
block := testutil.NewBlockOrFail(t, "data")
|
||||||
err := off.HasBlock(&block)
|
err := off.HasBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("")
|
t.Fatal("")
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
|
|||||||
return k, err
|
return k, err
|
||||||
}
|
}
|
||||||
if s.Remote != nil {
|
if s.Remote != nil {
|
||||||
err = s.Remote.HasBlock(b)
|
err = s.Remote.HasBlock(*b)
|
||||||
}
|
}
|
||||||
return k, err
|
return k, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user