mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-05 12:39:23 +01:00
[lib] add scheduler to node context
- also update test setup & access point in denial of service test
This commit is contained in:
19
src/init.cpp
19
src/init.cpp
@@ -157,7 +157,6 @@ NODISCARD static bool CreatePidFile()
|
||||
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
||||
|
||||
static boost::thread_group threadGroup;
|
||||
static CScheduler scheduler;
|
||||
|
||||
void Interrupt(NodeContext& node)
|
||||
{
|
||||
@@ -295,6 +294,7 @@ void Shutdown(NodeContext& node)
|
||||
globalVerifyHandle.reset();
|
||||
ECC_Stop();
|
||||
if (node.mempool) node.mempool = nullptr;
|
||||
node.scheduler.reset();
|
||||
LogPrintf("%s: done\n", __func__);
|
||||
}
|
||||
|
||||
@@ -1265,16 +1265,19 @@ bool AppInitMain(NodeContext& node)
|
||||
}
|
||||
}
|
||||
|
||||
assert(!node.scheduler);
|
||||
node.scheduler = MakeUnique<CScheduler>();
|
||||
|
||||
// Start the lightweight task scheduler thread
|
||||
CScheduler::Function serviceLoop = std::bind(&CScheduler::serviceQueue, &scheduler);
|
||||
CScheduler::Function serviceLoop = [&node]{ node.scheduler->serviceQueue(); };
|
||||
threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
|
||||
|
||||
// Gather some entropy once per minute.
|
||||
scheduler.scheduleEvery([]{
|
||||
node.scheduler->scheduleEvery([]{
|
||||
RandAddPeriodic();
|
||||
}, 60000);
|
||||
|
||||
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
|
||||
GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
|
||||
|
||||
// Create client interfaces for wallets that are supposed to be loaded
|
||||
// according to -wallet and -disablewallet options. This only constructs
|
||||
@@ -1324,7 +1327,7 @@ bool AppInitMain(NodeContext& node)
|
||||
assert(!node.connman);
|
||||
node.connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));
|
||||
|
||||
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), scheduler));
|
||||
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler));
|
||||
RegisterValidationInterface(node.peer_logic.get());
|
||||
|
||||
// sanitize comments per BIP-0014, format user agent and check total size
|
||||
@@ -1816,7 +1819,7 @@ bool AppInitMain(NodeContext& node)
|
||||
connOptions.m_specified_outgoing = connect;
|
||||
}
|
||||
}
|
||||
if (!node.connman->Start(scheduler, connOptions)) {
|
||||
if (!node.connman->Start(*node.scheduler, connOptions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1845,11 +1848,11 @@ bool AppInitMain(NodeContext& node)
|
||||
uiInterface.InitMessage(_("Done loading").translated);
|
||||
|
||||
for (const auto& client : node.chain_clients) {
|
||||
client->start(scheduler);
|
||||
client->start(*node.scheduler);
|
||||
}
|
||||
|
||||
BanMan* banman = node.banman.get();
|
||||
scheduler.scheduleEvery([banman]{
|
||||
node.scheduler->scheduleEvery([banman]{
|
||||
banman->DumpBanlist();
|
||||
}, DUMP_BANS_INTERVAL * 1000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user