Net: Fixed a race condition when disabling the network.
Net: Fixed a race condition when disabling the network.

Summary:
This change addresses a race condition where setnetworkactive=false wouldn't always disconnect all peers.

Before this change, the following could happen:
1. Thread A -- Begins connecting to a node.
2. Thread B -- Sets kNetworkActive=false and disconnects connected nodes.
3. Thread A -- Finishes connecting and adds node to list of connected nodes.

The node that was connected from Thread A remains connected and active,
even though kNetworkActive=false.

To fix the race, disconnections when kNetworkActive=false are now handled in the main network loop.

fixes #13038

This is a backport of core PR13212 and include elements of PR10824

Test Plan:
  make check

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Subscribers: teamcity

Differential Revision: https://reviews.bitcoinabc.org/D1878

Bitcoin-ABC/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,cculianu/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,cculianu/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,cculianu/bitcoin-abc,cculianu/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,cculianu/bitcoin-abc,cculianu/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,cculianu/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,cculianu/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,ftrader-bitcoinabc/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc