find 'best' local address for a particular peer
| 156 | |
| 157 | // find 'best' local address for a particular peer |
| 158 | bool GetLocal(CService& addr, const CNetAddr *paddrPeer) |
| 159 | { |
| 160 | if (!fListen) |
| 161 | return false; |
| 162 | |
| 163 | int nBestScore = -1; |
| 164 | int nBestReachability = -1; |
| 165 | { |
| 166 | LOCK(g_maplocalhost_mutex); |
| 167 | for (const auto& entry : mapLocalHost) |
| 168 | { |
| 169 | int nScore = entry.second.nScore; |
| 170 | int nReachability = entry.first.GetReachabilityFrom(paddrPeer); |
| 171 | if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) |
| 172 | { |
| 173 | addr = CService(entry.first, entry.second.nPort); |
| 174 | nBestReachability = nReachability; |
| 175 | nBestScore = nScore; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | return nBestScore >= 0; |
| 180 | } |
| 181 | |
| 182 | //! Convert the serialized seeds into usable address objects. |
| 183 | static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn) |
no test coverage detected