aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp29
-rw-r--r--src/net.h28
-rw-r--r--src/rpc/net.cpp17
3 files changed, 46 insertions, 28 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 045939c2ea..8ca6df0f9b 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -91,9 +91,6 @@ std::vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
-std::vector<std::string> vAddedNodes;
-CCriticalSection cs_vAddedNodes;
-
NodeId nLastNodeId = 0;
CCriticalSection cs_nLastNodeId;
@@ -1718,7 +1715,7 @@ void CConnman::ThreadOpenConnections()
}
}
-std::vector<AddedNodeInfo> GetAddedNodeInfo()
+std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo()
{
std::vector<AddedNodeInfo> ret;
@@ -2246,6 +2243,30 @@ std::vector<CAddress> CConnman::GetAddresses()
return addrman.GetAddr();
}
+bool CConnman::AddNode(const std::string& strNode)
+{
+ LOCK(cs_vAddedNodes);
+ for(std::vector<std::string>::const_iterator it = vAddedNodes.begin(); it != vAddedNodes.end(); ++it) {
+ if (strNode == *it)
+ return false;
+ }
+
+ vAddedNodes.push_back(strNode);
+ return true;
+}
+
+bool CConnman::RemoveAddedNode(const std::string& strNode)
+{
+ LOCK(cs_vAddedNodes);
+ for(std::vector<std::string>::iterator it = vAddedNodes.begin(); it != vAddedNodes.end(); ++it) {
+ if (strNode == *it) {
+ vAddedNodes.erase(it);
+ return true;
+ }
+ }
+ return false;
+}
+
void RelayTransaction(const CTransaction& tx)
{
CInv inv(MSG_TX, tx.GetHash());
diff --git a/src/net.h b/src/net.h
index 81de7f5a98..f343646cba 100644
--- a/src/net.h
+++ b/src/net.h
@@ -87,6 +87,14 @@ unsigned int SendBufferSize();
typedef int NodeId;
+struct AddedNodeInfo
+{
+ std::string strAddedNode;
+ CService resolvedAddress;
+ bool fConnected;
+ bool fInbound;
+};
+
CNode* FindNode(const CNetAddr& ip);
CNode* FindNode(const CSubNet& subNet);
CNode* FindNode(const std::string& addrName);
@@ -137,6 +145,11 @@ public:
void SetBanned(const banmap_t &banmap);
void AddOneShot(const std::string& strDest);
+
+ bool AddNode(const std::string& node);
+ bool RemoveAddedNode(const std::string& node);
+ std::vector<AddedNodeInfo> GetAddedNodeInfo();
+
private:
struct ListenSocket {
SOCKET socket;
@@ -173,6 +186,8 @@ private:
CAddrMan addrman;
std::deque<std::string> vOneShots;
CCriticalSection cs_vOneShots;
+ std::vector<std::string> vAddedNodes;
+ CCriticalSection cs_vAddedNodes;
};
extern std::unique_ptr<CConnman> g_connman;
void MapPort(bool fUseUPnP);
@@ -252,9 +267,6 @@ extern std::vector<CNode*> vNodes;
extern CCriticalSection cs_vNodes;
extern limitedmap<uint256, int64_t> mapAlreadyAskedFor;
-extern std::vector<std::string> vAddedNodes;
-extern CCriticalSection cs_vAddedNodes;
-
extern NodeId nLastNodeId;
extern CCriticalSection cs_nLastNodeId;
@@ -807,14 +819,4 @@ void RelayTransaction(const CTransaction& tx);
/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds);
-struct AddedNodeInfo
-{
- std::string strAddedNode;
- CService resolvedAddress;
- bool fConnected;
- bool fInbound;
-};
-
-std::vector<AddedNodeInfo> GetAddedNodeInfo();
-
#endif // BITCOIN_NET_H
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 0244da9fea..ab475f7125 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -226,23 +226,15 @@ UniValue addnode(const UniValue& params, bool fHelp)
return NullUniValue;
}
- LOCK(cs_vAddedNodes);
- vector<string>::iterator it = vAddedNodes.begin();
- for(; it != vAddedNodes.end(); it++)
- if (strNode == *it)
- break;
-
if (strCommand == "add")
{
- if (it != vAddedNodes.end())
+ if(!g_connman->AddNode(strNode))
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
- vAddedNodes.push_back(strNode);
}
else if(strCommand == "remove")
{
- if (it == vAddedNodes.end())
+ if(!g_connman->RemoveAddedNode(strNode))
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
- vAddedNodes.erase(it);
}
return NullUniValue;
@@ -299,7 +291,10 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getaddednodeinfo", "true, \"192.168.0.201\"")
);
- std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo();
+ if(!g_connman)
+ throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
+
+ std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
if (params.size() == 1) {
bool found = false;