Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <memory> | #include <memory> | ||||
static const bool DEFAULT_PROXYRANDOMIZE = true; | static const bool DEFAULT_PROXYRANDOMIZE = true; | ||||
static const bool DEFAULT_REST_ENABLE = false; | static const bool DEFAULT_REST_ENABLE = false; | ||||
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false; | static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false; | ||||
// Dump addresses to banlist.dat every 15 minutes (900s) | |||||
static constexpr int DUMP_BANS_INTERVAL = 60 * 15; | |||||
std::unique_ptr<CConnman> g_connman; | std::unique_ptr<CConnman> g_connman; | ||||
std::unique_ptr<PeerLogicValidation> peerLogic; | std::unique_ptr<PeerLogicValidation> peerLogic; | ||||
std::unique_ptr<BanMan> g_banman; | |||||
#if !(ENABLE_WALLET) | #if !(ENABLE_WALLET) | ||||
class DummyWalletInit : public WalletInitInterface { | class DummyWalletInit : public WalletInitInterface { | ||||
public: | public: | ||||
void AddWalletOptions() const override {} | void AddWalletOptions() const override {} | ||||
bool ParameterInteraction() const override { return true; } | bool ParameterInteraction() const override { return true; } | ||||
void RegisterRPC(CRPCTable &) const override {} | void RegisterRPC(CRPCTable &) const override {} | ||||
bool Verify(const CChainParams &chainParams) const override { return true; } | bool Verify(const CChainParams &chainParams) const override { return true; } | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | void Shutdown() { | ||||
// the CScheduler/checkqueue threadGroup | // the CScheduler/checkqueue threadGroup | ||||
threadGroup.interrupt_all(); | threadGroup.interrupt_all(); | ||||
threadGroup.join_all(); | threadGroup.join_all(); | ||||
// After the threads that potentially access these pointers have been | // After the threads that potentially access these pointers have been | ||||
// stopped, destruct and reset all to nullptr. | // stopped, destruct and reset all to nullptr. | ||||
peerLogic.reset(); | peerLogic.reset(); | ||||
g_connman.reset(); | g_connman.reset(); | ||||
g_banman.reset(); | |||||
g_txindex.reset(); | g_txindex.reset(); | ||||
if (g_is_mempool_loaded && | if (g_is_mempool_loaded && | ||||
gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | ||||
DumpMempool(); | DumpMempool(); | ||||
} | } | ||||
// FlushStateToDisk generates a ChainStateFlushed callback, which we should | // FlushStateToDisk generates a ChainStateFlushed callback, which we should | ||||
▲ Show 20 Lines • Show All 1,692 Lines • ▼ Show 20 Lines | #endif | ||||
// Step 6: network initialization | // Step 6: network initialization | ||||
// Note that we absolutely cannot open any actual connections | // Note that we absolutely cannot open any actual connections | ||||
// until the very end ("start node") as the UTXO/block state | // until the very end ("start node") as the UTXO/block state | ||||
// is not yet setup and may end up being set up twice if we | // is not yet setup and may end up being set up twice if we | ||||
// need to reindex later. | // need to reindex later. | ||||
assert(!g_banman); | |||||
g_banman = std::make_unique<BanMan>(config.GetChainParams(), &uiInterface); | |||||
assert(!g_connman); | assert(!g_connman); | ||||
g_connman = std::make_unique<CConnman>( | g_connman = std::make_unique<CConnman>( | ||||
config, GetRand(std::numeric_limits<uint64_t>::max()), | config, GetRand(std::numeric_limits<uint64_t>::max()), | ||||
GetRand(std::numeric_limits<uint64_t>::max())); | GetRand(std::numeric_limits<uint64_t>::max())); | ||||
CConnman &connman = *g_connman; | |||||
peerLogic.reset(new PeerLogicValidation( | peerLogic.reset(new PeerLogicValidation( | ||||
&connman, scheduler, | g_connman.get(), g_banman.get(), scheduler, | ||||
gArgs.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61))); | gArgs.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61))); | ||||
RegisterValidationInterface(peerLogic.get()); | RegisterValidationInterface(peerLogic.get()); | ||||
// sanitize comments per BIP-0014, format user agent and check total size | // sanitize comments per BIP-0014, format user agent and check total size | ||||
std::vector<std::string> uacomments; | std::vector<std::string> uacomments; | ||||
for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { | for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { | ||||
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) | if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) | ||||
return InitError(strprintf( | return InitError(strprintf( | ||||
▲ Show 20 Lines • Show All 469 Lines • ▼ Show 20 Lines | #endif | ||||
connOptions.nLocalServices = nLocalServices; | connOptions.nLocalServices = nLocalServices; | ||||
connOptions.nMaxConnections = nMaxConnections; | connOptions.nMaxConnections = nMaxConnections; | ||||
connOptions.nMaxOutbound = | connOptions.nMaxOutbound = | ||||
std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections); | std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections); | ||||
connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS; | connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS; | ||||
connOptions.nMaxFeeler = 1; | connOptions.nMaxFeeler = 1; | ||||
connOptions.nBestHeight = chain_active_height; | connOptions.nBestHeight = chain_active_height; | ||||
connOptions.uiInterface = &uiInterface; | connOptions.uiInterface = &uiInterface; | ||||
connOptions.m_banman = g_banman.get(); | |||||
connOptions.m_msgproc = peerLogic.get(); | connOptions.m_msgproc = peerLogic.get(); | ||||
connOptions.nSendBufferMaxSize = | connOptions.nSendBufferMaxSize = | ||||
1000 * gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); | 1000 * gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); | ||||
connOptions.nReceiveFloodSize = | connOptions.nReceiveFloodSize = | ||||
1000 * gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); | 1000 * gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); | ||||
connOptions.m_added_nodes = gArgs.GetArgs("-addnode"); | connOptions.m_added_nodes = gArgs.GetArgs("-addnode"); | ||||
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe; | connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe; | ||||
Show All 34 Lines | #endif | ||||
// Initiate outbound connections unless connect=0 | // Initiate outbound connections unless connect=0 | ||||
connOptions.m_use_addrman_outgoing = !gArgs.IsArgSet("-connect"); | connOptions.m_use_addrman_outgoing = !gArgs.IsArgSet("-connect"); | ||||
if (!connOptions.m_use_addrman_outgoing) { | if (!connOptions.m_use_addrman_outgoing) { | ||||
const auto connect = gArgs.GetArgs("-connect"); | const auto connect = gArgs.GetArgs("-connect"); | ||||
if (connect.size() != 1 || connect[0] != "0") { | if (connect.size() != 1 || connect[0] != "0") { | ||||
connOptions.m_specified_outgoing = connect; | connOptions.m_specified_outgoing = connect; | ||||
} | } | ||||
} | } | ||||
if (!connman.Start(scheduler, connOptions)) { | if (!g_connman->Start(scheduler, connOptions)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 13: finished | // Step 13: finished | ||||
SetRPCWarmupFinished(); | SetRPCWarmupFinished(); | ||||
uiInterface.InitMessage(_("Done loading")); | uiInterface.InitMessage(_("Done loading")); | ||||
g_wallet_init_interface.Start(scheduler); | g_wallet_init_interface.Start(scheduler); | ||||
scheduler.scheduleEvery( | |||||
[] { | |||||
g_banman->DumpBanlist(); | |||||
return true; | |||||
}, | |||||
DUMP_BANS_INTERVAL * 1000); | |||||
return true; | return true; | ||||
} | } |