Skip to content

Commit

Permalink
Invoke DisconnectNodes from getconnectioncount/getpeerinfo/getnetwork…
Browse files Browse the repository at this point in the history
…info

This ensures disconnected nodes don't appear for callers
  • Loading branch information
codablock committed Apr 17, 2020
1 parent 3054854 commit 2f1b3a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ class CConnman

void WakeMessageHandler();
void WakeSelect();
void DisconnectNodes();

/** Attempts to obfuscate tx time through exponentially distributed emitting.
Works assuming that a single interval is used.
Expand All @@ -476,7 +477,6 @@ class CConnman
void ThreadOpenConnections(std::vector<std::string> connect);
void ThreadMessageHandler();
void AcceptConnection(const ListenSocket& hListenSocket);
void DisconnectNodes();
void NotifyNumConnectionsChanged();
void InactivityCheck(CNode *pnode);
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
Expand Down
7 changes: 7 additions & 0 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ UniValue getconnectioncount(const JSONRPCRequest& request)
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");

g_connman->DisconnectNodes();
return (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
}

Expand Down Expand Up @@ -126,6 +127,8 @@ UniValue getpeerinfo(const JSONRPCRequest& request)
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");

g_connman->DisconnectNodes();

std::vector<CNodeStats> vstats;
g_connman->GetNodeStats(vstats);

Expand Down Expand Up @@ -466,6 +469,10 @@ UniValue getnetworkinfo(const JSONRPCRequest& request)
+ HelpExampleRpc("getnetworkinfo", "")
);

if (g_connman) {
g_connman->DisconnectNodes();
}

LOCK(cs_main);
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("version", CLIENT_VERSION));
Expand Down

0 comments on commit 2f1b3a3

Please sign in to comment.