We currently have two structures for per-peer data: CNode in net, which should just contain connection layer data (eg socket, send/recv buffers, etc), but currently also contains some application layer data (eg tx/block inventory). CNodeState in net processing, which contains p2p application layer data, but requires cs_main to be locked for access. This PR adds a third struct Peer, which is for p2p application layer data, and doesn't require cs_main. Eventually all application layer data from CNode should be moved to Peer, and any data that doesn't strictly require cs_main should be moved from CNodeState to Peer (probably all of CNodeState eventually). Peer objects are stored as shared pointers in a net processing global map g_peer_map, which is protected by g_peer_mutex. To use a Peer object, g_peer_mutex is locked, a copy of the shared pointer is taken, and the lock is released. Individual members of Peer are protected by different mutexes that guard related data. The lifetime of the Peer object is managed by the shared_ptr refcount. This PR adds the Peer object and moves the misbehaving data from CNodeState to Peer. This allows us to immediately remove 15 LOCK(cs_main) instances. For more motivation see #19398
Backport of core PR19607.
Depends on D8793.
Includes changes from our codebase that don't exist in core.