diff options
| author | Jonas Schnelli <[email protected]> | 2016-11-11 11:16:34 +0100 |
|---|---|---|
| committer | Jonas Schnelli <[email protected]> | 2016-11-11 11:16:40 +0100 |
| commit | ab914a65301bd48f2b6c7a64bf57295ae74f2902 (patch) | |
| tree | 4d5cc61cffd8d24d7c09f1d9cf9a6c5317cf2e5a /src/net.cpp | |
| parent | Merge #9058: Fixes for p2p-compactblocks.py test timeouts on travis (#8842) (diff) | |
| parent | Qt: New network_disabled icon (diff) | |
| download | discoin-ab914a65301bd48f2b6c7a64bf57295ae74f2902.tar.xz discoin-ab914a65301bd48f2b6c7a64bf57295ae74f2902.zip | |
Merge #8996: Network activity toggle
19f46f1 Qt: New network_disabled icon (Luke Dashjr)
54cf997 RPC/Net: Use boolean consistently for networkactive, and remove from getinfo (Luke Dashjr)
b2b33d9 Overhaul network activity toggle (Jonas Schnelli)
32efa79 Qt: Add GUI feedback and control of network activity state. (Jon Lund Steffensen)
e38993b RPC: Add "togglenetwork" method to toggle network activity temporarily (Jon Lund Steffensen)
7c9a98a Allow network activity to be temporarily suspended. (Jon Lund Steffensen)
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index e47a8bb16..15c4514f1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -985,6 +985,12 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { return; } + if (!fNetworkActive) { + LogPrintf("connection from %s dropped: not accepting new connections\n", addr.ToString()); + CloseSocket(hSocket); + return; + } + if (!IsSelectableSocket(hSocket)) { LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString()); @@ -1784,6 +1790,9 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai // Initiate outbound network connection // boost::this_thread::interruption_point(); + if (!fNetworkActive) { + return false; + } if (!pszDest) { if (IsLocal(addrConnect) || FindNode((CNetAddr)addrConnect) || IsBanned(addrConnect) || @@ -2025,8 +2034,30 @@ void Discover(boost::thread_group& threadGroup) #endif } +void CConnman::SetNetworkActive(bool active) +{ + if (fDebug) { + LogPrint("net", "SetNetworkActive: %s\n", active); + } + + if (!active) { + fNetworkActive = false; + + LOCK(cs_vNodes); + // Close sockets to all nodes + BOOST_FOREACH(CNode* pnode, vNodes) { + pnode->CloseSocketDisconnect(); + } + } else { + fNetworkActive = true; + } + + uiInterface.NotifyNetworkActiveChanged(fNetworkActive); +} + CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In) { + fNetworkActive = true; setBannedIsDirty = false; fAddressesInitialized = false; nLastNodeId = 0; |