aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-11-27 13:34:08 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-11-27 13:45:14 +0100
commit2a94cd67e80555aec3ba13d5129b1f5402b0c5b4 (patch)
treee215dd05d37b8c17f1fe3e5d4ff5841a74620481 /src
parent5ca149a3db4a9f4e5ea93353494b40f2f1713e76 (diff)
parenta46f87f0c17323d8853d95f8ea99f8fb0f3bda1a (diff)
downloadbitcoin-2a94cd67e80555aec3ba13d5129b1f5402b0c5b4.tar.xz
Merge pull request #6780
a46f87f Initialize logging before we do parameter interaction (Jonas Schnelli) df66147 Move -blocksonly parameter interaction to the new ParameterInteraction() function (Jonas Schnelli) 68354e7 [QT] Call inits parameter interaction before we create the options model (Jonas Schnelli) 411b05a Refactor parameter interaction, call it before AppInit2() (Jonas Schnelli)
Diffstat (limited to 'src')
-rw-r--r--src/bitcoind.cpp3
-rw-r--r--src/init.cpp152
-rw-r--r--src/init.h4
-rw-r--r--src/qt/bitcoin.cpp10
4 files changed, 102 insertions, 67 deletions
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index addf0e6a26..4cee2d3cf0 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -151,6 +151,9 @@ bool AppInit(int argc, char* argv[])
#endif
SoftSetBoolArg("-server", true);
+ // Set this early so that parameter interactions go to console
+ InitLogging();
+ InitParameterInteraction();
fRet = AppInit2(threadGroup, scheduler);
}
catch (const std::exception& e) {
diff --git a/src/init.cpp b/src/init.cpp
index 3ae3e44406..bc6d724d71 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -682,6 +682,91 @@ bool AppInitServers(boost::thread_group& threadGroup)
return true;
}
+// Parameter interaction based on rules
+void InitParameterInteraction()
+{
+ // when specifying an explicit binding address, you want to listen on it
+ // even when -connect or -proxy is specified
+ if (mapArgs.count("-bind")) {
+ if (SoftSetBoolArg("-listen", true))
+ LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
+ }
+ if (mapArgs.count("-whitebind")) {
+ if (SoftSetBoolArg("-listen", true))
+ LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
+ }
+
+ if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
+ // when only connecting to trusted nodes, do not seed via DNS, or listen by default
+ if (SoftSetBoolArg("-dnsseed", false))
+ LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
+ if (SoftSetBoolArg("-listen", false))
+ LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
+ }
+
+ if (mapArgs.count("-proxy")) {
+ // to protect privacy, do not listen by default if a default proxy server is specified
+ if (SoftSetBoolArg("-listen", false))
+ LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
+ // to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
+ // to listen locally, so don't rely on this happening through -listen below.
+ if (SoftSetBoolArg("-upnp", false))
+ LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
+ // to protect privacy, do not discover addresses by default
+ if (SoftSetBoolArg("-discover", false))
+ LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
+ }
+
+ if (!GetBoolArg("-listen", DEFAULT_LISTEN)) {
+ // do not map ports or try to retrieve public IP when not listening (pointless)
+ if (SoftSetBoolArg("-upnp", false))
+ LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
+ if (SoftSetBoolArg("-discover", false))
+ LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
+ if (SoftSetBoolArg("-listenonion", false))
+ LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
+ }
+
+ if (mapArgs.count("-externalip")) {
+ // if an explicit public IP is specified, do not try to find others
+ if (SoftSetBoolArg("-discover", false))
+ LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
+ }
+
+ if (GetBoolArg("-salvagewallet", false)) {
+ // Rewrite just private keys: rescan to find transactions
+ if (SoftSetBoolArg("-rescan", true))
+ LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
+ }
+
+ // -zapwallettx implies a rescan
+ if (GetBoolArg("-zapwallettxes", false)) {
+ if (SoftSetBoolArg("-rescan", true))
+ LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
+ }
+
+ // disable walletbroadcast and whitelistalwaysrelay in blocksonly mode
+ if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
+ if (SoftSetBoolArg("-whitelistalwaysrelay", false))
+ LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__);
+#ifdef ENABLE_WALLET
+ if (SoftSetBoolArg("-walletbroadcast", false))
+ LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
+#endif
+ }
+}
+
+void InitLogging()
+{
+ fPrintToConsole = GetBoolArg("-printtoconsole", false);
+ fLogTimestamps = GetBoolArg("-logtimestamps", true);
+ fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
+ fLogIPs = GetBoolArg("-logips", false);
+
+ LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+ LogPrintf("Bitcoin version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
+}
+
/** Initialize bitcoin.
* @pre Parameters should be parsed and config file should be read.
*/
@@ -746,74 +831,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// ********************************************************* Step 2: parameter interactions
const CChainParams& chainparams = Params();
- // Set this early so that parameter interactions go to console
- fPrintToConsole = GetBoolArg("-printtoconsole", false);
- fLogTimestamps = GetBoolArg("-logtimestamps", true);
- fLogTimeMicros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
- fLogIPs = GetBoolArg("-logips", false);
-
- LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- LogPrintf("Bitcoin version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
-
- // when specifying an explicit binding address, you want to listen on it
- // even when -connect or -proxy is specified
- if (mapArgs.count("-bind")) {
- if (SoftSetBoolArg("-listen", true))
- LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
- }
- if (mapArgs.count("-whitebind")) {
- if (SoftSetBoolArg("-listen", true))
- LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
- }
-
- if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
- // when only connecting to trusted nodes, do not seed via DNS, or listen by default
- if (SoftSetBoolArg("-dnsseed", false))
- LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
- if (SoftSetBoolArg("-listen", false))
- LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
- }
-
- if (mapArgs.count("-proxy")) {
- // to protect privacy, do not listen by default if a default proxy server is specified
- if (SoftSetBoolArg("-listen", false))
- LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
- // to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
- // to listen locally, so don't rely on this happening through -listen below.
- if (SoftSetBoolArg("-upnp", false))
- LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
- // to protect privacy, do not discover addresses by default
- if (SoftSetBoolArg("-discover", false))
- LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
- }
-
- if (!GetBoolArg("-listen", DEFAULT_LISTEN)) {
- // do not map ports or try to retrieve public IP when not listening (pointless)
- if (SoftSetBoolArg("-upnp", false))
- LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
- if (SoftSetBoolArg("-discover", false))
- LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
- if (SoftSetBoolArg("-listenonion", false))
- LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
- }
-
- if (mapArgs.count("-externalip")) {
- // if an explicit public IP is specified, do not try to find others
- if (SoftSetBoolArg("-discover", false))
- LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
- }
-
- if (GetBoolArg("-salvagewallet", false)) {
- // Rewrite just private keys: rescan to find transactions
- if (SoftSetBoolArg("-rescan", true))
- LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
- }
- // -zapwallettx implies a rescan
- if (GetBoolArg("-zapwallettxes", false)) {
- if (SoftSetBoolArg("-rescan", true))
- LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
- }
// if using block pruning, then disable txindex
if (GetArg("-prune", 0)) {
diff --git a/src/init.h b/src/init.h
index 8cd51b0286..d4872e7794 100644
--- a/src/init.h
+++ b/src/init.h
@@ -23,6 +23,10 @@ bool ShutdownRequested();
/** Interrupt threads */
void Interrupt(boost::thread_group& threadGroup);
void Shutdown();
+//!Initialize the logging infrastructure
+void InitLogging();
+//!Parameter interaction: change current parameters depending on various rules
+void InitParameterInteraction();
bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler);
/** The help message mode determines what help message to show */
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 06a6c239ef..d407e539ef 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -201,6 +201,8 @@ public:
/// Create payment server
void createPaymentServer();
#endif
+ /// parameter interaction/setup based on rules
+ void parameterSetup();
/// Create options model
void createOptionsModel(bool resetSettings);
/// Create main window
@@ -397,6 +399,12 @@ void BitcoinApplication::startThread()
coreThread->start();
}
+void BitcoinApplication::parameterSetup()
+{
+ InitLogging();
+ InitParameterInteraction();
+}
+
void BitcoinApplication::requestInitialize()
{
qDebug() << __func__ << ": Requesting initialize";
@@ -644,6 +652,8 @@ int main(int argc, char *argv[])
// Install qDebug() message handler to route to debug.log
qInstallMessageHandler(DebugMessageHandler);
#endif
+ // Allow parameter interaction before we create the options model
+ app.parameterSetup();
// Load GUI settings from QSettings
app.createOptionsModel(mapArgs.count("-resetguisettings") != 0);