jbenet/go-ipfs — pull request #409 by whyrusleeping (2014-12-07 07:59:06+00:00)
Title: prevent sending of same block to a peer twice

I noticed a problem with bitswap, and that is that since ReceiveMessage is run asynchronously, we could be processing the wantlist of the same peer multiple times, sending them the same block multiple times. This is compounded by the fact that, for every block we send to a peer, they will send us their wantlist again, prompting us to send them every block in their wantlist, again (while the other loop over their wantlist is still running and sending blocks). The fix in this PR is not the best fix in my opinion, there is still the possiblity for a 'race condition' to cause a block to be sent multiple times to the same peer. Also, only ever sending a block to the same peer once is not a good strategy, so I want to discuss what the right way to address this is.