net: keep reference to each node during socket wait
Summary:
Create the snapshot of CConnman::vNodes to operate on earlier in
CConnman::SocketHandler(), before calling CConnman::SocketEvents()
and pass the vNodes copy from the snapshot to SocketEvents().
This will keep the refcount of each node incremented during
SocketEvents() so that the CNode object is not destroyed before
SocketEvents() has finished.
Currently in SocketEvents() we only remember file descriptor numbers
(when not holding CConnman::cs_vNodes) which is safe, but we will
change this to remember pointers to CNode::m_sock.
This is a partial backport of core#21943
https://github.com/bitcoin/bitcoin/pull/21943/commits/664ac22c5379db65757fc3aab91fff8765683e7f
https://github.com/bitcoin/bitcoin/pull/21943/commits/c7eb19ec8302e6a5abd89c0566540c2c862e9121
Depends on D17106
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, roqqit
Reviewed By: roqqit
Differential Revision: https://reviews.bitcoinabc.org/D17107