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

Method GetAddr_

src/addrman.cpp:772–808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

770}
771
772std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
773{
774 AssertLockHeld(cs);
775
776 size_t nNodes = vRandom.size();
777 if (max_pct != 0) {
778 nNodes = max_pct * nNodes / 100;
779 }
780 if (max_addresses != 0) {
781 nNodes = std::min(nNodes, max_addresses);
782 }
783
784 // gather a list of random nodes, skipping those of low quality
785 const int64_t now{GetAdjustedTime()};
786 std::vector<CAddress> addresses;
787 for (unsigned int n = 0; n < vRandom.size(); n++) {
788 if (addresses.size() >= nNodes)
789 break;
790
791 int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n;
792 SwapRandom(n, nRndPos);
793 const auto it{mapInfo.find(vRandom[n])};
794 assert(it != mapInfo.end());
795
796 const AddrInfo& ai{it->second};
797
798 // Filter by network (optional)
799 if (network != std::nullopt && ai.GetNetClass() != network) continue;
800
801 // Filter for quality
802 if (ai.IsTerrible(now)) continue;
803
804 addresses.push_back(ai);
805 }
806 LogPrint(BCLog::ADDRMAN, "GetAddr returned %d random addresses\n", addresses.size());
807 return addresses;
808}
809
810void AddrManImpl::Connected_(const CService& addr, int64_t nTime)
811{

Callers

nothing calls this directly

Calls 8

GetAdjustedTimeFunction · 0.85
randrangeMethod · 0.80
findMethod · 0.80
GetNetClassMethod · 0.80
IsTerribleMethod · 0.80
sizeMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected