Skip to content

Commit

Permalink
Use a local FastRandomContext in a few more places in net
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzbawls committed Apr 14, 2021
1 parent e862564 commit 1cdf124
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6>& vSeedsIn
const int64_t nOneWeek = 7 * 24 * 60 * 60;
std::vector<CAddress> vSeedsOut;
vSeedsOut.reserve(vSeedsIn.size());
FastRandomContext rng;
for (std::vector<SeedSpec6>::const_iterator i(vSeedsIn.begin()); i != vSeedsIn.end(); ++i) {
struct in6_addr ip;
memcpy(&ip, i->addr, sizeof(ip));
CAddress addr(CService(ip, i->port), NODE_NETWORK);
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
addr.nTime = GetTime() - rng.randrange(nOneWeek) - nOneWeek;
vSeedsOut.push_back(addr);
}
return vSeedsOut;
Expand Down Expand Up @@ -174,14 +175,14 @@ void AdvertiseLocal(CNode* pnode)
// If discovery is enabled, sometimes give our peer the address it
// tells us that it sees us as in case it has a better idea of our
// address than we do.
FastRandomContext rng;
if (IsPeerAddrLocalGood(pnode) && (!addrLocal.IsRoutable() ||
GetRand((GetnScore(addrLocal) > LOCAL_MANUAL) ? 8 : 2) == 0)) {
rng.randbits((GetnScore(addrLocal) > LOCAL_MANUAL) ? 3 : 1) == 0)) {
addrLocal.SetIP(pnode->GetAddrLocal());
}
if (addrLocal.IsRoutable()) {
LogPrintf("%s: advertising address %s\n", __func__, addrLocal.ToString());
FastRandomContext insecure_rand;
pnode->PushAddress(addrLocal, insecure_rand);
pnode->PushAddress(addrLocal, rng);
}
}
}
Expand Down

0 comments on commit 1cdf124

Please sign in to comment.