fix bug in DHT logging. clean up some whitespace

This commit is contained in:
Arvid Norberg 2015-05-17 02:00:43 +00:00
parent 58ae099cf8
commit c871610408
2 changed files with 60 additions and 55 deletions

View File

@ -1176,7 +1176,7 @@ namespace libtorrent {
snprintf(msg, sizeof(msg), " ERROR: %s", convert_from_native(error.message()).c_str());
return torrent_alert::message() + msg;
}
torrent_added_alert::torrent_added_alert(aux::stack_allocator& alloc
, torrent_handle const& h)
: torrent_alert(alloc, h)
@ -1213,7 +1213,7 @@ namespace libtorrent {
: socket_type(t)
, ip(i)
{}
std::string incoming_connection_alert::message() const
{
char msg[600];
@ -1244,7 +1244,7 @@ namespace libtorrent {
, params(p)
, error(ec)
{}
std::string add_torrent_alert::message() const
{
char msg[600];
@ -1348,7 +1348,7 @@ namespace libtorrent {
, old_ih(old_hash)
, new_ih(new_hash)
{}
std::string torrent_update_alert::message() const
{
char msg[200];
@ -1364,7 +1364,7 @@ namespace libtorrent {
: handle(h)
, item(item)
{}
std::string rss_item_alert::message() const
{
char msg[500];
@ -1406,7 +1406,7 @@ namespace libtorrent {
, error_code const& ec)
: error(ec), operation(op_t(op))
{}
std::string dht_error_alert::message() const
{
static const char* const operation_names[] =
@ -1431,7 +1431,7 @@ namespace libtorrent {
, sha1_hash const& t, entry const& i)
: target(t), item(i)
{}
std::string dht_immutable_item_alert::message() const
{
char msg[1050];
@ -1694,7 +1694,7 @@ namespace libtorrent {
+ (operation?operation:"") + " (" + filename()
+ ") error: " + convert_from_native(error.message());
}
incoming_request_alert::incoming_request_alert(aux::stack_allocator& alloc
, peer_request r, torrent_handle h
, tcp::endpoint const& ep, peer_id const& peer_id)
@ -1734,7 +1734,7 @@ namespace libtorrent {
};
char ret[900];
snprintf(ret, sizeof(ret), "%s: %s", dht_modules[module]
snprintf(ret, sizeof(ret), "DHT %s: %s", dht_modules[module]
, log_message());
return ret;
}

View File

@ -302,7 +302,7 @@ namespace aux {
{
session_impl* ses = (session_impl*)arg;
const char* servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
if (!servername || strlen(servername) < 40)
return SSL_TLSEXT_ERR_ALERT_FATAL;
@ -689,7 +689,7 @@ namespace aux {
if (flags & session::save_dht_settings)
{
entry::dictionary_type& dht_sett = e["dht"].dict();
dht_sett["max_peers_reply"] = m_dht_settings.max_peers_reply;
dht_sett["search_branching"] = m_dht_settings.search_branching;
dht_sett["max_fail_count"] = m_dht_settings.max_fail_count;
@ -734,7 +734,7 @@ namespace aux {
{
return proxy_settings(m_settings);
}
void session_impl::load_state(bdecode_node const* e)
{
TORRENT_ASSERT(is_single_thread());
@ -802,7 +802,7 @@ namespace aux {
if (val) m_settings.set_int(settings_pack::allowed_enc_level, val.int_value());
}
#endif
settings = e->dict_find_dict("settings");
if (settings)
{
@ -966,7 +966,7 @@ namespace aux {
if (t.should_check_files()) t.start_checking();
}
}
void session_impl::abort()
{
TORRENT_ASSERT(is_single_thread());
@ -1842,7 +1842,7 @@ retry:
int port = m_listen_interfaces[i].second;
int num_device_fails = 0;
#if TORRENT_USE_IPV6
const int first_family = 0;
#else
@ -2054,7 +2054,7 @@ retry:
&& proxy_type != settings_pack::socks5_pw
&& proxy_type != settings_pack::socks4)
return;
if (m_socks_listen_socket) return;
m_socks_listen_socket = boost::shared_ptr<socket_type>(new socket_type(m_io_service));
@ -2232,7 +2232,7 @@ retry:
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<socket_acceptor> listener = listen_socket.lock();
if (!listener) return;
if (e == asio::error::operation_aborted) return;
if (m_abort) return;
@ -2505,7 +2505,7 @@ retry:
#ifndef TORRENT_DISABLE_LOGGING
session_log(" There are no torrents, disconnect");
#endif
return;
return;
}
// figure out which peer classes this is connections has,
@ -2568,7 +2568,7 @@ retry:
#ifndef TORRENT_DISABLE_LOGGING
session_log(" There are no _active_ torrents, disconnect");
#endif
return;
return;
}
}
@ -2693,7 +2693,7 @@ retry:
std::pair<int, int> out_ports(start, start + num);
if (m_next_port < out_ports.first || m_next_port > out_ports.second)
m_next_port = out_ports.first;
int port = m_next_port;
++m_next_port;
if (m_next_port > out_ports.second) m_next_port = out_ports.first;
@ -3043,7 +3043,7 @@ retry:
m_peak_up_rate = (std::max)(m_stat.upload_rate(), m_peak_up_rate);
m_peak_down_rate = (std::max)(m_stat.download_rate(), m_peak_down_rate);
m_stat.second_tick(tick_interval_ms);
// --------------------------------------------------------------
@ -3185,7 +3185,7 @@ retry:
torrent_map::iterator i = std::max_element(m_torrents.begin(), m_torrents.end()
, boost::bind(&torrent::num_peers, boost::bind(&torrent_map::value_type::second, _1))
< boost::bind(&torrent::num_peers, boost::bind(&torrent_map::value_type::second, _2)));
TORRENT_ASSERT(i != m_torrents.end());
int peers_to_disconnect = (std::min)((std::max)(
int(i->second->num_peers() * m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
@ -3228,7 +3228,7 @@ retry:
int log2(boost::uint32_t v)
{
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
static const int MultiplyDeBruijnBitPosition[32] =
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
@ -3463,7 +3463,7 @@ retry:
t->set_announce_to_dht(dht_limit >= 0);
t->set_announce_to_trackers(tracker_limit >= 0);
t->set_announce_to_lsd(lsd_limit >= 0);
if (!t->is_paused() && t->is_inactive()
&& hard_limit > 0)
{
@ -3542,7 +3542,7 @@ retry:
lsd_limit = (std::numeric_limits<int>::max)();
if (tracker_limit == -1)
tracker_limit = (std::numeric_limits<int>::max)();
for (torrent_map::iterator i = m_torrents.begin()
, end(m_torrents.end()); i != end; ++i)
{
@ -3621,7 +3621,7 @@ retry:
{
TORRENT_ASSERT(is_single_thread());
if (m_stats_counters[counters::num_unchoke_slots] == 0) return;
std::vector<torrent_peer*> opt_unchoke;
for (connection_map::iterator i = m_connections.begin()
@ -3715,7 +3715,7 @@ retry:
pi->optimistically_unchoked = false;
m_stats_counters.inc_stats_counter(counters::num_peers_up_unchoked_optimistic, -1);
t->choke_peer(*p);
}
}
}
}
}
@ -3800,7 +3800,7 @@ retry:
m_prio_torrents.pop_front();
t = NULL;
}
if (t == NULL)
{
if ((m_download_connect_attempts >= m_settings.get_int(
@ -4176,7 +4176,7 @@ retry:
torrent* t = i->second.get();
if (t == me) continue;
if (t->queue_position() == -1) continue;
if (t->queue_position() >= p
if (t->queue_position() >= p
&& t->queue_position() < me->queue_position())
{
t->set_queue_position_impl(t->queue_position()+1);
@ -4294,7 +4294,7 @@ retry:
session_vlog(fmt, v);
va_end(v);
}
TORRENT_FORMAT(2, 0)
void session_impl::session_vlog(char const* fmt, va_list& v) const
{
@ -4334,7 +4334,7 @@ retry:
t->status(&*i, flags);
}
}
void session_impl::post_torrent_updates(boost::uint32_t flags)
{
INVARIANT_CHECK;
@ -4538,7 +4538,7 @@ retry:
ec = errors::session_is_closing;
return torrent_handle();
}
// figure out the info hash of the torrent
sha1_hash const* ih = 0;
sha1_hash tmp;
@ -4941,7 +4941,7 @@ retry:
std::string net_interfaces = m_settings.get_str(settings_pack::listen_interfaces);
std::vector<std::pair<std::string, int> > new_listen_interfaces;
// declared in string_util.hpp
parse_comma_separated_string_port(net_interfaces, new_listen_interfaces);
@ -4979,7 +4979,7 @@ retry:
#endif
// it may have been a device name.
std::vector<ip_interface> ifs = enum_net_interfaces(m_io_service, ec);
#ifndef TORRENT_DISABLE_LOGGING
if (ec)
session_log("failed to enumerate interfaces [ %s ]"
@ -5038,7 +5038,7 @@ retry:
, end(m_torrents.end()); i != end; ++i)
i->second->update_auto_sequential();
}
void session_impl::update_max_failcount()
{
for (torrent_map::iterator i = m_torrents.begin()
@ -5086,7 +5086,7 @@ retry:
void session_impl::update_dht()
{
#ifndef TORRENT_DISABLE_DHT
#ifndef TORRENT_DISABLE_DHT
if (m_settings.get_bool(settings_pack::enable_dht))
start_dht();
else
@ -5792,7 +5792,7 @@ retry:
int unchoke_limit = m_settings.get_int(settings_pack::unchoke_slots_limit);
int allowed_upload_slots = unchoke_limit;
if (allowed_upload_slots < 0)
allowed_upload_slots = (std::numeric_limits<int>::max)();
@ -5942,7 +5942,7 @@ retry:
void session_impl::on_trigger_auto_manage()
{
assert(m_pending_auto_manage);
if (!m_need_auto_manage || m_abort)
if (!m_need_auto_manage || m_abort)
{
m_pending_auto_manage = false;
return;
@ -5953,7 +5953,7 @@ retry:
recalculate_auto_managed_torrents();
m_pending_auto_manage = false;
}
void session_impl::update_socket_buffer_size()
{
error_code ec;
@ -6114,10 +6114,10 @@ retry:
int last_average = 0;
int average = m_settings.get_int(settings_pack::connections_limit) / m_torrents.size();
// the number of slots that are unused by torrents
int extra = m_settings.get_int(settings_pack::connections_limit) % m_torrents.size();
// run 3 iterations of this, then we're probably close enough
for (int iter = 0; iter < 4; ++iter)
{
@ -6297,7 +6297,7 @@ retry:
if (ec && m_alerts.should_post<lsd_error_alert>())
m_alerts.emplace_alert<lsd_error_alert>(ec);
}
#ifndef TORRENT_DISABLE_LOGGING
void session_impl::on_lsd_log(char const* log)
{
@ -6404,7 +6404,7 @@ retry:
m_lsd->close();
m_lsd.reset();
}
void session_impl::stop_natpmp()
{
if (m_natpmp)
@ -6419,7 +6419,7 @@ retry:
}
m_natpmp.reset();
}
void session_impl::stop_upnp()
{
if (m_upnp)
@ -6494,7 +6494,7 @@ retry:
char buf[1024];
int offset = 0;
char const* prefix[] =
{ "<== ", "<== ERROR ", "==> ", "==> ERROR " };
{ "<== ", "==> ", "<== ERROR ", "==> ERROR " };
offset += snprintf(&buf[offset], sizeof(buf) - offset, prefix[dir]);
va_list v;
@ -6504,10 +6504,15 @@ retry:
bdecode_node print;
error_code ec;
int ret = bdecode(buf, buf + len, print, ec, NULL, 100, 100);
int ret = bdecode(pkt, pkt + len, print, ec, NULL, 100, 100);
// TODO: 3 there should be a separate dht_log_alert for messages that
// contains the raw packet separately. This printing should be moved
// down to the ::message() function of that alert
std::string msg = print_entry(print, true);
if (offset < sizeof(buf)) buf[offset++] = ' ';
strncpy(&buf[offset], msg.c_str(), sizeof(buf) - offset);
m_alerts.emplace_alert<dht_log_alert>(dht_log_alert::tracker, buf);
@ -6579,14 +6584,14 @@ retry:
{
m_disk_thread.free_disk_buffer(buf);
}
char* session_impl::allocate_disk_buffer(bool& exceeded
, boost::shared_ptr<disk_observer> o
, char const* category)
{
return m_disk_thread.allocate_disk_buffer(exceeded, o, category);
}
char* session_impl::allocate_buffer()
{
TORRENT_ASSERT(is_single_thread());
@ -6608,7 +6613,7 @@ retry:
#else
m_send_buffers.free(buf);
#endif
}
}
#if TORRENT_USE_INVARIANT_CHECKS
void session_impl::check_invariant() const
@ -6652,7 +6657,7 @@ retry:
int torrent_state_gauges[counters::num_error_torrents - counters::num_checking_torrents + 1];
memset(torrent_state_gauges, 0, sizeof(torrent_state_gauges));
#if defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
#if TORRENT_HAS_BOOST_UNORDERED
@ -6807,7 +6812,7 @@ retry:
, std::list<address> const& ip_list
, struct tracker_response const& resp)
{
#ifndef TORRENT_DISABLE_LOGGING
#ifndef TORRENT_DISABLE_LOGGING
debug_log("TRACKER RESPONSE\n"
"interval: %d\n"
"external ip: %s\n"
@ -6826,7 +6831,7 @@ retry:
}
for (std::vector<ipv4_peer_entry>::const_iterator i = resp.peers4.begin();
i != resp.peers4.end(); ++i)
{
{
debug_log(" %s:%d", print_address(address_v4(i->ip)).c_str(), i->port);
}
#if TORRENT_USE_IPV6
@ -6852,12 +6857,12 @@ retry:
debug_log("*** tracker error: %d: %s %s"
, response_code, ec.message().c_str(), str.c_str());
}
void tracker_logger::debug_log(const char* fmt, ...) const
{
va_list v;
va_list v;
va_start(v, fmt);
char usr[1024];
vsnprintf(usr, sizeof(usr), fmt, v);
va_end(v);