@@ -1862,7 +1862,7 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ
1862
1862
CSemaphoreGrant grant (*semOutbound, true );
1863
1863
if (!grant) return false ;
1864
1864
1865
- OpenNetworkConnection (CAddress (), false , & grant, address.c_str (), conn_type, /* use_v2transport=*/ false );
1865
+ OpenNetworkConnection (CAddress (), false , std::move ( grant) , address.c_str (), conn_type, /* use_v2transport=*/ false );
1866
1866
return true ;
1867
1867
}
1868
1868
@@ -2294,9 +2294,9 @@ void CConnman::ProcessAddrFetch()
2294
2294
m_addr_fetches.pop_front ();
2295
2295
}
2296
2296
CAddress addr;
2297
- CSemaphoreGrant grant (*semOutbound, true );
2297
+ CSemaphoreGrant grant (*semOutbound, /* fTry= */ true );
2298
2298
if (grant) {
2299
- OpenNetworkConnection (addr, false , & grant, strDest.c_str (), ConnectionType::ADDR_FETCH, /* use_v2transport=*/ false );
2299
+ OpenNetworkConnection (addr, false , std::move ( grant) , strDest.c_str (), ConnectionType::ADDR_FETCH, /* use_v2transport=*/ false );
2300
2300
}
2301
2301
}
2302
2302
@@ -2398,7 +2398,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
2398
2398
for (const std::string& strAddr : connect)
2399
2399
{
2400
2400
CAddress addr (CService (), NODE_NONE);
2401
- OpenNetworkConnection (addr, false , nullptr , strAddr.c_str (), ConnectionType::MANUAL, /* use_v2transport=*/ false );
2401
+ OpenNetworkConnection (addr, false , {} , strAddr.c_str (), ConnectionType::MANUAL, /* use_v2transport=*/ false );
2402
2402
for (int i = 0 ; i < 10 && i < nLoop; i++)
2403
2403
{
2404
2404
if (!interruptNet.sleep_for (std::chrono::milliseconds (500 )))
@@ -2703,7 +2703,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
2703
2703
const bool count_failures{((int )outbound_ipv46_peer_netgroups.size () + outbound_privacy_network_peers) >= std::min (nMaxConnections - 1 , 2 )};
2704
2704
// Use BIP324 transport when both us and them have NODE_V2_P2P set.
2705
2705
const bool use_v2transport (addrConnect.nServices & GetLocalServices () & NODE_P2P_V2);
2706
- OpenNetworkConnection (addrConnect, count_failures, & grant, /* strDest=*/ nullptr , conn_type, use_v2transport);
2706
+ OpenNetworkConnection (addrConnect, count_failures, std::move ( grant) , /* strDest=*/ nullptr , conn_type, use_v2transport);
2707
2707
}
2708
2708
}
2709
2709
}
@@ -2785,16 +2785,16 @@ void CConnman::ThreadOpenAddedConnections()
2785
2785
bool tried = false ;
2786
2786
for (const AddedNodeInfo& info : vInfo) {
2787
2787
if (!info.fConnected ) {
2788
- if (!grant. TryAcquire () ) {
2788
+ if (!grant) {
2789
2789
// If we've used up our semaphore and need a new one, let's not wait here since while we are waiting
2790
2790
// the addednodeinfo state might change.
2791
2791
break ;
2792
2792
}
2793
2793
tried = true ;
2794
2794
CAddress addr (CService (), NODE_NONE);
2795
- OpenNetworkConnection (addr, false , & grant, info.m_params .m_added_node .c_str (), ConnectionType::MANUAL, info.m_params .m_use_v2transport );
2796
- if (!interruptNet.sleep_for (std::chrono::milliseconds (500 )))
2797
- return ;
2795
+ OpenNetworkConnection (addr, false , std::move ( grant) , info.m_params .m_added_node .c_str (), ConnectionType::MANUAL, info.m_params .m_use_v2transport );
2796
+ if (!interruptNet.sleep_for (std::chrono::milliseconds (500 ))) return ;
2797
+ grant = CSemaphoreGrant (*semAddnode, /* fTry= */ true ) ;
2798
2798
}
2799
2799
}
2800
2800
// Retry every 60 seconds if a connection was attempted, otherwise two seconds
@@ -2804,7 +2804,7 @@ void CConnman::ThreadOpenAddedConnections()
2804
2804
}
2805
2805
2806
2806
// if successful, this moves the passed grant to the constructed node
2807
- void CConnman::OpenNetworkConnection (const CAddress& addrConnect, bool fCountFailure , CSemaphoreGrant *grantOutbound , const char *pszDest, ConnectionType conn_type, bool use_v2transport)
2807
+ void CConnman::OpenNetworkConnection (const CAddress& addrConnect, bool fCountFailure , CSemaphoreGrant&& grant_outbound , const char *pszDest, ConnectionType conn_type, bool use_v2transport)
2808
2808
{
2809
2809
AssertLockNotHeld (m_unused_i2p_sessions_mutex);
2810
2810
assert (conn_type != ConnectionType::INBOUND);
@@ -2830,8 +2830,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
2830
2830
2831
2831
if (!pnode)
2832
2832
return ;
2833
- if (grantOutbound)
2834
- grantOutbound->MoveTo (pnode->grantOutbound );
2833
+ pnode->grantOutbound = std::move (grant_outbound);
2835
2834
2836
2835
m_msgproc->InitializeNode (*pnode, nLocalServices);
2837
2836
{
0 commit comments