MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / GetLocal

Function GetLocal

src/net.cpp:134–156  ·  view source on GitHub ↗

find 'best' local address for a particular peer

Source from the content-addressed store, hash-verified

132
133// find 'best' local address for a particular peer
134bool 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.
159static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn)

Callers 1

GetLocalAddressFunction · 0.85

Calls 4

GetReachabilityFromMethod · 0.80
CServiceClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected