diff options
Diffstat (limited to 'src/p2p/net_peerlist_boost_serialization.h')
-rw-r--r-- | src/p2p/net_peerlist_boost_serialization.h | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/p2p/net_peerlist_boost_serialization.h b/src/p2p/net_peerlist_boost_serialization.h index 6ea2d48fd..079524aa1 100644 --- a/src/p2p/net_peerlist_boost_serialization.h +++ b/src/p2p/net_peerlist_boost_serialization.h @@ -31,11 +31,19 @@ #pragma once #include "net/net_utils_base.h" +#include "p2p/p2p_protocol_defs.h" namespace boost { namespace serialization { + template <class T, class Archive> + inline void do_serialize(Archive &a, epee::net_utils::network_address& na, T local) + { + if (typename Archive::is_saving()) local = na.as<T>(); + a & local; + if (!typename Archive::is_saving()) na = local; + } template <class Archive, class ver_type> inline void serialize(Archive &a, epee::net_utils::network_address& na, const ver_type ver) { @@ -46,10 +54,8 @@ namespace boost switch (type) { case epee::net_utils::ipv4_network_address::ID: - if (!typename Archive::is_saving()) - na.reset(new epee::net_utils::ipv4_network_address(0, 0)); - a & na.as<epee::net_utils::ipv4_network_address>(); - break; + do_serialize(a, na, epee::net_utils::ipv4_network_address{0, 0}); + break; default: throw std::runtime_error("Unsupported network address type"); } @@ -57,13 +63,14 @@ namespace boost template <class Archive, class ver_type> inline void serialize(Archive &a, epee::net_utils::ipv4_network_address& na, const ver_type ver) { - a & na.m_ip; - a & na.m_port; + uint32_t ip{na.ip()}; + uint16_t port{na.port()}; + a & ip; + a & port; if (!typename Archive::is_saving()) - na.init_ids(); + na = epee::net_utils::ipv4_network_address{ip, port}; } - template <class Archive, class ver_type> inline void serialize(Archive &a, nodetool::peerlist_entry& pl, const ver_type ver) { |