improved session logging

This commit is contained in:
Arvid Norberg 2007-12-19 21:36:54 +00:00
parent 9aa2ddec80
commit d1311e2bb8
3 changed files with 21 additions and 7 deletions

View File

@ -124,6 +124,7 @@ namespace libtorrent
, m_in_constructor(true) , m_in_constructor(true)
#endif #endif
{ {
TORRENT_ASSERT(peerinfo->banned == false);
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
std::fill(m_country, m_country + 2, 0); std::fill(m_country, m_country + 2, 0);
#endif #endif
@ -1950,7 +1951,7 @@ namespace libtorrent
void peer_connection::timed_out() void peer_connection::timed_out()
{ {
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << "CONNECTION TIMED OUT: " << m_remote.address().to_string() (*m_ses.m_logger) << time_now_string() << " CONNECTION TIMED OUT: " << m_remote.address().to_string()
<< "\n"; << "\n";
#endif #endif
m_ses.connection_failed(self(), m_remote, "timed out"); m_ses.connection_failed(self(), m_remote, "timed out");
@ -2642,7 +2643,8 @@ namespace libtorrent
if (error) if (error)
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << "**ERROR**: " << error.message() << "[in peer_connection::on_receive_data]\n"; (*m_logger) << time_now_string() << " **ERROR**: "
<< error.message() << "[in peer_connection::on_receive_data]\n";
#endif #endif
on_receive(error, bytes_transferred); on_receive(error, bytes_transferred);
throw std::runtime_error(error.message()); throw std::runtime_error(error.message());
@ -2760,7 +2762,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << "CONNECTING: " << m_remote.address().to_string() (*m_ses.m_logger) << time_now_string() << " CONNECTING: " << m_remote.address().to_string()
<< ":" << m_remote.port() << "\n"; << ":" << m_remote.port() << "\n";
#endif #endif
@ -2801,7 +2803,7 @@ namespace libtorrent
if (e) if (e)
{ {
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << "CONNECTION FAILED: " << m_remote.address().to_string() (*m_ses.m_logger) << time_now_string() << " CONNECTION FAILED: " << m_remote.address().to_string()
<< ": " << e.message() << "\n"; << ": " << e.message() << "\n";
#endif #endif
m_ses.connection_failed(self(), m_remote, e.message().c_str()); m_ses.connection_failed(self(), m_remote, e.message().c_str());
@ -2814,7 +2816,7 @@ namespace libtorrent
// this means the connection just succeeded // this means the connection just succeeded
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << "COMPLETED: " << m_remote.address().to_string() << "\n"; (*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string() << "\n";
#endif #endif
on_connected(); on_connected();

View File

@ -1054,7 +1054,7 @@ namespace detail
} }
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_logger) << endp << " <== INCOMING CONNECTION\n"; (*m_logger) << time_now_string() << " <== INCOMING CONNECTION " << endp << "\n";
#endif #endif
// local addresses do not count, since it's likely // local addresses do not count, since it's likely
@ -1163,6 +1163,10 @@ namespace detail
// too expensive // too expensive
// INVARIANT_CHECK; // INVARIANT_CHECK;
#if defined(TORRENT_LOGGING)
(*m_logger) << time_now_string() << " CLOSING CONNECTION " << p->remote() << "\n";
#endif
TORRENT_ASSERT(p->is_disconnecting()); TORRENT_ASSERT(p->is_disconnecting());
connection_map::iterator i = m_connections.find(p); connection_map::iterator i = m_connections.find(p);
if (i != m_connections.end()) if (i != m_connections.end())

View File

@ -1078,9 +1078,13 @@ namespace libtorrent
if (p->connection) if (p->connection)
{ {
#ifdef TORRENT_LOGGING
(*m_ses.m_logger) << time_now_string() << " *** BANNING PEER [ " << p->ip
<< " ] 'too many corrupt pieces'\n";
#if defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING)
(*p->connection->m_logger) << "*** BANNING PEER [ " << p->ip (*p->connection->m_logger) << "*** BANNING PEER [ " << p->ip
<< " ] 'too many corrupt pieces'\n"; << " ] 'too many corrupt pieces'\n";
#endif
#endif #endif
p->connection->disconnect(); p->connection->disconnect();
} }
@ -2194,6 +2198,10 @@ namespace libtorrent
} }
catch (std::exception& e) catch (std::exception& e)
{ {
#if defined(TORRENT_LOGGING)
(*m_ses.m_logger) << time_now_string() << " CLOSING CONNECTION "
<< p->remote() << " policy::new_connection threw: " << e.what() << "\n";
#endif
m_connections.erase(ci); m_connections.erase(ci);
throw; throw;
} }