Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
// Writes do not need similar protection, as failure to write is handled by | // Writes do not need similar protection, as failure to write is handled by | ||||
// the caller. | // the caller. | ||||
}; | }; | ||||
static std::unique_ptr<CCoinsViewErrorCatcher> pcoinscatcher; | static std::unique_ptr<CCoinsViewErrorCatcher> pcoinscatcher; | ||||
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; | static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; | ||||
void Interrupt(boost::thread_group &threadGroup) { | static boost::thread_group threadGroup; | ||||
static CScheduler scheduler; | |||||
void Interrupt() { | |||||
InterruptHTTPServer(); | InterruptHTTPServer(); | ||||
InterruptHTTPRPC(); | InterruptHTTPRPC(); | ||||
InterruptRPC(); | InterruptRPC(); | ||||
InterruptREST(); | InterruptREST(); | ||||
InterruptTorControl(); | InterruptTorControl(); | ||||
InterruptMapPort(); | InterruptMapPort(); | ||||
if (g_connman) { | if (g_connman) { | ||||
g_connman->Interrupt(); | g_connman->Interrupt(); | ||||
} | } | ||||
threadGroup.interrupt_all(); | |||||
} | } | ||||
void Shutdown() { | void Shutdown() { | ||||
LogPrintf("%s: In progress...\n", __func__); | LogPrintf("%s: In progress...\n", __func__); | ||||
static CCriticalSection cs_Shutdown; | static CCriticalSection cs_Shutdown; | ||||
TRY_LOCK(cs_Shutdown, lockShutdown); | TRY_LOCK(cs_Shutdown, lockShutdown); | ||||
if (!lockShutdown) { | if (!lockShutdown) { | ||||
return; | return; | ||||
Show All 16 Lines | void Shutdown() { | ||||
// Because these depend on each-other, we make sure that neither can be | // Because these depend on each-other, we make sure that neither can be | ||||
// using the other before destroying them. | // using the other before destroying them. | ||||
UnregisterValidationInterface(peerLogic.get()); | UnregisterValidationInterface(peerLogic.get()); | ||||
g_connman->Stop(); | g_connman->Stop(); | ||||
peerLogic.reset(); | peerLogic.reset(); | ||||
g_connman.reset(); | g_connman.reset(); | ||||
StopTorControl(); | StopTorControl(); | ||||
// After everything has been shut down, but before things get flushed, stop | |||||
// the CScheduler/checkqueue threadGroup | |||||
threadGroup.interrupt_all(); | |||||
threadGroup.join_all(); | |||||
if (fDumpMempoolLater && | if (fDumpMempoolLater && | ||||
gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | ||||
DumpMempool(); | DumpMempool(); | ||||
} | } | ||||
if (fFeeEstimatesInitialized) { | if (fFeeEstimatesInitialized) { | ||||
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; | fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; | ||||
CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, | CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, | ||||
▲ Show 20 Lines • Show All 889 Lines • ▼ Show 20 Lines | if (!Random_SanityCheck()) { | ||||
InitError("OS cryptographic RNG sanity check failure. Aborting."); | InitError("OS cryptographic RNG sanity check failure. Aborting."); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
static bool AppInitServers(Config &config, | static bool AppInitServers(Config &config, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor, | HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | ||||
boost::thread_group &threadGroup) { | |||||
RPCServerSignals::OnStarted(&OnRPCStarted); | RPCServerSignals::OnStarted(&OnRPCStarted); | ||||
RPCServerSignals::OnStopped(&OnRPCStopped); | RPCServerSignals::OnStopped(&OnRPCStopped); | ||||
if (!InitHTTPServer(config)) { | if (!InitHTTPServer(config)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!StartRPC()) { | if (!StartRPC()) { | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 608 Lines • ▼ Show 20 Lines | bool AppInitLockDataDirectory() { | ||||
if (!LockDataDirectory(false)) { | if (!LockDataDirectory(false)) { | ||||
// Detailed error printed inside LockDataDirectory | // Detailed error printed inside LockDataDirectory | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool AppInitMain(Config &config, | bool AppInitMain(Config &config, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor, | HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | ||||
boost::thread_group &threadGroup, CScheduler &scheduler) { | |||||
// Step 4a: application initialization | // Step 4a: application initialization | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
CreatePidFile(GetPidFile(), getpid()); | CreatePidFile(GetPidFile(), getpid()); | ||||
#endif | #endif | ||||
BCLog::Logger &logger = GetLogger(); | BCLog::Logger &logger = GetLogger(); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | #endif | ||||
/** | /** | ||||
* Start the RPC server. It will be started in "warmup" mode and not | * Start the RPC server. It will be started in "warmup" mode and not | ||||
* process calls yet (but it will verify that the server is there and will | * process calls yet (but it will verify that the server is there and will | ||||
* be ready later). Warmup mode will be completed when initialisation is | * be ready later). Warmup mode will be completed when initialisation is | ||||
* finished. | * finished. | ||||
*/ | */ | ||||
if (gArgs.GetBoolArg("-server", false)) { | if (gArgs.GetBoolArg("-server", false)) { | ||||
uiInterface.InitMessage.connect(SetRPCWarmupStatus); | uiInterface.InitMessage.connect(SetRPCWarmupStatus); | ||||
if (!AppInitServers(config, httpRPCRequestProcessor, threadGroup)) { | if (!AppInitServers(config, httpRPCRequestProcessor)) { | ||||
return InitError( | return InitError( | ||||
_("Unable to start HTTP server. See debug log for details.")); | _("Unable to start HTTP server. See debug log for details.")); | ||||
} | } | ||||
} | } | ||||
// Step 5: verify wallet database integrity | // Step 5: verify wallet database integrity | ||||
if (!g_wallet_init_interface->Verify(chainparams)) { | if (!g_wallet_init_interface->Verify(chainparams)) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 535 Lines • Show Last 20 Lines |