|
4 | 4 |
|
5 | 5 | #include <net_types.h> |
6 | 6 |
|
| 7 | +#include <logging.h> |
7 | 8 | #include <netaddress.h> |
8 | 9 | #include <netbase.h> |
9 | 10 | #include <univalue.h> |
10 | 11 |
|
| 12 | +static const char* BANMAN_JSON_VERSION_KEY{"version"}; |
| 13 | + |
11 | 14 | CBanEntry::CBanEntry(const UniValue& json) |
12 | | - : nVersion(json["version"].get_int()), nCreateTime(json["ban_created"].get_int64()), |
| 15 | + : nVersion(json[BANMAN_JSON_VERSION_KEY].get_int()), |
| 16 | + nCreateTime(json["ban_created"].get_int64()), |
13 | 17 | nBanUntil(json["banned_until"].get_int64()) |
14 | 18 | { |
15 | 19 | } |
16 | 20 |
|
17 | 21 | UniValue CBanEntry::ToJson() const |
18 | 22 | { |
19 | 23 | UniValue json(UniValue::VOBJ); |
20 | | - json.pushKV("version", nVersion); |
| 24 | + json.pushKV(BANMAN_JSON_VERSION_KEY, nVersion); |
21 | 25 | json.pushKV("ban_created", nCreateTime); |
22 | 26 | json.pushKV("banned_until", nBanUntil); |
23 | 27 | return json; |
@@ -54,11 +58,16 @@ UniValue BanMapToJson(const banmap_t& bans) |
54 | 58 | void BanMapFromJson(const UniValue& bans_json, banmap_t& bans) |
55 | 59 | { |
56 | 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 | + } |
57 | 66 | CSubNet subnet; |
58 | 67 | const auto& subnet_str = ban_entry_json[BANMAN_JSON_ADDR_KEY].get_str(); |
59 | 68 | if (!LookupSubNet(subnet_str, subnet)) { |
60 | | - throw std::runtime_error( |
61 | | - strprintf("Cannot parse banned address or subnet: %s", subnet_str)); |
| 69 | + LogPrintf("Dropping entry with unparseable address or subnet (%s) from ban list\n", subnet_str); |
| 70 | + continue; |
62 | 71 | } |
63 | 72 | bans.insert_or_assign(subnet, CBanEntry{ban_entry_json}); |
64 | 73 | } |
|
0 commit comments