MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetAddedNodeInfo

Method GetAddedNodeInfo

src/net.cpp:2202–2254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2200}
2201
2202std::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
2256void CConnman::ThreadOpenAddedConnections()
2257{

Callers 2

FUZZ_TARGET_INITFunction · 0.80
getaddednodeinfoFunction · 0.80

Calls 15

MaybeFlipIPv6toCJDNSFunction · 0.85
LookupNumericFunction · 0.85
cbeginMethod · 0.80
cendMethod · 0.80
IsInboundConnMethod · 0.80
GetDefaultPortMethod · 0.80
findMethod · 0.80
emplace_backMethod · 0.80
ParamsClass · 0.70
CServiceClass · 0.70
reserveMethod · 0.45
sizeMethod · 0.45

Tested by 1

FUZZ_TARGET_INITFunction · 0.64