Skip to content

Commit 18480ce

Browse files
jonasschnelliFuzzbawls
authored andcommitted
Refactor parameter interaction, call it before AppInit2()
1 parent bb9b762 commit 18480ce

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

src/init.cpp

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -842,34 +842,22 @@ bool AppInitBasicSetup()
842842
return true;
843843
}
844844

845-
/** Initialize pivx.
846-
* @pre Parameters should be parsed and config file should be read.
847-
*/
848-
bool AppInit2()
845+
// Parameter interaction based on rules
846+
void InitParameterInteraction()
849847
{
850-
// ********************************************************* Step 1: setup
851-
if (!AppInitBasicSetup())
852-
return false;
853-
854-
// ********************************************************* Step 2: parameter interactions
855-
// Set this early so that parameter interactions go to console
856-
fPrintToConsole = GetBoolArg("-printtoconsole", false);
857-
fLogTimestamps = GetBoolArg("-logtimestamps", true);
858-
fLogIPs = GetBoolArg("-logips", false);
859-
860848
if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) {
861849
// when specifying an explicit binding address, you want to listen on it
862850
// even when -connect or -proxy is specified
863851
if (SoftSetBoolArg("-listen", true))
864-
LogPrintf("AppInit2 : parameter interaction: -bind or -whitebind set -> setting -listen=1\n");
852+
LogPrintf("%s : parameter interaction: -bind or -whitebind set -> setting -listen=1\n", __func__);
865853
}
866854

867855
if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
868856
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
869857
if (SoftSetBoolArg("-dnsseed", false))
870-
LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -dnsseed=0\n");
858+
LogPrintf("%s : parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
871859
if (SoftSetBoolArg("-listen", false))
872-
LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -listen=0\n");
860+
LogPrintf("%s : parameter interaction: -connect set -> setting -listen=0\n", __func__);
873861
}
874862

875863
if (mapArgs.count("-proxy")) {
@@ -882,41 +870,60 @@ bool AppInit2()
882870
LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
883871
// to protect privacy, do not discover addresses by default
884872
if (SoftSetBoolArg("-discover", false))
885-
LogPrintf("AppInit2 : parameter interaction: -proxy set -> setting -discover=0\n");
873+
LogPrintf("%s : parameter interaction: -proxy set -> setting -discover=0\n", __func__);
886874
}
887875

888876
if (!GetBoolArg("-listen", true)) {
889877
// do not map ports or try to retrieve public IP when not listening (pointless)
890878
if (SoftSetBoolArg("-upnp", false))
891-
LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -upnp=0\n");
879+
LogPrintf("%s : parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
892880
if (SoftSetBoolArg("-discover", false))
893-
LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -discover=0\n");
881+
LogPrintf("%s : parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
894882
if (SoftSetBoolArg("-listenonion", false))
895-
LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -listenonion=0\n");
883+
LogPrintf("%s : parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
896884
}
897885

898886
if (mapArgs.count("-externalip")) {
899887
// if an explicit public IP is specified, do not try to find others
900888
if (SoftSetBoolArg("-discover", false))
901-
LogPrintf("AppInit2 : parameter interaction: -externalip set -> setting -discover=0\n");
889+
LogPrintf("%s : parameter interaction: -externalip set -> setting -discover=0\n", __func__);
902890
}
903891

904892
if (GetBoolArg("-salvagewallet", false)) {
905893
// Rewrite just private keys: rescan to find transactions
906894
if (SoftSetBoolArg("-rescan", true))
907-
LogPrintf("AppInit2 : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n");
895+
LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
908896
}
909897

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

916904
if (!GetBoolArg("-enableswifttx", fEnableSwiftTX)) {
917905
if (SoftSetArg("-swifttxdepth", "0"))
918-
LogPrintf("AppInit2 : parameter interaction: -enableswifttx=false -> setting -nSwiftTXDepth=0\n");
906+
LogPrintf("%s : parameter interaction: -enableswifttx=false -> setting -nSwiftTXDepth=0\n", __func__);
919907
}
908+
}
909+
910+
/** Initialize pivx.
911+
* @pre Parameters should be parsed and config file should be read.
912+
*/
913+
bool AppInit2()
914+
{
915+
// ********************************************************* Step 1: setup
916+
if (!AppInitBasicSetup())
917+
return false;
918+
919+
// ********************************************************* Step 2: parameter interactions
920+
// Set this early so that parameter interactions go to console
921+
fPrintToConsole = GetBoolArg("-printtoconsole", false);
922+
fLogTimestamps = GetBoolArg("-logtimestamps", true);
923+
fLogIPs = GetBoolArg("-logips", false);
924+
925+
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
926+
LogPrintf("PIVX version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
920927

921928
// Make sure enough file descriptors are available
922929
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);

src/init.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ bool ShutdownRequested();
2727
void Interrupt();
2828
void Shutdown();
2929
void PrepareShutdown();
30+
//!Parameter interaction: change current parameters depending on various rules
31+
void InitParameterInteraction();
3032
bool AppInit2();
3133

3234
/** Initialize PIVX core: Basic context setup.

src/pivxd.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ bool AppInit(int argc, char* argv[])
140140
#endif
141141
SoftSetBoolArg("-server", true);
142142

143+
InitParameterInteraction();
143144
fRet = AppInit2();
144145
} catch (const std::exception& e) {
145146
PrintExceptionContinue(&e, "AppInit()");

0 commit comments

Comments
 (0)