diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-12-10 13:08:23 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-12-10 13:08:23 +0200 |
commit | f51bac990e11a8f2f232449b1035e0152c316d82 (patch) | |
tree | b6beba24b3b3db4bd4414d297ada48f340e67c6f | |
parent | Merge pull request #2900 (diff) | |
parent | net_utils_base: fix peer list parsing (diff) | |
download | monero-f51bac990e11a8f2f232449b1035e0152c316d82.tar.xz |
Merge pull request #2906
27aa8ce9 net_utils_base: fix peer list parsing (moneromooo-monero)
fe5ab2c4 epee: fix kv_unserialize return value when a field is not found (moneromooo-monero)
-rw-r--r-- | contrib/epee/include/net/net_utils_base.h | 28 | ||||
-rw-r--r-- | contrib/epee/include/serialization/keyvalue_serialization_overloads.h | 4 |
2 files changed, 27 insertions, 5 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<is_store>::serialize(type, stg, hparent_section, "type"); + if (!epee::serialization::selector<is_store>::serialize(type, stg, hparent_section, "type")) + return false; switch (type) { case ipv4_network_address::ID: + { if (!is_store) + { const_cast<network_address&>(this_ref) = ipv4_network_address{0, 0}; - KV_SERIALIZE(template as_mutable<ipv4_network_address>()); + auto &addr = this_ref.template as_mutable<ipv4_network_address>(); + if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "addr")) + MDEBUG("Found as addr: " << this_ref.str()); + else if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "template as<ipv4_network_address>()")) + MDEBUG("Found as template as<ipv4_network_address>(): " << this_ref.str()); + else if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "template as_mutable<ipv4_network_address>()")) + MDEBUG("Found as template as_mutable<ipv4_network_address>(): " << this_ref.str()); + else + { + MWARNING("Address not found"); + return false; + } + } + else + { + auto &addr = this_ref.template as_mutable<ipv4_network_address>(); + if (!epee::serialization::selector<is_store>::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() }; 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<class serializible_type, class t_storage> 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<serializible_type>& 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); |