find 'best' local address for a particular peer
| 133 | |
| 134 | // find 'best' local address for a particular peer |
| 135 | bool GetLocal(CService& addr, const CNetAddr* paddrPeer) |
| 136 | { |
| 137 | if (!fListen) |
| 138 | return false; |
| 139 | |
| 140 | int nBestScore = -1; |
| 141 | int nBestReachability = -1; |
| 142 | { |
| 143 | LOCK(cs_mapLocalHost); |
| 144 | for (map<CNetAddr, LocalServiceInfo>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) { |
| 145 | int nScore = (*it).second.nScore; |
| 146 | int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); |
| 147 | if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) { |
| 148 | addr = CService((*it).first, (*it).second.nPort); |
| 149 | nBestReachability = nReachability; |
| 150 | nBestScore = nScore; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | return nBestScore >= 0; |
| 155 | } |
| 156 | |
| 157 | //! Convert the pnSeed6 array into usable address objects. |
| 158 | static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn) |
no test coverage detected