diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 8f16ea83b..ab259d900 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -349,6 +349,10 @@ namespace libtorrent // -------------------------------------------- // PEER MANAGEMENT +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + void log_to_all_peers(char const* message); +#endif + // add or remove a url that will be attempted for // finding the file(s) in this torrent. void add_web_seed(std::string const& url, web_seed_entry::type_t type) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 85fb57edf..b13d881ad 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -191,7 +191,8 @@ namespace libtorrent error_code ec; m_logger = m_ses.create_log(m_remote.address().to_string(ec) + "_" + to_string(m_remote.port()).elems, m_ses.listen_port()); - (*m_logger) << time_now_string() << " *** OUTGOING CONNECTION\n"; + (*m_logger) << time_now_string() << " *** OUTGOING CONNECTION: " + << print_endpoint(m_remote) << "\n"; #endif #ifdef TORRENT_DEBUG piece_failed = false; @@ -328,7 +329,8 @@ namespace libtorrent TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec); m_logger = m_ses.create_log(remote().address().to_string(ec) + "_" + to_string(remote().port()).elems, m_ses.listen_port()); - (*m_logger) << time_now_string() << " *** INCOMING CONNECTION\n"; + (*m_logger) << time_now_string() << " *** INCOMING CONNECTION: " + << print_endpoint(m_remote) << "\n"; #endif #ifndef TORRENT_DISABLE_GEO_IP diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 761179c8a..ac2182115 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2557,12 +2557,18 @@ namespace aux { --type_limit; --dht_limit; --tracker_limit; +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + t->log_to_all_peers("AUTO MANAGER STARTING TORRENT"); +#endif t->set_announce_to_dht(dht_limit >= 0); t->set_announce_to_trackers(tracker_limit >= 0); t->set_allow_peers(true); } else { +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + t->log_to_all_peers("AUTO MANAGER PAUSING TORRENT"); +#endif t->set_allow_peers(false); } } diff --git a/src/torrent.cpp b/src/torrent.cpp index d0d2e47b2..cb9c8cf04 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -500,12 +500,8 @@ namespace libtorrent INVARIANT_CHECK; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - for (peer_iterator i = m_connections.begin(); - i != m_connections.end(); ++i) - { - (*(*i)->m_logger) << "*** DESTRUCTING TORRENT\n"; - } +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + log_to_all_peers("DESTRUCTING TORRENT"); #endif TORRENT_ASSERT(m_abort); @@ -2491,12 +2487,8 @@ namespace libtorrent stop_announcing(); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - for (peer_iterator i = m_connections.begin(); - i != m_connections.end(); ++i) - { - (*(*i)->m_logger) << time_now_string() << " *** ABORTING TORRENT\n"; - } +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + log_to_all_peers("ABORTING TORRENT"); #endif // disconnect all peers and close all @@ -5217,12 +5209,9 @@ namespace libtorrent void torrent::delete_files() { TORRENT_ASSERT(m_ses.is_network_thread()); -#if defined TORRENT_VERBOSE_LOGGING - for (peer_iterator i = m_connections.begin(); - i != m_connections.end(); ++i) - { - (*(*i)->m_logger) << "*** DELETING FILES IN TORRENT\n"; - } + +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + log_to_all_peers("DELETING FILES IN TORRENT"); #endif disconnect_all(errors::torrent_removed); @@ -5257,6 +5246,16 @@ namespace libtorrent bool checking_files = should_check_files(); m_error = ec; m_error_file = error_file; + +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + if (ec) + { + char buf[1024]; + snprintf(buf, sizeof(buf), "TORRENT ERROR: %s: %s", ec.message().c_str(), error_file.c_str()); + log_to_all_peers(buf); + } +#endif + if (checking_files && !should_check_files()) { // stop checking @@ -5456,12 +5455,8 @@ namespace libtorrent } #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - for (peer_iterator i = m_connections.begin(); - i != m_connections.end(); ++i) - { - (*(*i)->m_logger) << "*** PAUSING TORRENT\n"; - } +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + log_to_all_peers("PAUSING TORRENT"); #endif // this will make the storage close all @@ -5483,6 +5478,17 @@ namespace libtorrent stop_announcing(); } +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING + void torrent::log_to_all_peers(char const* message) + { + for (peer_iterator i = m_connections.begin(); + i != m_connections.end(); ++i) + { + (*(*i)->m_logger) << time_now_string() << " *** " << message << "\n"; + } + } +#endif + void torrent::set_allow_peers(bool b) { TORRENT_ASSERT(m_ses.is_network_thread());