Skip to content

Commit

Permalink
Refactor parameter interaction, call it before AppInit2()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli authored and Fuzzbawls committed Mar 11, 2020
1 parent bb9b762 commit 18480ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
57 changes: 32 additions & 25 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,34 +842,22 @@ bool AppInitBasicSetup()
return true;
}

/** Initialize pivx.
* @pre Parameters should be parsed and config file should be read.
*/
bool AppInit2()
// Parameter interaction based on rules
void InitParameterInteraction()
{
// ********************************************************* Step 1: setup
if (!AppInitBasicSetup())
return false;

// ********************************************************* Step 2: parameter interactions
// Set this early so that parameter interactions go to console
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
fLogIPs = GetBoolArg("-logips", false);

if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) {
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
if (SoftSetBoolArg("-listen", true))
LogPrintf("AppInit2 : parameter interaction: -bind or -whitebind set -> setting -listen=1\n");
LogPrintf("%s : parameter interaction: -bind or -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("AppInit2 : parameter interaction: -connect set -> setting -dnsseed=0\n");
LogPrintf("%s : parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
if (SoftSetBoolArg("-listen", false))
LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -listen=0\n");
LogPrintf("%s : parameter interaction: -connect set -> setting -listen=0\n", __func__);
}

if (mapArgs.count("-proxy")) {
Expand All @@ -882,41 +870,60 @@ bool AppInit2()
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("AppInit2 : parameter interaction: -proxy set -> setting -discover=0\n");
LogPrintf("%s : parameter interaction: -proxy set -> setting -discover=0\n", __func__);
}

if (!GetBoolArg("-listen", true)) {
// do not map ports or try to retrieve public IP when not listening (pointless)
if (SoftSetBoolArg("-upnp", false))
LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -upnp=0\n");
LogPrintf("%s : parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
if (SoftSetBoolArg("-discover", false))
LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -discover=0\n");
LogPrintf("%s : parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
if (SoftSetBoolArg("-listenonion", false))
LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -listenonion=0\n");
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("AppInit2 : parameter interaction: -externalip set -> setting -discover=0\n");
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("AppInit2 : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n");
LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
}

// -zapwallettx implies a rescan
if (GetBoolArg("-zapwallettxes", false)) {
if (SoftSetBoolArg("-rescan", true))
LogPrintf("AppInit2 : parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n");
LogPrintf("%s : parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
}

if (!GetBoolArg("-enableswifttx", fEnableSwiftTX)) {
if (SoftSetArg("-swifttxdepth", "0"))
LogPrintf("AppInit2 : parameter interaction: -enableswifttx=false -> setting -nSwiftTXDepth=0\n");
LogPrintf("%s : parameter interaction: -enableswifttx=false -> setting -nSwiftTXDepth=0\n", __func__);
}
}

/** Initialize pivx.
* @pre Parameters should be parsed and config file should be read.
*/
bool AppInit2()
{
// ********************************************************* Step 1: setup
if (!AppInitBasicSetup())
return false;

// ********************************************************* Step 2: parameter interactions
// Set this early so that parameter interactions go to console
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
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("PIVX version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);

// Make sure enough file descriptors are available
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);
Expand Down
2 changes: 2 additions & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ bool ShutdownRequested();
void Interrupt();
void Shutdown();
void PrepareShutdown();
//!Parameter interaction: change current parameters depending on various rules
void InitParameterInteraction();
bool AppInit2();

/** Initialize PIVX core: Basic context setup.
Expand Down
1 change: 1 addition & 0 deletions src/pivxd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ bool AppInit(int argc, char* argv[])
#endif
SoftSetBoolArg("-server", true);

InitParameterInteraction();
fRet = AppInit2();
} catch (const std::exception& e) {
PrintExceptionContinue(&e, "AppInit()");
Expand Down

0 comments on commit 18480ce

Please sign in to comment.