forked from premiere/premiere-libtorrent
some cleanup of the dht_socket_interface and fix tests and simulations to build with the dht disabled
This commit is contained in:
parent
297b8943d0
commit
06b52f1421
|
@ -144,9 +144,8 @@ namespace libtorrent { namespace dht
|
||||||
void refresh_key(error_code const& e);
|
void refresh_key(error_code const& e);
|
||||||
|
|
||||||
// implements udp_socket_interface
|
// implements udp_socket_interface
|
||||||
virtual bool has_quota();
|
virtual bool has_quota() TORRENT_OVERRIDE;
|
||||||
virtual bool send_packet(libtorrent::entry& e, udp::endpoint const& addr
|
virtual bool send_packet(libtorrent::entry& e, udp::endpoint const& addr) TORRENT_OVERRIDE;
|
||||||
, int send_flags);
|
|
||||||
|
|
||||||
// this is the bdecode_node DHT messages are parsed into. It's a member
|
// 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
|
// in order to avoid having to deallocate and re-allocate it for every
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
struct udp_socket_interface
|
struct udp_socket_interface
|
||||||
{
|
{
|
||||||
virtual bool has_quota() = 0;
|
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:
|
protected:
|
||||||
~udp_socket_interface() {}
|
~udp_socket_interface() {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,10 +73,9 @@ namespace libtorrent
|
||||||
~udp_socket();
|
~udp_socket();
|
||||||
|
|
||||||
enum flags_t {
|
enum flags_t {
|
||||||
dont_drop = 1
|
peer_connection = 1
|
||||||
, peer_connection = 2
|
, tracker_connection = 2
|
||||||
, tracker_connection = 4
|
, dont_queue = 4
|
||||||
, dont_queue = 8
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_open() const
|
bool is_open() const
|
||||||
|
|
|
@ -52,6 +52,8 @@ namespace lt = libtorrent;
|
||||||
using namespace sim;
|
using namespace sim;
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
lt::time_point start_time;
|
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 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
|
// since the simulaton is single threaded, we can get away with allocating
|
||||||
// just a single send buffer
|
// just a single send buffer
|
||||||
|
@ -329,4 +331,5 @@ void dht_network::stop()
|
||||||
for (auto& n : m_nodes) n.stop();
|
for (auto& n : m_nodes) n.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace lt = libtorrent;
|
||||||
|
|
||||||
TORRENT_TEST(dht_bootstrap)
|
TORRENT_TEST(dht_bootstrap)
|
||||||
{
|
{
|
||||||
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
sim::default_config cfg;
|
sim::default_config cfg;
|
||||||
sim::simulation sim{cfg};
|
sim::simulation sim{cfg};
|
||||||
|
|
||||||
|
@ -124,5 +125,7 @@ TORRENT_TEST(dht_bootstrap)
|
||||||
|
|
||||||
sim.run();
|
sim.run();
|
||||||
|
|
||||||
|
#endif // TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,8 @@ using namespace sim::asio;
|
||||||
using sim::simulation;
|
using sim::simulation;
|
||||||
using sim::default_config;
|
using sim::default_config;
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
dht_settings test_settings() {
|
dht_settings test_settings() {
|
||||||
|
@ -98,8 +100,11 @@ void test_expiration(high_resolution_clock::duration const& expiry_time
|
||||||
sim.run(ec);
|
sim.run(ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
TORRENT_TEST(dht_storage_counters)
|
TORRENT_TEST(dht_storage_counters)
|
||||||
{
|
{
|
||||||
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
dht_settings sett = test_settings();
|
dht_settings sett = test_settings();
|
||||||
boost::shared_ptr<dht_storage_interface> s(dht_default_storage_constructor(node_id(0), sett));
|
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.immutable_data = 0;
|
||||||
c.mutable_data = 0;
|
c.mutable_data = 0;
|
||||||
test_expiration(hours(1), s, c); // test expiration of everything after 3 hours
|
test_expiration(hours(1), s, c); // test expiration of everything after 3 hours
|
||||||
|
#endif // TORRENT_DISABLE_DHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -418,9 +418,7 @@ namespace libtorrent { namespace dht
|
||||||
return m_send_quota > 0;
|
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)
|
||||||
bool dht_tracker::send_packet(libtorrent::entry& e, udp::endpoint const& addr
|
|
||||||
, int send_flags)
|
|
||||||
{
|
{
|
||||||
using libtorrent::bencode;
|
using libtorrent::bencode;
|
||||||
using libtorrent::entry;
|
using libtorrent::entry;
|
||||||
|
@ -449,7 +447,7 @@ namespace libtorrent { namespace dht
|
||||||
m_send_quota -= m_send_buf.size();
|
m_send_quota -= m_send_buf.size();
|
||||||
|
|
||||||
error_code ec;
|
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)
|
if (ec)
|
||||||
{
|
{
|
||||||
m_counters.inc_stats_counter(counters::dht_messages_out_dropped);
|
m_counters.inc_stats_counter(counters::dht_messages_out_dropped);
|
||||||
|
|
|
@ -252,7 +252,7 @@ void node::incoming(msg const& m)
|
||||||
// want to open up a magnification opportunity
|
// want to open up a magnification opportunity
|
||||||
// entry e;
|
// entry e;
|
||||||
// incoming_error(e, "missing 'y' entry");
|
// incoming_error(e, "missing 'y' entry");
|
||||||
// m_sock.send_packet(e, m.addr, 0);
|
// m_sock.send_packet(e, m.addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ void node::incoming(msg const& m)
|
||||||
|
|
||||||
entry e;
|
entry e;
|
||||||
incoming_request(m, e);
|
incoming_request(m, e);
|
||||||
m_sock->send_packet(e, m.addr, 0);
|
m_sock->send_packet(e, m.addr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'e':
|
case 'e':
|
||||||
|
|
|
@ -297,7 +297,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id)
|
||||||
// attack.
|
// attack.
|
||||||
// entry e;
|
// entry e;
|
||||||
// incoming_error(e, "invalid transaction id");
|
// incoming_error(e, "invalid transaction id");
|
||||||
// m_sock->send_packet(e, m.addr, 0);
|
// m_sock->send_packet(e, m.addr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint target_addr
|
||||||
, print_endpoint(target_addr).c_str());
|
, print_endpoint(target_addr).c_str());
|
||||||
#endif
|
#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));
|
m_transactions.insert(std::make_pair(tid, o));
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
|
|
|
@ -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;
|
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 has_quota() TORRENT_OVERRIDE { return true; }
|
||||||
bool send_packet(entry& msg, udp::endpoint const& ep, int flags)
|
bool send_packet(entry& msg, udp::endpoint const& ep) TORRENT_OVERRIDE
|
||||||
{
|
{
|
||||||
// TODO: ideally the mock_socket would contain this queue of packets, to
|
// TODO: ideally the mock_socket would contain this queue of packets, to
|
||||||
// make tests independent
|
// make tests independent
|
||||||
|
|
|
@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
#if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT
|
||||||
|
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
#include "libtorrent/session.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)
|
TORRENT_TEST(direct_dht_request)
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
#if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT
|
||||||
settings_pack sp;
|
settings_pack sp;
|
||||||
sp.set_bool(settings_pack::enable_lsd, false);
|
sp.set_bool(settings_pack::enable_lsd, false);
|
||||||
sp.set_bool(settings_pack::enable_natpmp, 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->response().type(), bdecode_node::none_t);
|
||||||
TEST_EQUAL(ra->userdata, (void*)123456);
|
TEST_EQUAL(ra->userdata, (void*)123456);
|
||||||
}
|
}
|
||||||
#endif // #ifndef TORRENT_DISABLE_EXTENSIONS
|
#endif // #if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue