From b13ac50f4e329b63ec35edd7626258cd233724f4 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 28 Jun 2017 11:00:14 -0400 Subject: [PATCH] update libsimulator (#2107) use move in simulations. don't pretend io_service to be movable --- simulation/libsimulator | 2 +- simulation/setup_dht.cpp | 47 +++------------------------------------- simulation/setup_dht.hpp | 2 +- 3 files changed, 5 insertions(+), 46 deletions(-) diff --git a/simulation/libsimulator b/simulation/libsimulator index 96e8e2414..84b5a4168 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 96e8e2414df955c04b37b6bccd2b7360a54ff2f1 +Subproject commit 84b5a4168dbc944043083b40ca662bc228b42218 diff --git a/simulation/setup_dht.cpp b/simulation/setup_dht.cpp index 0bf8f61ee..8b4f16185 100644 --- a/simulation/setup_dht.cpp +++ b/simulation/setup_dht.cpp @@ -86,20 +86,11 @@ struct dht_node final : lt::dht::socket_manager, lt::aux::session_listen_socket , m_dht_storage(lt::dht::dht_default_storage_constructor(sett)) , m_add_dead_nodes((flags & dht_network::add_dead_nodes) != 0) , m_ipv6((flags & dht_network::bind_ipv6) != 0) -#if LIBSIMULATOR_USE_MOVE , m_socket(m_io_service) , m_dht(this, this, sett, id_from_addr(m_io_service.get_ips().front()) , nullptr, cnt , [](lt::dht::node_id const&, std::string const&) -> lt::dht::node* { return nullptr; } , *m_dht_storage) -#else - , m_socket(new asio::ip::udp::socket(m_io_service)) - , m_dht(new lt::dht::node(this, this, sett - , id_from_addr(m_io_service.get_ips().front()) - , nullptr, cnt - , [](lt::dht::node_id const&, std::string const&) -> lt::dht::node* { return nullptr; } - , *m_dht_storage)) -#endif { m_dht_storage->update_node_ids({id_from_addr(m_io_service.get_ips().front())}); error_code ec; @@ -114,7 +105,6 @@ struct dht_node final : lt::dht::socket_manager, lt::aux::session_listen_socket { this->on_read(ec, bytes_transferred); }); } -#if LIBSIMULATOR_USE_MOVE // This type is not copyable, because the socket and the dht node is not // copyable. dht_node(dht_node const&) = delete; @@ -122,28 +112,9 @@ struct dht_node final : lt::dht::socket_manager, lt::aux::session_listen_socket // it's also not movable, because it passes in its this-pointer to the async // receive function, which pins this object down. However, std::vector cannot - // hold non-movable and non-copyable types. Instead, pretend that it's - // movable and make sure it never needs to be moved (for instance, by - // reserving space in the vector before emplacing any nodes). - dht_node(dht_node&& n) noexcept - : m_add_dead_nodes(n.m_add_dead_nodes) - , m_ipv6(n.m_ipv6) - , m_socket(std::move(n.m_socket)) - , m_dht(this, this, n.m_dht.settings(), n.m_dht.nid() - , n.m_dht.observer(), n.m_dht.stats_counters() - , [](lt::dht::node_id const&, std::string const&) -> lt::dht::node* { return nullptr; } - , *n.m_dht_storage) - { - assert(false && "dht_node is not movable"); - throw std::runtime_error("dht_node is not movable"); - } - dht_node& operator=(dht_node&&) - noexcept - { - assert(false && "dht_node is not movable"); - throw std::runtime_error("dht_node is not movable"); - } -#endif + // hold non-movable and non-copyable types. + dht_node(dht_node&& n) = delete; + dht_node& operator=(dht_node&&) = delete; void on_read(lt::error_code const& ec, std::size_t bytes_transferred) { @@ -263,28 +234,17 @@ struct dht_node final : lt::dht::socket_manager, lt::aux::session_listen_socket sock().close(); } -#if LIBSIMULATOR_USE_MOVE lt::dht::node& dht() { return m_dht; } lt::dht::node const& dht() const { return m_dht; } -#else - lt::dht::node& dht() { return *m_dht; } - lt::dht::node const& dht() const { return *m_dht; } -#endif private: asio::io_service m_io_service; std::shared_ptr m_dht_storage; bool const m_add_dead_nodes; bool const m_ipv6; -#if LIBSIMULATOR_USE_MOVE lt::udp::socket m_socket; lt::udp::socket& sock() { return m_socket; } lt::dht::node m_dht; -#else - std::shared_ptr m_socket; - lt::udp::socket& sock() { return *m_socket; } - std::shared_ptr m_dht; -#endif lt::udp::endpoint m_ep; char m_buffer[1300]; }; @@ -293,7 +253,6 @@ dht_network::dht_network(sim::simulation& sim, int num_nodes, std::uint32_t flag { m_sett.ignore_dark_internet = false; m_sett.restrict_routing_ips = false; - m_nodes.reserve(num_nodes); // TODO: how can we introduce churn among peers? diff --git a/simulation/setup_dht.hpp b/simulation/setup_dht.hpp index 903af8d92..acb92b8ec 100644 --- a/simulation/setup_dht.hpp +++ b/simulation/setup_dht.hpp @@ -72,7 +72,7 @@ private: // used for all the nodes in the network lt::counters m_cnt; lt::dht_settings m_sett; - std::vector m_nodes; + std::list m_nodes; }; #endif