MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetLocal

Function GetLocal

src/net.cpp:158–180  ·  view source on GitHub ↗

find 'best' local address for a particular peer

Source from the content-addressed store, hash-verified

156
157// find 'best' local address for a particular peer
158bool 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.
183static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)

Callers 1

GetLocalAddressFunction · 0.85

Calls 2

GetReachabilityFromMethod · 0.80
CServiceClass · 0.70

Tested by

no test coverage detected