if successful, this moves the passed grant to the constructed node
| 3065 | |
| 3066 | // if successful, this moves the passed grant to the constructed node |
| 3067 | bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, |
| 3068 | bool fCountFailure, |
| 3069 | CountingSemaphoreGrant<>&& grant_outbound, |
| 3070 | const char* pszDest, |
| 3071 | ConnectionType conn_type, |
| 3072 | bool use_v2transport, |
| 3073 | const std::optional<Proxy>& proxy_override) |
| 3074 | { |
| 3075 | AssertLockNotHeld(m_nodes_mutex); |
| 3076 | AssertLockNotHeld(m_unused_i2p_sessions_mutex); |
| 3077 | assert(conn_type != ConnectionType::INBOUND); |
| 3078 | |
| 3079 | // |
| 3080 | // Initiate outbound network connection |
| 3081 | // |
| 3082 | if (m_interrupt_net->interrupted()) { |
| 3083 | return false; |
| 3084 | } |
| 3085 | if (!fNetworkActive) { |
| 3086 | return false; |
| 3087 | } |
| 3088 | if (!pszDest) { |
| 3089 | bool banned_or_discouraged = m_banman && (m_banman->IsDiscouraged(addrConnect) || m_banman->IsBanned(addrConnect)); |
| 3090 | if (IsLocal(addrConnect) || banned_or_discouraged || AlreadyConnectedToAddress(addrConnect)) { |
| 3091 | return false; |
| 3092 | } |
| 3093 | } else if (AlreadyConnectedToHost(pszDest)) { |
| 3094 | return false; |
| 3095 | } |
| 3096 | |
| 3097 | CNode* pnode = ConnectNode(addrConnect, pszDest, fCountFailure, conn_type, use_v2transport, proxy_override); |
| 3098 | |
| 3099 | if (!pnode) |
| 3100 | return false; |
| 3101 | pnode->grantOutbound = std::move(grant_outbound); |
| 3102 | |
| 3103 | m_msgproc->InitializeNode(*pnode, m_local_services); |
| 3104 | { |
| 3105 | LOCK(m_nodes_mutex); |
| 3106 | m_nodes.push_back(pnode); |
| 3107 | |
| 3108 | // update connection count by network |
| 3109 | if (pnode->IsManualOrFullOutboundConn()) ++m_network_conn_counts[pnode->addr.GetNetwork()]; |
| 3110 | } |
| 3111 | |
| 3112 | TRACEPOINT(net, outbound_connection, |
| 3113 | pnode->GetId(), |
| 3114 | pnode->m_addr_name.c_str(), |
| 3115 | pnode->ConnectionTypeAsString().c_str(), |
| 3116 | pnode->ConnectedThroughNetwork(), |
| 3117 | GetNodeCount(ConnectionDirection::Out)); |
| 3118 | |
| 3119 | return true; |
| 3120 | } |
| 3121 | |
| 3122 | std::optional<Network> CConnman::PrivateBroadcast::PickNetwork(std::optional<Proxy>& proxy) const |
| 3123 | { |
no test coverage detected