MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ThreadMessageHandler

Method ThreadMessageHandler

src/net.cpp:3193–3232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3191Mutex NetEventsInterface::g_msgproc_mutex;
3192
3193void CConnman::ThreadMessageHandler()
3194{
3195 AssertLockNotHeld(m_nodes_mutex);
3196
3197 LOCK(NetEventsInterface::g_msgproc_mutex);
3198
3199 while (!flagInterruptMsgProc)
3200 {
3201 bool fMoreWork = false;
3202
3203 {
3204 // Randomize the order in which we process messages from/to our peers.
3205 // This prevents attacks in which an attacker exploits having multiple
3206 // consecutive connections in the m_nodes list.
3207 const NodesSnapshot snap{*this, /*shuffle=*/true};
3208
3209 for (CNode* pnode : snap.Nodes()) {
3210 if (pnode->fDisconnect)
3211 continue;
3212
3213 // Receive messages
3214 bool fMoreNodeWork{m_msgproc->ProcessMessages(*pnode, flagInterruptMsgProc)};
3215 fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
3216 if (flagInterruptMsgProc)
3217 return;
3218 // Send messages
3219 m_msgproc->SendMessages(*pnode);
3220
3221 if (flagInterruptMsgProc)
3222 return;
3223 }
3224 }
3225
3226 WAIT_LOCK(mutexMsgProc, lock);
3227 if (!fMoreWork) {
3228 condMsgProc.wait_until(lock, std::chrono::steady_clock::now() + std::chrono::milliseconds(100), [this]() EXCLUSIVE_LOCKS_REQUIRED(mutexMsgProc) { return fMsgProcWake; });
3229 }
3230 fMsgProcWake = false;
3231 }
3232}
3233
3234void CConnman::ThreadI2PAcceptIncoming()
3235{

Callers

nothing calls this directly

Calls 4

EXCLUSIVE_LOCKS_REQUIREDFunction · 0.70
ProcessMessagesMethod · 0.45
SendMessagesMethod · 0.45
wait_untilMethod · 0.45

Tested by

no test coverage detected