Commit 5d2b9d6c authored by Jeromy's avatar Jeromy

only pass keys down newBlocks chan in bitswap

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent 7dfc5ccf
...@@ -90,7 +90,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork, ...@@ -90,7 +90,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
network: network, network: network,
findKeys: make(chan *blockRequest, sizeBatchRequestChan), findKeys: make(chan *blockRequest, sizeBatchRequestChan),
process: px, process: px,
newBlocks: make(chan blocks.Block, HasBlockBufferSize), newBlocks: make(chan key.Key, HasBlockBufferSize),
provideKeys: make(chan key.Key, provideKeysBufferSize), provideKeys: make(chan key.Key, provideKeysBufferSize),
wm: NewWantManager(ctx, network), wm: NewWantManager(ctx, network),
} }
...@@ -137,7 +137,7 @@ type Bitswap struct { ...@@ -137,7 +137,7 @@ type Bitswap struct {
process process.Process process process.Process
newBlocks chan blocks.Block newBlocks chan key.Key
provideKeys chan key.Key provideKeys chan key.Key
...@@ -308,12 +308,17 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error { ...@@ -308,12 +308,17 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error {
return err return err
} }
// NOTE: There exists the possiblity for a race condition here. If a user
// creates a node, then adds it to the dagservice while another goroutine
// is waiting on a GetBlock for that object, they will receive a reference
// to the same node. We should address this soon, but i'm not going to do
// it now as it requires more thought and isnt causing immediate problems.
bs.notifications.Publish(blk) bs.notifications.Publish(blk)
bs.engine.AddBlock(blk) bs.engine.AddBlock(blk)
select { select {
case bs.newBlocks <- blk: case bs.newBlocks <- blk.Key():
// send block off to be reprovided // send block off to be reprovided
case <-bs.process.Closing(): case <-bs.process.Closing():
return bs.process.Close() return bs.process.Close()
......
...@@ -127,17 +127,17 @@ func (bs *Bitswap) provideCollector(ctx context.Context) { ...@@ -127,17 +127,17 @@ func (bs *Bitswap) provideCollector(ctx context.Context) {
for { for {
select { select {
case blk, ok := <-bs.newBlocks: case blkey, ok := <-bs.newBlocks:
if !ok { if !ok {
log.Debug("newBlocks channel closed") log.Debug("newBlocks channel closed")
return return
} }
if keysOut == nil { if keysOut == nil {
nextKey = blk.Key() nextKey = blkey
keysOut = bs.provideKeys keysOut = bs.provideKeys
} else { } else {
toProvide = append(toProvide, blk.Key()) toProvide = append(toProvide, blkey)
} }
case keysOut <- nextKey: case keysOut <- nextKey:
if len(toProvide) > 0 { if len(toProvide) > 0 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment