bitcoin/bitcoin — pull request #4831 by laanwj (2014-09-03 09:38:45+00:00)
Title: net: Better askfor request management

- Instead of naively planning requests every two minutes into (potentially) the far future w/ mapAlreadyAskedFor, actively keep track of requests, and which nodes offer the requested items
- Better handles the case where nodes announce an inv and go away, or stop responding
- Maintains state separate from CNode, which makes it easier to review and understand separately from the rest, as well as localizes changes if extension of the logic is necessary

I also think it can serve as an example of how to 'peel off' a single concern from net/main.

Uses CTimeoutCondition from @ashleyholman (#4230).

Cases to test:

- Announce and don't reply to getdata, make sure retry chooses different node after `REQUEST_TIMEOUT`
- Node disconnects and was the current node requested from - should immediately try to get from different node
- Last node that had announced a certain transaction goes away - request should be discarded

TODO:

- Slim down debug logging
- Make sure `RequestItem`'s handling of CNode locking is correct

Known issues:

- Doesn't currently group getdata requests (sends a getdata request per item instead of one getdata for many invs) - wouldn't be too difficult to fit in but I'm not sure it is worth the complexity, as usually only one inv is sent at a time