make dht_tracker be held by shared_ptr instead of intrusive_ptr. remove redundant performance counter (total dht sent/received). report DHT IP overhead to the IP overhead counters
This commit is contained in:
parent
58d93e5aa1
commit
22a02f4a1f
|
@ -973,7 +973,7 @@ namespace libtorrent
|
||||||
mutable int m_next_port;
|
mutable int m_next_port;
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
boost::intrusive_ptr<dht::dht_tracker> m_dht;
|
boost::shared_ptr<dht::dht_tracker> m_dht;
|
||||||
dht_settings m_dht_settings;
|
dht_settings m_dht_settings;
|
||||||
|
|
||||||
// these are used when starting the DHT
|
// these are used when starting the DHT
|
||||||
|
|
|
@ -40,8 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/intrusive_ptr.hpp>
|
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||||
#include <boost/detail/atomic_count.hpp>
|
|
||||||
|
|
||||||
#include "libtorrent/kademlia/node.hpp"
|
#include "libtorrent/kademlia/node.hpp"
|
||||||
#include "libtorrent/kademlia/node_id.hpp"
|
#include "libtorrent/kademlia/node_id.hpp"
|
||||||
|
@ -73,15 +72,11 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
struct dht_tracker;
|
struct dht_tracker;
|
||||||
|
|
||||||
// TODO: 3 remove these
|
struct dht_tracker
|
||||||
TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(dht_tracker const*);
|
: udp_socket_interface
|
||||||
TORRENT_EXTRA_EXPORT void intrusive_ptr_release(dht_tracker const*);
|
, udp_socket_observer
|
||||||
|
, boost::enable_shared_from_this<dht_tracker>
|
||||||
struct dht_tracker : udp_socket_interface, udp_socket_observer
|
|
||||||
{
|
{
|
||||||
friend void intrusive_ptr_add_ref(dht_tracker const*);
|
|
||||||
friend void intrusive_ptr_release(dht_tracker const*);
|
|
||||||
|
|
||||||
dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
|
dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
|
||||||
, dht_settings const& settings, counters& cnt, entry const* state = 0);
|
, dht_settings const& settings, counters& cnt, entry const* state = 0);
|
||||||
virtual ~dht_tracker();
|
virtual ~dht_tracker();
|
||||||
|
@ -121,8 +116,6 @@ namespace libtorrent { namespace dht
|
||||||
void dht_status(std::vector<dht_routing_bucket>& table
|
void dht_status(std::vector<dht_routing_bucket>& table
|
||||||
, std::vector<dht_lookup>& requests);
|
, std::vector<dht_lookup>& requests);
|
||||||
|
|
||||||
void network_stats(int& sent, int& received);
|
|
||||||
|
|
||||||
// translate bittorrent kademlia message into the generic kademlia message
|
// translate bittorrent kademlia message into the generic kademlia message
|
||||||
// used by the library
|
// used by the library
|
||||||
virtual bool incoming_packet(error_code const& ec
|
virtual bool incoming_packet(error_code const& ec
|
||||||
|
@ -130,8 +123,8 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
boost::intrusive_ptr<dht_tracker> self()
|
boost::shared_ptr<dht_tracker> self()
|
||||||
{ return boost::intrusive_ptr<dht_tracker>(this); }
|
{ return shared_from_this(); }
|
||||||
|
|
||||||
void on_name_lookup(error_code const& e
|
void on_name_lookup(error_code const& e
|
||||||
, udp::resolver::iterator host);
|
, udp::resolver::iterator host);
|
||||||
|
@ -165,14 +158,6 @@ namespace libtorrent { namespace dht
|
||||||
// used to resolve hostnames for nodes
|
// used to resolve hostnames for nodes
|
||||||
udp::resolver m_host_resolver;
|
udp::resolver m_host_resolver;
|
||||||
|
|
||||||
// sent and received bytes since queried last time
|
|
||||||
// TODO: 3 these members are probably unnecessary
|
|
||||||
int m_sent_bytes;
|
|
||||||
int m_received_bytes;
|
|
||||||
|
|
||||||
// reference counter for intrusive_ptr
|
|
||||||
mutable boost::detail::atomic_count m_refs;
|
|
||||||
|
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
int m_replies_sent[5];
|
int m_replies_sent[5];
|
||||||
int m_queries_received[5];
|
int m_queries_received[5];
|
||||||
|
|
|
@ -228,11 +228,6 @@ namespace libtorrent
|
||||||
dht_put_in,
|
dht_put_in,
|
||||||
dht_put_out,
|
dht_put_out,
|
||||||
|
|
||||||
// TODO: 3 these counters are redundant with dht_bytes_in and dht_bytes_out
|
|
||||||
// remove them
|
|
||||||
sent_dht_bytes,
|
|
||||||
recv_dht_bytes,
|
|
||||||
|
|
||||||
// uTP counters.
|
// uTP counters.
|
||||||
utp_packet_loss,
|
utp_packet_loss,
|
||||||
utp_timeout,
|
utp_timeout,
|
||||||
|
|
|
@ -89,21 +89,6 @@ namespace libtorrent { namespace dht
|
||||||
int g_failed_announces = 0;
|
int g_failed_announces = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void intrusive_ptr_add_ref(dht_tracker const* c)
|
|
||||||
{
|
|
||||||
TORRENT_ASSERT(c != 0);
|
|
||||||
TORRENT_ASSERT(c->m_refs >= 0);
|
|
||||||
++c->m_refs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void intrusive_ptr_release(dht_tracker const* c)
|
|
||||||
{
|
|
||||||
TORRENT_ASSERT(c != 0);
|
|
||||||
TORRENT_ASSERT(c->m_refs > 0);
|
|
||||||
if (--c->m_refs == 0)
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
std::string parse_dht_client(lazy_entry const& e)
|
std::string parse_dht_client(lazy_entry const& e)
|
||||||
{
|
{
|
||||||
|
@ -190,9 +175,6 @@ namespace libtorrent { namespace dht
|
||||||
, m_refresh_bucket(160)
|
, m_refresh_bucket(160)
|
||||||
, m_abort(false)
|
, m_abort(false)
|
||||||
, m_host_resolver(sock.get_io_service())
|
, m_host_resolver(sock.get_io_service())
|
||||||
, m_sent_bytes(0)
|
|
||||||
, m_received_bytes(0)
|
|
||||||
, m_refs(0)
|
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
m_counter = 0;
|
m_counter = 0;
|
||||||
|
@ -272,14 +254,6 @@ namespace libtorrent { namespace dht
|
||||||
m_dht.status(table, requests);
|
m_dht.status(table, requests);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dht_tracker::network_stats(int& sent, int& received)
|
|
||||||
{
|
|
||||||
sent = m_sent_bytes;
|
|
||||||
received = m_received_bytes;
|
|
||||||
m_sent_bytes = 0;
|
|
||||||
m_received_bytes = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dht_tracker::connection_timeout(error_code const& e)
|
void dht_tracker::connection_timeout(error_code const& e)
|
||||||
{
|
{
|
||||||
if (e || m_abort) return;
|
if (e || m_abort) return;
|
||||||
|
@ -325,6 +299,8 @@ namespace libtorrent { namespace dht
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
|
// TODO: 3 move all this out of libtorrent. It can be done in libtorrent-webui
|
||||||
|
// just like session_stats
|
||||||
static bool first = true;
|
static bool first = true;
|
||||||
|
|
||||||
std::ofstream st("dht_routing_table_state.txt", std::ios_base::trunc);
|
std::ofstream st("dht_routing_table_state.txt", std::ios_base::trunc);
|
||||||
|
@ -511,8 +487,11 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
if (size <= 20 || *buf != 'd' || buf[size-1] != 'e') return false;
|
if (size <= 20 || *buf != 'd' || buf[size-1] != 'e') return false;
|
||||||
|
|
||||||
|
m_counters.inc_stats_counter(counters::dht_bytes_in, size);
|
||||||
// account for IP and UDP overhead
|
// account for IP and UDP overhead
|
||||||
m_received_bytes += size + (ep.address().is_v6() ? 48 : 28);
|
m_counters.inc_stats_counter(counters::recv_ip_overhead_bytes
|
||||||
|
, ep.address().is_v6() ? 48 : 28);
|
||||||
|
m_counters.inc_stats_counter(counters::dht_messages_in);
|
||||||
|
|
||||||
if (m_settings.ignore_dark_internet && ep.address().is_v4())
|
if (m_settings.ignore_dark_internet && ep.address().is_v4())
|
||||||
{
|
{
|
||||||
|
@ -535,8 +514,6 @@ namespace libtorrent { namespace dht
|
||||||
++m_total_message_input;
|
++m_total_message_input;
|
||||||
m_total_in_bytes += size;
|
m_total_in_bytes += size;
|
||||||
#endif
|
#endif
|
||||||
m_counters.inc_stats_counter(counters::dht_bytes_in, size);
|
|
||||||
m_counters.inc_stats_counter(counters::dht_messages_in);
|
|
||||||
|
|
||||||
using libtorrent::entry;
|
using libtorrent::entry;
|
||||||
using libtorrent::bdecode;
|
using libtorrent::bdecode;
|
||||||
|
@ -692,10 +669,10 @@ namespace libtorrent { namespace dht
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// account for IP and UDP overhead
|
|
||||||
m_sent_bytes += m_send_buf.size() + (addr.address().is_v6() ? 48 : 28);
|
|
||||||
|
|
||||||
m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size());
|
m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size());
|
||||||
|
// account for IP and UDP overhead
|
||||||
|
m_counters.inc_stats_counter(counters::sent_ip_overhead_bytes
|
||||||
|
, addr.address().is_v6() ? 48 : 28);
|
||||||
m_counters.inc_stats_counter(counters::dht_messages_out);
|
m_counters.inc_stats_counter(counters::dht_messages_out);
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
m_total_out_bytes += m_send_buf.size();
|
m_total_out_bytes += m_send_buf.size();
|
||||||
|
|
|
@ -3007,27 +3007,9 @@ retry:
|
||||||
if (!t.want_tick()) --i;
|
if (!t.want_tick()) --i;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
|
||||||
int dht_down = 0;
|
|
||||||
int dht_up = 0;
|
|
||||||
if (m_dht)
|
|
||||||
{
|
|
||||||
m_dht->network_stats(dht_up, dht_down);
|
|
||||||
m_stats_counters.inc_stats_counter(counters::sent_dht_bytes, dht_up);
|
|
||||||
m_stats_counters.inc_stats_counter(counters::recv_dht_bytes, dht_down);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: this should apply to all bandwidth channels
|
// TODO: this should apply to all bandwidth channels
|
||||||
if (m_settings.get_bool(settings_pack::rate_limit_ip_overhead))
|
if (m_settings.get_bool(settings_pack::rate_limit_ip_overhead))
|
||||||
{
|
{
|
||||||
peer_class* gpc = m_classes.at(m_global_class);
|
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
|
||||||
gpc->channel[peer_connection::download_channel].use_quota(dht_down);
|
|
||||||
gpc->channel[peer_connection::upload_channel].use_quota(dht_up);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int up_limit = upload_rate_limit(m_global_class);
|
int up_limit = upload_rate_limit(m_global_class);
|
||||||
int down_limit = download_rate_limit(m_global_class);
|
int down_limit = download_rate_limit(m_global_class);
|
||||||
|
|
||||||
|
@ -5309,8 +5291,8 @@ retry:
|
||||||
s.total_tracker_upload = m_stats_counters[counters::sent_tracker_bytes];
|
s.total_tracker_upload = m_stats_counters[counters::sent_tracker_bytes];
|
||||||
|
|
||||||
// dht
|
// dht
|
||||||
s.total_dht_download = m_stats_counters[counters::recv_dht_bytes];
|
s.total_dht_download = m_stats_counters[counters::dht_bytes_in];
|
||||||
s.total_dht_upload = m_stats_counters[counters::sent_dht_bytes];
|
s.total_dht_upload = m_stats_counters[counters::dht_bytes_out];
|
||||||
|
|
||||||
// deprecated
|
// deprecated
|
||||||
s.tracker_download_rate = 0;
|
s.tracker_download_rate = 0;
|
||||||
|
@ -5383,7 +5365,9 @@ retry:
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
stop_dht();
|
stop_dht();
|
||||||
m_dht = new dht::dht_tracker(*this, m_udp_socket, m_dht_settings, m_stats_counters, &startup_state);
|
m_dht = boost::make_shared<dht::dht_tracker>(boost::ref(*this)
|
||||||
|
, boost::ref(m_udp_socket), boost::cref(m_dht_settings)
|
||||||
|
, boost::ref(m_stats_counters), &startup_state);
|
||||||
|
|
||||||
for (std::list<udp::endpoint>::iterator i = m_dht_router_nodes.begin()
|
for (std::list<udp::endpoint>::iterator i = m_dht_router_nodes.begin()
|
||||||
, end(m_dht_router_nodes.end()); i != end; ++i)
|
, end(m_dht_router_nodes.end()); i != end; ++i)
|
||||||
|
@ -5401,7 +5385,7 @@ retry:
|
||||||
if (!m_dht) return;
|
if (!m_dht) return;
|
||||||
m_udp_socket.unsubscribe(m_dht.get());
|
m_udp_socket.unsubscribe(m_dht.get());
|
||||||
m_dht->stop();
|
m_dht->stop();
|
||||||
m_dht = 0;
|
m_dht.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_impl::set_dht_settings(dht_settings const& settings)
|
void session_impl::set_dht_settings(dht_settings const& settings)
|
||||||
|
|
|
@ -439,10 +439,6 @@ namespace libtorrent
|
||||||
METRIC(dht, dht_put_in)
|
METRIC(dht, dht_put_in)
|
||||||
METRIC(dht, dht_put_out)
|
METRIC(dht, dht_put_out)
|
||||||
|
|
||||||
// the number of bytes sent and received by the DHT
|
|
||||||
METRIC(dht, sent_dht_bytes)
|
|
||||||
METRIC(dht, recv_dht_bytes)
|
|
||||||
|
|
||||||
// uTP counters. Each counter represents the number of time each event
|
// uTP counters. Each counter represents the number of time each event
|
||||||
// has occurred.
|
// has occurred.
|
||||||
METRIC(utp, utp_packet_loss)
|
METRIC(utp, utp_packet_loss)
|
||||||
|
|
Loading…
Reference in New Issue