Refactor parameter interaction, call it before AppInit2()
This commit is contained in:
parent
5bedad9580
commit
ef6b9b0fb2
|
@ -167,6 +167,7 @@ bool AppInit(int argc, char* argv[])
|
||||||
#endif
|
#endif
|
||||||
SoftSetBoolArg("-server", true);
|
SoftSetBoolArg("-server", true);
|
||||||
|
|
||||||
|
InitParameterInteraction();
|
||||||
fRet = AppInit2(threadGroup, scheduler);
|
fRet = AppInit2(threadGroup, scheduler);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
|
|
112
src/init.cpp
112
src/init.cpp
|
@ -774,6 +774,64 @@ bool AppInitServers(boost::thread_group& threadGroup)
|
||||||
return true;
|
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 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 try to retrieve public IP when not listening (pointless)
|
||||||
|
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__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Initialize bitcoin.
|
/** Initialize bitcoin.
|
||||||
* @pre Parameters should be parsed and config file should be read.
|
* @pre Parameters should be parsed and config file should be read.
|
||||||
*/
|
*/
|
||||||
|
@ -864,60 +922,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||||
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
|
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
|
||||||
LogPrintf("Zcash version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
|
LogPrintf("Zcash 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 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 try to retrieve public IP when not listening (pointless)
|
|
||||||
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__);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure enough file descriptors are available
|
// Make sure enough file descriptors are available
|
||||||
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);
|
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);
|
||||||
nMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
|
nMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
|
||||||
|
|
|
@ -26,6 +26,8 @@ bool ShutdownRequested();
|
||||||
/** Interrupt threads */
|
/** Interrupt threads */
|
||||||
void Interrupt(boost::thread_group& threadGroup);
|
void Interrupt(boost::thread_group& threadGroup);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
//!Parameter interaction: change current parameters depending on various rules
|
||||||
|
void InitParameterInteraction();
|
||||||
bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler);
|
bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler);
|
||||||
|
|
||||||
/** The help message mode determines what help message to show */
|
/** The help message mode determines what help message to show */
|
||||||
|
|
Loading…
Reference in New Issue