learn a new local address
| 276 | |
| 277 | // learn a new local address |
| 278 | bool AddLocal(const CService& addr_, int nScore) |
| 279 | { |
| 280 | CService addr{MaybeFlipIPv6toCJDNS(addr_)}; |
| 281 | |
| 282 | if (!addr.IsRoutable()) |
| 283 | return false; |
| 284 | |
| 285 | if (!fDiscover && nScore < LOCAL_MANUAL) |
| 286 | return false; |
| 287 | |
| 288 | if (!g_reachable_nets.Contains(addr)) |
| 289 | return false; |
| 290 | |
| 291 | if (fLogIPs) { |
| 292 | LogInfo("AddLocal(%s,%i)\n", addr.ToStringAddrPort(), nScore); |
| 293 | } |
| 294 | |
| 295 | { |
| 296 | LOCK(g_maplocalhost_mutex); |
| 297 | const auto [it, is_newly_added] = mapLocalHost.emplace(addr, LocalServiceInfo()); |
| 298 | LocalServiceInfo &info = it->second; |
| 299 | if (is_newly_added || nScore >= info.nScore) { |
| 300 | info.nScore = SaturatingAdd(nScore, is_newly_added ? 0 : 1); |
| 301 | info.nPort = addr.GetPort(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | bool AddLocal(const CNetAddr &addr, int nScore) |
| 309 | { |