Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only pass keys down newBlocks chan in bitswap #3271

Merged
merged 1 commit into from
Sep 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions exchange/bitswap/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
network: network,
findKeys: make(chan *blockRequest, sizeBatchRequestChan),
process: px,
newBlocks: make(chan blocks.Block, HasBlockBufferSize),
newBlocks: make(chan key.Key, HasBlockBufferSize),
provideKeys: make(chan key.Key, provideKeysBufferSize),
wm: NewWantManager(ctx, network),
}
Expand Down Expand Up @@ -137,7 +137,7 @@ type Bitswap struct {

process process.Process

newBlocks chan blocks.Block
newBlocks chan key.Key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to newKeys?
but current name also fits.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, newBlocks still makes sense to me. I'm going to keep it as is


provideKeys chan key.Key

Expand Down Expand Up @@ -308,12 +308,17 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error {
return err
}

// NOTE: There exists the possiblity for a race condition here. If a user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create issue for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created: #3274

// 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.engine.AddBlock(blk)

select {
case bs.newBlocks <- blk:
case bs.newBlocks <- blk.Key():
// send block off to be reprovided
case <-bs.process.Closing():
return bs.process.Close()
Expand Down
6 changes: 3 additions & 3 deletions exchange/bitswap/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ func (bs *Bitswap) provideCollector(ctx context.Context) {

for {
select {
case blk, ok := <-bs.newBlocks:
case blkey, ok := <-bs.newBlocks:
if !ok {
log.Debug("newBlocks channel closed")
return
}

if keysOut == nil {
nextKey = blk.Key()
nextKey = blkey
keysOut = bs.provideKeys
} else {
toProvide = append(toProvide, blk.Key())
toProvide = append(toProvide, blkey)
}
case keysOut <- nextKey:
if len(toProvide) > 0 {
Expand Down