find 'best' local address for a particular peer
| 101 | |
| 102 | // find 'best' local address for a particular peer |
| 103 | bool GetLocal(CService& addr, const CNetAddr *paddrPeer) |
| 104 | { |
| 105 | if (!fListen) |
| 106 | return false; |
| 107 | |
| 108 | int nBestScore = -1; |
| 109 | int nBestReachability = -1; |
| 110 | { |
| 111 | LOCK(cs_mapLocalHost); |
| 112 | for (const auto& entry : mapLocalHost) |
| 113 | { |
| 114 | int nScore = entry.second.nScore; |
| 115 | int nReachability = entry.first.GetReachabilityFrom(paddrPeer); |
| 116 | if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) |
| 117 | { |
| 118 | addr = CService(entry.first, entry.second.nPort); |
| 119 | nBestReachability = nReachability; |
| 120 | nBestScore = nScore; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | return nBestScore >= 0; |
| 125 | } |
| 126 | |
| 127 | //! Convert the pnSeed6 array into usable address objects. |
| 128 | static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn) |
no test coverage detected