From 06b52f1421bd0d21597a9cf551aaf6c74df597bc Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 18 Jan 2016 00:07:21 -0500 Subject: [PATCH] some cleanup of the dht_socket_interface and fix tests and simulations to build with the dht disabled --- include/libtorrent/kademlia/dht_tracker.hpp | 5 ++--- include/libtorrent/kademlia/node.hpp | 2 +- include/libtorrent/udp_socket.hpp | 7 +++---- simulation/setup_dht.cpp | 5 ++++- simulation/test_dht.cpp | 3 +++ simulation/test_dht_storage.cpp | 6 ++++++ src/kademlia/dht_tracker.cpp | 6 ++---- src/kademlia/node.cpp | 4 ++-- src/kademlia/rpc_manager.cpp | 4 ++-- test/test_dht.cpp | 6 +++--- test/test_direct_dht.cpp | 8 ++++---- 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index e2cc65c38..c86cf9421 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -144,9 +144,8 @@ namespace libtorrent { namespace dht void refresh_key(error_code const& e); // implements udp_socket_interface - virtual bool has_quota(); - virtual bool send_packet(libtorrent::entry& e, udp::endpoint const& addr - , int send_flags); + virtual bool has_quota() TORRENT_OVERRIDE; + virtual bool send_packet(libtorrent::entry& e, udp::endpoint const& addr) TORRENT_OVERRIDE; // this is the bdecode_node DHT messages are parsed into. It's a member // in order to avoid having to deallocate and re-allocate it for every diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index c55503e98..8fa0ace9b 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -91,7 +91,7 @@ public: struct udp_socket_interface { virtual bool has_quota() = 0; - virtual bool send_packet(entry& e, udp::endpoint const& addr, int flags) = 0; + virtual bool send_packet(entry& e, udp::endpoint const& addr) = 0; protected: ~udp_socket_interface() {} }; diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 4293b46b2..54dc6d755 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -73,10 +73,9 @@ namespace libtorrent ~udp_socket(); enum flags_t { - dont_drop = 1 - , peer_connection = 2 - , tracker_connection = 4 - , dont_queue = 8 + peer_connection = 1 + , tracker_connection = 2 + , dont_queue = 4 }; bool is_open() const diff --git a/simulation/setup_dht.cpp b/simulation/setup_dht.cpp index 64bce3385..6af902673 100644 --- a/simulation/setup_dht.cpp +++ b/simulation/setup_dht.cpp @@ -52,6 +52,8 @@ namespace lt = libtorrent; using namespace sim; using namespace libtorrent; +#ifndef TORRENT_DISABLE_DHT + namespace { lt::time_point start_time; @@ -155,7 +157,7 @@ struct dht_node final : lt::dht::udp_socket_interface } bool has_quota() override { return true; } - bool send_packet(entry& e, udp::endpoint const& addr, int flags) override + bool send_packet(entry& e, udp::endpoint const& addr) override { // since the simulaton is single threaded, we can get away with allocating // just a single send buffer @@ -329,4 +331,5 @@ void dht_network::stop() for (auto& n : m_nodes) n.stop(); } +#endif // TORRENT_DISABLE_DHT diff --git a/simulation/test_dht.cpp b/simulation/test_dht.cpp index b671ece3e..85e20665c 100644 --- a/simulation/test_dht.cpp +++ b/simulation/test_dht.cpp @@ -49,6 +49,7 @@ namespace lt = libtorrent; TORRENT_TEST(dht_bootstrap) { +#ifndef TORRENT_DISABLE_DHT sim::default_config cfg; sim::simulation sim{cfg}; @@ -124,5 +125,7 @@ TORRENT_TEST(dht_bootstrap) sim.run(); +#endif // TORRENT_DISABLE_DHT + } diff --git a/simulation/test_dht_storage.cpp b/simulation/test_dht_storage.cpp index f45f2f4f3..e0b947992 100644 --- a/simulation/test_dht_storage.cpp +++ b/simulation/test_dht_storage.cpp @@ -52,6 +52,8 @@ using namespace sim::asio; using sim::simulation; using sim::default_config; +#ifndef TORRENT_DISABLE_DHT + namespace { dht_settings test_settings() { @@ -98,8 +100,11 @@ void test_expiration(high_resolution_clock::duration const& expiry_time sim.run(ec); } +#endif // TORRENT_DISABLE_DHT + TORRENT_TEST(dht_storage_counters) { +#ifndef TORRENT_DISABLE_DHT dht_settings sett = test_settings(); boost::shared_ptr s(dht_default_storage_constructor(node_id(0), sett)); @@ -151,5 +156,6 @@ TORRENT_TEST(dht_storage_counters) c.immutable_data = 0; c.mutable_data = 0; test_expiration(hours(1), s, c); // test expiration of everything after 3 hours +#endif // TORRENT_DISABLE_DHT } diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 98cf7c5be..c626baec6 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -418,9 +418,7 @@ namespace libtorrent { namespace dht return m_send_quota > 0; } - // TODO: 4 do we need the flags here? - bool dht_tracker::send_packet(libtorrent::entry& e, udp::endpoint const& addr - , int send_flags) + bool dht_tracker::send_packet(libtorrent::entry& e, udp::endpoint const& addr) { using libtorrent::bencode; using libtorrent::entry; @@ -449,7 +447,7 @@ namespace libtorrent { namespace dht m_send_quota -= m_send_buf.size(); error_code ec; - m_sock.send(addr, &m_send_buf[0], int(m_send_buf.size()), ec, send_flags); + m_sock.send(addr, &m_send_buf[0], int(m_send_buf.size()), ec, 0); if (ec) { m_counters.inc_stats_counter(counters::dht_messages_out_dropped); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index efeb77016..9b017fcc6 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -252,7 +252,7 @@ void node::incoming(msg const& m) // want to open up a magnification opportunity // entry e; // incoming_error(e, "missing 'y' entry"); -// m_sock.send_packet(e, m.addr, 0); +// m_sock.send_packet(e, m.addr); return; } @@ -305,7 +305,7 @@ void node::incoming(msg const& m) entry e; incoming_request(m, e); - m_sock->send_packet(e, m.addr, 0); + m_sock->send_packet(e, m.addr); break; } case 'e': diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 63aaa4a8d..7d58c857a 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -297,7 +297,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id) // attack. // entry e; // incoming_error(e, "invalid transaction id"); -// m_sock->send_packet(e, m.addr, 0); +// m_sock->send_packet(e, m.addr); return false; } @@ -473,7 +473,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint target_addr , print_endpoint(target_addr).c_str()); #endif - if (m_sock->send_packet(e, target_addr, 1)) + if (m_sock->send_packet(e, target_addr)) { m_transactions.insert(std::make_pair(tid, o)); #if TORRENT_USE_ASSERTS diff --git a/test/test_dht.cpp b/test/test_dht.cpp index f7afa9775..d95a8e4e8 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -95,10 +95,10 @@ static void nop(void* userdata, libtorrent::dht::node_entry const& n) {} std::list > g_sent_packets; -struct mock_socket : udp_socket_interface +struct mock_socket TORRENT_FINAL : udp_socket_interface { - bool has_quota() { return true; } - bool send_packet(entry& msg, udp::endpoint const& ep, int flags) + bool has_quota() TORRENT_OVERRIDE { return true; } + bool send_packet(entry& msg, udp::endpoint const& ep) TORRENT_OVERRIDE { // TODO: ideally the mock_socket would contain this queue of packets, to // make tests independent diff --git a/test/test_direct_dht.cpp b/test/test_direct_dht.cpp index c0887d067..206be5c65 100644 --- a/test/test_direct_dht.cpp +++ b/test/test_direct_dht.cpp @@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" -#ifndef TORRENT_DISABLE_EXTENSIONS +#if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT #include "libtorrent/config.hpp" #include "libtorrent/session.hpp" @@ -85,11 +85,11 @@ dht_direct_response_alert* get_direct_response(lt::session& ses) } -#endif // #ifndef TORRENT_DISABLE_EXTENSIONS +#endif // #if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT TORRENT_TEST(direct_dht_request) { -#ifndef TORRENT_DISABLE_EXTENSIONS +#if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT settings_pack sp; sp.set_bool(settings_pack::enable_lsd, false); sp.set_bool(settings_pack::enable_natpmp, false); @@ -134,5 +134,5 @@ TORRENT_TEST(direct_dht_request) TEST_EQUAL(ra->response().type(), bdecode_node::none_t); TEST_EQUAL(ra->userdata, (void*)123456); } -#endif // #ifndef TORRENT_DISABLE_EXTENSIONS +#endif // #if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT }