forked from premiere/premiere-libtorrent
don't use iostream in dht routing table debug logging
This commit is contained in:
parent
202b4921b6
commit
ddfef97696
|
@ -48,7 +48,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// returns true if a different IP is the top vote now
|
// returns true if a different IP is the top vote now
|
||||||
// i.e. we changed our idea of what our external IP is
|
// i.e. we changed our idea of what our external IP is
|
||||||
bool cast_vote(address const& ip, int source_type, address const& sorce);
|
bool cast_vote(address const& ip, int source_type, address const& source);
|
||||||
|
|
||||||
address external_address() const { return m_external_address; }
|
address external_address() const { return m_external_address; }
|
||||||
|
|
||||||
|
|
|
@ -266,6 +266,11 @@ namespace libtorrent { namespace dht
|
||||||
TORRENT_LOG(dht_tracker) << " *** new write key";
|
TORRENT_LOG(dht_tracker) << " *** new write key";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
|
std::ofstream st("dht_routing_table_state.txt", std::ios_base::trunc);
|
||||||
|
m_dht.print_state(st);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dht_tracker::announce(sha1_hash const& ih, int listen_port, int flags
|
void dht_tracker::announce(sha1_hash const& ih, int listen_port, int flags
|
||||||
|
|
|
@ -47,6 +47,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "libtorrent/invariant_check.hpp"
|
#include "libtorrent/invariant_check.hpp"
|
||||||
|
|
||||||
|
#if (defined TORRENT_DHT_VERBOSE_LOGGING || defined TORRENT_DEBUG) && TORRENT_USE_IOSTREAM
|
||||||
|
#include "libtorrent/socket_io.hpp" // for print_endpoint
|
||||||
|
#endif
|
||||||
|
|
||||||
using boost::uint8_t;
|
using boost::uint8_t;
|
||||||
|
|
||||||
#if BOOST_VERSION <= 104700
|
#if BOOST_VERSION <= 104700
|
||||||
|
@ -195,36 +199,50 @@ int routing_table::depth() const
|
||||||
|
|
||||||
void routing_table::print_state(std::ostream& os) const
|
void routing_table::print_state(std::ostream& os) const
|
||||||
{
|
{
|
||||||
os << "kademlia routing table state\n"
|
std::vector<char> buf(2048);
|
||||||
<< "bucket_size: " << m_bucket_size << "\n"
|
int cursor = 0;
|
||||||
<< "global node count: " << num_global_nodes() << "\n"
|
|
||||||
<< "node_id: " << m_id << "\n\n";
|
|
||||||
|
|
||||||
os << "number of nodes per bucket:\n";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, "kademlia routing table state\n"
|
||||||
|
"bucket_size: %d\n"
|
||||||
|
"global node count: %" PRId64 "\n"
|
||||||
|
"node_id: %s\n\n"
|
||||||
|
"number of nodes per bucket:\n"
|
||||||
|
, m_bucket_size
|
||||||
|
, num_global_nodes()
|
||||||
|
, to_hex(m_id.to_string()).c_str());
|
||||||
|
if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2);
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
for (table_t::const_iterator i = m_buckets.begin(), end(m_buckets.end());
|
for (table_t::const_iterator i = m_buckets.begin(), end(m_buckets.end());
|
||||||
i != end; ++i, ++idx)
|
i != end; ++i, ++idx)
|
||||||
{
|
{
|
||||||
os << std::setw(2) << idx << ": ";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, "%2d: ", idx);
|
||||||
for (int k = 0; k < int(i->live_nodes.size()); ++k)
|
for (int k = 0; k < int(i->live_nodes.size()); ++k)
|
||||||
os << "#";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor, "#");
|
||||||
for (int k = 0; k < int(i->replacements.size()); ++k)
|
for (int k = 0; k < int(i->replacements.size()); ++k)
|
||||||
os << "-";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor, "-");
|
||||||
os << "\n";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor, "\n");
|
||||||
|
|
||||||
|
if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_point now = aux::time_now();
|
time_point now = aux::time_now();
|
||||||
|
|
||||||
os << "\nnodes:";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, "\nnodes:");
|
||||||
|
|
||||||
int bucket_index = 0;
|
int bucket_index = 0;
|
||||||
for (table_t::const_iterator i = m_buckets.begin(), end(m_buckets.end());
|
for (table_t::const_iterator i = m_buckets.begin(), end(m_buckets.end());
|
||||||
i != end; ++i, ++bucket_index)
|
i != end; ++i, ++bucket_index)
|
||||||
{
|
{
|
||||||
os << "\n=== BUCKET == " << bucket_index
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
<< " == " << i->live_nodes.size() << "|" << i->replacements.size()
|
, "\n=== BUCKET == %d == %d|%d ==== \n"
|
||||||
<< " ===== \n";
|
, bucket_index, int(i->live_nodes.size())
|
||||||
|
, int(i->replacements.size()));
|
||||||
|
if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2);
|
||||||
|
|
||||||
int id_shift;
|
int id_shift;
|
||||||
// the last bucket is special, since it hasn't been split yet, it
|
// the last bucket is special, since it hasn't been split yet, it
|
||||||
|
@ -251,28 +269,47 @@ void routing_table::print_state(std::ostream& os) const
|
||||||
node_id id = j->id;
|
node_id id = j->id;
|
||||||
id <<= id_shift;
|
id <<= id_shift;
|
||||||
|
|
||||||
os << " prefx: " << std::setw(2) << std::hex << ((id[0] & top_mask) >> mask_shift) << std::dec
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
<< " id: " << j->id;
|
, " prefix: %2x id: %s"
|
||||||
if (j->rtt == 0xffff)
|
, ((id[0] & top_mask) >> mask_shift)
|
||||||
os << " rtt: ";
|
, to_hex(j->id.to_string()).c_str());
|
||||||
else
|
|
||||||
os << " rtt: " << std::setw(4) << j->rtt;
|
|
||||||
|
|
||||||
os << " fail: " << j->fail_count()
|
if (j->rtt == 0xffff)
|
||||||
<< " ping: " << j->pinged()
|
{
|
||||||
<< " dist: " << std::setw(3) << distance_exp(m_id, j->id);
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, " rtt: ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, " rtt: %4d", j->rtt);
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, " fail: %4d ping: %d dist: %3d"
|
||||||
|
, j->fail_count()
|
||||||
|
, j->pinged()
|
||||||
|
, distance_exp(m_id, j->id));
|
||||||
|
|
||||||
if (j->last_queried == min_time())
|
if (j->last_queried == min_time())
|
||||||
os << " query: ";
|
{
|
||||||
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, " query: ");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
os << " query: " << std::setw(3) << total_seconds(now - j->last_queried);
|
{
|
||||||
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, " query: %3d", int(total_seconds(now - j->last_queried)));
|
||||||
|
}
|
||||||
|
|
||||||
os << " ip: " << j->ep()
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
<< "\n";
|
, " ip: %s\n", print_endpoint(j->ep()).c_str());
|
||||||
|
if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
os << "\nnode spread per bucket:\n";
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, "\nnode spread per bucket:\n");
|
||||||
bucket_index = 0;
|
bucket_index = 0;
|
||||||
for (table_t::const_iterator i = m_buckets.begin(), end(m_buckets.end());
|
for (table_t::const_iterator i = m_buckets.begin(), end(m_buckets.end());
|
||||||
i != end; ++i, ++bucket_index)
|
i != end; ++i, ++bucket_index)
|
||||||
|
@ -316,12 +353,20 @@ void routing_table::print_state(std::ostream& os) const
|
||||||
sub_buckets[b] = true;
|
sub_buckets[b] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << std::dec << std::setw(2) << bucket_index << " mask: " << std::setw(2)
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
<< std::hex << (top_mask >> mask_shift) << ": [";
|
, "%2d mask: %2x: [", bucket_index, (top_mask >> mask_shift));
|
||||||
|
|
||||||
for (int i = 0; i < bucket_size_limit; ++i) os << (sub_buckets[i] ? "X" : " ");
|
for (int i = 0; i < bucket_size_limit; ++i)
|
||||||
os << "]\n";
|
{
|
||||||
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, (sub_buckets[i] ? "X" : " "));
|
||||||
|
}
|
||||||
|
cursor += snprintf(&buf[cursor], buf.size() - cursor
|
||||||
|
, "]\n");
|
||||||
|
if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2);
|
||||||
}
|
}
|
||||||
|
buf[cursor] = '\0';
|
||||||
|
os << &buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue