From d1311e2bb80c9bb50cd5e5cfba521719a2a9362c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 19 Dec 2007 21:36:54 +0000 Subject: [PATCH] improved session logging --- src/peer_connection.cpp | 14 ++++++++------ src/session_impl.cpp | 6 +++++- src/torrent.cpp | 8 ++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 52b7903c7..80e5457de 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -124,6 +124,7 @@ namespace libtorrent , m_in_constructor(true) #endif { + TORRENT_ASSERT(peerinfo->banned == false); #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES std::fill(m_country, m_country + 2, 0); #endif @@ -1950,7 +1951,7 @@ namespace libtorrent void peer_connection::timed_out() { #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"; #endif m_ses.connection_failed(self(), m_remote, "timed out"); @@ -2642,7 +2643,8 @@ namespace libtorrent if (error) { #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 on_receive(error, bytes_transferred); throw std::runtime_error(error.message()); @@ -2665,7 +2667,7 @@ namespace libtorrent m_last_receive = time_now(); m_recv_pos += bytes_transferred; TORRENT_ASSERT(m_recv_pos <= int(m_recv_buffer.size())); - + on_receive(error, bytes_transferred); TORRENT_ASSERT(m_packet_size > 0); @@ -2760,7 +2762,7 @@ namespace libtorrent INVARIANT_CHECK; #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"; #endif @@ -2801,7 +2803,7 @@ namespace libtorrent if (e) { #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"; #endif m_ses.connection_failed(self(), m_remote, e.message().c_str()); @@ -2814,7 +2816,7 @@ namespace libtorrent // this means the connection just succeeded #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 on_connected(); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 193291964..dd243e0f0 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1054,7 +1054,7 @@ namespace detail } #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) - (*m_logger) << endp << " <== INCOMING CONNECTION\n"; + (*m_logger) << time_now_string() << " <== INCOMING CONNECTION " << endp << "\n"; #endif // local addresses do not count, since it's likely @@ -1163,6 +1163,10 @@ namespace detail // too expensive // INVARIANT_CHECK; +#if defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " CLOSING CONNECTION " << p->remote() << "\n"; +#endif + TORRENT_ASSERT(p->is_disconnecting()); connection_map::iterator i = m_connections.find(p); if (i != m_connections.end()) diff --git a/src/torrent.cpp b/src/torrent.cpp index 450a3da3d..83137f31d 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1078,9 +1078,13 @@ namespace libtorrent 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) (*p->connection->m_logger) << "*** BANNING PEER [ " << p->ip << " ] 'too many corrupt pieces'\n"; +#endif #endif p->connection->disconnect(); } @@ -2194,6 +2198,10 @@ namespace libtorrent } 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); throw; }