@cryptotaxi247 / kubo / commits / ad14d6c56

refac(bitswap:interface) GetBlock, HaveBlock -> Block, HasBlock

Brian Tiger Chow committed Sep 15, 2014 at 04:50 UTC ad14d6c561e481223800c21fb0c2fb09095ea744
3 files changed +7 -8
bitswap/bitswap.go
+3 -3
@@ -85,7 +85,7 @@ func NewSession(parent context.Context, p *peer.Peer, d ds.Datastore, r routing.
85 }
86
87 // GetBlock attempts to retrieve a particular block from peers, within timeout.
88 -func (bs *BitSwap) GetBlock(k u.Key, timeout time.Duration) (
88 +func (bs *BitSwap) Block(k u.Key, timeout time.Duration) (
89 *blocks.Block, error) {
90 u.DOut("Bitswap GetBlock: '%s'\n", k.Pretty())
91 begin := time.Now()
@@ -139,9 +139,9 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
139 return &block, nil
140 }
141
142 -// HaveBlock announces the existance of a block to BitSwap, potentially sending
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) HaveBlock(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()) {
bitswap/interface.go
+2 -3
@@ -11,13 +11,12 @@ type Exchange interface {
11
12 // Block returns the block associated with a given key.
13 // TODO(brian): pass a context instead of a timeout
14 - // TODO(brian): rename -> Block
15 - GetBlock(k u.Key, timeout time.Duration) (*blocks.Block, error)
14 + Block(k u.Key, timeout time.Duration) (*blocks.Block, error)
15
16 // HasBlock asserts the existence of this block
17 // TODO(brian): rename -> HasBlock
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?
22 - HaveBlock(*blocks.Block) error
21 + HasBlock(*blocks.Block) error
22 }
blockservice/blockservice.go
+2 -2
@@ -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.HaveBlock(b)
45 + err = s.Remote.HasBlock(b)
46 }
47 return k, err
48 }
@@ -65,7 +65,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
65 }, nil
66 } else if err == ds.ErrNotFound && s.Remote != nil {
67 u.DOut("Blockservice: Searching bitswap.\n")
68 - blk, err := s.Remote.GetBlock(k, time.Second*5)
68 + blk, err := s.Remote.Block(k, time.Second*5)
69 if err != nil {
70 return nil, err
71 }