@@ -788,10 +788,17 @@ void InitLogging()
788
788
LogPrintf (" Bitcoin version %s\n " , FormatFullVersion ());
789
789
}
790
790
791
- /* * Initialize bitcoin.
792
- * @pre Parameters should be parsed and config file should be read.
793
- */
794
- bool AppInit2 (boost::thread_group& threadGroup, CScheduler& scheduler)
791
+ namespace { // Variables internal to initialization process only
792
+
793
+ ServiceFlags nRelevantServices = NODE_NETWORK;
794
+ int nMaxConnections;
795
+ int nUserMaxConnections;
796
+ int nFD;
797
+ ServiceFlags nLocalServices = NODE_NETWORK;
798
+
799
+ }
800
+
801
+ bool AppInitBasicSetup ()
795
802
{
796
803
// ********************************************************* Step 1: setup
797
804
#ifdef _MSC_VER
@@ -843,9 +850,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
843
850
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
844
851
signal (SIGPIPE, SIG_IGN);
845
852
#endif
853
+ return true ;
854
+ }
846
855
847
- // ********************************************************* Step 2: parameter interactions
856
+ bool AppInitParameterInteraction ()
857
+ {
848
858
const CChainParams& chainparams = Params ();
859
+ // ********************************************************* Step 2: parameter interactions
849
860
850
861
// also see: InitParameterInteraction()
851
862
@@ -857,12 +868,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
857
868
858
869
// Make sure enough file descriptors are available
859
870
int nBind = std::max ((int )mapArgs.count (" -bind" ) + (int )mapArgs.count (" -whitebind" ), 1 );
860
- int nUserMaxConnections = GetArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
861
- int nMaxConnections = std::max (nUserMaxConnections, 0 );
871
+ nUserMaxConnections = GetArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
872
+ nMaxConnections = std::max (nUserMaxConnections, 0 );
862
873
863
874
// Trim requested connection counts, to fit into system limitations
864
875
nMaxConnections = std::max (std::min (nMaxConnections, (int )(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0 );
865
- int nFD = RaiseFileDescriptorLimit (nMaxConnections + MIN_CORE_FILEDESCRIPTORS);
876
+ nFD = RaiseFileDescriptorLimit (nMaxConnections + MIN_CORE_FILEDESCRIPTORS);
866
877
if (nFD < MIN_CORE_FILEDESCRIPTORS)
867
878
return InitError (_ (" Not enough file descriptors available." ));
868
879
nMaxConnections = std::min (nFD - MIN_CORE_FILEDESCRIPTORS, nMaxConnections);
@@ -977,9 +988,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
977
988
// Option to startup with mocktime set (used for regression testing):
978
989
SetMockTime (GetArg (" -mocktime" , 0 )); // SetMockTime(0) is a no-op
979
990
980
- ServiceFlags nLocalServices = NODE_NETWORK;
981
- ServiceFlags nRelevantServices = NODE_NETWORK;
982
-
983
991
if (GetBoolArg (" -peerbloomfilters" , DEFAULT_PEERBLOOMFILTERS))
984
992
nLocalServices = ServiceFlags (nLocalServices | NODE_BLOOM);
985
993
@@ -1028,8 +1036,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
1028
1036
}
1029
1037
}
1030
1038
}
1039
+ return true ;
1040
+ }
1031
1041
1032
- // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
1042
+ bool AppInitSanityChecks ()
1043
+ {
1044
+ // ********************************************************* Step 4: sanity checks
1033
1045
1034
1046
// Initialize elliptic curve code
1035
1047
ECC_Start ();
@@ -1048,11 +1060,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
1048
1060
1049
1061
try {
1050
1062
static boost::interprocess::file_lock lock (pathLockFile.string ().c_str ());
1051
- if (!lock.try_lock ())
1063
+ if (!lock.try_lock ()) {
1052
1064
return InitError (strprintf (_ (" Cannot obtain a lock on data directory %s. %s is probably already running." ), strDataDir, _ (PACKAGE_NAME)));
1065
+ }
1053
1066
} catch (const boost::interprocess::interprocess_exception& e) {
1054
1067
return InitError (strprintf (_ (" Cannot obtain a lock on data directory %s. %s is probably already running." ) + " %s." , strDataDir, _ (PACKAGE_NAME), e.what ()));
1055
1068
}
1069
+ return true ;
1070
+ }
1071
+
1072
+ bool AppInitMain (boost::thread_group& threadGroup, CScheduler& scheduler)
1073
+ {
1074
+ const CChainParams& chainparams = Params ();
1075
+ // ********************************************************* Step 4a: application initialization
1056
1076
1057
1077
#ifndef WIN32
1058
1078
CreatePidFile (GetPidFile (), getpid ());
@@ -1066,7 +1086,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
1066
1086
if (!fLogTimestamps )
1067
1087
LogPrintf (" Startup time: %s\n " , DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , GetTime ()));
1068
1088
LogPrintf (" Default data directory %s\n " , GetDefaultDataDir ().string ());
1069
- LogPrintf (" Using data directory %s\n " , strDataDir );
1089
+ LogPrintf (" Using data directory %s\n " , GetDataDir (). string () );
1070
1090
LogPrintf (" Using config file %s\n " , GetConfigFile (GetArg (" -conf" , BITCOIN_CONF_FILENAME)).string ());
1071
1091
LogPrintf (" Using at most %i connections (%i file descriptors available)\n " , nMaxConnections, nFD);
1072
1092
0 commit comments