Skip to content

Commit 8098379

Browse files
committed
Use a local FastRandomContext in a few more places in net
1 parent 9695f31 commit 8098379

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/net.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn
134134
const int64_t nOneWeek = 7*24*60*60;
135135
std::vector<CAddress> vSeedsOut;
136136
vSeedsOut.reserve(vSeedsIn.size());
137+
FastRandomContext rng;
137138
for (const auto& seed_in : vSeedsIn) {
138139
struct in6_addr ip;
139140
memcpy(&ip, seed_in.addr, sizeof(ip));
140141
CAddress addr(CService(ip, seed_in.port), GetDesirableServiceFlags(NODE_NONE));
141-
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
142+
addr.nTime = GetTime() - rng.randrange(nOneWeek) - nOneWeek;
142143
vSeedsOut.push_back(addr);
143144
}
144145
return vSeedsOut;
@@ -189,16 +190,16 @@ void AdvertiseLocal(CNode *pnode)
189190
// If discovery is enabled, sometimes give our peer the address it
190191
// tells us that it sees us as in case it has a better idea of our
191192
// address than we do.
193+
FastRandomContext rng;
192194
if (IsPeerAddrLocalGood(pnode) && (!addrLocal.IsRoutable() ||
193-
GetRand((GetnScore(addrLocal) > LOCAL_MANUAL) ? 8:2) == 0))
195+
rng.randbits((GetnScore(addrLocal) > LOCAL_MANUAL) ? 3 : 1) == 0))
194196
{
195197
addrLocal.SetIP(pnode->GetAddrLocal());
196198
}
197199
if (addrLocal.IsRoutable() || gArgs.GetBoolArg("-addrmantest", false))
198200
{
199201
LogPrint(BCLog::NET, "AdvertiseLocal: advertising address %s\n", addrLocal.ToString());
200-
FastRandomContext insecure_rand;
201-
pnode->PushAddress(addrLocal, insecure_rand);
202+
pnode->PushAddress(addrLocal, rng);
202203
}
203204
}
204205
}

0 commit comments

Comments
 (0)