Determine the "best" local address for a particular peer.
| 164 | |
| 165 | // Determine the "best" local address for a particular peer. |
| 166 | [[nodiscard]] static std::optional<CService> GetLocal(const CNode& peer) |
| 167 | { |
| 168 | if (!fListen) return std::nullopt; |
| 169 | |
| 170 | std::optional<CService> addr; |
| 171 | int nBestScore = -1; |
| 172 | int nBestReachability = -1; |
| 173 | { |
| 174 | LOCK(g_maplocalhost_mutex); |
| 175 | for (const auto& [local_addr, local_service_info] : mapLocalHost) { |
| 176 | // For privacy reasons, don't advertise our privacy-network address |
| 177 | // to other networks and don't advertise our other-network address |
| 178 | // to privacy networks. |
| 179 | if (local_addr.GetNetwork() != peer.ConnectedThroughNetwork() |
| 180 | && (local_addr.IsPrivacyNet() || peer.IsConnectedThroughPrivacyNet())) { |
| 181 | continue; |
| 182 | } |
| 183 | const int nScore{local_service_info.nScore}; |
| 184 | const int nReachability{local_addr.GetReachabilityFrom(peer.addr)}; |
| 185 | if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) { |
| 186 | addr.emplace(CService{local_addr, local_service_info.nPort}); |
| 187 | nBestReachability = nReachability; |
| 188 | nBestScore = nScore; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | return addr; |
| 193 | } |
| 194 | |
| 195 | //! Convert the serialized seeds into usable address objects. |
| 196 | static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn) |
no test coverage detected