bitcoin/bitcoin — pull request #3276 by sipa (2013-11-18 00:35:55+00:00)
Title: Add main-specific node state & move ban score

Currently, the protocol processing happens mostly in main, while most of its data structures are defined in net. This leads to weird situations where they need to access eachother's locks, and it is unclear what functionality belongs where.

This pull request introduces a main-specific CNodeState, which is managed entirely by main, so doesn't require CNode's locks. The intention is to move all processing-related fields in CNode to CNodeState, so ultimately main doesn't need access to CNode anymore, decoupling the two. This is a long way out, and we'll probably want to separate protocol processing to a different module than block validation, but it's what we have now.

For now, only node banning is moved to CNodeState. The reason for this is asynchronous processing. When blocks or transactions are processed by background threads, or in any way not directly the result of a single message being processed, we may want to attribute errors still to the original sender's DoS score. Going back and forth between main and net for this becomes increasingly ugly, as this can be done perfectly well inside main.

The direct motivation for this is an attempt at implementing BIP37-filtered-block-based fetching, and headers-first.