diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-06-28 09:00:29 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-06-28 09:11:24 +0100 |
commit | 8f96cfc20a92f00e5b87969d589c4ec360020366 (patch) | |
tree | f9a727ce5cfbb978d9bf08c98536d542ae107479 /src/p2p | |
parent | Merge pull request #2111 (diff) | |
download | monero-8f96cfc20a92f00e5b87969d589c4ec360020366.tar.xz |
Remove typeid use in network_address
Since I had to add an ID to the derived classes anyway,
this can be used instead. This removes an apparently
pointless warning from CLANG too.
Diffstat (limited to '')
-rw-r--r-- | src/p2p/net_node.inl | 16 | ||||
-rw-r--r-- | src/p2p/net_peerlist_boost_serialization.h | 12 | ||||
-rw-r--r-- | src/p2p/p2p_protocol_defs.h | 4 |
3 files changed, 12 insertions, 20 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index c250d5185..b23090c7d 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -939,8 +939,8 @@ namespace nodetool << (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never") << ")..."); - CHECK_AND_ASSERT_MES(na.type() == typeid(epee::net_utils::ipv4_network_address), false, - "Only IPv4 addresses are supported here, got " << na.type().name()); + CHECK_AND_ASSERT_MES(na.get_type_id() == epee::net_utils::ipv4_network_address::ID, false, + "Only IPv4 addresses are supported here"); const epee::net_utils::ipv4_network_address &ipv4 = na.as<const epee::net_utils::ipv4_network_address>(); typename net_server::t_connection_context con = AUTO_VAL_INIT(con); @@ -1004,8 +1004,8 @@ namespace nodetool << (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never") << ")..."); - CHECK_AND_ASSERT_MES(na.type() == typeid(epee::net_utils::ipv4_network_address), false, - "Only IPv4 addresses are supported here, got " << na.type().name()); + CHECK_AND_ASSERT_MES(na.get_type_id() == epee::net_utils::ipv4_network_address::ID, false, + "Only IPv4 addresses are supported here"); const epee::net_utils::ipv4_network_address &ipv4 = na.as<epee::net_utils::ipv4_network_address>(); typename net_server::t_connection_context con = AUTO_VAL_INIT(con); @@ -1510,8 +1510,8 @@ namespace nodetool if(!node_data.my_port) return false; - CHECK_AND_ASSERT_MES(context.m_remote_address.type() == typeid(epee::net_utils::ipv4_network_address), false, - "Only IPv4 addresses are supported here, got " << context.m_remote_address.type().name()); + CHECK_AND_ASSERT_MES(context.m_remote_address.get_type_id() == epee::net_utils::ipv4_network_address::ID, false, + "Only IPv4 addresses are supported here"); const epee::net_utils::network_address na = context.m_remote_address; uint32_t actual_ip = na.as<const epee::net_utils::ipv4_network_address>().ip(); @@ -1670,8 +1670,8 @@ namespace nodetool //try ping to be sure that we can add this peer to peer_list try_ping(arg.node_data, context, [peer_id_l, port_l, context, this]() { - CHECK_AND_ASSERT_MES(context.m_remote_address.type() == typeid(epee::net_utils::ipv4_network_address), void(), - "Only IPv4 addresses are supported here, got " << context.m_remote_address.type().name()); + CHECK_AND_ASSERT_MES(context.m_remote_address.get_type_id() == epee::net_utils::ipv4_network_address::ID, void(), + "Only IPv4 addresses are supported here"); //called only(!) if success pinged, update local peerlist peerlist_entry pe; const epee::net_utils::network_address na = context.m_remote_address; diff --git a/src/p2p/net_peerlist_boost_serialization.h b/src/p2p/net_peerlist_boost_serialization.h index 0a21895cf..43c5ea5f0 100644 --- a/src/p2p/net_peerlist_boost_serialization.h +++ b/src/p2p/net_peerlist_boost_serialization.h @@ -36,24 +36,16 @@ namespace boost { namespace serialization { - enum { sertype_ipv4_address }; - static inline uint8_t get_type(const epee::net_utils::network_address &na) - { - if (na.type() == typeid(epee::net_utils::ipv4_network_address)) - return sertype_ipv4_address; - throw std::runtime_error("Unsupported network address type"); - return 0; - } template <class Archive, class ver_type> inline void serialize(Archive &a, epee::net_utils::network_address& na, const ver_type ver) { uint8_t type; if (typename Archive::is_saving()) - type = get_type(na); + type = na.get_type_id(); a & type; switch (type) { - case sertype_ipv4_address: + 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>(); diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index d60990f8a..a471211a6 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -188,7 +188,7 @@ namespace nodetool std::list<peerlist_entry_base<network_address_old>> local_peerlist; for (const auto &p: this_ref.local_peerlist_new) { - if (p.adr.type() == typeid(epee::net_utils::ipv4_network_address)) + if (p.adr.get_type_id() == epee::net_utils::ipv4_network_address::ID) { const epee::net_utils::network_address &na = p.adr; const epee::net_utils::ipv4_network_address &ipv4 = na.as<const epee::net_utils::ipv4_network_address>(); @@ -247,7 +247,7 @@ namespace nodetool std::list<peerlist_entry_base<network_address_old>> local_peerlist; for (const auto &p: this_ref.local_peerlist_new) { - if (p.adr.type() == typeid(epee::net_utils::ipv4_network_address)) + if (p.adr.get_type_id() == epee::net_utils::ipv4_network_address::ID) { const epee::net_utils::network_address &na = p.adr; const epee::net_utils::ipv4_network_address &ipv4 = na.as<const epee::net_utils::ipv4_network_address>(); |