update libsimulator (#2107)

use move in simulations. don't pretend io_service to be movable
This commit is contained in:
Arvid Norberg 2017-06-28 11:00:14 -04:00 committed by GitHub
parent 20e05a12ac
commit b13ac50f4e
3 changed files with 5 additions and 46 deletions

@ -1 +1 @@
Subproject commit 96e8e2414df955c04b37b6bccd2b7360a54ff2f1
Subproject commit 84b5a4168dbc944043083b40ca662bc228b42218

View File

@ -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<dht::dht_storage_interface> 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<lt::udp::socket> m_socket;
lt::udp::socket& sock() { return *m_socket; }
std::shared_ptr<lt::dht::node> 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?

View File

@ -72,7 +72,7 @@ private:
// used for all the nodes in the network
lt::counters m_cnt;
lt::dht_settings m_sett;
std::vector<dht_node> m_nodes;
std::list<dht_node> m_nodes;
};
#endif