diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2013-03-26 02:33:25 +0100 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2016-10-24 10:23:58 +0000 |
commit | 7c9a98aac843c9efabd8653caebc35e968b2f335 (patch) | |
tree | 3792d80c0d93ba74067a3d59cad4e39527a3a914 /src/net.cpp | |
parent | 5d0219d983b6cb8de5b4faf3f78a6781c99e442b (diff) |
Allow network activity to be temporarily suspended.
Added the function SetNetworkActive() which when called with argument set to false disconnects all nodes and sets the flag fNetworkActive to false. As long as this flag is false no new connections are attempted and no incoming connections are accepted. Network activity is reenabled by calling the function with argument true.
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index cce06f2d64..973e278e0e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -990,6 +990,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()); @@ -1783,6 +1789,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) || @@ -2024,8 +2033,28 @@ 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; + } +} + CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In) { + fNetworkActive = true; setBannedIsDirty = false; fAddressesInitialized = false; nLastNodeId = 0; |