@cryptotaxi247 / kubo / commits / 601a2faa2

move public method to top of file

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 2, 2014 at 19:37 UTC 601a2faa287eb17ef93f2414a678e332e6cf562a
1 file changed +16 -16
exchange/bitswap/bitswap.go
+16 -16
@@ -145,6 +145,22 @@ func (bs *bitswap) GetBlocks(ctx context.Context, keys []u.Key) (<-chan *blocks.
145 }
146 }
147
148 +// HasBlock announces the existance of a block to this bitswap service. The
149 +// service will potentially notify its peers.
150 +func (bs *bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
151 + if err := bs.blockstore.Put(blk); err != nil {
152 + return err
153 + }
154 + bs.wantlist.Remove(blk.Key())
155 + bs.notifications.Publish(blk)
156 + child, _ := context.WithTimeout(ctx, hasBlockTimeout)
157 + if err := bs.sendToPeersThatWant(child, blk); err != nil {
158 + return err
159 + }
160 + child, _ = context.WithTimeout(ctx, hasBlockTimeout)
161 + return bs.routing.Provide(child, blk.Key())
162 +}
163 +
164 func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) error {
165 if peers == nil {
166 panic("Cant send wantlist to nil peerchan")
@@ -245,22 +261,6 @@ func (bs *bitswap) loop(parent context.Context) {
261 }
262 }
263
248 -// HasBlock announces the existance of a block to this bitswap service. The
249 -// service will potentially notify its peers.
250 -func (bs *bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
251 - if err := bs.blockstore.Put(blk); err != nil {
252 - return err
253 - }
254 - bs.wantlist.Remove(blk.Key())
255 - bs.notifications.Publish(blk)
256 - child, _ := context.WithTimeout(ctx, hasBlockTimeout)
257 - if err := bs.sendToPeersThatWant(child, blk); err != nil {
258 - return err
259 - }
260 - child, _ = context.WithTimeout(ctx, hasBlockTimeout)
261 - return bs.routing.Provide(child, blk.Key())
262 -}
263 -
264 // TODO(brian): handle errors
265 func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsmsg.BitSwapMessage) (
266 peer.Peer, bsmsg.BitSwapMessage) {