some cleanup of the dht_socket_interface and fix tests and simulations to build with the dht disabled

This commit is contained in:
arvidn 2016-01-18 00:07:21 -05:00
parent 297b8943d0
commit 06b52f1421
11 changed files with 32 additions and 24 deletions

View File

@ -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

View File

@ -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() {}
};

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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<dht_storage_interface> 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
}

View File

@ -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);

View File

@ -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':

View File

@ -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

View File

@ -95,10 +95,10 @@ static void nop(void* userdata, libtorrent::dht::node_entry const& n) {}
std::list<std::pair<udp::endpoint, entry> > 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

View File

@ -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
}