Fill addrman with lots of addresses from lots of sources. */
| 88 | |
| 89 | /** Fill addrman with lots of addresses from lots of sources. */ |
| 90 | void FillAddrman(AddrMan& addrman, FuzzedDataProvider& fuzzed_data_provider) |
| 91 | { |
| 92 | // Add a fraction of the addresses to the "tried" table. |
| 93 | // 0, 1, 2, 3 corresponding to 0%, 100%, 50%, 33% |
| 94 | const size_t n = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 3); |
| 95 | |
| 96 | const size_t num_sources = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 50); |
| 97 | CNetAddr prev_source; |
| 98 | // Generate a FastRandomContext seed to use inside the loops instead of |
| 99 | // fuzzed_data_provider. When fuzzed_data_provider is exhausted it |
| 100 | // just returns 0. |
| 101 | FastRandomContext fast_random_context{ConsumeUInt256(fuzzed_data_provider)}; |
| 102 | for (size_t i = 0; i < num_sources; ++i) { |
| 103 | const auto source = RandAddr(fuzzed_data_provider, fast_random_context); |
| 104 | const size_t num_addresses = fast_random_context.randrange(500) + 1; // [1..500] |
| 105 | |
| 106 | for (size_t j = 0; j < num_addresses; ++j) { |
| 107 | const auto addr = CAddress{CService{RandAddr(fuzzed_data_provider, fast_random_context), 8333}, NODE_NETWORK}; |
| 108 | const auto time_penalty = fast_random_context.randrange(100000001); |
| 109 | addrman.Add({addr}, source, time_penalty); |
| 110 | |
| 111 | if (n > 0 && addrman.size() % n == 0) { |
| 112 | addrman.Good(addr, GetTime()); |
| 113 | } |
| 114 | |
| 115 | // Add 10% of the addresses from more than one source. |
| 116 | if (fast_random_context.randrange(10) == 0 && prev_source.IsValid()) { |
| 117 | addrman.Add({addr}, prev_source, time_penalty); |
| 118 | } |
| 119 | } |
| 120 | prev_source = source; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | class AddrManDeterministic : public AddrMan |
| 125 | { |
no test coverage detected