Browse Source

net: move OpenNetworkConnection into CConnman

0.14
Cory Fields 9 years ago
parent
commit
b1a5f43208
  1. 4
      src/net.cpp
  2. 4
      src/net.h
  3. 5
      src/rpc/net.cpp

4
src/net.cpp

@ -375,7 +375,7 @@ CNode* FindNode(const NodeId nodeid)
return NULL; return NULL;
} }
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure) CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure)
{ {
if (pszDest == NULL) { if (pszDest == NULL) {
if (IsLocal(addrConnect)) if (IsLocal(addrConnect))
@ -1809,7 +1809,7 @@ void CConnman::ThreadOpenAddedConnections()
} }
// if successful, this moves the passed grant to the constructed node // if successful, this moves the passed grant to the constructed node
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot, bool fFeeler) bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot, bool fFeeler)
{ {
// //
// Initiate outbound network connection // Initiate outbound network connection

4
src/net.h

@ -93,7 +93,6 @@ CNode* FindNode(const CSubNet& subNet);
CNode* FindNode(const std::string& addrName); CNode* FindNode(const std::string& addrName);
CNode* FindNode(const CService& ip); CNode* FindNode(const CService& ip);
CNode* FindNode(const NodeId id); //TODO: Remove this CNode* FindNode(const NodeId id); //TODO: Remove this
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
class CConnman class CConnman
{ {
@ -103,6 +102,7 @@ public:
bool Start(boost::thread_group& threadGroup, std::string& strNodeError); bool Start(boost::thread_group& threadGroup, std::string& strNodeError);
void Stop(); void Stop();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false); bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
private: private:
struct ListenSocket { struct ListenSocket {
@ -120,6 +120,8 @@ private:
void ThreadSocketHandler(); void ThreadSocketHandler();
void ThreadDNSAddressSeed(); void ThreadDNSAddressSeed();
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure);
std::vector<ListenSocket> vhListenSocket; std::vector<ListenSocket> vhListenSocket;
}; };
extern std::unique_ptr<CConnman> g_connman; extern std::unique_ptr<CConnman> g_connman;

5
src/rpc/net.cpp

@ -214,12 +214,15 @@ UniValue addnode(const UniValue& params, bool fHelp)
+ HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"") + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")
); );
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
string strNode = params[0].get_str(); string strNode = params[0].get_str();
if (strCommand == "onetry") if (strCommand == "onetry")
{ {
CAddress addr; CAddress addr;
OpenNetworkConnection(addr, false, NULL, strNode.c_str()); g_connman->OpenNetworkConnection(addr, false, NULL, strNode.c_str());
return NullUniValue; return NullUniValue;
} }

Loading…
Cancel
Save