@cryptotaxi247 / kubo / commits / 0ab86de40

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

Brian Tiger Chow committed Sep 15, 2014 at 07:59 UTC 0ab86de407ffc593fd4aa3503abe14dd13ad1d11
5 files changed +8 -8
bitswap/bitswap.go
+4 -4
@@ -141,7 +141,7 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
141
142 // HasBlock announces the existance of a block to BitSwap, potentially sending
143 // it to peers (Partners) whose WantLists include it.
144 -func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
144 +func (bs *BitSwap) HasBlock(blk blocks.Block) error {
145 go func() {
146 for _, ledger := range bs.partners {
147 if ledger.WantListContains(blk.Key()) {
@@ -155,10 +155,10 @@ func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
155 return bs.routing.Provide(blk.Key())
156 }
157
158 -func (bs *BitSwap) SendBlock(p *peer.Peer, b *blocks.Block) {
158 +func (bs *BitSwap) SendBlock(p *peer.Peer, b blocks.Block) {
159 message := bsmsg.New()
160 // TODO(brian): change interface to accept value instead of pointer
161 - message.AppendBlock(*b)
161 + message.AppendBlock(b)
162 bs.sender.SendMessage(context.Background(), p, message)
163 }
164
@@ -190,7 +190,7 @@ func (bs *BitSwap) peerWantsBlock(p *peer.Peer, wanted u.Key) {
190 u.PErr("newBlock error: %v\n", err)
191 return
192 }
193 - bs.SendBlock(p, bblk)
193 + bs.SendBlock(p, *bblk)
194 ledger.SentBytes(len(blk))
195 } else {
196 u.DOut("Decided not to send block.")
bitswap/interface.go
+1 -1
@@ -18,5 +18,5 @@ type Exchange interface {
18 // TODO(brian): accept a value, not a pointer
19 // TODO(brian): remove error return value. Should callers be concerned with
20 // whether the block was made available on the network?
21 - HasBlock(*blocks.Block) error
21 + HasBlock(blocks.Block) error
22 }
bitswap/offline.go
+1 -1
@@ -25,6 +25,6 @@ func (_ *offlineExchange) Block(k u.Key, timeout time.Duration) (*blocks.Block,
25 }
26
27 // HasBlock always returns nil.
28 -func (_ *offlineExchange) HasBlock(*blocks.Block) error {
28 +func (_ *offlineExchange) HasBlock(blocks.Block) error {
29 return nil
30 }
bitswap/offline_test.go
+1 -1
@@ -20,7 +20,7 @@ func TestBlockReturnsErr(t *testing.T) {
20 func TestHasBlockReturnsNil(t *testing.T) {
21 off := NewOfflineExchange()
22 block := testutil.NewBlockOrFail(t, "data")
23 - err := off.HasBlock(&block)
23 + err := off.HasBlock(block)
24 if err != nil {
25 t.Fatal("")
26 }
blockservice/blockservice.go
+1 -1
@@ -42,7 +42,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
42 return k, err
43 }
44 if s.Remote != nil {
45 - err = s.Remote.HasBlock(b)
45 + err = s.Remote.HasBlock(*b)
46 }
47 return k, err
48 }