@@ -144,7 +144,6 @@ bool fDiscover = true;
144144bool fListen = true ;
145145Mutex g_maplocalhost_mutex;
146146std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY (g_maplocalhost_mutex);
147- static bool vfLimited[NET_MAX] GUARDED_BY(g_maplocalhost_mutex) = {};
148147std::string strSubVersion;
149148
150149size_t CSerializedNetMsg::GetMemoryUsage () const noexcept
@@ -260,7 +259,7 @@ static int GetnScore(const CService& addr)
260259{
261260 CService addrLocal = pnode->GetAddrLocal ();
262261 return fDiscover && pnode->addr .IsRoutable () && addrLocal.IsRoutable () &&
263- IsReachable (addrLocal. GetNetwork () );
262+ g_reachable_nets. Contains (addrLocal );
264263}
265264
266265std::optional<CService> GetLocalAddrForPeer (CNode& node)
@@ -294,22 +293,6 @@ std::optional<CService> GetLocalAddrForPeer(CNode& node)
294293 return std::nullopt ;
295294}
296295
297- /* *
298- * If an IPv6 address belongs to the address range used by the CJDNS network and
299- * the CJDNS network is reachable (-cjdnsreachable config is set), then change
300- * the type from NET_IPV6 to NET_CJDNS.
301- * @param[in] service Address to potentially convert.
302- * @return a copy of `service` either unmodified or changed to CJDNS.
303- */
304- CService MaybeFlipIPv6toCJDNS (const CService& service)
305- {
306- CService ret{service};
307- if (ret.IsIPv6 () && ret.HasCJDNSPrefix () && IsReachable (NET_CJDNS)) {
308- ret.m_net = NET_CJDNS;
309- }
310- return ret;
311- }
312-
313296// learn a new local address
314297bool AddLocal (const CService& addr_, int nScore)
315298{
@@ -321,7 +304,7 @@ bool AddLocal(const CService& addr_, int nScore)
321304 if (!fDiscover && nScore < LOCAL_MANUAL)
322305 return false ;
323306
324- if (!IsReachable (addr))
307+ if (!g_reachable_nets. Contains (addr))
325308 return false ;
326309
327310 LogPrintf (" AddLocal(%s,%i)\n " , addr.ToStringAddrPort (), nScore);
@@ -351,25 +334,6 @@ void RemoveLocal(const CService& addr)
351334 mapLocalHost.erase (addr);
352335}
353336
354- void SetReachable (enum Network net, bool reachable)
355- {
356- if (net == NET_UNROUTABLE || net == NET_INTERNAL)
357- return ;
358- LOCK (g_maplocalhost_mutex);
359- vfLimited[net] = !reachable;
360- }
361-
362- bool IsReachable (enum Network net)
363- {
364- LOCK (g_maplocalhost_mutex);
365- return !vfLimited[net];
366- }
367-
368- bool IsReachable (const CNetAddr &addr)
369- {
370- return IsReachable (addr.GetNetwork ());
371- }
372-
373337/* * vote for a local address */
374338bool SeenLocal (const CService& addr)
375339{
@@ -402,20 +366,6 @@ CNode* CConnman::FindNode(const CNetAddr& ip, bool fExcludeDisconnecting)
402366 return nullptr ;
403367}
404368
405- CNode* CConnman::FindNode (const CSubNet& subNet, bool fExcludeDisconnecting )
406- {
407- LOCK (m_nodes_mutex);
408- for (CNode* pnode : m_nodes) {
409- if (fExcludeDisconnecting && pnode->fDisconnect ) {
410- continue ;
411- }
412- if (subNet.Match (static_cast <CNetAddr>(pnode->addr ))) {
413- return pnode;
414- }
415- }
416- return nullptr ;
417- }
418-
419369CNode* CConnman::FindNode (const std::string& addrName, bool fExcludeDisconnecting )
420370{
421371 LOCK (m_nodes_mutex);
@@ -3177,7 +3127,7 @@ std::unordered_set<Network> CConnman::GetReachableEmptyNetworks() const
31773127 for (int n = 0 ; n < NET_MAX; n++) {
31783128 enum Network net = (enum Network)n;
31793129 if (net == NET_UNROUTABLE || net == NET_INTERNAL) continue ;
3180- if (IsReachable (net) && addrman.Size (net, std::nullopt ) == 0 ) {
3130+ if (g_reachable_nets. Contains (net) && addrman.Size (net, std::nullopt ) == 0 ) {
31813131 networks.insert (net);
31823132 }
31833133 }
@@ -3197,7 +3147,7 @@ bool CConnman::MaybePickPreferredNetwork(std::optional<Network>& network)
31973147
31983148 LOCK (m_nodes_mutex);
31993149 for (const auto net : nets) {
3200- if (IsReachable (net) && m_network_conn_counts[net] == 0 && addrman.Size (net) != 0 ) {
3150+ if (g_reachable_nets. Contains (net) && m_network_conn_counts[net] == 0 && addrman.Size (net) != 0 ) {
32013151 network = net;
32023152 return true ;
32033153 }
@@ -3432,7 +3382,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, CDe
34323382 // so low that less than MAX_OUTBOUND_FULL_RELAY_CONNECTIONS are made,
34333383 // to prevent interactions with otherwise protected outbound peers.
34343384 next_extra_network_peer = GetExponentialRand (now, EXTRA_NETWORK_PEER_INTERVAL);
3435- } else if (nOutboundOnionRelay < m_max_outbound_onion && IsReachable (Network::NET_ONION)) {
3385+ } else if (nOutboundOnionRelay < m_max_outbound_onion && g_reachable_nets. Contains (Network::NET_ONION)) {
34363386 onion_only = true ;
34373387 } else {
34383388 // skip to next iteration of while loop
@@ -3450,7 +3400,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, CDe
34503400 if (anchor && !m_anchors.empty ()) {
34513401 const CAddress addr = m_anchors.back ();
34523402 m_anchors.pop_back ();
3453- if (!addr.IsValid () || IsLocal (addr) || !IsReachable (addr) ||
3403+ if (!addr.IsValid () || IsLocal (addr) || !g_reachable_nets. Contains (addr) ||
34543404 !HasAllDesirableServiceFlags (addr.nServices ) ||
34553405 outbound_ipv46_peer_netgroups.count (m_netgroupman.GetGroup (addr))) continue ;
34563406 addrConnect = addr;
@@ -3510,9 +3460,13 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, CDe
35103460 break ;
35113461 }
35123462
3513- if (!IsReachable (addr))
3463+ if (!g_reachable_nets. Contains (addr)) {
35143464 continue ;
3515- if (onion_only && !addr.IsTor ()) continue ;
3465+ }
3466+
3467+ if (onion_only && !addr.IsTor ()) {
3468+ continue ;
3469+ }
35163470
35173471 // only consider very recently tried nodes after 30 failed attempts
35183472 if (current_time - addr_last_try < 10min && nTries < 30 ) {
0 commit comments