From 1ce3308431ae7eff917971b5e5af16ee85fe5f11 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 6 May 2016 11:50:24 -0700 Subject: [PATCH] Add ability to fetch CNode by NodeId --- src/net.cpp | 10 ++++++++++ src/net.h | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index e17cf0541..734fcf96d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -370,6 +370,16 @@ CNode* FindNode(const CService& addr) return NULL; } +//TODO: This is used in only one place in main, and should be removed +CNode* FindNode(const NodeId nodeid) +{ + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + if (pnode->GetId() == nodeid) + return (pnode); + return NULL; +} + CNode* ConnectNode(CAddress addrConnect, const char *pszDest) { if (pszDest == NULL) { diff --git a/src/net.h b/src/net.h index 67a58aaac..dcd5123eb 100644 --- a/src/net.h +++ b/src/net.h @@ -77,6 +77,8 @@ static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Defaul unsigned int ReceiveFloodSize(); unsigned int SendBufferSize(); +typedef int NodeId; + void AddOneShot(const std::string& strDest); void AddressCurrentlyConnected(const CService& addr); CNode* FindNode(const CNetAddr& ip); @@ -84,6 +86,7 @@ CNode* FindNode(const CSubNet& subNet); CNode* FindNode(const std::string& addrName); CNode* FindNode(const CService& ip); CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL); +CNode* FindNode(const NodeId id); //TODO: Remove this bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false); void MapPort(bool fUseUPnP); unsigned short GetListenPort(); @@ -92,8 +95,6 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler); bool StopNode(); void SocketSendData(CNode *pnode); -typedef int NodeId; - struct CombinerAll { typedef bool result_type;