learn a new local address
| 285 | |
| 286 | // learn a new local address |
| 287 | bool AddLocal(const CService& addr_, int nScore) |
| 288 | { |
| 289 | CService addr{MaybeFlipIPv6toCJDNS(addr_)}; |
| 290 | |
| 291 | if (!addr.IsRoutable()) |
| 292 | return false; |
| 293 | |
| 294 | if (!fDiscover && nScore < LOCAL_MANUAL) |
| 295 | return false; |
| 296 | |
| 297 | if (!IsReachable(addr)) |
| 298 | return false; |
| 299 | |
| 300 | LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore); |
| 301 | |
| 302 | { |
| 303 | LOCK(g_maplocalhost_mutex); |
| 304 | const auto [it, is_newly_added] = mapLocalHost.emplace(addr, LocalServiceInfo()); |
| 305 | LocalServiceInfo &info = it->second; |
| 306 | if (is_newly_added || nScore >= info.nScore) { |
| 307 | info.nScore = nScore + (is_newly_added ? 0 : 1); |
| 308 | info.nPort = addr.GetPort(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | bool AddLocal(const CNetAddr &addr, int nScore) |
| 316 | { |