added more bandwidth monitoring of DHT and TCP/IP overhead. added monitoring of the running DHT lookups

This commit is contained in:
Arvid Norberg
2008-09-20 17:42:25 +00:00
parent 98f9d5826c
commit 0338510b9b
22 changed files with 472 additions and 274 deletions

View File

@@ -83,6 +83,7 @@ namespace libtorrent {
progress_notification = 0x80,
ip_block_notification = 0x100,
performance_warning = 0x200,
dht_notification = 0x400,
all_categories = 0xffffffff
};

View File

@@ -1122,6 +1122,54 @@ namespace libtorrent
return "blocked peer: " + ip.to_string(ec);
}
};
struct TORRENT_EXPORT dht_announce_alert: alert
{
dht_announce_alert(address const& ip_, int port_
, sha1_hash const& info_hash_)
: ip(ip_)
, port(port_)
, info_hash(info_hash_)
{}
address ip;
int port;
sha1_hash info_hash;
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new dht_announce_alert(*this)); }
virtual char const* what() const { return "incoming dht announce"; }
const static int static_category = alert::dht_notification;
virtual int category() const { return static_category; }
virtual std::string message() const
{
error_code ec;
return "incoming dht annonce: " + ip.to_string(ec) + ":"
+ boost::lexical_cast<std::string>(port) + " ("
+ boost::lexical_cast<std::string>(info_hash) + ")";
}
};
struct TORRENT_EXPORT dht_get_peers_alert: alert
{
dht_get_peers_alert(sha1_hash const& info_hash_)
: info_hash(info_hash_)
{}
sha1_hash info_hash;
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new dht_get_peers_alert(*this)); }
virtual char const* what() const { return "incoming dht get_peers request"; }
const static int static_category = alert::dht_notification;
virtual int category() const { return static_category; }
virtual std::string message() const
{
error_code ec;
return "incoming dht get_peers: "
+ boost::lexical_cast<std::string>(info_hash);
}
};
}

View File

@@ -57,28 +57,18 @@ public:
void(std::vector<node_entry> const&)
> done_callback;
static void initiate(
node_id target
, int branch_factor
, int max_results
, routing_table& table
, rpc_manager& rpc
closest_nodes(
node_impl& node
, node_id target
, done_callback const& callback
);
virtual char const* name() const { return "closest nodes"; }
private:
void done();
void invoke(node_id const& id, udp::endpoint addr);
closest_nodes(
node_id target
, int branch_factor
, int max_results
, routing_table& table
, rpc_manager& rpc
, done_callback const& callback
);
done_callback m_done_callback;
};

View File

