MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / GetAddedNodeInfo

Method GetAddedNodeInfo

src/net.cpp:2132–2187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2130}
2131
2132std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const {
2133 std::vector<AddedNodeInfo> ret;
2134
2135 std::list<std::string> lAddresses(0);
2136 {
2137 LOCK(m_added_nodes_mutex);
2138 ret.reserve(m_added_nodes.size());
2139 std::copy(m_added_nodes.cbegin(), m_added_nodes.cend(),
2140 std::back_inserter(lAddresses));
2141 }
2142
2143 // Build a map of all already connected addresses (by IP:port and by name)
2144 // to inbound/outbound and resolved CService
2145 std::map<CService, bool> mapConnected;
2146 std::map<std::string, std::pair<bool, CService>> mapConnectedByName;
2147 {
2148 LOCK(m_nodes_mutex);
2149 for (const CNode *pnode : m_nodes) {
2150 if (pnode->addr.IsValid()) {
2151 mapConnected[pnode->addr] = pnode->IsInboundConn();
2152 }
2153 std::string addrName{pnode->m_addr_name};
2154 if (!addrName.empty()) {
2155 mapConnectedByName[std::move(addrName)] =
2156 std::make_pair(pnode->IsInboundConn(),
2157 static_cast<const CService &>(pnode->addr));
2158 }
2159 }
2160 }
2161
2162 for (const std::string &strAddNode : lAddresses) {
2163 CService service(
2164 LookupNumeric(strAddNode, Params().GetDefaultPort(strAddNode)));
2165 AddedNodeInfo addedNode{strAddNode, CService(), false, false};
2166 if (service.IsValid()) {
2167 // strAddNode is an IP:port
2168 auto it = mapConnected.find(service);
2169 if (it != mapConnected.end()) {
2170 addedNode.resolvedAddress = service;
2171 addedNode.fConnected = true;
2172 addedNode.fInbound = it->second;
2173 }
2174 } else {
2175 // strAddNode is a name
2176 auto it = mapConnectedByName.find(strAddNode);
2177 if (it != mapConnectedByName.end()) {
2178 addedNode.resolvedAddress = it->second.second;
2179 addedNode.fConnected = true;
2180 addedNode.fInbound = it->second.first;
2181 }
2182 }
2183 ret.emplace_back(std::move(addedNode));
2184 }
2185
2186 return ret;
2187}
2188
2189void CConnman::ThreadOpenAddedConnections() {

Callers 2

FUZZ_TARGET_INITFunction · 0.80
getaddednodeinfoFunction · 0.80

Calls 14

LookupNumericFunction · 0.85
IsInboundConnMethod · 0.80
GetDefaultPortMethod · 0.80
ParamsClass · 0.70
CServiceClass · 0.70
reserveMethod · 0.45
sizeMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
IsValidMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45

Tested by 1

FUZZ_TARGET_INITFunction · 0.64