Skip to content

Commit 62fe6aa

Browse files
committed
net: Add -networkactive option
The `setnetworkactive' RPC command is already present. This new option allows to start the client with disabled p2p network activity for testing or reindexing.
1 parent f7c19e8 commit 62fe6aa

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ void SetupServerArgs(NodeContext& node)
456456
gArgs.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
457457
gArgs.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
458458
gArgs.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
459+
gArgs.AddArg("-networkactive", "Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_BOOL, OptionsCategory::CONNECTION);
459460
gArgs.AddArg("-timeout=<n>", strprintf("Specify connection timeout in milliseconds (minimum: 1, default: %d)", DEFAULT_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
460461
gArgs.AddArg("-peertimeout=<n>", strprintf("Specify p2p connection timeout in seconds. This option determines the amount of time a peer may be inactive before the connection to it is dropped. (minimum: 1, default: %d)", DEFAULT_PEER_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
461462
gArgs.AddArg("-torcontrol=<ip>:<port>", strprintf("Tor control port to use if onion listening enabled (default: %s)", DEFAULT_TOR_CONTROL), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
@@ -1372,7 +1373,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
13721373
assert(!node.banman);
13731374
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
13741375
assert(!node.connman);
1375-
node.connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));
1376+
node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), gArgs.GetBoolArg("-networkactive", true));
13761377
// Make mempool generally available in the node context. For example the connection manager, wallet, or RPC threads,
13771378
// which are all started after this, may use it from the node context.
13781379
assert(!node.mempool);

src/net.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2262,12 +2262,14 @@ void CConnman::SetNetworkActive(bool active)
22622262
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
22632263
}
22642264

2265-
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)
2265+
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, bool network_active)
2266+
: nSeed0(nSeed0In), nSeed1(nSeed1In)
22662267
{
22672268
SetTryNewOutboundPeer(false);
22682269

22692270
Options connOptions;
22702271
Init(connOptions);
2272+
SetNetworkActive(network_active);
22712273
}
22722274

22732275
NodeId CConnman::GetNewNodeId()

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class CConnman
181181
}
182182
}
183183

184-
CConnman(uint64_t seed0, uint64_t seed1);
184+
CConnman(uint64_t seed0, uint64_t seed1, bool network_active = true);
185185
~CConnman();
186186
bool Start(CScheduler& scheduler, const Options& options);
187187

0 commit comments

Comments
 (0)