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