@@ -55,6 +55,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/udp_socket.hpp"
#include "libtorrent/socket.hpp"
namespace libtorrent { namespace aux { struct session_impl; } }
namespace libtorrent { namespace dht
{
@@ -71,7 +73,8 @@ namespace libtorrent { namespace dht
{
friend void intrusive_ptr_add_ref(dht_tracker const*);
friend void intrusive_ptr_release(dht_tracker const*);
dht_tracker(udp_socket& sock, dht_settings const& settings);
dht_tracker(libtorrent::aux::session_impl& ses, udp_socket& sock
, dht_settings const& settings);
void start(entry const& bootstrap);
void stop();
@@ -110,6 +113,7 @@ namespace libtorrent { namespace dht
void send_packet(msg const& m);
node_impl m_dht;
libtorrent::aux::session_impl& m_ses;
udp_socket& m_sock;
std::vector<char> m_send_buf;

View File

@@ -51,6 +51,7 @@ namespace libtorrent { namespace dht
typedef std::vector<char> packet_t;
class rpc_manager;
class node_impl;
// -------- find data -----------
@@ -59,30 +60,18 @@ class find_data : public traversal_algorithm
public:
typedef boost::function<void(msg const*)> done_callback;
static void initiate(
node_id target
, int branch_factor
, int max_results
, routing_table& table
, rpc_manager& rpc
, done_callback const& callback
);
void got_data(msg const* m);
find_data(node_impl& node, node_id target
, done_callback const& callback);
virtual char const* name() const { return "get_peers"; }
private:
void done();
void invoke(node_id const& id, udp::endpoint addr);
find_data(
node_id target
, int branch_factor
, int max_results
, routing_table& table
, rpc_manager& rpc
, done_callback const& callback
);
done_callback m_done_callback;
boost::shared_ptr<packet_t> m_packet;
bool m_done;

View File

@@ -53,6 +53,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
namespace libtorrent {
namespace aux { struct session_impl; }
struct session_status;
}
namespace libtorrent { namespace dht
{
@@ -60,6 +67,8 @@ namespace libtorrent { namespace dht
TORRENT_DECLARE_LOG(node);
#endif
struct traversal_algorithm;
// this is the entry for every peer
// the timestamp is there to make it possible
// to remove stale peers
@@ -154,13 +163,11 @@ private:
boost::function<void(std::vector<tcp::endpoint> const&, sha1_hash const&)> m_fun;
};
class node_impl : boost::noncopyable
{
typedef std::map<node_id, torrent_entry> table_t;
public:
node_impl(boost::function<void(msg const&)> const& f
node_impl(libtorrent::aux::session_impl& ses, boost::function<void(msg const&)> const& f
, dht_settings const& settings);
virtual ~node_impl() {}
@@ -225,6 +232,16 @@ public:
void replacement_cache(bucket_t& nodes) const
{ m_table.replacement_cache(nodes); }
int branch_factor() const { return m_settings.search_branching; }
void add_traversal_algorithm(traversal_algorithm* a)
{ m_running_requests.insert(a); }
void remove_traversal_algorithm(traversal_algorithm* a)
{ m_running_requests.erase(a); }
void status(libtorrent::session_status& s);
protected:
// is called when a find data request is received. Should
// return false if the data is not stored on this node. If
@@ -243,17 +260,27 @@ protected:
int m_max_peers_reply;
private:
// this list must be destructed after the rpc manager
// since it might have references to it
std::set<traversal_algorithm*> m_running_requests;
void incoming_request(msg const& h);
node_id m_id;
public:
routing_table m_table;
rpc_manager m_rpc;
private:
table_t m_map;
ptime m_last_tracker_tick;
// secret random numbers used to create write tokens
int m_secret[2];
libtorrent::aux::session_impl& m_ses;
};

View File

@@ -57,35 +57,16 @@ class refresh : public traversal_algorithm
public:
typedef boost::function<void()> done_callback;
template<class InIt>
static void initiate(
node_id target
, int branch_factor
, int max_active_pings
, int max_results
, routing_table& table
, InIt first
, InIt last
, rpc_manager& rpc
, done_callback const& callback
);
void ping_reply(node_id id);
void ping_timeout(node_id id, bool prevent_request = false);
private:
template<class InIt>
refresh(
node_id target
, int branch_factor
, int max_active_pings
, int max_results
, routing_table& table
, InIt first
, InIt last
, rpc_manager& rpc
, done_callback const& callback
);
refresh(node_impl& node, node_id target, InIt first, InIt last
, done_callback const& callback);
virtual char const* name() const { return "refresh"; }
private:
void done();
void invoke(node_id const& id, udp::endpoint addr);
@@ -155,26 +136,13 @@ private:
template<class InIt>
inline refresh::refresh(
node_id target
, int branch_factor
, int max_active_pings
, int max_results
, routing_table& table
node_impl& node
, node_id target
, InIt first
, InIt last
, rpc_manager& rpc
, done_callback const& callback
)
: traversal_algorithm(
target
, branch_factor
, max_results
, table
, rpc
, first
, last
)
, m_max_active_pings(max_active_pings)
, done_callback const& callback)
: traversal_algorithm(node, target, first, last)
, m_max_active_pings(10)
, m_active_pings(0)
, m_done_callback(callback)
{
@@ -182,32 +150,6 @@ inline refresh::refresh(
add_requests();
}
template<class InIt>
inline void refresh::initiate(
node_id target
, int branch_factor
, int max_active_pings
, int max_results
, routing_table& table
, InIt first
, InIt last
, rpc_manager& rpc
, done_callback const& callback
)
{
new refresh(
target
, branch_factor
, max_active_pings
, max_results
, table
, first
, last
, rpc
, callback
);
}
} } // namespace libtorrent::dht
#endif // REFRESH_050324_HPP

View File

@@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/bind.hpp>
#include <boost/pool/pool.hpp>
namespace libtorrent { struct dht_lookup; }
namespace libtorrent { namespace dht
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
@@ -52,6 +53,7 @@ TORRENT_DECLARE_LOG(traversal);
#endif
class rpc_manager;
class node_impl;
// this class may not be instantiated as a stack object
class traversal_algorithm : boost::noncopyable
@@ -60,23 +62,21 @@ public:
void traverse(node_id const& id, udp::endpoint addr);
void finished(node_id const& id);
void failed(node_id const& id, bool prevent_request = false);
virtual ~traversal_algorithm() {}
virtual ~traversal_algorithm();
boost::pool<>& allocator() const;
void status(dht_lookup& l);
virtual char const* name() const { return "traversal_algorithm"; }
protected:
template<class InIt>
traversal_algorithm(
node_id target
, int branch_factor
, int max_results
, routing_table& table
, rpc_manager& rpc
, InIt start
, InIt end
);
traversal_algorithm(node_impl& node, node_id target, InIt start, InIt end);
void add_requests();
void add_entry(node_id const& id, udp::endpoint addr, unsigned char flags);
void add_router_entries();
void init();
virtual void done() = 0;
virtual void invoke(node_id const& id, udp::endpoint addr) = 0;
@@ -107,33 +107,29 @@ protected:
int m_ref_count;
node_impl& m_node;
node_id m_target;
int m_branch_factor;
int m_max_results;
std::vector<result> m_results;
std::set<udp::endpoint> m_failed;
routing_table& m_table;
rpc_manager& m_rpc;
int m_invoke_count;
int m_branch_factor;
int m_responses;
int m_timeouts;
};
template<class InIt>
traversal_algorithm::traversal_algorithm(
node_id target
, int branch_factor
, int max_results
, routing_table& table
, rpc_manager& rpc
node_impl& node
, node_id target
, InIt start // <- nodes to initiate traversal with
, InIt end
)
, InIt end)
: m_ref_count(0)
, m_node(node)
, m_target(target)
, m_branch_factor(branch_factor)
, m_max_results(max_results)
, m_table(table)
, m_rpc(rpc)
, m_invoke_count(0)
, m_branch_factor(3)
, m_responses(0)
, m_timeouts(0)
{
using boost::bind;
@@ -144,15 +140,8 @@ traversal_algorithm::traversal_algorithm(
// in case the routing table is empty, use the
// router nodes in the table
if (start == end)
{
for (routing_table::router_iterator i = table.router_begin()
, end(table.router_end()); i != end; ++i)
{
add_entry(node_id(0), *i, result::initial);
}
}
if (start == end) add_router_entries();
init();
}
} } // namespace libtorrent::dht

View File

@@ -37,22 +37,43 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
#ifndef TORRENT_DISABLE_DHT
struct dht_lookup
{
char const* type;
int outstanding_requests;
int timeouts;
int responses;
int branch_factor;
};
#endif
struct TORRENT_EXPORT session_status
{
bool has_incoming_connections;
float upload_rate;
float download_rate;
float payload_upload_rate;
float payload_download_rate;
size_type total_download;
size_type total_upload;
float payload_upload_rate;
float payload_download_rate;
size_type total_payload_download;
size_type total_payload_upload;
float ip_overhead_upload_rate;
float ip_overhead_download_rate;
size_type total_ip_overhead_download;
size_type total_ip_overhead_upload;
float dht_upload_rate;
float dht_download_rate;
size_type total_dht_download;
size_type total_dht_upload;
size_type total_redundant_bytes;
size_type total_failed_bytes;
@@ -68,6 +89,7 @@ namespace libtorrent
int dht_node_cache;
int dht_torrents;
size_type dht_global_nodes;
std::vector<dht_lookup> active_requests;
#endif
};

View File

@@ -122,6 +122,18 @@ namespace libtorrent
m_stat[i] += s.m_stat[i];
}
void received_dht_bytes(int bytes)
{
TORRENT_ASSERT(bytes >= 0);
m_stat[download_dht_protocol].add(bytes);
}
void sent_dht_bytes(int bytes)
{
TORRENT_ASSERT(bytes >= 0);
m_stat[upload_dht_protocol].add(bytes);
}
void received_bytes(int bytes_payload, int bytes_protocol)
{
TORRENT_ASSERT(bytes_payload >= 0);
@@ -162,6 +174,8 @@ namespace libtorrent
int upload_ip_overhead() const { return m_stat[upload_ip_protocol].counter(); }
int download_ip_overhead() const { return m_stat[download_ip_protocol].counter(); }
int upload_dht() const { return m_stat[upload_dht_protocol].counter(); }
int download_dht() const { return m_stat[download_dht_protocol].counter(); }
// should be called once every second
void second_tick(float tick_interval)
@@ -174,7 +188,8 @@ namespace libtorrent
{
return (m_stat[upload_payload].rate_sum()
+ m_stat[upload_protocol].rate_sum()
+ m_stat[upload_ip_protocol].rate_sum())
+ m_stat[upload_ip_protocol].rate_sum()
+ m_stat[upload_dht_protocol].rate_sum())
/ float(stat_channel::history);
}
@@ -182,13 +197,29 @@ namespace libtorrent
{
return (m_stat[download_payload].rate_sum()
+ m_stat[download_protocol].rate_sum()
+ m_stat[download_ip_protocol].rate_sum())
+ m_stat[download_ip_protocol].rate_sum()
+ m_stat[download_dht_protocol].rate_sum())
/ float(stat_channel::history);
}
size_type total_upload() const
{
return m_stat[upload_payload].total()
+ m_stat[upload_protocol].total()
+ m_stat[upload_ip_protocol].total()
+ m_stat[upload_dht_protocol].total();
}
size_type total_download() const
{
return m_stat[download_payload].total()
+ m_stat[download_protocol].total()
+ m_stat[download_ip_protocol].total()
+ m_stat[download_dht_protocol].total();
}
float upload_payload_rate() const
{ return m_stat[upload_payload].rate(); }
float download_payload_rate() const
{ return m_stat[download_payload].rate(); }
@@ -202,6 +233,11 @@ namespace libtorrent
size_type total_protocol_download() const
{ return m_stat[download_protocol].total(); }
size_type total_transfer(int channel) const
{ return m_stat[channel].total(); }
float transfer_rate(int channel) const
{ return m_stat[channel].rate(); }
// this is used to offset the statistics when a
// peer_connection is opened and have some previous
// transfers from earlier connections.
@@ -218,20 +254,22 @@ namespace libtorrent
size_type last_payload_uploaded() const
{ return m_stat[upload_payload].counter(); }
private:
// these are the channels we keep stats for
enum
{
upload_payload,
upload_protocol,
upload_ip_protocol,
upload_dht_protocol,
download_payload,
download_protocol,
download_ip_protocol,
download_dht_protocol,
num_channels
};
private:
stat_channel m_stat[num_channels];
};

View File

@@ -230,6 +230,8 @@ namespace libtorrent
bool is_auto_managed() const { return m_auto_managed; }
void auto_managed(bool a);
bool should_check_files() const;
void delete_files();
// ============ start deprecation =============