net processing: swap out signals for an interface class #10756

Open
wants to merge 3 commits into
from
View
@@ -194,11 +194,10 @@ void Shutdown()
#endif
MapPort(false);
UnregisterValidationInterface(peerLogic.get());
- peerLogic.reset();
g_connman.reset();
+ peerLogic.reset();
StopTorControl();
- UnregisterNodeSignals(GetNodeSignals());
if (fDumpMempoolLater && GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
DumpMempool();
}
@@ -1250,7 +1249,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
peerLogic.reset(new PeerLogicValidation(&connman));
RegisterValidationInterface(peerLogic.get());
- RegisterNodeSignals(GetNodeSignals());
// sanitize comments per BIP-0014, format user agent and check total size
std::vector<std::string> uacomments;
@@ -1608,6 +1606,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
connOptions.nMaxFeeler = 1;
connOptions.nBestHeight = chainActive.Height();
connOptions.uiInterface = &uiInterface;
+ connOptions.messageInterface = peerLogic.get();
connOptions.nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
connOptions.nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
View
@@ -89,10 +89,6 @@ std::string strSubVersion;
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
-// Signals for message handling
-static CNodeSignals g_signals;
-CNodeSignals& GetNodeSignals() { return g_signals; }
-
void CConnman::AddOneShot(const std::string& strDest)
{
LOCK(cs_vOneShots);
@@ -1114,7 +1110,9 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addr, CalculateKeyedNetGroup(addr), nonce, addr_bind, "", true);
pnode->AddRef();
pnode->fWhitelisted = whitelisted;
- GetNodeSignals().InitializeNode(pnode, *this);
+ if (messageInterface) {
+ messageInterface->InitializeNode(pnode);
+ }
LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString());
@@ -1966,7 +1964,9 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
if (fAddnode)
pnode->fAddnode = true;
- GetNodeSignals().InitializeNode(pnode, *this);
+ if (messageInterface) {
+ messageInterface->InitializeNode(pnode);
+ }
{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
@@ -1995,16 +1995,17 @@ void CConnman::ThreadMessageHandler()
if (pnode->fDisconnect)
continue;
- // Receive messages
- bool fMoreNodeWork = GetNodeSignals().ProcessMessages(pnode, *this, flagInterruptMsgProc);
- fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
- if (flagInterruptMsgProc)
- return;
-
- // Send messages
- {
- LOCK(pnode->cs_sendProcessing);
- GetNodeSignals().SendMessages(pnode, *this, flagInterruptMsgProc);
+ if (messageInterface) {
+ // Receive messages
+ bool fMoreNodeWork = messageInterface->ProcessMessages(pnode, flagInterruptMsgProc);
+ fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
+ if (flagInterruptMsgProc)
+ return;
+ // Send messages
+ {
+ LOCK(pnode->cs_sendProcessing);
+ messageInterface->SendMessages(pnode, flagInterruptMsgProc);
+ }
}
if (flagInterruptMsgProc)
return;
@@ -2212,6 +2213,7 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
nMaxAddnode = 0;
nBestHeight = 0;
clientInterface = NULL;
+ messageInterface = NULL;
flagInterruptMsgProc = false;
}
@@ -2274,6 +2276,7 @@ bool CConnman::Start(CScheduler& scheduler, Options connOptions)
SetBestHeight(connOptions.nBestHeight);
clientInterface = connOptions.uiInterface;
+ messageInterface = connOptions.messageInterface;
if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) {
if (clientInterface) {
@@ -2459,9 +2462,12 @@ void CConnman::DeleteNode(CNode* pnode)
{
assert(pnode);
bool fUpdateConnectionTime = false;
- GetNodeSignals().FinalizeNode(pnode->GetId(), fUpdateConnectionTime);
- if(fUpdateConnectionTime)
- addrman.Connected(pnode->addr);
+ if (messageInterface) {
+ messageInterface->FinalizeNode(pnode->GetId(), fUpdateConnectionTime);
+ if(fUpdateConnectionTime) {
+ addrman.Connected(pnode->addr);
+ }
+ }
delete pnode;
}
View
@@ -33,7 +33,6 @@
#include <arpa/inet.h>
#endif
-#include <boost/signals2/signal.hpp>
class CScheduler;
class CNode;
@@ -116,7 +115,7 @@ struct CSerializedNetMsg
std::string command;
};
-
+class NetEventsInterface;
class CConnman
{
public:
@@ -138,6 +137,7 @@ class CConnman
int nMaxFeeler = 0;
int nBestHeight = 0;
CClientUIInterface* uiInterface = nullptr;
+ NetEventsInterface* messageInterface = nullptr;
unsigned int nSendBufferMaxSize = 0;
unsigned int nReceiveFloodSize = 0;
uint64_t nMaxOutboundTimeframe = 0;
@@ -381,6 +381,7 @@ class CConnman
int nMaxFeeler;
std::atomic<int> nBestHeight;
CClientUIInterface* clientInterface;
+ NetEventsInterface* messageInterface;
/** SipHasher seeds for deterministic randomness */
const uint64_t nSeed0, nSeed1;
@@ -421,19 +422,19 @@ struct CombinerAll
}
};
-// Signals for message handling
-struct CNodeSignals
+// Interface for message handling
+class NetEventsInterface
{
- boost::signals2::signal<bool (CNode*, CConnman&, std::atomic<bool>&), CombinerAll> ProcessMessages;
- boost::signals2::signal<bool (CNode*, CConnman&, std::atomic<bool>&), CombinerAll> SendMessages;
- boost::signals2::signal<void (CNode*, CConnman&)> InitializeNode;
- boost::signals2::signal<void (NodeId, bool&)> FinalizeNode;
+protected:
+ NetEventsInterface() = default;
+public:
+ virtual ~NetEventsInterface() = default;
+ virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
+ virtual bool SendMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
+ virtual void InitializeNode(CNode* pnode) = 0;
+ virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
};
-
-CNodeSignals& GetNodeSignals();
-
-
enum
{
LOCAL_NONE, // unknown
Oops, something went wrong.