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:
Arvid Norberg 2015-01-17 22:06:30 +00:00
parent 58d93e5aa1
commit 22a02f4a1f
6 changed files with 24 additions and 87 deletions

View File

@ -973,7 +973,7 @@ namespace libtorrent
mutable int m_next_port;
#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;
// these are used when starting the DHT

View File

@ -40,8 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <numeric>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/detail/atomic_count.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include "libtorrent/kademlia/node.hpp"
#include "libtorrent/kademlia/node_id.hpp"
@ -73,15 +72,11 @@ namespace libtorrent { namespace dht
struct dht_tracker;
// TODO: 3 remove these
TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(dht_tracker const*);
TORRENT_EXTRA_EXPORT void intrusive_ptr_release(dht_tracker const*);
struct dht_tracker : udp_socket_interface, udp_socket_observer
struct dht_tracker
: udp_socket_interface
, udp_socket_observer
, boost::enable_shared_from_this<dht_tracker>
{
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_settings const& settings, counters& cnt, entry const* state = 0);
virtual ~dht_tracker();
@ -121,8 +116,6 @@ namespace libtorrent { namespace dht
void dht_status(std::vector<dht_routing_bucket>& table
, std::vector<dht_lookup>& requests);
void network_stats(int& sent, int& received);
// translate bittorrent kademlia message into the generic kademlia message
// used by the library
virtual bool incoming_packet(error_code const& ec
@ -130,8 +123,8 @@ namespace libtorrent { namespace dht
private:
boost::intrusive_ptr<dht_tracker> self()
{ return boost::intrusive_ptr<dht_tracker>(this); }
boost::shared_ptr<dht_tracker> self()
{ return shared_from_this(); }
void on_name_lookup(error_code const& e
, udp::resolver::iterator host);
@ -165,14 +158,6 @@ namespace libtorrent { namespace dht
// used to resolve hostnames for nodes
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
int m_replies_sent[5];
int m_queries_received[5];

View File

@ -228,11 +228,6 @@ namespace libtorrent
dht_put_in,
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_packet_loss,
utp_timeout,

View File

@ -89,21 +89,6 @@ namespace libtorrent { namespace dht
int g_failed_announces = 0;
#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
std::string parse_dht_client(lazy_entry const& e)
{
@ -190,9 +175,6 @@ namespace libtorrent { namespace dht
, m_refresh_bucket(160)
, m_abort(false)
, m_host_resolver(sock.get_io_service())
, m_sent_bytes(0)
, m_received_bytes(0)
, m_refs(0)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
m_counter = 0;
@ -272,14 +254,6 @@ namespace libtorrent { namespace dht
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)
{
if (e || m_abort) return;
@ -325,6 +299,8 @@ namespace libtorrent { namespace dht
}
#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;
std::ofstream st("dht_routing_table_state.txt", std::ios_base::trunc);
@ -511,9 +487,12 @@ namespace libtorrent { namespace dht
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
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())
{
address_v4::bytes_type b = ep.address().to_v4().to_bytes();
@ -535,8 +514,6 @@ namespace libtorrent { namespace dht
++m_total_message_input;
m_total_in_bytes += size;
#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::bdecode;
@ -692,10 +669,10 @@ namespace libtorrent { namespace dht
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());
// 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);
#ifdef TORRENT_DHT_VERBOSE_LOGGING
m_total_out_bytes += m_send_buf.size();

View File

@ -3007,27 +3007,9 @@ retry:
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
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 down_limit = download_rate_limit(m_global_class);
@ -5309,8 +5291,8 @@ retry:
s.total_tracker_upload = m_stats_counters[counters::sent_tracker_bytes];
// dht
s.total_dht_download = m_stats_counters[counters::recv_dht_bytes];
s.total_dht_upload = m_stats_counters[counters::sent_dht_bytes];
s.total_dht_download = m_stats_counters[counters::dht_bytes_in];
s.total_dht_upload = m_stats_counters[counters::dht_bytes_out];
// deprecated
s.tracker_download_rate = 0;
@ -5383,7 +5365,9 @@ retry:
INVARIANT_CHECK;
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()
, end(m_dht_router_nodes.end()); i != end; ++i)
@ -5401,7 +5385,7 @@ retry:
if (!m_dht) return;
m_udp_socket.unsubscribe(m_dht.get());
m_dht->stop();
m_dht = 0;
m_dht.reset();
}
void session_impl::set_dht_settings(dht_settings const& settings)

View File

@ -439,10 +439,6 @@ namespace libtorrent
METRIC(dht, dht_put_in)
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
// has occurred.
METRIC(utp, utp_packet_loss)