MCPcopy Create free account
hub / github.com/apple/foundationdb / randomSubNetImpl

Method randomSubNetImpl

fdbrpc/IPAllowList.cpp:183–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181 SubNetTest(AuthAllowedSubnet const& subnet) : subnet(subnet) {}
182 template <bool V4>
183 static SubNetTest randomSubNetImpl() {
184 constexpr int width = V4 ? 4 : 16;
185 std::array<unsigned char, width> binAddr;
186 unsigned char rnd[4];
187 for (int i = 0; i < binAddr.size(); ++i) {
188 if (i % 4 == 0) {
189 auto tmp = deterministicRandom()->randomUInt32();
190 ::memcpy(rnd, &tmp, 4);
191 }
192 binAddr[i] = rnd[i % 4];
193 }
194 auto netmaskWeight = deterministicRandom()->randomInt(1, width);
195 std::string address;
196 if constexpr (V4) {
197 address_v4 a(binAddr);
198 address = a.to_string();
199 } else {
200 address_v6 a(binAddr);
201 address = a.to_string();
202 }
203 return SubNetTest(AuthAllowedSubnet::fromString(fmt::format("{}/{}", address, netmaskWeight)));
204 }
205 static SubNetTest randomSubNet() {
206 if (deterministicRandom()->coinflip()) {
207 return randomSubNetImpl<true>();

Callers

nothing calls this directly

Calls 7

deterministicRandomFunction · 0.85
memcpyFunction · 0.85
SubNetTestClass · 0.85
randomUInt32Method · 0.80
formatFunction · 0.50
sizeMethod · 0.45
randomIntMethod · 0.45

Tested by

no test coverage detected