* Convert a JSON array to a `banmap_t` object. * @param[in] bans_json JSON to convert, must be as returned by `BanMapToJson()`. * @param[out] bans Bans list to create from the JSON. * @throws std::runtime_error if the JSON does not have the expected fields or they contain * unparsable values. */
| 56 | * unparsable values. |
| 57 | */ |
| 58 | void BanMapFromJson(const UniValue& bans_json, banmap_t& bans) |
| 59 | { |
| 60 | for (const auto& ban_entry_json : bans_json.getValues()) { |
| 61 | const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].get_int()}; |
| 62 | if (version != CBanEntry::CURRENT_VERSION) { |
| 63 | LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version); |
| 64 | continue; |
| 65 | } |
| 66 | CSubNet subnet; |
| 67 | const auto& subnet_str = ban_entry_json[BANMAN_JSON_ADDR_KEY].get_str(); |
| 68 | if (!LookupSubNet(subnet_str, subnet)) { |
| 69 | LogPrintf("Dropping entry with unparseable address or subnet (%s) from ban list\n", subnet_str); |
| 70 | continue; |
| 71 | } |
| 72 | bans.insert_or_assign(subnet, CBanEntry{ban_entry_json}); |
| 73 | } |
| 74 | } |
no test coverage detected