| 2200 | } |
| 2201 | |
| 2202 | std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const |
| 2203 | { |
| 2204 | std::vector<AddedNodeInfo> ret; |
| 2205 | |
| 2206 | std::list<std::string> lAddresses(0); |
| 2207 | { |
| 2208 | LOCK(m_added_nodes_mutex); |
| 2209 | ret.reserve(m_added_nodes.size()); |
| 2210 | std::copy(m_added_nodes.cbegin(), m_added_nodes.cend(), std::back_inserter(lAddresses)); |
| 2211 | } |
| 2212 | |
| 2213 | |
| 2214 | // Build a map of all already connected addresses (by IP:port and by name) to inbound/outbound and resolved CService |
| 2215 | std::map<CService, bool> mapConnected; |
| 2216 | std::map<std::string, std::pair<bool, CService>> mapConnectedByName; |
| 2217 | { |
| 2218 | LOCK(m_nodes_mutex); |
| 2219 | for (const CNode* pnode : m_nodes) { |
| 2220 | if (pnode->addr.IsValid()) { |
| 2221 | mapConnected[pnode->addr] = pnode->IsInboundConn(); |
| 2222 | } |
| 2223 | std::string addrName{pnode->m_addr_name}; |
| 2224 | if (!addrName.empty()) { |
| 2225 | mapConnectedByName[std::move(addrName)] = std::make_pair(pnode->IsInboundConn(), static_cast<const CService&>(pnode->addr)); |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | for (const std::string& strAddNode : lAddresses) { |
| 2231 | CService service{MaybeFlipIPv6toCJDNS(LookupNumeric(strAddNode, Params().GetDefaultPort(strAddNode)))}; |
| 2232 | AddedNodeInfo addedNode{strAddNode, CService(), false, false}; |
| 2233 | if (service.IsValid()) { |
| 2234 | // strAddNode is an IP:port |
| 2235 | auto it = mapConnected.find(service); |
| 2236 | if (it != mapConnected.end()) { |
| 2237 | addedNode.resolvedAddress = service; |
| 2238 | addedNode.fConnected = true; |
| 2239 | addedNode.fInbound = it->second; |
| 2240 | } |
| 2241 | } else { |
| 2242 | // strAddNode is a name |
| 2243 | auto it = mapConnectedByName.find(strAddNode); |
| 2244 | if (it != mapConnectedByName.end()) { |
| 2245 | addedNode.resolvedAddress = it->second.second; |
| 2246 | addedNode.fConnected = true; |
| 2247 | addedNode.fInbound = it->second.first; |
| 2248 | } |
| 2249 | } |
| 2250 | ret.emplace_back(std::move(addedNode)); |
| 2251 | } |
| 2252 | |
| 2253 | return ret; |
| 2254 | } |
| 2255 | |
| 2256 | void CConnman::ThreadOpenAddedConnections() |
| 2257 | { |