| 3027 | } |
| 3028 | |
| 3029 | void CConnman::ThreadOpenAddedConnections() |
| 3030 | { |
| 3031 | AssertLockNotHeld(m_nodes_mutex); |
| 3032 | AssertLockNotHeld(m_reconnections_mutex); |
| 3033 | AssertLockNotHeld(m_unused_i2p_sessions_mutex); |
| 3034 | |
| 3035 | while (true) |
| 3036 | { |
| 3037 | CountingSemaphoreGrant<> grant(*semAddnode); |
| 3038 | std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(/*include_connected=*/false); |
| 3039 | bool tried = false; |
| 3040 | for (const AddedNodeInfo& info : vInfo) { |
| 3041 | if (!grant) { |
| 3042 | // If we've used up our semaphore and need a new one, let's not wait here since while we are waiting |
| 3043 | // the addednodeinfo state might change. |
| 3044 | break; |
| 3045 | } |
| 3046 | tried = true; |
| 3047 | OpenNetworkConnection(/*addrConnect=*/CAddress{CService{}, NODE_NONE}, |
| 3048 | /*fCountFailure=*/false, |
| 3049 | /*grant_outbound=*/std::move(grant), |
| 3050 | /*pszDest=*/info.m_params.m_added_node.c_str(), |
| 3051 | /*conn_type=*/ConnectionType::MANUAL, |
| 3052 | /*use_v2transport=*/info.m_params.m_use_v2transport, |
| 3053 | /*proxy_override=*/std::nullopt); |
| 3054 | if (!m_interrupt_net->sleep_for(500ms)) return; |
| 3055 | grant = CountingSemaphoreGrant<>(*semAddnode, /*fTry=*/true); |
| 3056 | } |
| 3057 | // See if any reconnections are desired. |
| 3058 | PerformReconnections(); |
| 3059 | // Retry every 60 seconds if a connection was attempted, otherwise two seconds |
| 3060 | if (!m_interrupt_net->sleep_for(tried ? 60s : 2s)) { |
| 3061 | return; |
| 3062 | } |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | // if successful, this moves the passed grant to the constructed node |
| 3067 | bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, |