aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorSergi Delgado Segura <sergi.delgado.s@gmail.com>2023-07-25 15:47:36 -0400
committerSergi Delgado Segura <sergi.delgado.s@gmail.com>2023-10-30 11:39:21 -0400
commit34b9ef443bc2655a85c8802edc5d5d48d792a286 (patch)
tree408f631ddc562eb97190e27a4c1b1cf20e918996 /src/net.cpp
parent94e8882d820969ddc83f24f4cbe1515a886da4ea (diff)
net/rpc: Makes CConnman::GetAddedNodeInfo able to return only non-connected address on request
`CConnman::GetAddedNodeInfo` is used both to get a list of addresses to manually connect to in `CConnman::ThreadOpenAddedConnections`, and to report about manually added connections in `getaddednodeinfo`. In both cases, all addresses added to `m_added_nodes` are returned, however the nodes we are already connected to are only relevant to the latter, in the former they are actively discarded. Parametrizes `CConnman::GetAddedNodeInfo` so we can ask for only addresses we are not connected to, to avoid passing useless information around.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 54a1eb6477..db1847808d 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2804,7 +2804,7 @@ std::vector<CAddress> CConnman::GetCurrentBlockRelayOnlyConns() const
return ret;
}
-std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
+std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo(bool include_connected) const
{
std::vector<AddedNodeInfo> ret;
@@ -2839,6 +2839,9 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
// strAddNode is an IP:port
auto it = mapConnected.find(service);
if (it != mapConnected.end()) {
+ if (!include_connected) {
+ continue;
+ }
addedNode.resolvedAddress = service;
addedNode.fConnected = true;
addedNode.fInbound = it->second;
@@ -2847,6 +2850,9 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
// strAddNode is a name
auto it = mapConnectedByName.find(addr.m_added_node);
if (it != mapConnectedByName.end()) {
+ if (!include_connected) {
+ continue;
+ }
addedNode.resolvedAddress = it->second.second;
addedNode.fConnected = true;
addedNode.fInbound = it->second.first;
@@ -2865,21 +2871,19 @@ void CConnman::ThreadOpenAddedConnections()
while (true)
{
CSemaphoreGrant grant(*semAddnode);
- std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo();
+ std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(/*include_connected=*/false);
bool tried = false;
for (const AddedNodeInfo& info : vInfo) {
- if (!info.fConnected) {
- if (!grant) {
- // If we've used up our semaphore and need a new one, let's not wait here since while we are waiting
- // the addednodeinfo state might change.
- break;
- }
- tried = true;
- CAddress addr(CService(), NODE_NONE);
- OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
- if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return;
- grant = CSemaphoreGrant(*semAddnode, /*fTry=*/true);
+ if (!grant) {
+ // If we've used up our semaphore and need a new one, let's not wait here since while we are waiting
+ // the addednodeinfo state might change.
+ break;
}
+ tried = true;
+ CAddress addr(CService(), NODE_NONE);
+ OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
+ if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return;
+ grant = CSemaphoreGrant(*semAddnode, /*fTry=*/true);
}
// Retry every 60 seconds if a connection was attempted, otherwise two seconds
if (!interruptNet.sleep_for(std::chrono::seconds(tried ? 60 : 2)))