From fe5ab2c4396aa3ceebfdba44922806060ce8b3eb Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 1 Dec 2017 16:43:57 +0000 Subject: [PATCH 1/2] epee: fix kv_unserialize return value when a field is not found --- .../include/serialization/keyvalue_serialization_overloads.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h index a94ecacc5..2e020b136 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h +++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h @@ -73,7 +73,7 @@ namespace epee template static bool unserialize_t_obj(serializible_type& obj, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) { - typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, true); + typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, false); if(!hchild_section) return false; return obj._load(stg, hchild_section); } @@ -90,7 +90,7 @@ namespace epee static bool unserialize_t_obj(enableable& obj, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) { obj.enabled = false; - typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, true); + typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, false); if(!hchild_section) return false; obj.enabled = true; return obj.v._load(stg, hchild_section); From 27aa8ce95bf0e863f3b6a8942a0a91bbb85b8e52 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 8 Dec 2017 18:26:36 +0000 Subject: [PATCH 2/2] net_utils_base: fix peer list parsing Fields are written with their "name" as key, and that name changed. --- contrib/epee/include/net/net_utils_base.h | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h index 0e31ee86f..04e3fe6a4 100644 --- a/contrib/epee/include/net/net_utils_base.h +++ b/contrib/epee/include/net/net_utils_base.h @@ -166,15 +166,37 @@ namespace net_utils BEGIN_KV_SERIALIZE_MAP() uint8_t type = is_store ? this_ref.get_type_id() : 0; - epee::serialization::selector::serialize(type, stg, hparent_section, "type"); + if (!epee::serialization::selector::serialize(type, stg, hparent_section, "type")) + return false; switch (type) { case ipv4_network_address::ID: + { if (!is_store) + { const_cast(this_ref) = ipv4_network_address{0, 0}; - KV_SERIALIZE(template as_mutable()); + auto &addr = this_ref.template as_mutable(); + if (epee::serialization::selector::serialize(addr, stg, hparent_section, "addr")) + MDEBUG("Found as addr: " << this_ref.str()); + else if (epee::serialization::selector::serialize(addr, stg, hparent_section, "template as()")) + MDEBUG("Found as template as(): " << this_ref.str()); + else if (epee::serialization::selector::serialize(addr, stg, hparent_section, "template as_mutable()")) + MDEBUG("Found as template as_mutable(): " << this_ref.str()); + else + { + MWARNING("Address not found"); + return false; + } + } + else + { + auto &addr = this_ref.template as_mutable(); + if (!epee::serialization::selector::serialize(addr, stg, hparent_section, "addr")) + return false; + } break; - default: MERROR("Unsupported network address type: " << type); return false; + } + default: MERROR("Unsupported network address type: " << (unsigned)type); return false; } END_KV_SERIALIZE_MAP() };