@cryptotaxi247 / kubo / commits / 01ce8e7d7

only pass keys down newBlocks chan in bitswap

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Sep 28, 2016 at 17:08 UTC 01ce8e7d7106481b9edc521ab4c9206a1e6d41f2
2 files changed +11 -6
exchange/bitswap/bitswap.go
+8 -3
@@ -90,7 +90,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
90 network: network,
91 findKeys: make(chan *blockRequest, sizeBatchRequestChan),
92 process: px,
93 - newBlocks: make(chan blocks.Block, HasBlockBufferSize),
93 + newBlocks: make(chan key.Key, HasBlockBufferSize),
94 provideKeys: make(chan key.Key, provideKeysBufferSize),
95 wm: NewWantManager(ctx, network),
96 }
@@ -137,7 +137,7 @@ type Bitswap struct {
137
138 process process.Process
139
140 - newBlocks chan blocks.Block
140 + newBlocks chan key.Key
141
142 provideKeys chan key.Key
143
@@ -308,12 +308,17 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error {
308 return err
309 }
310
311 + // NOTE: There exists the possiblity for a race condition here. If a user
312 + // creates a node, then adds it to the dagservice while another goroutine
313 + // is waiting on a GetBlock for that object, they will receive a reference
314 + // to the same node. We should address this soon, but i'm not going to do
315 + // it now as it requires more thought and isnt causing immediate problems.
316 bs.notifications.Publish(blk)
317
318 bs.engine.AddBlock(blk)
319
320 select {
316 - case bs.newBlocks <- blk:
321 + case bs.newBlocks <- blk.Key():
322 // send block off to be reprovided
323 case <-bs.process.Closing():
324 return bs.process.Close()
exchange/bitswap/workers.go
+3 -3
@@ -127,17 +127,17 @@ func (bs *Bitswap) provideCollector(ctx context.Context) {
127
128 for {
129 select {
130 - case blk, ok := <-bs.newBlocks:
130 + case blkey, ok := <-bs.newBlocks:
131 if !ok {
132 log.Debug("newBlocks channel closed")
133 return
134 }
135
136 if keysOut == nil {
137 - nextKey = blk.Key()
137 + nextKey = blkey
138 keysOut = bs.provideKeys
139 } else {
140 - toProvide = append(toProvide, blk.Key())
140 + toProvide = append(toProvide, blkey)
141 }
142 case keysOut <- nextKey:
143 if len(toProvide) > 0 {