From 09bc1550e974bbad91c7876e7be3c1119765b07e Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 9 Dec 2014 09:08:26 +0000 Subject: [PATCH] simplify the debug logging mechanism. There's now only one build option, logging=on or logging=off. When logging is enabled, the log level is controlled by the alert mask. All log events are delivered as alerts and it's up to the client to write them to disk in whatever way seems appropriate. removed the pointless logger plugin --- CMakeLists.txt | 5 - ChangeLog | 2 + Jamfile | 11 +- configure.ac | 14 +- docs/building.rst | 20 +- include/libtorrent/Makefile.am | 1 - include/libtorrent/alert.hpp | 17 + include/libtorrent/alert_types.hpp | 71 +++- include/libtorrent/aux_/session_impl.hpp | 32 +- include/libtorrent/aux_/session_interface.hpp | 12 +- include/libtorrent/config.hpp | 5 - include/libtorrent/debug.hpp | 111 ------ include/libtorrent/extensions/logger.hpp | 60 --- include/libtorrent/lsd.hpp | 4 +- include/libtorrent/peer_connection.hpp | 11 +- .../libtorrent/peer_connection_interface.hpp | 2 +- include/libtorrent/peer_list.hpp | 1 - include/libtorrent/piece_picker.hpp | 1 - include/libtorrent/session.hpp | 19 +- include/libtorrent/torrent.hpp | 8 +- include/libtorrent/tracker_manager.hpp | 2 +- include/libtorrent/upnp.hpp | 5 - include/libtorrent/utp_stream.hpp | 2 +- src/Makefile.am | 1 - src/alert.cpp | 15 + src/bt_peer_connection.cpp | 126 +++---- src/http_seed_connection.cpp | 10 +- src/http_tracker_connection.cpp | 4 +- src/logger.cpp | 237 ------------ src/lsd.cpp | 27 +- src/lt_trackers.cpp | 36 +- src/metadata_transfer.cpp | 12 +- src/peer_connection.cpp | 357 ++++++++---------- src/peer_list.cpp | 8 +- src/request_blocks.cpp | 6 +- src/session.cpp | 9 +- src/session_impl.cpp | 223 +++++------ src/smart_ban.cpp | 8 +- src/torrent.cpp | 208 +++++----- src/tracker_manager.cpp | 4 +- src/udp_tracker_connection.cpp | 26 +- src/ut_metadata.cpp | 22 +- src/ut_pex.cpp | 20 +- src/utp_stream.cpp | 2 +- src/web_peer_connection.cpp | 16 +- test/test_peer_list.cpp | 4 +- 46 files changed, 650 insertions(+), 1147 deletions(-) delete mode 100644 include/libtorrent/extensions/logger.hpp delete mode 100644 src/logger.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 139409606..b3bc7e80a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,6 @@ set(sources upnp utp_socket_manager utp_stream - logger file_pool lsd disk_io_job @@ -151,7 +150,6 @@ option(unicode "enable unicode support" ON) option(deprecated-functions "enable deprecated functions for backwards compatibility" ON) option(exceptions "build with exception support" ON) option(logging "build with logging" OFF) -option(verbose-logging "build with verbose logging" OFF) option(build_tests "build tests" OFF) set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo) @@ -190,9 +188,6 @@ endif (encryption) if (logging) add_definitions(-DTORRENT_LOGGING) endif() -if (verbose-logging) - add_definitions(-DTORRENT_VERBOSE_LOGGING) -endif() foreach(s ${sources}) list(APPEND sources2 src/${s}) diff --git a/ChangeLog b/ChangeLog index bbd2951a1..d5a6d8762 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * greatly simplify the debug logging infrastructure. logs are now delivered + as alerts, and log level is controlled by the alert mask. * removed auto_expand_choker. use rate_based_choker instead * optimize UDP tracker packet handling * support SSL over uTP connections diff --git a/Jamfile b/Jamfile index 4b3a914db..3f61f80ca 100755 --- a/Jamfile +++ b/Jamfile @@ -399,10 +399,8 @@ feature.compose on : TORRENT_DISK_STATS ; feature simulate-slow-read : off on : composite propagated ; feature.compose on : TORRENT_SIMULATE_SLOW_READ ; -feature logging : none default errors verbose : composite propagated link-incompatible ; -feature.compose default : TORRENT_LOGGING ; -feature.compose errors : TORRENT_ERROR_LOGGING ; -feature.compose verbose : TORRENT_VERBOSE_LOGGING ; +feature logging : off on : composite propagated link-incompatible ; +feature.compose on : TORRENT_LOGGING ; feature dht : on off logging : composite propagated link-incompatible ; feature.compose off : TORRENT_DISABLE_DHT ; @@ -455,13 +453,13 @@ variant test_release on on source multi ; variant test_debug : debug - : openssl verbose on + : openssl on on logging on debug on full shared on on source multi ; variant test_barebones : debug - : off off off none shared + : off off off off shared off off on on source multi ; @@ -604,7 +602,6 @@ SOURCES = utf8 utp_socket_manager utp_stream - logger file_pool lsd disk_buffer_pool diff --git a/configure.ac b/configure.ac index 3629d126b..d7b90abec 100644 --- a/configure.ac +++ b/configure.ac @@ -379,24 +379,14 @@ AC_MSG_CHECKING([whether logging to disk should be enabled]) AS_CASE(["$ARG_ENABLE_LOGGING"], ["yes"|"default"], [ AC_MSG_RESULT([yes]) - AC_DEFINE([TORRENT_LOGGING],[1],[Define to enable logging of the session events.]) + AC_DEFINE([TORRENT_LOGGING],[1],[Define to enable support for logging alerts]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_LOGGING " ], ["no"|"none"], [ AC_MSG_RESULT([no]) ], - ["verbose"], [ - AC_MSG_RESULT([verbose]) - AC_DEFINE([TORRENT_VERBOSE_LOGGING],[1],[Define to enable logging of the session events and every peer connection.]) - COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_VERBOSE_LOGGING " - ], - ["errors"], [ - AC_MSG_RESULT([errors]) - AC_DEFINE([TORRENT_ERROR_LOGGING],[1],[Define to enable logging of the session events and every peer connection limited to errors.]) - COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_ERROR_LOGGING " - ], [AC_MSG_RESULT([$ARG_ENABLE_LOGGING]) - AC_MSG_ERROR([Unknown option "$ARG_ENABLE_LOGGING". Use either "yes", "no", "verbose" or "errors".])] + AC_MSG_ERROR([Unknown option "$ARG_ENABLE_LOGGING". Use either "yes" or "no"])] ) AC_MSG_CHECKING([whether disk activity logging should be enabled]) diff --git a/docs/building.rst b/docs/building.rst index 52f15aad7..83d13bfb8 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -249,10 +249,11 @@ Build features: | | * ``shared`` - links dynamically against the boost | | | libraries. | +--------------------------+----------------------------------------------------+ -| ``logging`` | * ``none`` - no logging. | -| | * ``default`` - basic session logging. | -| | * ``verbose`` - verbose peer wire logging. | -| | * ``errors`` - like verbose, but limited to errors.| +| ``logging`` | * ``off`` - default. logging disabled. | +| | * ``on`` - logging alerts available, still need to | +| | be enabled by the alert mask. The reason logging | +| | is disabled by default is to keep the binary | +| | size down. | +--------------------------+----------------------------------------------------+ | ``dht`` | * ``on`` - build with support for tracker less | | | torrents and DHT support. | @@ -552,13 +553,10 @@ defines you can use to control the build. | | compilation units having different views of | | | structs and class layouts and sizes. | +----------------------------------------+-------------------------------------------------+ -| ``TORRENT_LOGGING`` | This macro will enable logging of the session | -| | events, such as tracker announces and incoming | -| | connections (as well as blocked connections). | -+----------------------------------------+-------------------------------------------------+ -| ``TORRENT_VERBOSE_LOGGING`` | If you define this macro, every peer connection | -| | will log its traffic to a log file as well as | -| | the session log. | +| ``TORRENT_LOGGING`` | This macro will enable support for logging | +| | alerts, like log_alert, torrent_log_alert and | +| | peer_log_alert. Without this build flag, you | +| | cannot enable those alerts. | +----------------------------------------+-------------------------------------------------+ | ``TORRENT_STORAGE_DEBUG`` | This will enable extra expensive invariant | | | checks in the storage, including logging of | diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 9ba58e94c..eec38adde 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -153,7 +153,6 @@ nobase_include_HEADERS = \ aux_/session_impl.hpp \ aux_/session_settings.hpp\ \ - extensions/logger.hpp \ extensions/lt_trackers.hpp \ extensions/metadata_transfer.hpp \ extensions/smart_ban.hpp \ diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index d86b94d74..66ffafd26 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -165,6 +165,23 @@ namespace libtorrent { // will make you receive rss_alert alerts. rss_notification = 0x1000, + // Enables debug logging alerts. These are only available when + // libtorrent is built with logging enabled (``TORRENT_LOGGING``). + // The alerts being posted are log_alert and are session wide. + session_log_notification = 0x2000, + + // Enables debug logging alerts for torrents. These are only available + // when libtorrent is built with logging enabled + // (``TORRENT_LOGGING``). The alerts being posted are + // torrent_log_alert and are torrent wide debug events. + torrent_log_notification = 0x4000, + + // Enables debug logging alerts for peers. These are only available + // when libtorrent is built with logging enabled + // (``TORRENT_LOGGING``). The alerts being posted are peer_log_alert + // and low-level peer events and messages. + peer_log_notification = 0x8000, + // The full bitmask, representing all available categories. // // since the enum is signed, make sure this isn't diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 96d3a004d..8eab84ed8 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2178,9 +2178,78 @@ namespace libtorrent udp::endpoint ip; }; + // This alert is posted by some session wide event. Its main purpose is + // trouble shooting and debugging. It's not enabled by the default alert + // mask and is enabled by the ``alert::session_log_notification`` bit. + // Furhtermore, it's by default disabled as a build configuration. To + // enable, build libtorrent with logging support enabled (``logging=on`` + // with bjam or define ``TORRENT_LOGGING``). + struct TORRENT_EXPORT log_alert : alert + { + // internal + log_alert(char const* log) + : msg(log) + {} + + TORRENT_DEFINE_ALERT(log_alert, 79); + + const static int static_category = alert::session_log_notification; + virtual std::string message() const; + + // the log message + std::string msg; + }; + + // This alert is posted by torrent wide events. It's meant to be used for + // trouble shooting and debugging. It's not enabled by the default alert + // mask and is enabled by the ``alert::torrent_log_notification`` bit. By + // default it is disabled as a build configuration. To enable, build + // libtorrent with logging support enabled (``logging=on`` with bjam or + // define ``TORRENT_LOGGING``). + struct TORRENT_EXPORT torrent_log_alert : torrent_alert + { + // internal + torrent_log_alert(torrent_handle h, char const* log) + : torrent_alert(h) + , msg(log) + {} + + TORRENT_DEFINE_ALERT(torrent_log_alert, 80); + + const static int static_category = alert::torrent_log_notification; + virtual std::string message() const; + + // the log message + std::string msg; + }; + + // This alert is posted by events specific to a peer. It's meant to be used + // for trouble shooting and debugging. It's not enabled by the default alert + // mask and is enabled by the ``alert::peer_log_notification`` bit. By + // default it is disabled as a build configuration. To enable, build + // libtorrent with logging support enabled (``logging=on`` with bjam or + // define ``TORRENT_LOGGING``). + struct TORRENT_EXPORT peer_log_alert : peer_alert + { + // internal + peer_log_alert(torrent_handle const& h, tcp::endpoint const& i + , peer_id const& pi, char const* log) + : peer_alert(h, i, pi) + , msg(log) + {} + + TORRENT_DEFINE_ALERT(peer_log_alert, 81); + + const static int static_category = alert::peer_log_notification; + virtual std::string message() const; + + // the log message + std::string msg; + }; + #undef TORRENT_DEFINE_ALERT - enum { num_alert_types = 79 }; + enum { num_alert_types = 82 }; } diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index f2e4977e9..49641a956 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -154,7 +154,7 @@ namespace libtorrent struct session_impl; struct session_settings; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING struct tracker_logger; #endif @@ -179,13 +179,6 @@ namespace libtorrent , uncork_interface , single_threaded { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - // this needs to be destructed last, since other components may log - // things as they are being destructed. That's why it's declared at - // the top of session_impl - boost::shared_ptr m_logger; -#endif - // the size of each allocation that is chained in the send buffer enum { send_buffer_size_impl = 128 }; @@ -206,9 +199,6 @@ namespace libtorrent void init(); void start_session(settings_pack const& pack); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - void set_log_path(std::string const& p) { m_logpath = p; } -#endif void set_load_function(user_load_function_t fun) { m_user_load_torrent = fun; } @@ -699,7 +689,7 @@ namespace libtorrent #endif // handles delayed alerts - alert_manager m_alerts; + mutable alert_manager m_alerts; // handles disk io requests asynchronously // peers have pointers into the disk buffer @@ -1117,35 +1107,21 @@ namespace libtorrent // accumulated error boost::uint16_t m_tick_residual; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - virtual boost::shared_ptr create_log(std::string const& name - , int instance, bool append = true); - +#if defined TORRENT_LOGGING virtual void session_log(char const* fmt, ...) const; virtual void session_vlog(char const* fmt, va_list& va) const; - -#if defined TORRENT_VERBOSE_LOGGING void log_all_torrents(peer_connection* p); -#endif // this list of tracker loggers serves as tracker_callbacks when // shutting down. This list is just here to keep them alive during // whe shutting down process std::list > m_tracker_loggers; - std::string get_log_path() const - { return m_logpath; } - - std::string m_logpath; FILE* m_request_logger; #endif private: -#ifdef TORRENT_UPNP_LOGGING - std::ofstream m_upnp_log; -#endif - // state for keeping track of external IPs external_ip m_external_ip; @@ -1202,7 +1178,7 @@ namespace libtorrent #endif }; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING struct tracker_logger : request_callback { tracker_logger(session_interface& ses); diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 2beb0636c..9dda85664 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING #include #endif @@ -70,9 +70,6 @@ namespace libtorrent struct bandwidth_manager; struct peer_class_pool; struct disk_observer; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - struct logger; -#endif struct torrent_peer; class alert_manager; struct disk_interface; @@ -305,16 +302,11 @@ namespace libtorrent { namespace aux virtual FILE* get_request_log() = 0; #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - virtual boost::shared_ptr create_log(std::string const& name - , int instance, bool append = true) = 0; +#if defined TORRENT_LOGGING virtual void session_log(char const* fmt, ...) const = 0; virtual void session_vlog(char const* fmt, va_list& va) const = 0; - virtual std::string get_log_path() const = 0; -#if defined TORRENT_VERBOSE_LOGGING virtual void log_all_torrents(peer_connection* p) = 0; #endif -#endif #ifdef TORRENT_BUFFER_STATS virtual void log_buffer_usage() = 0; diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index e63b8ae8f..054825a1c 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -388,11 +388,6 @@ int snprintf(char* buf, int len, char const* fmt, ...) #include #endif -#if (defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)) \ - && !defined (TORRENT_UPNP_LOGGING) && TORRENT_USE_IOSTREAM -#define TORRENT_UPNP_LOGGING -#endif - #ifndef TORRENT_ICONV_ARG #define TORRENT_ICONV_ARG (char**) #endif diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp index d16eb2950..8d1ada442 100644 --- a/include/libtorrent/debug.hpp +++ b/include/libtorrent/debug.hpp @@ -195,116 +195,5 @@ namespace libtorrent #endif } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - -#include -#include "libtorrent/config.hpp" -#include "libtorrent/file.hpp" -#include "libtorrent/thread.hpp" - -#if TORRENT_USE_IOSTREAM -#include -#include -#include -#endif - -namespace libtorrent -{ - // DEBUG API - - // TODO: rewrite this class to use FILE* instead and - // have a printf-like interface - struct logger - { -#if TORRENT_USE_IOSTREAM - // all log streams share a single file descriptor - // and re-opens the file for each log line - // these members are defined in session_impl.cpp - static std::ofstream log_file; - static std::string open_filename; - static mutex file_mutex; -#endif - - ~logger() - { - mutex::scoped_lock l(file_mutex); - log_file.close(); - open_filename.clear(); - } - - logger(std::string const& logpath, std::string const& filename - , int instance, bool append) - { - char log_name[512]; - snprintf(log_name, sizeof(log_name), "libtorrent_logs%d", instance); - std::string dir(complete(combine_path(combine_path(logpath, log_name), filename)) + ".log"); - error_code ec; - if (!exists(parent_path(dir))) - create_directories(parent_path(dir), ec); - m_filename = dir; - - mutex::scoped_lock l(file_mutex); - open(!append); - log_file << "\n\n\n*** starting log ***\n"; - } - - void move_log_file(std::string const& logpath, std::string const& new_name, int instance) - { - mutex::scoped_lock l(file_mutex); - if (open_filename == m_filename) - { - log_file.close(); - open_filename.clear(); - } - - char log_name[512]; - snprintf(log_name, sizeof(log_name), "libtorrent_logs%d", instance); - std::string dir(combine_path(combine_path(complete(logpath), log_name), new_name) + ".log"); - - error_code ec; - create_directories(parent_path(dir), ec); - - if (ec) - fprintf(stderr, "Failed to create logfile directory %s: %s\n" - , parent_path(dir).c_str(), ec.message().c_str()); - ec.clear(); - rename(m_filename, dir, ec); - if (ec) - fprintf(stderr, "Failed to move logfile %s: %s\n" - , parent_path(dir).c_str(), ec.message().c_str()); - - m_filename = dir; - } - -#if TORRENT_USE_IOSTREAM - void open(bool truncate) - { - if (open_filename == m_filename) return; - log_file.close(); - log_file.clear(); - log_file.open(m_filename.c_str(), truncate ? std::ios_base::trunc : std::ios_base::app); - open_filename = m_filename; - if (!log_file.good()) - fprintf(stderr, "Failed to open logfile %s: %s\n", m_filename.c_str(), strerror(errno)); - } -#endif - - template - logger& operator<<(T const& v) - { -#if TORRENT_USE_IOSTREAM - mutex::scoped_lock l(file_mutex); - open(false); - log_file << v; -#endif - return *this; - } - - std::string m_filename; - }; - -} - -#endif // TORRENT_VERBOSE_LOGGING || TORRENT_LOGGING || TORRENT_ERROR_LOGGING #endif // TORRENT_DEBUG_HPP_INCLUDED diff --git a/include/libtorrent/extensions/logger.hpp b/include/libtorrent/extensions/logger.hpp deleted file mode 100644 index 5e5e6cb3a..000000000 --- a/include/libtorrent/extensions/logger.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - -Copyright (c) 2006, Arvid Norberg -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution. - * Neither the name of the author nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -*/ - -#ifndef TORRENT_LOGGER_HPP_INCLUDED -#define TORRENT_LOGGER_HPP_INCLUDED - -#ifdef _MSC_VER -#pragma warning(push, 1) -#endif - -#include - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#include "libtorrent/config.hpp" - -#if TORRENT_USE_IOSTREAM - -namespace libtorrent -{ - struct torrent_plugin; - class torrent; - boost::shared_ptr create_logger_plugin(torrent*); -} - -#endif - -#endif // TORRENT_LOGGER_HPP_INCLUDED - diff --git a/include/libtorrent/lsd.hpp b/include/libtorrent/lsd.hpp index 061bf9420..a4f0e65ed 100644 --- a/include/libtorrent/lsd.hpp +++ b/include/libtorrent/lsd.hpp @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING #include #endif @@ -96,7 +96,7 @@ private: #if TORRENT_USE_IPV6 bool m_disabled6; #endif -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING FILE* m_log; #endif }; diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 9e20440fe..36365a58f 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING #include "libtorrent/debug.hpp" #endif @@ -417,7 +417,7 @@ namespace libtorrent void set_holepunch_mode() { m_holepunch_mode = true; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** HOLEPUNCH MODE ***"); #endif } @@ -553,12 +553,11 @@ namespace libtorrent void decrease_est_reciprocation_rate(); int est_reciprocation_rate() const { return m_est_reciprocation_rate; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING virtual void peer_log(char const* fmt, ...) const; - boost::shared_ptr m_logger; #endif -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING ptime m_connect_time; ptime m_bitfield_time; ptime m_unchoke_time; @@ -654,7 +653,7 @@ namespace libtorrent virtual boost::optional downloading_piece_progress() const { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** downloading_piece_progress() dispatched to the base class!"); #endif return boost::optional(); diff --git a/include/libtorrent/peer_connection_interface.hpp b/include/libtorrent/peer_connection_interface.hpp index 64c79cf80..440f23967 100644 --- a/include/libtorrent/peer_connection_interface.hpp +++ b/include/libtorrent/peer_connection_interface.hpp @@ -85,7 +85,7 @@ namespace libtorrent virtual bool failed() const = 0; virtual stat const& statistics() const = 0; virtual void get_peer_info(peer_info& p) const = 0; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING virtual void peer_log(char const* fmt, ...) const = 0; #endif diff --git a/include/libtorrent/peer_list.hpp b/include/libtorrent/peer_list.hpp index 6009e9b29..ffb1d01a8 100644 --- a/include/libtorrent/peer_list.hpp +++ b/include/libtorrent/peer_list.hpp @@ -49,7 +49,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct logger; struct external_ip; struct ip_filter; class port_filter; diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index a5a260691..634ee3aa0 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -70,7 +70,6 @@ namespace libtorrent class torrent; class peer_connection; struct bitfield; - struct logger; struct counters; struct TORRENT_EXTRA_EXPORT piece_block diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index eccf3414d..5cd26e512 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -164,12 +164,6 @@ namespace libtorrent boost::shared_ptr m_impl; }; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING -#define TORRENT_LOGPATH_ARG_DEFAULT , std::string logpath = "." -#else -#define TORRENT_LOGPATH_ARG_DEFAULT -#endif - // This free function returns the list of available metrics exposed by // libtorrent's statistics API. Each metric has a name and a *value index*. // The value index is the index into the array in session_stats_alert where @@ -221,8 +215,7 @@ namespace libtorrent session(fingerprint const& print = fingerprint("LT" , LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0) , int flags = start_default_features | add_default_plugins - , boost::uint32_t alert_mask = alert::error_notification - TORRENT_LOGPATH_ARG_DEFAULT) + , boost::uint32_t alert_mask = alert::error_notification) { TORRENT_CFG(); settings_pack pack; @@ -236,17 +229,13 @@ namespace libtorrent } init(print); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - set_log_path(logpath); -#endif start(flags, pack); } session(fingerprint const& print , std::pair listen_port_range , char const* listen_interface = "0.0.0.0" , int flags = start_default_features | add_default_plugins - , int alert_mask = alert::error_notification - TORRENT_LOGPATH_ARG_DEFAULT) + , int alert_mask = alert::error_notification) { TORRENT_CFG(); TORRENT_ASSERT(listen_port_range.first > 0); @@ -267,9 +256,6 @@ namespace libtorrent pack.set_bool(settings_pack::enable_dht, false); } init(print); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - set_log_path(logpath); -#endif start(flags, pack); } @@ -1233,7 +1219,6 @@ namespace libtorrent private: void init(fingerprint const& id); - void set_log_path(std::string const& p); void start(int flags, settings_pack const& pack); // data shared between the main thread diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 769d8a5d6..fb03c1445 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -93,10 +93,6 @@ namespace libtorrent { class http_parser; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - struct logger; -#endif - class piece_manager; struct torrent_plugin; struct bitfield; @@ -977,11 +973,9 @@ namespace libtorrent time_t last_seen_complete() const { return m_last_seen_complete; } // LOGGING -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING virtual void debug_log(const char* fmt, ...) const; void log_to_all_peers(char const* message); - boost::shared_ptr m_logger; - ptime m_logger_time; ptime m_dht_start_time; #endif diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index c59d506f1..bf0bd1eff 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -221,7 +221,7 @@ namespace libtorrent , const std::string& msg , int retry_interval) = 0; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING virtual void debug_log(const char* fmt, ...) const = 0; #endif }; diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 727927a0d..25c700e06 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -49,11 +49,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include - -#if defined(TORRENT_UPNP_LOGGING) -#include -#endif - namespace libtorrent { diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 71712a2d6..80d5e1520 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -156,7 +156,7 @@ void utp_send_ack(utp_socket_impl* s); void utp_socket_drained(utp_socket_impl* s); void utp_writable(utp_socket_impl* s); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING int socket_impl_size(); #endif diff --git a/src/Makefile.am b/src/Makefile.am index e1191d9b8..7f8654294 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -77,7 +77,6 @@ libtorrent_rasterbar_la_SOURCES = \ ip_filter.cpp \ ip_voter.cpp \ lazy_bdecode.cpp \ - logger.cpp \ lsd.cpp \ lt_trackers.cpp \ magnet_uri.cpp \ diff --git a/src/alert.cpp b/src/alert.cpp index 50958f40c..ec30ff64d 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -715,5 +715,20 @@ namespace libtorrent { return msg; } + std::string log_alert::message() const + { + return msg; + } + + std::string torrent_log_alert::message() const + { + return torrent_alert::message() + ": " + msg; + } + + std::string peer_log_alert::message() const + { + return torrent_alert::message() + " [" + print_endpoint(ip) + "] " + msg; + } + } // namespace libtorrent diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index aac5feb13..7635de1cd 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -125,7 +125,7 @@ namespace libtorrent , m_in_constructor(true) #endif { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** bt_peer_connection"); #endif @@ -173,7 +173,7 @@ namespace libtorrent if (t->graceful_pause()) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** ON_CONNECTED [ graceful-paused ]"); #endif disconnect(error_code(errors::torrent_paused), op_bittorrent); @@ -193,7 +193,7 @@ namespace libtorrent if (is_ssl(*get_socket())) out_enc_policy = settings_pack::pe_disabled; #endif -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING char const* policy_name[] = {"forced", "enabled", "disabled"}; peer_log("*** outgoing encryption policy: %s", policy_name[out_enc_policy]); #endif @@ -254,7 +254,7 @@ namespace libtorrent void bt_peer_connection::on_metadata() { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** ON_METADATA"); #endif // connections that are still in the handshake @@ -278,7 +278,7 @@ namespace libtorrent TORRENT_ASSERT(m_sent_handshake && m_sent_bitfield); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> DHT_PORT [ %d ]", listen_port); #endif char msg[] = {0,0,0,3, msg_dht_port, 0, 0}; @@ -294,7 +294,7 @@ namespace libtorrent INVARIANT_CHECK; TORRENT_ASSERT(m_sent_handshake); m_sent_bitfield = true; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> HAVE_ALL"); #endif char msg[] = {0,0,0,1, msg_have_all}; @@ -308,7 +308,7 @@ namespace libtorrent INVARIANT_CHECK; TORRENT_ASSERT(m_sent_handshake); m_sent_bitfield = true; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> HAVE_NONE"); #endif char msg[] = {0,0,0,1, msg_have_none}; @@ -325,7 +325,7 @@ namespace libtorrent if (!m_supports_fast) return; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> REJECT_PIECE [ piece: %d | s: %d | l: %d ]" , r.piece, r.start, r.length); #endif @@ -371,7 +371,7 @@ namespace libtorrent TORRENT_ASSERT(t); TORRENT_ASSERT(t->valid_metadata()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> SUGGEST [ piece: %d num_peers: %d ]", piece , t->has_picker() ? t->picker().get_availability(piece) : -1); #endif @@ -436,7 +436,7 @@ namespace libtorrent TORRENT_ASSERT(!m_dh_key_exchange.get()); TORRENT_ASSERT(!m_sent_handshake); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING if (is_outgoing()) peer_log("*** initiating encrypted handshake"); #endif @@ -450,7 +450,7 @@ namespace libtorrent int pad_size = random() % 512; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log(" pad size: %d", pad_size); #endif @@ -464,7 +464,7 @@ namespace libtorrent std::generate(ptr, ptr + pad_size, random_byte); send_buffer(msg, buf_size); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log(" sent DH key"); #endif } @@ -528,7 +528,7 @@ namespace libtorrent if ((crypto_provide & settings_pack::pe_both) == 0) crypto_provide = settings_pack::pe_both; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING char const* level[] = {"plaintext", "rc4", "plaintext rc4"}; peer_log(" crypto provide : [ %s ]" , level[crypto_provide-1]); @@ -568,7 +568,7 @@ namespace libtorrent else // 0x01 m_rc4_encrypted = false; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log(" crypto select : [ %s ]" , (crypto_select == 0x01) ? "plaintext" : "rc4"); #endif @@ -645,7 +645,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log(" computed RC4 keys"); #endif } @@ -777,7 +777,7 @@ namespace libtorrent // we support FAST extension *(ptr + 7) |= 0x04; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING std::string bitmask; for (int k = 0; k < 8; ++k) { @@ -808,7 +808,7 @@ namespace libtorrent memcpy(ptr, &m_our_peer_id[0], 20); ptr += 20; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING { char hex_pid[41]; to_hex((char const*)&m_our_peer_id[0], 20, hex_pid); @@ -891,7 +891,7 @@ namespace libtorrent { INVARIANT_CHECK; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== KEEPALIVE"); #endif incoming_keepalive(); @@ -1231,7 +1231,7 @@ namespace libtorrent if (recv_pos < header_size) return; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING // peer_log("<== PIECE_FRAGMENT p: %d start: %d length: %d" // , p.piece, p.start, p.length); #endif @@ -1251,7 +1251,7 @@ namespace libtorrent if (merkle && list_size > 0) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== HASHPIECE [ piece: %d list: %d ]", p.piece, list_size); #endif lazy_entry hash_list; @@ -1502,7 +1502,7 @@ namespace libtorrent #endif else { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING error_code ec; static const char* hp_msg_name[] = {"rendezvous", "connect", "failed"}; peer_log("<== HOLEPUNCH [ msg: %s from %s to: unknown address type ]" @@ -1520,7 +1520,7 @@ namespace libtorrent { case hp_rendezvous: // rendezvous { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HOLEPUNCH [ msg: rendezvous to: %s ]" , print_address(ep.address()).c_str()); #endif @@ -1554,7 +1554,7 @@ namespace libtorrent torrent_peer* p = t->add_peer(ep, peer_info::pex); if (p == 0 || p->connection) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HOLEPUNCH [ msg:connect to: %s error: failed to add peer ]" , print_address(ep.address()).c_str()); #endif @@ -1564,7 +1564,7 @@ namespace libtorrent } if (p->banned) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HOLEPUNCH [ msg:connect to: %s error: peer banned ]" , print_address(ep.address()).c_str()); #endif @@ -1583,7 +1583,7 @@ namespace libtorrent t->update_want_peers(); if (p->connection) p->connection->set_holepunch_mode(); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HOLEPUNCH [ msg:connect to: %s ]" , print_address(ep.address()).c_str()); #endif @@ -1591,7 +1591,7 @@ namespace libtorrent case hp_failed: { boost::uint32_t error = detail::read_uint32(ptr); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING error_code ec; char const* err_msg[] = {"no such peer", "not connected", "no support", "no self"}; peer_log("<== HOLEPUNCH [ msg:failed error: %d msg: %s ]", error @@ -1600,7 +1600,7 @@ namespace libtorrent // #error deal with holepunch errors (void)error; } break; -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING default: { error_code ec; @@ -1620,7 +1620,7 @@ namespace libtorrent else detail::write_uint8(1, ptr); detail::write_endpoint(ep, ptr); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING error_code ec; static const char* hp_msg_name[] = {"rendezvous", "connect", "failed"}; static const char* hp_error_string[] = {"", "no such peer", "not connected", "no support", "no self"}; @@ -1691,13 +1691,13 @@ namespace libtorrent if (!m_recv_buffer.packet_finished()) return; if (m_recv_buffer.packet_size() != 3) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== UPLOAD_ONLY [ ERROR: unexpected packet size: %d ]", m_recv_buffer.packet_size()); #endif return; } bool ul = detail::read_uint8(recv_buffer.begin) != 0; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== UPLOAD_ONLY [ %s ]", (ul?"true":"false")); #endif set_upload_only(ul); @@ -1709,13 +1709,13 @@ namespace libtorrent if (!m_recv_buffer.packet_finished()) return; if (m_recv_buffer.packet_size() != 3) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== SHARE_MODE [ ERROR: unexpected packet size: %d ]", m_recv_buffer.packet_size()); #endif return; } bool sm = detail::read_uint8(recv_buffer.begin) != 0; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== SHARE_MODE [ %s ]", (sm?"true":"false")); #endif set_share_mode(sm); @@ -1725,7 +1725,7 @@ namespace libtorrent if (extended_id == holepunch_msg) { if (!m_recv_buffer.packet_finished()) return; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== HOLEPUNCH"); #endif on_holepunch(); @@ -1737,7 +1737,7 @@ namespace libtorrent if (!m_recv_buffer.packet_finished()) return; if (m_recv_buffer.packet_size() != 6) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== DONT_HAVE [ ERROR: unexpected packet size: %d ]", m_recv_buffer.packet_size()); #endif return; @@ -1747,7 +1747,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING if (m_recv_buffer.packet_finished()) peer_log("<== EXTENSION MESSAGE [ msg: %d size: %d ]" , extended_id, m_recv_buffer.packet_size()); @@ -1780,14 +1780,14 @@ namespace libtorrent int ret = lazy_bdecode(recv_buffer.begin + 2, recv_buffer.end, root, ec, &pos); if (ret != 0 || ec || root.type() != lazy_entry::dict_t) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** invalid extended handshake: %s pos: %d" , ec.message().c_str(), pos); #endif return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== EXTENDED HANDSHAKE: %s", print_entry(root).c_str()); #endif @@ -1972,7 +1972,7 @@ namespace libtorrent // connections, don't sent upload-only if (!m_settings.get_bool(settings_pack::close_redundant_connections)) return; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> UPLOAD_ONLY [ %d ]" , int(t->is_upload_only() && !t->super_seeding())); #endif @@ -2073,7 +2073,7 @@ namespace libtorrent if (t->super_seeding()) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log(" *** NOT SENDING BITFIELD, super seeding"); #endif if (m_supports_fast) write_have_none(); @@ -2104,7 +2104,7 @@ namespace libtorrent else if (t->num_have() == 0) { // don't send a bitfield if we don't have any pieces -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log(" *** NOT SENDING BITFIELD"); #endif m_sent_bitfield = true; @@ -2175,7 +2175,7 @@ namespace libtorrent , end(t->predictive_pieces().end()); i != end; ++i) msg[5 + *i / 8] |= (0x80 >> (*i & 7)); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING std::string bitfield_string; bitfield_string.resize(num_pieces); @@ -2196,7 +2196,7 @@ namespace libtorrent { for (int i = 0; i < num_lazy_pieces; ++i) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> HAVE [ piece: %d ]", lazy_pieces[i]); #endif write_have(lazy_pieces[i]); @@ -2312,7 +2312,7 @@ namespace libtorrent stats_counters().inc_stats_counter(counters::num_outgoing_ext_handshake); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> EXTENDED HANDSHAKE: %s", handshake.to_string().c_str()); #endif } @@ -2526,7 +2526,7 @@ namespace libtorrent if (!m_enc_handler.is_recv_plaintext()) { int consumed = m_enc_handler.decrypt(m_recv_buffer, bytes_transferred); - #ifdef TORRENT_VERBOSE_LOGGING + #ifdef TORRENT_LOGGING if (consumed + bytes_transferred > 0) peer_log("<== decrypted block [ s = %d ]", consumed + bytes_transferred); #endif @@ -2598,7 +2598,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** received DH key"); #endif @@ -2697,7 +2697,7 @@ namespace libtorrent else { std::size_t bytes_processed = syncoffset + 20; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** sync point (hash) found at offset %d" , m_sync_bytes_read + bytes_processed - 20); #endif @@ -2746,7 +2746,7 @@ namespace libtorrent } init_pe_rc4_handler(m_dh_key_exchange->get_secret(), ti->info_hash()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** stream key found, torrent located"); #endif } @@ -2769,7 +2769,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** verification constant found"); #endif m_state = read_pe_cryptofield; @@ -2833,7 +2833,7 @@ namespace libtorrent else { std::size_t bytes_processed = syncoffset + 8; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** sync point (verification constant) found at offset %d" , m_sync_bytes_read + bytes_processed - 8); #endif @@ -2868,7 +2868,7 @@ namespace libtorrent boost::uint32_t crypto_field = detail::read_uint32(recv_buffer.begin); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** crypto %s : [%s%s ]" , is_outgoing() ? "select" : "provide" , (crypto_field & 1) ? " plaintext" : "" @@ -2982,7 +2982,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** len(IA) : %d", len_ia); #endif if (len_ia == 0) @@ -3028,7 +3028,7 @@ namespace libtorrent buffer::interval wr_buf = m_recv_buffer.mutable_buffer(); rc4_decrypt(wr_buf.begin, m_recv_buffer.packet_size()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** decrypted ia : %d bytes", m_recv_buffer.packet_size()); #endif @@ -3077,7 +3077,7 @@ namespace libtorrent wr_buf.begin += m_recv_buffer.packet_size(); rc4_decrypt(wr_buf.begin, wr_buf.left()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** decrypted remaining %d bytes", wr_buf.left()); #endif } @@ -3118,14 +3118,14 @@ namespace libtorrent memcmp(recv_buffer.begin, protocol_string, 20) != 0) { #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** unrecognized protocol header"); #endif #ifdef TORRENT_USE_OPENSSL if (is_ssl(*get_socket())) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** SSL peers are not allowed to use any other encryption"); #endif disconnect(errors::invalid_info_hash, op_bittorrent, 1); @@ -3151,7 +3151,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** attempting encrypted connection"); #endif m_state = read_pe_dhkey; @@ -3179,7 +3179,7 @@ namespace libtorrent } #endif -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== BitTorrent protocol"); #endif } @@ -3199,7 +3199,7 @@ namespace libtorrent recv_buffer = m_recv_buffer.get(); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING std::string extensions; extensions.resize(8 * 8); for (int i=0; i < 8; ++i) @@ -3255,14 +3255,14 @@ namespace libtorrent if (!std::equal(recv_buffer.begin + 8, recv_buffer.begin + 28 , (const char*)t->torrent_file().info_hash().begin())) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** received invalid info_hash"); #endif disconnect(errors::invalid_info_hash, op_bittorrent, 1); return; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<<< info_hash received"); #endif } @@ -3298,7 +3298,7 @@ namespace libtorrent if (!m_recv_buffer.packet_finished()) return; recv_buffer = m_recv_buffer.get(); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING { char hex_pid[41]; to_hex(recv_buffer.begin, 20, hex_pid); @@ -3380,7 +3380,7 @@ namespace libtorrent if (m_supports_extensions) write_extensions(); #endif -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("<== HANDSHAKE"); #endif // consider this a successful connection, reset the failcount @@ -3496,7 +3496,7 @@ namespace libtorrent int bt_peer_connection::hit_send_barrier(std::vector& iovec) { int next_barrier = m_enc_handler.encrypt(iovec); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING if (next_barrier != 0) peer_log("==> encrypted block [ s = %d ]", next_barrier); #endif diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index ac58b9cc8..54ea8a110 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -77,7 +77,7 @@ namespace libtorrent prefer_whole_pieces(1); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** http_seed_connection"); #endif } @@ -195,7 +195,7 @@ namespace libtorrent request += "\r\n\r\n"; m_first_request = false; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> %s", request.c_str()); #endif @@ -214,7 +214,7 @@ namespace libtorrent if (error) { received_bytes(0, bytes_transferred); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** http_seed_connection error: %s", error.message().c_str()); #endif return; @@ -376,7 +376,7 @@ namespace libtorrent } else { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size); #endif TORRENT_ASSERT(bytes_transferred >= size_t(header_size - m_partial_chunk_header)); @@ -414,7 +414,7 @@ namespace libtorrent int retry_time = atol(std::string(recv_buffer.begin, recv_buffer.end).c_str()); if (retry_time <= 0) retry_time = 60; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** retrying in %d seconds", retry_time); #endif diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 390772b0b..da99c52d0 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -240,7 +240,7 @@ namespace libtorrent // the url + 100 estimated header size sent_bytes(url.size() + 100); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) @@ -274,7 +274,7 @@ namespace libtorrent ++i; } -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) { diff --git a/src/logger.cpp b/src/logger.cpp deleted file mode 100644 index 6c42ce856..000000000 --- a/src/logger.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - -Copyright (c) 2006-2014, Arvid Norberg -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution. - * Neither the name of the author nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -*/ - -#ifdef _MSC_VER -#pragma warning(push, 1) -#endif - -#include - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#include - -#include "libtorrent/extensions/logger.hpp" -#include "libtorrent/extensions.hpp" -#include "libtorrent/entry.hpp" -#include "libtorrent/peer_request.hpp" - -#if TORRENT_USE_IOSTREAM && !defined TORRENT_DISABLE_EXTENSIONS - -#include -#include "libtorrent/file.hpp" -#include "libtorrent/time.hpp" -#include "libtorrent/lazy_entry.hpp" -#include "libtorrent/peer_connection.hpp" - -namespace libtorrent { - - class peer_connection; - -namespace -{ - - struct logger_peer_plugin : peer_plugin - { - logger_peer_plugin(std::string const& filename) - { - error_code ec; - std::string dir = complete("libtorrent_ext_logs"); - if (!exists(dir)) create_directories(dir, ec); - m_file.open(combine_path(dir, filename).c_str(), std::ios_base::out); - m_file << "\n\n\n"; - log_timestamp(); - m_file << "*** starting log ***\n"; - } - - void log_timestamp() - { - m_file << time_now_string() << ": "; - } - - // can add entries to the extension handshake - virtual void add_handshake(entry&) {} - - // called when the extension handshake from the other end is received - virtual bool on_extension_handshake(lazy_entry const& h) - { - log_timestamp(); - m_file << "<== EXTENSION_HANDSHAKE\n" << print_entry(h); - return true; - } - - // returning true from any of the message handlers - // indicates that the plugin has handeled the message. - // it will break the plugin chain traversing and not let - // anyone else handle the message, including the default - // handler. - - virtual bool on_choke() - { - log_timestamp(); - m_file << "<== CHOKE\n"; - m_file.flush(); - return false; - } - - virtual bool on_unchoke() - { - log_timestamp(); - m_file << "<== UNCHOKE\n"; - m_file.flush(); - return false; - } - - virtual bool on_interested() - { - log_timestamp(); - m_file << "<== INTERESTED\n"; - m_file.flush(); - return false; - } - - virtual bool on_not_interested() - { - log_timestamp(); - m_file << "<== NOT_INTERESTED\n"; - m_file.flush(); - return false; - } - - virtual bool on_have(int index) - { - log_timestamp(); - m_file << "<== HAVE [" << index << "]\n"; - m_file.flush(); - return false; - } - - virtual bool on_bitfield(bitfield const& bitfield_) - { - log_timestamp(); - m_file << "<== BITFIELD\n"; - m_file.flush(); - return false; - } - - virtual bool on_request(peer_request const& r) - { - log_timestamp(); - m_file << "<== REQUEST [ piece: " << r.piece << " | s: " << r.start - << " | l: " << r.length << " ]\n"; - m_file.flush(); - return false; - } - - virtual bool on_piece(peer_request const& r, disk_buffer_holder& data) - { - log_timestamp(); - m_file << "<== PIECE [ piece: " << r.piece << " | s: " << r.start - << " | l: " << r.length << " ]\n"; - m_file.flush(); - return false; - } - - virtual bool on_cancel(peer_request const& r) - { - log_timestamp(); - m_file << "<== CANCEL [ piece: " << r.piece << " | s: " << r.start - << " | l: " << r.length << " ]\n"; - m_file.flush(); - return false; - } - - // called when an extended message is received. If returning true, - // the message is not processed by any other plugin and if false - // is returned the next plugin in the chain will receive it to - // be able to handle it - virtual bool on_extended(int length - , int msg, buffer::const_interval body) - { return false; } - - virtual bool on_unknown_message(int length, int msg - , buffer::const_interval body) - { - if (body.left() < length) return false; - log_timestamp(); - m_file << "<== UNKNOWN [ msg: " << msg - << " | l: " << length << " ]\n"; - m_file.flush(); - return false; - } - - virtual void on_piece_pass(int index) - { - log_timestamp(); - m_file << "*** HASH PASSED *** [ piece: " << index << " ]\n"; - m_file.flush(); - } - - virtual void on_piece_failed(int index) - { - log_timestamp(); - m_file << "*** HASH FAILED *** [ piece: " << index << " ]\n"; - m_file.flush(); - } - - private: - std::ofstream m_file; - }; - - struct logger_plugin : torrent_plugin - { - virtual boost::shared_ptr new_connection( - peer_connection* pc) - { - error_code ec; - return boost::shared_ptr(new logger_peer_plugin( - pc->remote().address().to_string(ec) + "_" - + to_string(pc->remote().port()).elems + ".log")); - } - }; - -} } - -namespace libtorrent -{ - - boost::shared_ptr create_logger_plugin(torrent*) - { - return boost::shared_ptr(new logger_plugin()); - } - -} - -#endif - diff --git a/src/lsd.cpp b/src/lsd.cpp index ff4a777a0..1d20833fd 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -80,7 +80,8 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb) , m_disabled6(false) #endif { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING + // TODO: instead if writing to a file, post alerts. Or call a log callback m_log = fopen("lsd.log", "w+"); if (m_log == NULL) { @@ -92,7 +93,7 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb) error_code ec; m_socket.open(ios, ec); -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (ec) { if (m_log) fprintf(m_log, "FAILED TO OPEN SOCKET: (%d) %s\n" @@ -102,7 +103,7 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb) #if TORRENT_USE_IPV6 m_socket6.open(ios, ec); -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (ec) { if (m_log) fprintf(m_log, "FAILED TO OPEN SOCKET6: (%d) %s\n" @@ -114,7 +115,7 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb) lsd::~lsd() { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fclose(m_log); #endif } @@ -149,7 +150,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast to_hex((char const*)&ih[0], 20, ih_hex); char msg[200]; -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s ==> announce: ih: %s port: %u\n" , time_now_string(), ih_hex, listen_port); #endif @@ -163,7 +164,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast if (ec) { m_disabled = true; -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s failed to send message: (%d) %s" , time_now_string(), ec.value(), ec.message().c_str()); #endif @@ -179,7 +180,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast if (ec) { m_disabled6 = true; -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s failed to send message6: (%d) %s" , time_now_string(), ec.value(), ec.message().c_str()); #endif @@ -228,7 +229,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer if (!p.header_finished() || error) { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s <== announce: incomplete HTTP message\n", time_now_string()); #endif return; @@ -236,7 +237,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer if (p.method() != "bt-search") { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s <== announce: invalid HTTP method: %s\n" , time_now_string(), p.method().c_str()); #endif @@ -246,7 +247,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer std::string const& port_str = p.header("port"); if (port_str.empty()) { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s <== announce: invalid BT-SEARCH, missing port\n" , time_now_string()); #endif @@ -266,7 +267,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer boost::int32_t cookie = strtol(cookie_iter->second.c_str(), NULL, 16); if (cookie == m_cookie) { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s <== announce: ignoring packet (cookie matched our own): %x == %x\n" , time_now_string(), cookie, m_cookie); #endif @@ -282,7 +283,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer std::string const& ih_str = i->second; if (ih_str.size() != 40) { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s <== announce: invalid BT-SEARCH, invalid infohash: %s\n" , time_now_string(), ih_str.c_str()); #endif @@ -294,7 +295,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer if (!ih.is_all_zeros() && port != 0) { -#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) +#if defined TORRENT_LOGGING if (m_log) fprintf(m_log, "%s *** incoming local announce %s:%d ih: %s\n" , time_now_string(), print_address(from.address()).c_str() , port, ih_str.c_str()); diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index 168b67ed8..299e781b3 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -210,27 +210,23 @@ namespace libtorrent { namespace // invalid tex message if (added == 0) { -#ifdef TORRENT_VERBOSE_LOGGING - (*m_pc.m_logger) << time_now_string() << " <== LT_TEX [ NOT A DICTIONARY ]\n"; +#ifdef TORRENT_LOGGING + m_pc.peer_log(" <== LT_TEX [ NOT A DICTIONARY ]"); #endif return true; } -#ifdef TORRENT_VERBOSE_LOGGING - std::stringstream log_line; -#endif if (m_tp.num_tex_trackers() >= 50) { -#ifdef TORRENT_VERBOSE_LOGGING - log_line << time_now_string() << " <== LT_TEX [ " - "we already have " << m_tp.num_tex_trackers() << " trackers " - "from tex, don't add any more"; - (*m_pc.m_logger) << log_line.str(); +#ifdef TORRENT_LOGGING + m_pc.peer_log(" <== LT_TEX [ we already have %d trackers " + "from tex, don't add any more", m_tp.num_tex_trackers()); #endif return true; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING + std::stringstream log_line; log_line << time_now_string() << " <== LT_TEX [ " "added: "; #endif @@ -264,7 +260,7 @@ namespace libtorrent { namespace if (m_tp.num_tex_trackers() >= 50) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING log_line << "**reached-limit** "; #endif break; @@ -276,13 +272,13 @@ namespace libtorrent { namespace if (m_torrent.add_tracker(e)) m_tp.increment_tracker_counter(); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING log_line << e.url << " "; #endif } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING log_line << "]\n"; - (*m_pc.m_logger) << log_line.str(); + m_pc.peer_log("%s", log_line.str().c_str()); #endif return true; } @@ -334,7 +330,7 @@ namespace libtorrent { namespace if (!m_torrent.valid_metadata() || m_torrent.torrent_file().priv()) return false; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING std::stringstream log_line; log_line << time_now_string() << " ==> LT_TEX [ " "added: "; @@ -346,16 +342,16 @@ namespace libtorrent { namespace { if (!send_tracker(*i)) continue; added.push_back(i->url); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING log_line << i->url << " "; #endif } std::vector tex_msg; bencode(std::back_inserter(tex_msg), tex); -#ifdef TORRENT_VERBOSE_LOGGING - log_line << "]\n"; - (*m_pc.m_logger) << log_line.str(); +#ifdef TORRENT_LOGGING + log_line << "]"; + m_pc.peer_log("%s", log_line.str().c_str()); #endif char msg[6]; diff --git a/src/metadata_transfer.cpp b/src/metadata_transfer.cpp index 9caa183bb..65382a233 100644 --- a/src/metadata_transfer.cpp +++ b/src/metadata_transfer.cpp @@ -304,7 +304,7 @@ namespace libtorrent { namespace // abort if the peer doesn't support the metadata extension if (m_message_index == 0) return; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("==> METADATA_REQUEST [ start: %d | size: %d ]\n" , start, size); #endif @@ -342,7 +342,7 @@ namespace libtorrent { namespace char msg[15]; char* ptr = msg; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("==> METADATA [ start: %d | total_size: %d | offset: %d | data_size: %d ]" , req.first, req.second, offset.first, offset.second); #endif @@ -363,7 +363,7 @@ namespace libtorrent { namespace } else { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("==> DONT HAVE METADATA\n"); #endif char msg[4+3]; @@ -404,7 +404,7 @@ namespace libtorrent { namespace int start = detail::read_uint8(body.begin); int size = detail::read_uint8(body.begin) + 1; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== METADATA_REQUEST [ start: %d | size: %d ]\n" , start, size); #endif @@ -427,7 +427,7 @@ namespace libtorrent { namespace int offset = detail::read_int32(body.begin); int data_size = length - 9; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== METADATA [ total_size: %d | offset: %d | data_size: %d ]" ,total_size, offset, data_size); #endif @@ -470,7 +470,7 @@ namespace libtorrent { namespace if (m_waiting_metadata_request) m_tp.cancel_metadata_request(m_last_metadata_request); m_waiting_metadata_request = false; -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== DONT HAVE METADATA\n"); #endif break; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index c0adf53c0..03bed1b7f 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING #include // for va_start, va_end #include // for vsnprintf #endif @@ -73,7 +73,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING #include "libtorrent/escape_string.hpp" #include "libtorrent/socket_io.hpp" #endif @@ -233,19 +233,10 @@ namespace libtorrent #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES std::fill(m_country, m_country + 2, 0); #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING error_code ec; TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec); tcp::endpoint local_ep = m_socket->local_endpoint(ec); - std::string log_name = "[" + local_ep.address().to_string(ec) + "#" - + to_string(local_ep.port()).elems + "]-" - "[" + m_remote.address().to_string(ec) + "#" - + to_string(m_remote.port()).elems + "]"; - - if (t) log_name = combine_path(to_hex(t->info_hash().to_string()) - , log_name); - - m_logger = m_ses.create_log(log_name, m_ses.listen_port()); peer_log("%s [ ep: %s type: %s seed: %d p: %p local: %s]" , m_outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" , print_endpoint(m_remote).c_str() @@ -349,7 +340,7 @@ namespace libtorrent if (m_remote.address().is_v4() && m_settings.get_int(settings_pack::peer_tos) != 0) { m_socket->set_option(type_of_service(m_settings.get_int(settings_pack::peer_tos)), ec); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> SET_TOS[ tos: %d e: %s ]", m_settings.get_int(settings_pack::peer_tos), ec.message().c_str()); #endif } @@ -361,13 +352,13 @@ namespace libtorrent #endif } -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SET_PEER_CLASS [ a: %s ]", print_address(m_remote.address()).c_str()); #endif m_ses.set_peer_classes(this, m_remote.address(), m_socket->type()); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING for (int i = 0; i < num_classes(); ++i) { peer_log("*** CLASS [ %s ]", m_ses.peer_classes().at(class_at(i))->label.c_str()); @@ -382,7 +373,7 @@ namespace libtorrent // if this is an incoming connection, we're done here if (!m_connecting) return; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> OPEN [ protocol: %s ]", (m_remote.address().is_v4()?"IPv4":"IPv6")); #endif error_code ec; @@ -395,7 +386,7 @@ namespace libtorrent tcp::endpoint bound_ip = m_ses.bind_outgoing_socket(*m_socket , m_remote.address(), ec); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> BIND [ dst: %s ec: %s ]", print_endpoint(bound_ip).c_str() , ec.message().c_str()); #endif @@ -405,14 +396,14 @@ namespace libtorrent return; } -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> ASYNC_CONNECT [ dst: %s ]", print_endpoint(m_remote).c_str()); #endif #if defined TORRENT_ASIO_DEBUGGING add_outstanding_async("peer_connection::on_connection_complete"); #endif -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING if (t) t->debug_log("START connect [%p] (%d)", this, int(t->num_peers())); #endif @@ -428,7 +419,7 @@ namespace libtorrent t->alerts().post_alert(peer_connect_alert( t->get_handle(), remote(), pid(), m_socket->type())); } -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** LOCAL ENDPOINT[ e: %s ]", print_endpoint(m_socket->local_endpoint(ec)).c_str()); #endif } @@ -463,14 +454,14 @@ namespace libtorrent // flag will be updated once they are. if (m_have_piece.size() == 0) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** UPDATE_INTEREST [ connections not initialized ]"); #endif return; } if (!t->ready_for_connections()) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** UPDATE_INTEREST [ not ready for connections ]"); #endif return; @@ -489,7 +480,7 @@ namespace libtorrent && !p.has_piece_passed(j)) { interested = true; -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** UPDATE_INTEREST [ interesting, piece: %d ]", j); #endif break; @@ -497,11 +488,9 @@ namespace libtorrent } } -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING if (!interested) - { peer_log("*** UPDATE_INTEREST [ not interesting ]"); - } #endif if (!interested) send_not_interested(); @@ -512,21 +501,26 @@ namespace libtorrent disconnect_if_redundant(); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING void peer_connection::peer_log(char const* fmt, ...) const { TORRENT_ASSERT(is_single_thread()); - if (!m_logger) return; + + if (!m_ses.alerts().should_post()) return; va_list v; va_start(v, fmt); - char usr[400]; - vsnprintf(usr, sizeof(usr), fmt, v); + char buf[512]; + vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); - char buf[450]; - snprintf(buf, sizeof(buf), "%s: %s\n", time_now_string(), usr); - (*m_logger) << buf; + + torrent_handle h; + boost::shared_ptr t = m_torrent.lock(); + if (t) h = t->get_handle(); + + m_ses.alerts().post_alert(peer_log_alert( + h, m_remote, m_peer_id, buf)); } #endif @@ -559,7 +553,7 @@ namespace libtorrent if (t->super_seeding()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SKIPPING ALLOWED SET BECAUSE OF SUPER SEEDING"); #endif return; @@ -567,7 +561,7 @@ namespace libtorrent if (upload_only()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SKIPPING ALLOWED SET BECAUSE PEER IS UPLOAD ONLY"); #endif return; @@ -589,7 +583,7 @@ namespace libtorrent // that the peer already has if (has_piece(i)) continue; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> ALLOWED_FAST [ %d ]", i); #endif write_allow_fast(i); @@ -633,7 +627,7 @@ namespace libtorrent if (std::find(m_accept_fast.begin(), m_accept_fast.end(), piece) == m_accept_fast.end()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> ALLOWED_FAST [ %d ]", piece); #endif write_allow_fast(piece); @@ -711,7 +705,7 @@ namespace libtorrent if (m_num_pieces == int(m_have_piece.size())) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); #endif @@ -815,7 +809,7 @@ namespace libtorrent m_extensions.clear(); #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** CONNECTION CLOSED"); #endif TORRENT_ASSERT(m_request_queue.empty()); @@ -903,7 +897,7 @@ namespace libtorrent // dont announce during handshake if (in_handshake()) return; -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< RECEIVED [ piece: %d ]", index); #endif @@ -946,7 +940,7 @@ namespace libtorrent // to peers that already have the piece if (!m_settings.get_bool(settings_pack::send_redundant_have)) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> HAVE [ piece: %d ] SUPRESSED", index); #endif return; @@ -955,7 +949,7 @@ namespace libtorrent if (disconnect_if_redundant()) return; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> HAVE [ piece: %d ]", index); #endif write_have(index); @@ -1168,8 +1162,9 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING m_connect_time = time_now_hires(); + peer_log("*** attached to torrent"); #endif TORRENT_ASSERT(!m_disconnecting); @@ -1177,20 +1172,9 @@ namespace libtorrent boost::weak_ptr wpt = m_ses.find_torrent(ih); boost::shared_ptr t = wpt.lock(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - // now that we know which torrent this peer belongs - // to. Move the log file into its directory - - error_code ec; - std::string log_name = combine_path(to_hex(ih.to_string()) - , m_remote.address().to_string(ec) + "_" - + to_string(m_remote.port()).elems); - m_logger->move_log_file(m_ses.get_log_path(), log_name, m_ses.listen_port()); -#endif - if (t && t->is_aborted()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** the torrent has been aborted"); #endif t.reset(); @@ -1199,7 +1183,7 @@ namespace libtorrent if (!t) { t = m_ses.delay_load_torrent(ih, this); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING if (t) peer_log("*** Delay loaded torrent: %s:", to_hex(ih.to_string()).c_str()); #endif @@ -1208,7 +1192,7 @@ namespace libtorrent if (!t) { // we couldn't find the torrent! -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** couldn't find a torrent with the given info_hash: %s torrents:", to_hex(ih.to_string()).c_str()); m_ses.log_all_torrents(this); #endif @@ -1241,7 +1225,7 @@ namespace libtorrent // and inconing_starts_queued_torrents is true // torrents that have errors should always reject // incoming peers -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("rejected connection to paused torrent"); #endif disconnect(errors::torrent_paused, op_bittorrent, 2); @@ -1255,7 +1239,7 @@ namespace libtorrent { // the torrent is an i2p torrent, the peer is a regular peer // and we don't allow mixed mode. Disconnect the peer. -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("rejected regular connection to i2p torrent"); #endif disconnect(errors::peer_banned, op_bittorrent, 2); @@ -1336,7 +1320,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== KEEPALIVE"); #endif } @@ -1370,7 +1354,7 @@ namespace libtorrent #endif if (is_disconnecting()) return; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== CHOKE"); #endif if (m_peer_choked == false) @@ -1429,7 +1413,7 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); TORRENT_ASSERT(t); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== REJECT_PIECE [ piece: %d | s: %x | l: %x ]" , r.piece, r.start, r.length); #endif @@ -1478,7 +1462,7 @@ namespace libtorrent check_invariant(); #endif } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING else { peer_log("*** PIECE NOT IN REQUEST QUEUE"); @@ -1518,7 +1502,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== SUGGEST_PIECE [ piece: %d ]", index); #endif boost::shared_ptr t = m_torrent.lock(); @@ -1535,7 +1519,7 @@ namespace libtorrent if (is_disconnecting()) return; if (index < 0) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("<== INVALID_SUGGEST_PIECE [ %d ]", index); #endif return; @@ -1545,7 +1529,7 @@ namespace libtorrent { if (index >= int(m_have_piece.size())) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("<== INVALID_SUGGEST [ %d | s: %d ]" , index, int(m_have_piece.size())); #endif @@ -1563,7 +1547,7 @@ namespace libtorrent m_suggested_pieces.push_back(index); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("** SUGGEST_PIECE [ piece: %d added to set: %d ]", index, int(m_suggested_pieces.size())); #endif } @@ -1580,7 +1564,7 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); TORRENT_ASSERT(t); -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING m_unchoke_time = time_now_hires(); t->debug_log("UNCHOKE [%p] (%d ms)", this, int(total_milliseconds(m_unchoke_time - m_bitfield_time))); #endif @@ -1593,7 +1577,7 @@ namespace libtorrent } #endif -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== UNCHOKE"); #endif if (m_peer_choked) @@ -1631,7 +1615,7 @@ namespace libtorrent } #endif -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== INTERESTED"); #endif if (m_peer_interested == false) @@ -1648,7 +1632,7 @@ namespace libtorrent if (t->graceful_pause()) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("DID NOT UNCHOKE [ graceful pause mode ]"); #endif return; @@ -1664,7 +1648,7 @@ namespace libtorrent // when sending the interested message. If the other end's client // has this problem, sending another unchoke here will kick it // to react to the fact that it's unchoked. -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("SENDING REDUNDANT UNCHOKE"); #endif write_unchoke(); @@ -1679,7 +1663,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); if (ignore_unchoke_slots()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("ABOUT TO UNCHOKE [ peer ignores unchoke slots ]"); #endif // if this peer is expempted from the choker @@ -1704,7 +1688,7 @@ namespace libtorrent t->unchoke_peer(*this); } -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING else { peer_log("DID NOT UNCHOKE [ the number of uploads (%d) " @@ -1733,7 +1717,7 @@ namespace libtorrent m_became_uninterested = time_now(); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== NOT_INTERESTED"); #endif if (m_peer_interested) @@ -1797,7 +1781,7 @@ namespace libtorrent // probably omitted, which is the same as 'have_none' if (!m_bitfield_received) incoming_have_none(); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HAVE [ piece: %d ]", index); #endif @@ -1824,7 +1808,7 @@ namespace libtorrent // if we got an invalid message, abort if (index >= int(m_have_piece.size()) || index < 0) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** ERROR: [ have-metadata have_piece.size: %d ]", index, int(m_have_piece.size())); #endif disconnect(errors::invalid_have, op_bittorrent, 2); @@ -1847,7 +1831,7 @@ namespace libtorrent if (m_have_piece[index]) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log(" got redundant HAVE message for index: %d", index); #endif return; @@ -1883,7 +1867,7 @@ namespace libtorrent // decrement the piece count without first incrementing it if (is_seed()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); #endif @@ -1953,7 +1937,7 @@ namespace libtorrent if (is_disconnecting()) return; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== DONT_HAVE [ piece: %d ]", index); #endif @@ -1966,7 +1950,7 @@ namespace libtorrent if (!m_have_piece[index]) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log(" got redundant DONT_HAVE message for index: %d", index); #endif return; @@ -2011,7 +1995,7 @@ namespace libtorrent if (is_disconnecting()) return; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING std::string bitfield_str; bitfield_str.resize(bits.size()); for (int i = 0; i < int(bits.size()); ++i) @@ -2038,7 +2022,7 @@ namespace libtorrent m_bitfield_received = true; -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING m_bitfield_time = time_now_hires(); t->debug_log("HANDSHAKE [%p] (%d ms)", this, int(total_milliseconds(m_bitfield_time - m_connect_time))); #endif @@ -2048,7 +2032,7 @@ namespace libtorrent // (since it doesn't exist yet) if (!t->ready_for_connections()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING if (m_num_pieces == int(bits.size())) peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); #endif @@ -2068,7 +2052,7 @@ namespace libtorrent int num_pieces = bits.count(); if (num_pieces == int(m_have_piece.size())) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); #endif @@ -2132,7 +2116,7 @@ namespace libtorrent if (m_upload_only && t->is_upload_only() && can_disconnect(error_code(errors::upload_upload_connection, get_libtorrent_category()))) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** the peer is upload-only and our torrent is also upload-only"); #endif disconnect(errors::upload_upload_connection, op_bittorrent); @@ -2145,7 +2129,7 @@ namespace libtorrent && t->are_files_checked() && can_disconnect(error_code(errors::uninteresting_upload_peer, get_libtorrent_category()))) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** the peer is upload-only and we're not interested in it"); #endif disconnect(errors::uninteresting_upload_peer, op_bittorrent); @@ -2182,7 +2166,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::piece_requests); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== REQUEST [ piece: %d s: %x l: %x ]" , r.piece, r.start, r.length); #endif @@ -2192,7 +2176,7 @@ namespace libtorrent { m_counters.inc_stats_counter(counters::invalid_piece_requests); ++m_num_invalid_requests; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** INVALID_REQUEST [ piece not superseeded " "i: %d t: %d n: %d h: %d ss1: %d ss2: %d ]" , m_peer_interested @@ -2232,7 +2216,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::invalid_piece_requests); // if we don't have valid metadata yet, // we shouldn't get a request -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** INVALID_REQUEST [ we don't have metadata yet ]"); peer_log("==> REJECT_PIECE [ piece: %d | s: %x | l: %x ] no metadata" , r.piece, r.start, r.length); @@ -2248,7 +2232,7 @@ namespace libtorrent // memory consumption. // ignore requests if the client // is making too many of them. -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** INVALID_REQUEST [ incoming request queue full %d ]" , int(m_requests.size())); peer_log("==> REJECT_PIECE [ piece: %d | s: %x | l: %x ] too many requests" @@ -2280,7 +2264,7 @@ namespace libtorrent { m_counters.inc_stats_counter(counters::invalid_piece_requests); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** INVALID_REQUEST [ " "i: %d t: %d n: %d h: %d block_limit: %d ]" , m_peer_interested @@ -2311,7 +2295,7 @@ namespace libtorrent disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2); return; } -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> CHOKE"); #endif write_choke(); @@ -2336,7 +2320,7 @@ namespace libtorrent if (m_choked && fast_idx == -1) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** REJECTING REQUEST [ peer choked and piece not in allowed fast set ]"); peer_log(" ==> REJECT_PIECE [ piece: %d | s: %d | l: %d ] peer choked" , r.piece, r.start, r.length); @@ -2428,7 +2412,7 @@ namespace libtorrent if (!verify_piece(r)) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** INVALID_PIECE [ piece: %d s: %d l: %d ]" , r.piece, r.start, r.length); #endif @@ -2475,7 +2459,7 @@ namespace libtorrent t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote , m_peer_id, b.block_index, b.piece_index)); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** The block we just got was not in the request queue ***"); #endif TORRENT_ASSERT(m_download_queue.front().block == b); @@ -2537,7 +2521,7 @@ namespace libtorrent if ((m_channel_state[download_channel] & peer_info::bw_disk) == 0) m_counters.inc_stats_counter(counters::num_peers_down_disk); m_channel_state[download_channel] |= peer_info::bw_disk; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** exceeded disk buffer watermark"); #endif } @@ -2599,7 +2583,7 @@ namespace libtorrent #endif #endif -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING hasher h; h.update(data.get(), p.length); peer_log("<== PIECE [ piece: %d | s: %x | l: %x | ds: %d | qs: %d | q: %d | hash: %s ]" @@ -2660,7 +2644,7 @@ namespace libtorrent t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote , m_peer_id, block_finished.block_index, block_finished.piece_index)); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** The block we just got was not in the request queue ***"); #endif #if TORRENT_USE_ASSERTS @@ -2703,9 +2687,7 @@ namespace libtorrent if (m_disconnecting) return; m_request_time.add_sample(total_milliseconds(now - m_requested)); -#if defined TORRENT_LOGGING \ - || defined TORRENT_ERROR_LOGGING \ - || defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** REQUEST-TIME (%d +- %d ms)" , m_request_time.mean(), m_request_time.avg_deviation()); #endif @@ -2736,12 +2718,10 @@ namespace libtorrent } } -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING t->debug_log("PIECE [%p] (%d ms) (%d)", this , int(total_milliseconds(time_now_hires() - m_unchoke_time)), t->num_have()); -#endif -#ifdef TORRENT_VERBOSE_LOGGING peer_log("*** FILE ASYNC WRITE [ piece: %d | s: %x | l: %x ]" , p.piece, p.start, p.length); #endif @@ -2777,9 +2757,7 @@ namespace libtorrent } m_request_time.add_sample(total_milliseconds(now - m_requested)); -#if defined TORRENT_LOGGING \ - || defined TORRENT_ERROR_LOGGING \ - || defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** REQUEST-TIME (%d +- %d ms)" , m_request_time.mean(), m_request_time.avg_deviation()); #endif @@ -2877,7 +2855,7 @@ namespace libtorrent torrent_ref_holder h(t.get(), "async_write"); if (t) t->dec_refcount("async_write"); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** FILE ASYNC WRITE COMPLETE [ ret: %d | piece: %d | s: %x | l: %x | e: %s ]" , j->ret, p.piece, p.start, p.length, j->error.ec.message().c_str()); #endif @@ -2982,7 +2960,7 @@ namespace libtorrent #endif if (is_disconnecting()) return; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== CANCEL [ piece: %d | s: %x | l: %x ]", r.piece, r.start, r.length); #endif @@ -2997,7 +2975,7 @@ namespace libtorrent if (m_requests.empty()) m_counters.inc_stats_counter(counters::num_peers_up_requests, -1); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> REJECT_PIECE [ piece: %d s: %x l: %x ] cancelled" , r.piece , r.start , r.length); #endif @@ -3010,7 +2988,7 @@ namespace libtorrent // queue entry around, mark it as having been requested from // disk and once the disk job comes back, discard it if it has // been cancelled. Maybe even be able to cancel disk jobs? -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** GOT CANCEL NOT IN THE QUEUE"); #endif } @@ -3025,7 +3003,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== DHT_PORT [ p: %d ]", listen_port); #endif #ifndef TORRENT_DISABLE_DHT @@ -3050,7 +3028,7 @@ namespace libtorrent // this function may end up doing that TORRENT_ASSERT(m_in_constructor == false); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HAVE_ALL"); #endif @@ -3068,7 +3046,7 @@ namespace libtorrent m_have_all = true; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); #endif @@ -3076,7 +3054,7 @@ namespace libtorrent m_upload_only = true; m_bitfield_received = true; -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING m_bitfield_time = time_now_hires(); t->debug_log("HANDSHAKE [%p] (%d ms)", this, int(total_milliseconds(m_bitfield_time - m_connect_time))); #endif @@ -3126,7 +3104,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<== HAVE_NONE"); #endif @@ -3148,7 +3126,7 @@ namespace libtorrent t->set_seed(m_peer_info, false); m_bitfield_received = true; -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING m_bitfield_time = time_now_hires(); t->debug_log("HANDSHAKE [%p] (%d ms)", this, int(total_milliseconds(m_bitfield_time - m_connect_time))); #endif @@ -3177,15 +3155,12 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); TORRENT_ASSERT(t); -#ifdef TORRENT_LOGGING +#if defined TORRENT_LOGGING { ptime now = time_now_hires(); t->debug_log("ALLOW FAST [%p] (%d ms)", this, int(total_milliseconds(now - m_connect_time))); if (m_peer_choked) m_unchoke_time = now; } -#endif - -#ifdef TORRENT_VERBOSE_LOGGING peer_log("<== ALLOWED_FAST [ %d ]", index); #endif @@ -3199,7 +3174,7 @@ namespace libtorrent if (is_disconnecting()) return; if (index < 0) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("<== INVALID_ALLOWED_FAST [ %d ]", index); #endif return; @@ -3209,7 +3184,7 @@ namespace libtorrent { if (index >= int(m_have_piece.size())) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("<== INVALID_ALLOWED_FAST [ %d | s: %d ]" , index, int(m_have_piece.size())); #endif @@ -3312,7 +3287,7 @@ namespace libtorrent if (t->upload_mode()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** PIECE_PICKER [ not_picking: %d,%d upload_mode ]" , block.piece_index, block.block_index); #endif @@ -3320,7 +3295,7 @@ namespace libtorrent } if (m_disconnecting) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** PIECE_PICKER [ not_picking: %d,%d disconnecting ]" , block.piece_index, block.block_index); #endif @@ -3359,7 +3334,7 @@ namespace libtorrent { if (i->busy) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** PIECE_PICKER [ not_picking: %d,%d already in download queue & busy ]" , block.piece_index, block.block_index); #endif @@ -3372,7 +3347,7 @@ namespace libtorrent { if (i->busy) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** PIECE_PICKER [ not_picking: %d,%d already in request queue & busy ]" , block.piece_index, block.block_index); #endif @@ -3383,7 +3358,7 @@ namespace libtorrent if (!t->picker().mark_as_downloading(block, peer_info_struct(), state)) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** PIECE_PICKER [ not_picking: %d,%d failed to mark_as_downloading ]" , block.piece_index, block.block_index); #endif @@ -3422,7 +3397,7 @@ namespace libtorrent TORRENT_ASSERT(t->valid_metadata()); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** CANCEL ALL REQUESTS"); #endif @@ -3458,7 +3433,7 @@ namespace libtorrent r.start = block_offset; r.length = block_size; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> CANCEL [ piece: %d s: %d l: %d b: %d ]" , b.piece_index, block_offset, block_size, b.block_index); #endif @@ -3526,7 +3501,7 @@ namespace libtorrent r.start = block_offset; r.length = block_size; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> CANCEL [ piece: %d s: %d l: %d b: %d ]" , block.piece_index, block_offset, block_size, block.block_index); #endif @@ -3551,7 +3526,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_up_unchoked_optimistic, -1); } -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> CHOKE"); #endif write_choke(); @@ -3576,7 +3551,7 @@ namespace libtorrent } peer_request const& r = *i; m_counters.inc_stats_counter(counters::choked_piece_requests); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> REJECT_PIECE [ piece: %d s: %d l: %d ] choking" , r.piece , r.start , r.length); #endif @@ -3625,7 +3600,7 @@ namespace libtorrent m_uploaded_at_last_unchoke = m_statistics.total_payload_upload(); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> UNCHOKE"); #endif return true; @@ -3641,7 +3616,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_down_interested); write_interested(); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> INTERESTED"); #endif } @@ -3671,7 +3646,7 @@ namespace libtorrent m_became_uninteresting = time_now(); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> NOT_INTERESTED"); #endif } @@ -3722,7 +3697,7 @@ namespace libtorrent if (t->graceful_pause() && m_outstanding_bytes == 0) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** GRACEFUL PAUSE [ NO MORE DOWNLOAD ]"); #endif disconnect(errors::torrent_paused, op_bittorrent); @@ -3786,14 +3761,6 @@ namespace libtorrent check_invariant(); #endif -/* -#ifdef TORRENT_VERBOSE_LOGGING - (*m_logger) << time_now_string() - << " *** REQUEST-QUEUE** [ " - "piece: " << block.piece_index << " | " - "block: " << block.block_index << " ]\n"; -#endif -*/ // if we are requesting large blocks, merge the smaller // blocks that are in the same piece into larger requests if (m_request_large_blocks) @@ -3819,7 +3786,7 @@ namespace libtorrent m_download_queue.push_back(block); if (m_queued_time_critical) --m_queued_time_critical; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** MERGING REQUEST [ piece: %d block: %d ]" , block.block.piece_index, block.block.block_index); #endif @@ -3856,7 +3823,7 @@ namespace libtorrent m_last_request = time_now(); } -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> REQUEST [ piece: %d | s: %x | l: %x | ds: %d B/s | " "dqs: %d rqs: %d blk: %s ]" , r.piece, r.start, r.length, statistics().download_rate() @@ -3873,7 +3840,7 @@ namespace libtorrent // previously did not have a request. That's when we start the // request timeout. m_requested = time_now(); -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING t->debug_log("REQUEST [%p] (%d ms)", this , int(total_milliseconds(time_now_hires() - m_unchoke_time))); #endif @@ -3885,10 +3852,10 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(e); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("CONNECTION FAILED: %s", print_endpoint(m_remote).c_str()); #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING m_ses.session_log(" CONNECTION FAILED: %s", print_endpoint(m_remote).c_str()); #endif @@ -3960,7 +3927,7 @@ namespace libtorrent // proper books in the piece_picker (when debugging is enabled) torrent_peer* self_peer = peer_info_struct(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING switch (error) { case 0: @@ -4413,7 +4380,7 @@ namespace libtorrent if (exceeded) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** exceeded disk buffer watermark"); #endif if ((m_channel_state[download_channel] & peer_info::bw_disk) == 0) @@ -4433,7 +4400,7 @@ namespace libtorrent m_superseed_piece[0] = -1; m_superseed_piece[1] = -1; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** ending super seed mode"); #endif boost::shared_ptr t = m_torrent.lock(); @@ -4449,7 +4416,7 @@ namespace libtorrent assert(!has_piece(new_piece)); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> HAVE [ piece: %d ] (super seed)", new_piece); #endif write_have(new_piece); @@ -4607,7 +4574,7 @@ namespace libtorrent if (d > seconds(connect_timeout) && can_disconnect(error_code(errors::timed_out, get_libtorrent_category()))) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** CONNECT FAILED [ waited %d seconds ] ***", int(total_seconds(d))); #endif connect_failed(errors::timed_out); @@ -4627,7 +4594,7 @@ namespace libtorrent if (may_timeout && d > seconds(timeout()) && !m_connecting && m_reading_bytes == 0 && can_disconnect(error_code(errors::timed_out_inactivity, get_libtorrent_category()))) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** LAST ACTIVITY [ %d seconds ago ] ***", int(total_seconds(d))); #endif disconnect(errors::timed_out_inactivity, op_bittorrent); @@ -4640,7 +4607,7 @@ namespace libtorrent && in_handshake() && d > seconds(m_settings.get_int(settings_pack::handshake_timeout))) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** NO HANDSHAKE [ waited %d seconds ] ***", int(total_seconds(d))); #endif disconnect(errors::timed_out_no_handshake, op_bittorrent); @@ -4661,7 +4628,7 @@ namespace libtorrent && d > seconds(60) && can_disconnect(error_code(errors::timed_out_no_request, get_libtorrent_category()))) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** NO REQUEST [ waited %d seconds ] ***", int(total_seconds(d))); #endif disconnect(errors::timed_out_no_request, op_bittorrent); @@ -4690,7 +4657,7 @@ namespace libtorrent || (t && t->num_peers() >= t->max_connections())) && can_disconnect(error_code(errors::timed_out_no_interest, get_libtorrent_category()))) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** MUTUAL NO INTEREST [ t1: %d t2: %d ]" , total_seconds(d1), total_seconds(d2)); #endif @@ -4742,7 +4709,7 @@ namespace libtorrent // requested (this has been observed by BitComet) // in this case we'll clear our download queue and // re-request the blocks. -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** PIECE_REQUEST TIMED OUT [ %d time: %d to: %d ]" , (int)m_download_queue.size(), total_seconds(now - m_last_piece) , piece_timeout); @@ -4936,7 +4903,7 @@ namespace libtorrent if (t->is_deleted()) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> REJECT_PIECE [ piece: %d s: %x l: %x ] torrent deleted" , r.piece , r.start , r.length); #endif @@ -4955,7 +4922,7 @@ namespace libtorrent ++m_outstanding_piece_verification; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SEED-MODE FILE ASYNC HASH [ piece: %d ]", r.piece); #endif // this means we're in seed mode and we haven't yet @@ -4979,7 +4946,7 @@ namespace libtorrent // hold off on sending it. If the piece fails later // we will reject this request if (t->is_predictive_piece(r.piece)) continue; -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> REJECT_PIECE [ piece: %d s: %x l: %x ] piece not passed hash check" , r.piece , r.start , r.length); #endif @@ -4987,7 +4954,7 @@ namespace libtorrent } else { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** FILE ASYNC READ [ piece: %d | s: %x | l: %x ]" , r.piece, r.start, r.length); #endif @@ -5042,7 +5009,7 @@ namespace libtorrent if (!m_settings.get_bool(settings_pack::disable_hash_checks) && sha1_hash(j->d.piece_hash) != t->torrent_file().hash_for_piece(j->piece)) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SEED-MODE FILE HASH [ piece: %d failed ]", j->piece); #endif @@ -5053,7 +5020,7 @@ namespace libtorrent TORRENT_ASSERT(t->verifying_piece(j->piece)); if (t->seed_mode()) t->verified(j->piece); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SEED-MODE FILE HASH [ piece: %d passed ]", j->piece); #endif if (t) @@ -5078,7 +5045,7 @@ namespace libtorrent int disk_rtt = int(total_microseconds(time_now_hires() - issue_time)); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** FILE ASYNC READ COMPLETE [ ret: %d | piece: %d | s: %x | l: %x" " | b: %p | c: %s | e: %s | rtt: %d us ]" , j->ret, r.piece, r.start, r.length, j->buffer @@ -5144,7 +5111,7 @@ namespace libtorrent return; } -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> PIECE [ piece: %d s: %x l: %x ]" , r.piece, r.start, r.length); #endif @@ -5165,7 +5132,7 @@ namespace libtorrent void peer_connection::assign_bandwidth(int channel, int amount) { TORRENT_ASSERT(is_single_thread()); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("%s ASSIGN BANDWIDHT [ bytes: %d ]" , channel == upload_channel ? ">>>" : "<<<", amount); #endif @@ -5258,7 +5225,7 @@ namespace libtorrent } #endif -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("%s REQUEST_BANDWIDTH [ bytes: %d quota: %d wanted_transfer: %d " "prio: %d num_channels: %d ]" , channel == download_channel ? "<<<" : ">>>", bytes @@ -5275,7 +5242,7 @@ namespace libtorrent if (ret == 0) m_channel_state[channel] |= peer_info::bw_limit; else { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("%s ASSIGN BANDWIDTH [ bytes: %d ]" , channel == download_channel ? "<<<" : ">>>", ret); #endif @@ -5336,7 +5303,7 @@ namespace libtorrent if ((m_channel_state[upload_channel] & peer_info::bw_disk) == 0) m_counters.inc_stats_counter(counters::num_peers_up_disk); m_channel_state[upload_channel] |= peer_info::bw_disk; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> waiting for disk [outstanding: %d]", m_reading_bytes); #endif @@ -5372,7 +5339,7 @@ namespace libtorrent if (!can_write()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING if (m_send_buffer.empty()) { peer_log(">>> SEND BUFFER DEPLETED [" @@ -5404,14 +5371,14 @@ namespace libtorrent if (m_corked) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> CORKED WRITE [ bytes: %d ]", amount_to_send); #endif return; } TORRENT_ASSERT((m_channel_state[upload_channel] & peer_info::bw_network) == 0); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> ASYNC_WRITE [ bytes: %d ]", amount_to_send); #endif std::vector const& vec = m_send_buffer.build_iovec(amount_to_send); @@ -5448,7 +5415,7 @@ namespace libtorrent if ((m_channel_state[download_channel] & peer_info::bw_disk) == 0) return; boost::shared_ptr me(self()); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** dropped below disk buffer watermark"); #endif m_counters.inc_stats_counter(counters::num_peers_down_disk, -1); @@ -5491,7 +5458,7 @@ namespace libtorrent if (!can_read()) { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< CANNOT READ [ quota: %d " "can-write-to-disk: %s queue-limit: %d disconnecting: %s " " connecting: %s ]" @@ -5546,7 +5513,7 @@ namespace libtorrent TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0); m_channel_state[download_channel] |= peer_info::bw_network; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< ASYNC_READ [ ]"); #endif @@ -5576,7 +5543,7 @@ namespace libtorrent { TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0); m_channel_state[download_channel] |= peer_info::bw_network; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< ASYNC_READ [ max: %d bytes ]", max_receive); #endif @@ -5636,7 +5603,7 @@ namespace libtorrent // this is weird. You would imagine read_some() would do this if (ret == 0 && !ec) ec = asio::error::eof; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]", max_receive, ret, ec ? ec.message().c_str() : ""); #endif return ret; @@ -5739,7 +5706,7 @@ namespace libtorrent return; } -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< READ_AVAILABLE [ bytes: %d ]", buffer_size); #endif @@ -5846,7 +5813,7 @@ namespace libtorrent , std::size_t bytes_transferred, int read_loops) { TORRENT_ASSERT(is_single_thread()); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" , bytes_transferred, error.message().c_str()); #endif @@ -5869,7 +5836,7 @@ namespace libtorrent if (error) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("*** ERROR [ in peer_connection::on_receive_data error: %s ]" , error.message().c_str()); #endif @@ -5884,7 +5851,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::on_read_counter); m_ses.received_buffer(bytes_transferred); -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" , bytes_transferred, error.message().c_str()); #endif @@ -5895,7 +5862,7 @@ namespace libtorrent int num_loops = 0; do { -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("<<< read %d bytes", int(bytes_transferred)); #endif // correct the dl quota usage, if not all of the buffer was actually read @@ -6025,7 +5992,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_down_disk); const_cast(this)->m_channel_state[download_channel] |= peer_info::bw_disk; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** exceeded disk buffer watermark"); #endif return false; @@ -6047,7 +6014,7 @@ namespace libtorrent INVARIANT_CHECK; -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING { boost::shared_ptr t = m_torrent.lock(); t->debug_log("END connect [%p]", this); @@ -6126,14 +6093,14 @@ namespace libtorrent received_synack(m_remote.address().is_v6()); TORRENT_ASSERT(m_socket); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> COMPLETED [ ep: %s ]", print_endpoint(m_remote).c_str()); #endif // set the socket to non-blocking, so that we can // read the entire buffer on each read event we get tcp::socket::non_blocking_io ioc(true); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** SET NON-BLOCKING"); #endif m_socket->io_control(ioc, ec); @@ -6156,7 +6123,7 @@ namespace libtorrent { error_code ec; m_socket->set_option(type_of_service(m_settings.get_int(settings_pack::peer_tos)), ec); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> SET_TOS[ tos: %d e: %s ]", m_settings.get_int(settings_pack::peer_tos), ec.message().c_str()); #endif } @@ -6200,7 +6167,7 @@ namespace libtorrent // in the current message queue m_ses.deferred_submit_jobs(); -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("*** ON_SEND_DATA [ bytes: %d error: %s ]" , int(bytes_transferred), error.message().c_str()); #endif @@ -6239,13 +6206,13 @@ namespace libtorrent if (m_send_barrier != INT_MAX) m_send_barrier -= bytes_transferred; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log(">>> wrote %d bytes", int(bytes_transferred)); #endif if (error) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer_log("**ERROR**: %s [in peer_connection::on_send_data]", error.message().c_str()); #endif disconnect(error, op_sock_write); @@ -6577,7 +6544,7 @@ namespace libtorrent // alive if (m_channel_state[upload_channel] & peer_info::bw_network) return; -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING peer_log("==> KEEPALIVE"); #endif diff --git a/src/peer_list.cpp b/src/peer_list.cpp index 9c11af3e0..6f6389503 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -65,7 +65,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket_io.hpp" // for print_endpoint #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING #include "libtorrent/socket_io.hpp" // for print_endpoint #include "libtorrent/ip_voter.hpp" // for external_ip #endif @@ -603,7 +603,7 @@ namespace libtorrent TORRENT_ASSERT(i->connection != &c); TORRENT_ASSERT(i->address() == c.remote().address()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING c.peer_log("*** DUPLICATE PEER [ this: \"%s\" that: \"%s\" ]" , print_address(c.remote().address()).c_str() , print_address(i->address()).c_str()); @@ -660,7 +660,7 @@ namespace libtorrent if (our_port < other_port) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING c.peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" < \"%d\" ]", our_port, other_port); i->connection->peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" < \"%d\" ]", our_port, other_port); #endif @@ -678,7 +678,7 @@ namespace libtorrent } else { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING c.peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" >= \"%d\" ]", our_port, other_port); i->connection->peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" >= \"%d\" ]", our_port, other_port); #endif diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index 49e48d66a..2bb4a0446 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -90,7 +90,7 @@ namespace libtorrent - (int)c.download_queue().size() - (int)c.request_queue().size(); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING c.peer_log("*** PIECE_PICKER [ dlq: %d rqq: %d target: %d req: %d engame: %d ]" , int(c.download_queue().size()), int(c.request_queue().size()) , c.desired_queue_size(), num_requests, c.endgame()); @@ -167,7 +167,7 @@ namespace libtorrent , state, c.picker_options(), suggested, t.num_peers() , ses.stats_counters()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING c.peer_log("*** PIECE_PICKER [ prefer_whole: %d picked: %d ]" , prefer_whole_pieces, int(interesting_pieces.size())); #endif @@ -232,7 +232,7 @@ namespace libtorrent = std::find_if(dq.begin(), dq.end(), has_block(*i)); if (j != dq.end()) TORRENT_ASSERT(j->timed_out || j->not_wanted); #endif -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING c.peer_log("*** PIECE_PICKER [ not_picking: %d,%d already in queue ]" , i->piece_index, i->block_index); #endif diff --git a/src/session.cpp b/src/session.cpp index 245b529e3..e154e3a8f 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -404,14 +404,6 @@ namespace libtorrent m_impl.reset(new session_impl(id)); } - void session::set_log_path(std::string const& p) - { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING \ - || defined TORRENT_ERROR_LOGGING - m_impl->set_log_path(p); -#endif - } - void session::start(int flags, settings_pack const& pack) { #ifndef TORRENT_DISABLE_EXTENSIONS @@ -419,6 +411,7 @@ namespace libtorrent { add_extension(create_ut_pex_plugin); add_extension(create_ut_metadata_plugin); + // TODO: 3 lt_trackers should not be on by default add_extension(create_lt_trackers_plugin); add_extension(create_smart_ban_plugin); } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index eba1d9c01..5f1a9722e 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -95,15 +95,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent_peer.hpp" #include "libtorrent/choker.hpp" -#if defined TORRENT_VERBOSE_LOGGING -#include "libtorrent/socket_io.hpp" -#endif - #ifndef TORRENT_WINDOWS #include #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING + +#include "libtorrent/socket_io.hpp" // for logging stat layout #include "libtorrent/stat.hpp" @@ -120,17 +118,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/udp_tracker_connection.hpp" -#include "libtorrent/debug.hpp" - -#if TORRENT_USE_IOSTREAM -namespace libtorrent { -std::ofstream logger::log_file; -std::string logger::open_filename; -mutex logger::file_mutex; -} -#endif // TORRENT_USE_IOSTREAM - -#endif +#endif // TORRENT_LOGGING #ifdef TORRENT_USE_GCRYPT @@ -415,9 +403,6 @@ namespace aux { , m_host_resolver(m_io_service) , m_download_connect_attempts(0) , m_tick_residual(0) -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - , m_logpath(".") -#endif , m_deferred_submit_disk_jobs(false) , m_pending_auto_manage(false) , m_need_auto_manage(false) @@ -475,9 +460,8 @@ namespace aux { void session_impl::start_session(settings_pack const& pack) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - m_logger = create_log("main_session", listen_port(), false); - session_log("log created"); +#if defined TORRENT_LOGGING + session_log("start session"); #endif error_code ec; @@ -533,22 +517,16 @@ namespace aux { // TODO: there's no rule here to make uTP connections not have the global or // local rate limits apply to it. This used to be the default. -#ifdef TORRENT_UPNP_LOGGING - m_upnp_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc); -#endif +#if defined TORRENT_LOGGING -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - - char tmp[300]; - snprintf(tmp, sizeof(tmp), "libtorrent configuration: %s\n" + session_log("libtorrent configuration: %s\n" "libtorrent version: %s\n" "libtorrent revision: %s\n\n" , TORRENT_CFG_STRING , LIBTORRENT_VERSION , LIBTORRENT_REVISION); - (*m_logger) << tmp; -#endif // TORRENT_VERBOSE_LOGGING +#endif // TORRENT_LOGGING #if TORRENT_USE_RLIMIT // ---- auto-cap max connections ---- @@ -556,7 +534,7 @@ namespace aux { struct rlimit rl; if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log(" max number of open files: %d", rl.rlim_cur); #endif // deduct some margin for epoll/kqueue, log files, @@ -568,7 +546,7 @@ namespace aux { m_settings.get_int(settings_pack::connections_limit) , int(rl.rlim_cur * 8 / 10))); // 20% goes towards regular files (see disk_io_thread) -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log(" max connections: %d", m_settings.get_int(settings_pack::connections_limit)); session_log(" max files: %d", int(rl.rlim_cur * 2 / 10)); #endif @@ -576,7 +554,7 @@ namespace aux { #endif // TORRENT_USE_RLIMIT -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log(" generated peer ID: %s", m_peer_id.to_string().c_str()); #endif @@ -585,7 +563,7 @@ namespace aux { // call update_* after settings set initialized m_io_service.post(boost::bind(&session_impl::init_settings, this)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log(" spawning network thread"); #endif m_thread.reset(new thread(boost::bind(&session_impl::main_thread, this))); @@ -675,7 +653,7 @@ namespace aux { void session_impl::init() { -#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING session_log(" *** session thread init"); #endif @@ -704,7 +682,7 @@ namespace aux { update_dht_announce_interval(); #endif -#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING session_log(" done starting session"); #endif } @@ -964,7 +942,7 @@ namespace aux { TORRENT_ASSERT(is_single_thread()); if (m_paused) return; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING session_log(" *** session paused ***"); #endif m_paused = true; @@ -1046,7 +1024,7 @@ namespace aux { m_i2p_listen_socket.reset(); #endif -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" aborting all torrents (%d)", m_torrents.size()); #endif // abort all torrents @@ -1057,12 +1035,12 @@ namespace aux { } m_torrents.clear(); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" aborting all tracker requests"); #endif m_tracker_manager.abort_all_requests(); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" aborting all connections (%d)", m_connections.size()); #endif // abort all connections @@ -1587,7 +1565,7 @@ namespace aux { if (m_alerts.should_post()) m_alerts.post_alert(listen_failed_alert(device, last_op, ec, sock_type)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("failed to open socket: %s: %s" , device.c_str(), ec.message().c_str()); #endif @@ -1629,7 +1607,7 @@ namespace aux { while (ec && retries > 0) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("failed to bind to interface [%s] \"%s\": %s" , device.c_str(), bind_ip.to_string(ec).c_str() , ec.message().c_str()); @@ -1657,7 +1635,7 @@ namespace aux { // not even that worked, give up if (m_alerts.should_post()) m_alerts.post_alert(listen_failed_alert(device, last_op, ec, sock_type)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("cannot bind to interface \"%s\": %s" , device.c_str(), ec.message().c_str()); #endif @@ -1675,7 +1653,7 @@ namespace aux { { if (m_alerts.should_post()) m_alerts.post_alert(listen_failed_alert(device, last_op, ec, sock_type)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("cannot listen on interface \"%s\": %s" , device.c_str(), ec.message().c_str()); #endif @@ -1692,11 +1670,9 @@ namespace aux { { if (m_alerts.should_post()) m_alerts.post_alert(listen_failed_alert(device, last_op, ec, sock_type)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - char msg[200]; - snprintf(msg, 200, "failed to get peer name \"%s\": %s" +#if defined TORRENT_LOGGING + session_log("failed to get peer name \"%s\": %s" , device.c_str(), ec.message().c_str()); - (*m_logger) << time_now_string() << msg << "\n"; #endif } } @@ -1706,7 +1682,7 @@ namespace aux { , (flags & open_ssl_socket) ? listen_succeeded_alert::tcp_ssl : listen_succeeded_alert::tcp)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log(" listening on: %s external port: %d" , print_endpoint(tcp::endpoint(bind_ip, port)).c_str(), ret.external_port); #endif @@ -1715,9 +1691,8 @@ namespace aux { void session_impl::open_listen_port() { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - m_logger = create_log("main_session", listen_port(), false); - session_log("log created"); +#if defined TORRENT_LOGGING + session_log("open listen port"); #endif TORRENT_ASSERT(is_single_thread()); @@ -1909,11 +1884,9 @@ retry: if (m_listen_sockets.empty() && ec) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - char msg[200]; - snprintf(msg, sizeof(msg), "cannot bind TCP listen socket to interface \"%s\": %s" +#if defined TORRENT_LOGGING + session_log("cannot bind TCP listen socket to interface \"%s\": %s" , print_endpoint(m_listen_interface).c_str(), ec.message().c_str()); - (*m_logger) << msg << "\n"; #endif if (m_listen_port_retries > 0) { @@ -1934,7 +1907,7 @@ retry: m_ssl_udp_socket.bind(ssl_bind_if, ec); if (ec) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("SSL: cannot bind to UDP interface \"%s\": %s" , print_endpoint(m_listen_interface).c_str(), ec.message().c_str()); #endif @@ -1959,7 +1932,7 @@ retry: m_udp_socket.bind(udp::endpoint(m_listen_interface.address(), m_listen_interface.port()), ec); if (ec) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("cannot bind to UDP interface \"%s\": %s" , print_endpoint(m_listen_interface).c_str(), ec.message().c_str()); #endif @@ -2014,10 +1987,6 @@ retry: tcp::endpoint local = m_listen_sockets.front().sock->local_endpoint(ec); if (!ec) remap_tcp_ports(3, local.port(), ssl_listen_port()); } - -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - m_logger = create_log("main_session", listen_port(), false); -#endif } void session_impl::remap_tcp_ports(boost::uint32_t mask, int tcp_port, int ssl_port) @@ -2109,10 +2078,8 @@ retry: if (m_alerts.should_post()) m_alerts.post_alert(i2p_alert(ec)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - char msg[200]; - snprintf(msg, sizeof(msg), "i2p open failed (%d) %s", ec.value(), ec.message().c_str()); - (*m_logger) << msg << "\n"; +#if defined TORRENT_LOGGING + session_log("i2p open failed (%d) %s", ec.value(), ec.message().c_str()); #endif } // now that we have our i2p connection established @@ -2156,7 +2123,7 @@ retry: if (m_alerts.should_post()) m_alerts.post_alert(listen_failed_alert("i2p", listen_failed_alert::accept , e, listen_failed_alert::i2p)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("cannot bind to port %d: %s" , m_listen_interface.port(), e.message().c_str()); #endif @@ -2179,7 +2146,7 @@ retry: && m_alerts.should_post()) m_alerts.post_alert(udp_error_alert(ep, ec)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("UDP socket error: (%d) %s", ec.value(), ec.message().c_str()); #endif } @@ -2236,7 +2203,7 @@ retry: if (e) { tcp::endpoint ep = listener->local_endpoint(ec); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("error accepting connection on '%s': %s" , print_endpoint(ep).c_str(), e.message().c_str()); #endif @@ -2333,7 +2300,7 @@ retry: tcp::endpoint endp = s->remote_endpoint(e); if (e) return; -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" *** peer SSL handshake done [ ip: %s ec: %s socket: %s ]" , print_endpoint(endp).c_str(), ec.message().c_str(), s->type_name()); #endif @@ -2366,7 +2333,7 @@ retry: if (m_paused) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" <== INCOMING CONNECTION [ ignored, paused ]"); #endif return; @@ -2378,7 +2345,7 @@ retry: if (ec) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("%s <== INCOMING CONNECTION FAILED, could " "not retrieve remote endpoint " , print_endpoint(endp).c_str(), ec.message().c_str()); @@ -2386,7 +2353,7 @@ retry: return; } -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" <== INCOMING CONNECTION %s type: %s" , print_endpoint(endp).c_str(), s->type_name()); #endif @@ -2394,7 +2361,7 @@ retry: if (!m_settings.get_bool(settings_pack::enable_incoming_utp) && is_utp(*s)) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" rejected uTP connection"); #endif if (m_alerts.should_post()) @@ -2406,7 +2373,7 @@ retry: if (!m_settings.get_bool(settings_pack::enable_incoming_tcp) && s->get()) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" rejected TCP connection"); #endif if (m_alerts.should_post()) @@ -2423,7 +2390,7 @@ retry: tcp::endpoint local = s->local_endpoint(ec); if (ec) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" rejected connection: (%d) %s", ec.value() , ec.message().c_str()); #endif @@ -2434,14 +2401,14 @@ retry: { if (ec) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" rejected connection, not allowed local interface: (%d) %s" , ec.value(), ec.message().c_str()); #endif return; } -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" rejected connection, not allowed local interface: %s" , local.address().to_string(ec).c_str()); #endif @@ -2465,7 +2432,7 @@ retry: if (m_stats_counters[counters::non_filter_torrents] == 0 && (m_ip_filter.access(endp.address()) & ip_filter::blocked)) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("filtered blocked ip"); #endif if (m_alerts.should_post()) @@ -2478,7 +2445,7 @@ retry: // if we don't reject the connection if (m_torrents.empty()) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" There are no torrents, disconnect"); #endif return; @@ -2514,7 +2481,7 @@ retry: , peer_connection::op_bittorrent , error_code(errors::too_many_connections, get_libtorrent_category()))); } -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("number of connections limit exceeded (conns: %d, limit: %d, slack: %d), connection rejected" , num_connections(), m_settings.get_int(settings_pack::connections_limit) , m_settings.get_int(settings_pack::connections_slack)); @@ -2541,7 +2508,7 @@ retry: } if (!has_active_torrent) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" There are no _active_ torrents, disconnect"); #endif return; @@ -2638,7 +2605,7 @@ retry: // TORRENT_ASSERT(!i->second->has_peer((peer_connection*)p)); #endif -#if defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" CLOSING CONNECTION %s : %s" , print_endpoint(p->remote()).c_str(), ec.message().c_str()); #endif @@ -2818,7 +2785,7 @@ retry: if (e) { -#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING session_log("*** TICK TIMER FAILED %s", e.message().c_str()); #endif ::abort(); @@ -3299,7 +3266,7 @@ retry: TORRENT_ASSERT(m_dht); m_dht_torrents.push_back(t); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING boost::shared_ptr tor = t.lock(); if (tor) session_log("prioritizing DHT announce: \"%s\"", tor->name().c_str()); @@ -3328,7 +3295,7 @@ retry: TORRENT_ASSERT(is_single_thread()); if (e) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("aborting DHT announce timer (%d): %s" , e.value(), e.message().c_str()); #endif @@ -3337,7 +3304,7 @@ retry: if (m_abort) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("aborting DHT announce timer: m_abort set"); #endif return; @@ -3471,7 +3438,7 @@ retry: { --hard_limit; --type_limit; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (!t->allows_peers()) t->log_to_all_peers("AUTO MANAGER STARTING TORRENT"); #endif @@ -3479,7 +3446,7 @@ retry: } else { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (t->allows_peers()) t->log_to_all_peers("AUTO MANAGER PAUSING TORRENT"); #endif @@ -4032,7 +3999,7 @@ retry: stop_loop = m_abort; } -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" locking mutex"); #endif @@ -4045,7 +4012,7 @@ retry: } #endif */ -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log(" cleaning up torrents"); #endif @@ -4250,18 +4217,10 @@ retry: return i->second; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - boost::shared_ptr session_impl::create_log(std::string const& name - , int instance, bool append) - { - error_code ec; - // current options are file_logger, cout_logger and null_logger - return boost::shared_ptr(new logger(m_logpath, name, instance, append)); - } - +#if defined TORRENT_LOGGING void session_impl::session_log(char const* fmt, ...) const { - if (!m_logger) return; + if (!m_alerts.should_post()) return; va_list v; va_start(v, fmt); @@ -4271,15 +4230,15 @@ retry: void session_impl::session_vlog(char const* fmt, va_list& v) const { - char usr[400]; - vsnprintf(usr, sizeof(usr), fmt, v); + if (!m_alerts.should_post()) return; + + char buf[1024]; + vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); - char buf[450]; - snprintf(buf, sizeof(buf), "%s: %s\n", time_now_string(), usr); - (*m_logger) << buf; + + m_alerts.post_alert(log_alert(buf)); } -#if defined TORRENT_VERBOSE_LOGGING void session_impl::log_all_torrents(peer_connection* p) { for (session_impl::torrent_map::const_iterator i = m_torrents.begin() @@ -4288,7 +4247,6 @@ retry: p->peer_log(" %s", to_hex(i->second->torrent_file().info_hash().to_string()).c_str()); } } -#endif #endif void session_impl::get_torrent_status(std::vector* ret @@ -4553,7 +4511,7 @@ retry: error_code ec; lazy_entry tmp; lazy_entry const* info = 0; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING session_log("adding magnet link with resume data"); #endif if (lazy_bdecode(¶ms.resume_data[0], ¶ms.resume_data[0] @@ -4561,7 +4519,7 @@ retry: && tmp.type() == lazy_entry::dict_t && (info = tmp.dict_find_dict("info"))) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING session_log("found metadata in resume data"); #endif // verify the info-hash of the metadata stored in the resume file matches @@ -4577,14 +4535,14 @@ retry: || !params.url.empty() || params.info_hash.is_all_zeros()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING session_log("info-hash matched"); #endif params.ti = boost::make_shared(resume_ih); if (params.ti->parse_info_section(*info, ec, 0)) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING session_log("successfully loaded metadata from resume file"); #endif // make the info-hash be the one in the resume file @@ -4593,20 +4551,20 @@ retry: } else { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING session_log("failed to load metadata from resume file: %s" , ec.message().c_str()); #endif } } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING else { session_log("metadata info-hash failed"); } #endif } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING else { session_log("no metadata found"); @@ -4934,7 +4892,7 @@ retry: // declared in string_util.hpp parse_comma_separated_string_port(net_interfaces, new_listen_interfaces); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("update listen interfaces: %s", net_interfaces.c_str()); #endif @@ -4962,14 +4920,14 @@ retry: device_name[0] == '[' ? device_name + 1 : device_name, ec)); if (ec) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("failed to treat %s as an IP address [ %s ]" , device_name, ec.message().c_str()); #endif // it may have been a device name. std::vector ifs = enum_net_interfaces(m_io_service, ec); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING if (ec) session_log("failed to enumerate interfaces [ %s ]" , ec.message().c_str()); @@ -4983,7 +4941,7 @@ retry: // connecting to) if (strcmp(ifs[i].name, device_name) != 0) continue; m_listen_interface.address(ifs[i].interface_address); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("binding to %s" , m_listen_interface.address().to_string(ec).c_str()); #endif @@ -4993,7 +4951,7 @@ retry: if (!found) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("failed to find device %s", device_name); #endif // effectively disable whatever socket decides to bind to this @@ -5155,7 +5113,7 @@ retry: if (t->torrent_file().priv() || (t->torrent_file().is_i2p() && !m_settings.get_bool(settings_pack::allow_i2p_mixed))) return; -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("added peer from local discovery: %s", print_endpoint(peer).c_str()); #endif t->add_peer(peer, peer_info::lsd); @@ -5170,11 +5128,6 @@ retry: { TORRENT_ASSERT(map_transport >= 0 && map_transport <= 1); // log message -#ifdef TORRENT_UPNP_LOGGING - char const* transport_names[] = {"NAT-PMP", "UPnP"}; - m_upnp_log << time_now_string() << " " - << transport_names[map_transport] << ": " << msg; -#endif if (m_alerts.should_post()) m_alerts.post_alert(portmap_log_alert(map_transport, msg)); } @@ -5706,7 +5659,7 @@ retry: m_ssl_udp_socket.set_option(type_of_service(m_settings.get_int(settings_pack::peer_tos)), ec); #endif -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING session_log(">>> SET_TOS [ udp_socket tos: %x e: %s ]" , m_settings.get_int(settings_pack::peer_tos) , ec.message().c_str()); @@ -5910,7 +5863,7 @@ retry: #ifndef TORRENT_DISABLE_DHT if (!m_dht) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("not starting DHT announce timer: m_dht == NULL"); #endif return; @@ -5921,7 +5874,7 @@ retry: // if we haven't started yet, don't actually trigger this if (!m_thread) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("not starting DHT announce timer: thread not running yet"); #endif return; @@ -5929,7 +5882,7 @@ retry: if (m_abort) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING session_log("not starting DHT announce timer: m_abort set"); #endif return; @@ -6338,14 +6291,14 @@ retry: void session_impl::set_external_address(address const& ip , int source_type, address const& source) { -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING session_log(": set_external_address(%s, %d, %s)", print_address(ip).c_str() , source_type, print_address(source).c_str()); #endif if (!m_external_ip.cast_vote(ip, source_type, source)) return; -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING session_log(" external IP updated"); #endif @@ -6616,7 +6569,7 @@ retry: } #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING tracker_logger::tracker_logger(session_interface& ses): m_ses(ses) {} void tracker_logger::tracker_warning(tracker_request const& req , std::string const& str) @@ -6629,7 +6582,7 @@ retry: , std::list
const& ip_list , struct tracker_response const& resp) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("TRACKER RESPONSE\n" "interval: %d\n" "external ip: %s\n" diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index 567d7943b..cfa8526d8 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -61,7 +61,7 @@ POSSIBILITY OF SUCH DAMAGE. //#define TORRENT_LOG_HASH_FAILURES -#ifdef TORRENT_LOGGING +#if defined TORRENT_LOGGING #include "libtorrent/socket_io.hpp" #endif @@ -138,7 +138,7 @@ namespace void on_piece_pass(int p) { -#ifdef TORRENT_LOGGING +#if defined TORRENT_LOGGING m_torrent.debug_log(" PIECE PASS [ p: %d | block_hash_size: %d ]" , p, int(m_block_hashes.size())); #endif @@ -274,7 +274,7 @@ namespace // this time the digest of the block is different // from the first time it sent it // at least one of them must be bad -#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING char const* client = "-"; peer_info info; if (p->connection) @@ -349,7 +349,7 @@ namespace } if (p == NULL) return; -#ifdef TORRENT_LOGGING +#if defined TORRENT_LOGGING char const* client = "-"; peer_info info; if (p->connection) diff --git a/src/torrent.cpp b/src/torrent.cpp index dc9689cd2..6ceaf22e8 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -95,7 +95,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif // BOOST_VERSION #endif // TORRENT_USE_OPENSSL -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING #include "libtorrent/aux_/session_impl.hpp" // for tracker_logger #endif @@ -255,16 +255,6 @@ namespace libtorrent m_save_path = canonicalize_path(m_save_path); #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - m_logger_time = time_now_hires(); - error_code ec; - - char buf[50]; - snprintf(buf, sizeof(buf), "torrent_%p", this); - - m_logger = m_ses.create_log(buf, m_ses.listen_port()); - debug_log("torrent started"); -#endif if (!m_apply_ip_filter) { inc_stats_counter(counters::non_filter_torrents); @@ -304,9 +294,6 @@ namespace libtorrent if (!m_url.empty() && m_uuid.empty()) m_uuid = m_url; TORRENT_ASSERT(is_single_thread()); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - debug_log("creating torrent: %s", torrent_file().name().c_str()); -#endif m_file_priority = p.file_priorities; if (m_seed_mode) @@ -703,12 +690,12 @@ namespace libtorrent // TODO: 2 post alert -#if defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** FAILED SEED MODE, rechecking"); #endif } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** LEAVING SEED MODE (%s)", seed ? "as seed" : "as non-seed"); #endif m_seed_mode = false; @@ -739,7 +726,7 @@ namespace libtorrent void torrent::start() { TORRENT_ASSERT(is_single_thread()); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("starting torrent"); #endif std::vector().swap(m_file_progress); @@ -752,7 +739,7 @@ namespace libtorrent + m_resume_data->buf.size(), m_resume_data->entry, ec, &pos) != 0) { m_resume_data.reset(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("resume data rejected: %s pos: %d", ec.message().c_str(), pos); #endif if (m_ses.alerts().should_post()) @@ -1055,7 +1042,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); if (!j->error) return; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("disk error: (%d) %s in file: %s", j->error.ec.value(), j->error.ec.message().c_str() , resolve_filename(j->error.file).c_str()); #endif @@ -1456,7 +1443,7 @@ namespace libtorrent GENERAL_NAMES* gens = static_cast( X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0)); -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING std::string names; bool match = false; #endif @@ -1469,14 +1456,14 @@ namespace libtorrent const char* torrent_name = reinterpret_cast(domain->data); std::size_t name_length = domain->length; -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING if (i > 1) names += " | n: "; names.append(torrent_name, name_length); #endif if (strncmp(torrent_name, "*", name_length) == 0 || strncmp(torrent_name, m_torrent_file->name().c_str(), name_length) == 0) { -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING match = true; // if we're logging, keep looping over all names, // for completeness of the log @@ -1501,7 +1488,7 @@ namespace libtorrent const char* torrent_name = reinterpret_cast(common_name->data); std::size_t name_length = common_name->length; -#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) +#if defined TORRENT_LOGGING if (!names.empty()) names += " | n: "; names.append(torrent_name, name_length); #endif @@ -1509,7 +1496,7 @@ namespace libtorrent if (strncmp(torrent_name, "*", name_length) == 0 || strncmp(torrent_name, m_torrent_file->name().c_str(), name_length) == 0) { -#if !defined(TORRENT_VERBOSE_LOGGING) && !defined(TORRENT_LOGGING) +#if !defined TORRENT_LOGGING return true; #else match = true; @@ -1517,7 +1504,7 @@ namespace libtorrent } } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("<== incoming SSL CONNECTION [ n: %s | match: %s ]" , names.c_str(), match?"yes":"no"); return match; @@ -1691,6 +1678,10 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); +#if defined TORRENT_LOGGING + debug_log("init torrent: %s", torrent_file().name().c_str()); +#endif + if (!need_loaded()) return; TORRENT_ASSERT(m_torrent_file->num_files() > 0); TORRENT_ASSERT(m_torrent_file->is_valid()); @@ -1745,7 +1736,7 @@ namespace libtorrent if (ev) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("fastresume data rejected: %s" , error_code(ev, get_libtorrent_category()).message().c_str()); #endif @@ -1906,7 +1897,7 @@ namespace libtorrent m_storage.get(), m_resume_data ? &m_resume_data->entry : NULL , boost::bind(&torrent::on_resume_data_checked , shared_from_this(), _1)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("init, async_check_fastresume"); #endif @@ -2221,7 +2212,7 @@ namespace libtorrent } } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING if (m_peer_list && m_peer_list->num_peers() > 0) debug_log("resume added peers (%d)", m_peer_list->num_peers()); #endif @@ -2234,13 +2225,13 @@ namespace libtorrent , resolve_filename(j->error.file), j->error.operation_str())); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING if (j->ret != 0) { debug_log("fastresume data rejected: ret: %d (%d) %s" , j->ret, j->error.ec.value(), j->error.ec.message().c_str()); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING else debug_log("fastresume data accepted"); #endif @@ -2462,7 +2453,7 @@ namespace libtorrent // resumed quickly, before the outstanding jobs completed if (m_checking_piece >= m_torrent_file->num_pieces()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("start_checking, checking_piece >= num_pieces. %d >= %d" , m_checking_piece, m_torrent_file->num_pieces()); #endif @@ -2475,7 +2466,7 @@ namespace libtorrent if (!need_loaded()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("start_checking, need_loaded() failed"); #endif return; @@ -2490,7 +2481,7 @@ namespace libtorrent , shared_from_this(), _1), (void*)1); if (m_checking_piece >= m_torrent_file->num_pieces()) break; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("start_checking, m_checking_piece: %d", m_checking_piece); #endif } @@ -2513,7 +2504,7 @@ namespace libtorrent { m_checking_piece = 0; m_num_checked_pieces = 0; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, disk_check_aborted"); #endif pause(); @@ -2554,7 +2545,7 @@ namespace libtorrent m_ses.alerts().post_alert(file_error_alert(j->error.ec, resolve_filename(j->error.file), j->error.operation_str(), get_handle())); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, fatal disk error: (%d) %s", j->error.ec.value(), j->error.ec.message().c_str()); #endif auto_managed(false); @@ -2573,7 +2564,7 @@ namespace libtorrent // we're using the piece hashes here, we need the torrent to be loaded if (!need_loaded()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, need_loaded failed"); #endif return; @@ -2619,7 +2610,7 @@ namespace libtorrent // we paused the checking if (!should_check_files()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, checking paused"); #endif return; @@ -2627,7 +2618,7 @@ namespace libtorrent if (!need_loaded()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, need_loaded failed"); #endif return; @@ -2638,13 +2629,13 @@ namespace libtorrent , disk_io_job::sequential_access | disk_io_job::volatile_read , boost::bind(&torrent::on_piece_hashed , shared_from_this(), _1), (void*)1); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, m_checking_piece: %d", m_checking_piece); #endif return; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("on_piece_hashed, completed"); #endif // we're done checking! @@ -2734,14 +2725,14 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); if (!m_ses.dht()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("DHT: no dht initialized"); #endif return; } if (!should_announce_dht()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING if (!m_ses.announce_dht()) debug_log("DHT: no listen sockets"); @@ -2782,7 +2773,7 @@ namespace libtorrent int port = m_ses.listen_port(); #endif -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("START DHT announce"); m_dht_start_time = time_now_hires(); #endif @@ -2814,7 +2805,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("END DHT announce (%d ms) (%d peers)" , int(total_milliseconds(time_now_hires() - m_dht_start_time)) , int(peers.size())); @@ -2849,7 +2840,7 @@ namespace libtorrent if (m_trackers.empty()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** announce_with_tracker: no trackers"); #endif return; @@ -2861,7 +2852,7 @@ namespace libtorrent // stopping if (e != tracker_request::stopped && !m_announce_to_trackers) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** announce_with_tracker: event != stopped && !m_announce_to_trackers"); #endif return; @@ -2870,7 +2861,7 @@ namespace libtorrent // if we're not allowing peers, there's no point in announcing if (e != tracker_request::stopped && !m_allow_peers) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** announce_with_tracker: event != stopped && !m_allow_peers"); #endif return; @@ -2922,7 +2913,7 @@ namespace libtorrent for (int i = 0; i < int(m_trackers.size()); ++i) { announce_entry& ae = m_trackers[i]; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** announce with tracker: considering \"%s\" " "[ announce_to_all_tiers: %d announce_to_all_trackers: %d" " i->tier: %d tier: %d " @@ -3003,7 +2994,7 @@ namespace libtorrent continue; } } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("==> TRACKER REQUEST \"%s\" event: %s abort: %d" , req.url.c_str() , (req.event==tracker_request::stopped?"stopped" @@ -3179,7 +3170,7 @@ namespace libtorrent if (resp.complete >= 0 && resp.incomplete >= 0) m_last_scrape = m_ses.session_time(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("TRACKER RESPONSE\n" "interval: %d\n" "external ip: %s\n" @@ -3319,7 +3310,7 @@ namespace libtorrent ?m_ses.get_ipv6_interface().address() :m_ses.get_ipv4_interface().address(); announce_with_tracker(r.event, bind_interface); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("announce again using %s as the bind interface" , print_address(bind_interface).c_str()); #endif @@ -3385,7 +3376,7 @@ namespace libtorrent continue; } -#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING external_ip const& external = m_ses.external_address(); debug_log(" *** FOUND CONNECTION CANDIDATE [" " ip: %s rank: %u external: %s t: %d ]" @@ -3491,7 +3482,7 @@ namespace libtorrent if (m_apply_ip_filter && m_ses.get_ip_filter().access(host.address()) & ip_filter::blocked) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING error_code ec; debug_log("blocked ip from tracker: %s", host.address().to_string(ec).c_str()); #endif @@ -3852,7 +3843,7 @@ namespace libtorrent // -1: disk failure // -2: piece failed check -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** PIECE_FINISHED [ p: %d | chk: %s | size: %d ]" , j->piece, ((ret == 0) ?"passed":ret == -1 @@ -4092,7 +4083,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(!m_picker->has_piece_passed(index)); -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("PIECE_PASSED (%d)", num_passed()); #endif @@ -4167,7 +4158,7 @@ namespace libtorrent for (peer_iterator p = m_connections.begin() , end(m_connections.end()); p != end; ++p) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING (*p)->peer_log(">>> PREDICTIVE_HAVE [ piece: %d expected in %d ms]" , index, milliseconds); #endif @@ -4309,11 +4300,11 @@ namespace libtorrent if (p->connection) { peer_connection* peer = static_cast(p->connection); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** BANNING PEER: \"%s\" Too many corrupt pieces" , print_endpoint(p->ip()).c_str()); #endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING peer->peer_log("*** BANNING PEER: Too many corrupt pieces"); #endif peer->disconnect(errors::too_many_corrupt_pieces, peer_connection_interface::op_bittorrent); @@ -4671,7 +4662,7 @@ namespace libtorrent error_code ec; m_inactivity_timer.cancel(ec); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING log_to_all_peers("ABORTING TORRENT"); #endif @@ -5419,7 +5410,7 @@ namespace libtorrent p->update_interest(); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** UPDATE_PEER_INTEREST [ finished: %d was_finished %d ]" , is_finished(), was_finished); #endif @@ -5898,7 +5889,7 @@ namespace libtorrent if (ec) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("failed to parse web seed url: %s", ec.message().c_str()); #endif if (m_ses.alerts().should_post()) @@ -5913,7 +5904,7 @@ namespace libtorrent if (web->peer_info.banned) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("banned web seed: %s", web->url.c_str()); #endif if (m_ses.alerts().should_post()) @@ -5985,7 +5976,7 @@ namespace libtorrent return; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("resolving web seed: %s", web->url.c_str()); #endif @@ -5993,7 +5984,7 @@ namespace libtorrent if (ps.type == settings_pack::http || ps.type == settings_pack::http_pw) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("resolving proxy for web seed: %s", web->url.c_str()); #endif @@ -6011,7 +6002,7 @@ namespace libtorrent } else { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("resolving web seed: %s", web->url.c_str()); #endif @@ -6031,10 +6022,8 @@ namespace libtorrent INVARIANT_CHECK; TORRENT_ASSERT(web->resolving == true); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("completed resolve proxy hostname for: %s", web->url.c_str()); -#endif -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING if (e) debug_log("proxy name lookup error: %s", e.message().c_str()); #endif @@ -6042,7 +6031,7 @@ namespace libtorrent if (web->removed) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("removed web seed"); #endif remove_web_seed(web); @@ -6118,13 +6107,13 @@ namespace libtorrent INVARIANT_CHECK; TORRENT_ASSERT(web->resolving == true); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("completed resolve: %s", web->url.c_str()); #endif web->resolving = false; if (web->removed) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("removed web seed"); #endif remove_web_seed(web); @@ -6137,7 +6126,7 @@ namespace libtorrent { if (m_ses.alerts().should_post()) m_ses.alerts().post_alert(url_seed_alert(get_handle(), web->url, e)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** HOSTNAME LOOKUP FAILED: %s: (%d) %s" , web->url.c_str(), e.value(), e.message().c_str()); #endif @@ -6153,7 +6142,7 @@ namespace libtorrent // fill in the peer struct's address field web->endpoints.push_back(tcp::endpoint(*i, port)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log(" -> %s", print_endpoint(tcp::endpoint(*i, port)).c_str()); #endif } @@ -6319,7 +6308,7 @@ namespace libtorrent , boost::int64_t(web->peer_info.prev_amount_upload) << 10); web->peer_info.prev_amount_download = 0; web->peer_info.prev_amount_upload = 0; -#if defined TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING debug_log("web seed connection started: [%s] %s" , print_endpoint(a).c_str(), web->url.c_str()); #endif @@ -6328,7 +6317,7 @@ namespace libtorrent if (c->is_disconnecting()) return; -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("START queue peer [%p] (%d)", c.get(), num_peers()); #endif } @@ -6336,7 +6325,7 @@ namespace libtorrent { TORRENT_DECLARE_DUMMY(std::exception, e); (void)e; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** PEER_ERROR: %s", e.what()); #endif c->disconnect(errors::no_error, peer_connection_interface::op_bittorrent, 1); @@ -6489,7 +6478,7 @@ namespace libtorrent { // unknown country! p->set_country("!!"); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("IP \"%s\" was mapped to unknown country: %d" , print_address(p->remote().address()).c_str(), country); #endif @@ -7666,7 +7655,7 @@ namespace libtorrent ++m_num_seeds; } -#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("incoming peer (%d)", int(m_connections.size())); #endif @@ -7819,9 +7808,6 @@ namespace libtorrent peer_connection* p = *m_connections.begin(); TORRENT_ASSERT(p->associated_torrent().lock().get() == this); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - p->peer_log("*** CLOSING CONNECTION \"%s\"", ec.message().c_str()); -#endif #if TORRENT_USE_ASSERTS std::size_t size = m_connections.size(); #endif @@ -7945,7 +7931,7 @@ namespace libtorrent TORRENT_ASSERT(p->associated_torrent().lock().get() == this); if (p->upload_only()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING p->peer_log("*** SEED, CLOSING CONNECTION"); #endif seeds.push_back(p); @@ -7986,7 +7972,7 @@ namespace libtorrent || m_state == torrent_status::checking_files || m_state == torrent_status::allocating) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** RESUME_DOWNLOAD [ skipping, state: %d ]" , int(m_state)); #endif @@ -7999,7 +7985,7 @@ namespace libtorrent m_completed_time = 0; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("*** RESUME_DOWNLOAD"); #endif send_upload_only(); @@ -8095,7 +8081,7 @@ namespace libtorrent if (m_abort) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("files_checked(), paused"); #endif return; @@ -8186,7 +8172,7 @@ namespace libtorrent pc->init(); } -#ifdef TORRENT_VERBOSE_LOGGING +#if defined TORRENT_LOGGING pc->peer_log("*** ON_FILES_CHECKED"); #endif if (pc->is_interesting() && !pc->has_peer_choked()) @@ -8665,7 +8651,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING log_to_all_peers("DELETING FILES IN TORRENT"); #endif @@ -8737,7 +8723,7 @@ namespace libtorrent if (alerts().should_post()) alerts().post_alert(torrent_error_alert(get_handle(), ec, resolve_filename(error_file))); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (ec) { char buf[1024]; @@ -9077,7 +9063,7 @@ namespace libtorrent update_want_peers(); update_want_scrape(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING log_to_all_peers("PAUSING TORRENT"); #endif @@ -9134,7 +9120,7 @@ namespace libtorrent if (p->outstanding_bytes() > 0) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING p->peer_log("*** CHOKING PEER: torrent graceful paused"); #endif // remove any un-sent requests from the queue @@ -9144,7 +9130,7 @@ namespace libtorrent continue; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING p->peer_log("*** CLOSING CONNECTION: torrent_paused"); #endif p->disconnect(errors::torrent_paused, peer_connection_interface::op_bittorrent); @@ -9166,11 +9152,11 @@ namespace libtorrent } } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING void torrent::log_to_all_peers(char const* message) { TORRENT_ASSERT(is_single_thread()); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i) { @@ -9295,7 +9281,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); if (!m_announcing) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** update tracker timer: not announcing"); #endif return; @@ -9309,7 +9295,7 @@ namespace libtorrent for (std::vector::iterator i = m_trackers.begin() , end(m_trackers.end()); i != end; ++i) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING char msg[1000]; snprintf(msg, sizeof(msg), "*** update tracker timer: considering \"%s\" " "[ announce_to_all_tiers: %d announce_to_all_trackers: %d" @@ -9347,7 +9333,7 @@ namespace libtorrent && !settings().get_bool(settings_pack::announce_to_all_tiers)) break; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING char msg[200]; snprintf(msg, sizeof(msg), "*** update tracker timer: next_announce < now %d" " m_waiting_tracker: %d next_announce_in: %d" @@ -9377,7 +9363,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); if (is_paused()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("start_announcing(), paused"); #endif return; @@ -9387,14 +9373,14 @@ namespace libtorrent // request the metadata from if (!m_files_checked && valid_metadata()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("start_announcing(), files not checked (with valid metadata)"); #endif return; } if (!m_torrent_file->is_valid() && !m_url.empty()) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("start_announcing(), downloading URL"); #endif return; @@ -9626,7 +9612,7 @@ namespace libtorrent { TORRENT_DECLARE_DUMMY(std::exception, e); (void)e; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING p->peer_log("*** ERROR %s", e.what()); #endif p->disconnect(errors::no_error, peer_connection_interface::op_bittorrent, 1); @@ -10558,7 +10544,7 @@ namespace libtorrent TORRENT_ASSERT(i->resolving == false); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("disconnect web seed: \"%s\"", i->url.c_str()); #endif TORRENT_ASSERT(i->peer_info.connection); @@ -11127,7 +11113,7 @@ namespace libtorrent m_state = s; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING debug_log("set_state() %d", m_state); #endif @@ -11466,7 +11452,7 @@ namespace libtorrent INVARIANT_CHECK; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** tracker error: (%d) %s %s", ec.value(), ec.message().c_str(), msg.c_str()); #endif if (r.kind == tracker_request::announce_request) @@ -11478,7 +11464,7 @@ namespace libtorrent ae->last_error = ec; ae->message = msg; int tracker_index = ae - &m_trackers[0]; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING debug_log("*** increment tracker fail count [%d]", ae->fails); #endif // never talk to this tracker again @@ -11512,20 +11498,20 @@ namespace libtorrent update_tracker_timer(time_now()); } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING void torrent::debug_log(char const* fmt, ...) const { - if (!m_logger) return; + if (!alerts().should_post()) return; va_list v; va_start(v, fmt); - char usr[400]; - vsnprintf(usr, sizeof(usr), fmt, v); + char buf[400]; + vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); - char buf[450]; - snprintf(buf, sizeof(buf), "%" PRId64 ": %s\n", total_microseconds(time_now_hires() - m_logger_time), usr); - (*m_logger) << buf; + + alerts().post_alert(torrent_log_alert( + const_cast(this)->get_handle(), buf)); } #endif diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 51d7690fc..297078a78 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -359,7 +359,7 @@ namespace libtorrent close_http_connections.push_back(*i); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr rc = c->requester(); if (rc) rc->debug_log("aborting: %s", req.url.c_str()); #endif @@ -374,7 +374,7 @@ namespace libtorrent close_udp_connections.push_back(c); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr rc = c->requester(); if (rc) rc->debug_log("aborting: %s", req.url.c_str()); #endif diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 42f405391..0c52e6691 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -55,7 +55,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/resolver_interface.hpp" #include "libtorrent/ip_filter.hpp" -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING #include "libtorrent/socket_io.hpp" #endif @@ -124,7 +124,7 @@ namespace libtorrent , boost::bind(&udp_tracker_connection::name_lookup , shared_from_this(), _1, _2, port)); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) cb->debug_log("*** UDP_TRACKER [ initiating name lookup: \"%s\" ]" , hostname.c_str()); @@ -153,7 +153,7 @@ namespace libtorrent return; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) cb->debug_log("*** UDP_TRACKER [ host: \"%s\" ip: \"%s\" | error: \"%s\" ]" , m_hostname.c_str(), print_endpoint(m_target).c_str(), ec.message().c_str()); @@ -162,7 +162,7 @@ namespace libtorrent // pick another target endpoint and try again m_target = pick_target_endpoint(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (cb) cb->debug_log("*** UDP_TRACKER trying next IP [ host: \"%s\" ip: \"%s\" ]" , m_hostname.c_str(), print_endpoint(m_target).c_str()); #endif @@ -185,7 +185,7 @@ namespace libtorrent } boost::shared_ptr cb = requester(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (cb) cb->debug_log("*** UDP_TRACKER [ name lookup successful ]"); #endif if (cancelled()) @@ -212,7 +212,7 @@ namespace libtorrent { if (m_man.ip_filter().access(k->address()) == ip_filter::blocked) { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (cb) cb->debug_log("*** UDP_TRACKER [ IP blocked by filter: %s ]" , print_address(k->address()).c_str()); #endif @@ -306,7 +306,7 @@ namespace libtorrent return; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) cb->debug_log("*** UDP_TRACKER [ timed out url: %s ]", tracker_req().url.c_str()); #endif @@ -346,7 +346,7 @@ namespace libtorrent if (e) fail(e); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) { @@ -361,7 +361,7 @@ namespace libtorrent int action = detail::read_int32(ptr); boost::uint32_t transaction = detail::read_uint32(ptr); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (cb) { cb->debug_log("*** UDP_TRACKER_PACKET [ action: %d ]", action); @@ -382,7 +382,7 @@ namespace libtorrent restart_read_timeout(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (cb) { cb->debug_log("*** UDP_TRACKER_RESPONSE [ tid: %x ]" @@ -443,7 +443,7 @@ namespace libtorrent void udp_tracker_connection::send_udp_connect() { -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) { @@ -547,7 +547,7 @@ namespace libtorrent } boost::shared_ptr cb = requester(); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING if (cb) { boost::shared_ptr cb = requester(); @@ -695,7 +695,7 @@ namespace libtorrent TORRENT_ASSERT(out - buf <= int(sizeof(buf))); -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING +#if defined TORRENT_LOGGING boost::shared_ptr cb = requester(); if (cb) { diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 8ac3d267c..2f3281ade 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -258,7 +258,7 @@ namespace libtorrent { namespace TORRENT_ASSERT(type >= 0 && type <= 2); TORRENT_ASSERT(!m_pc.associated_torrent().expired()); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING char const* names[] = {"request", "data", "dont-have"}; char const* n = ""; if (type >= 0 && type < 3) n = names[type]; @@ -280,7 +280,7 @@ namespace libtorrent { namespace if (piece < 0 || piece >= int(m_tp.get_metadata_size() + 16 * 1024 - 1)/(16*1024)) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("*** UT_METADATA [ invalid piece %d metadata size: %d ]" , piece, int(m_tp.get_metadata_size())); #endif @@ -330,7 +330,7 @@ namespace libtorrent { namespace if (length > 17 * 1024) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== UT_METADATA [ packet too big %d ]", length); #endif m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2); @@ -343,7 +343,7 @@ namespace libtorrent { namespace entry msg = bdecode(body.begin, body.end, len); if (msg.type() != entry::dictionary_t) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== UT_METADATA [ not a dictionary ]"); #endif m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2); @@ -355,7 +355,7 @@ namespace libtorrent { namespace if (type_ent == 0 || type_ent->type() != entry::int_t || piece_ent == 0 || piece_ent->type() != entry::int_t) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== UT_METADATA [ missing or invalid keys ]"); #endif m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2); @@ -364,7 +364,7 @@ namespace libtorrent { namespace int type = type_ent->integer(); int piece = piece_ent->integer(); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== UT_METADATA [ type: %d | piece: %d ]", type, piece); #endif @@ -393,7 +393,7 @@ namespace libtorrent { namespace // unwanted piece? if (i == m_sent_requests.end()) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("*** UT_METADATA [ UNWANTED / TIMED OUT ]"); #endif return true; @@ -541,7 +541,7 @@ namespace libtorrent { namespace { if (m_torrent.valid_metadata()) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING source.m_pc.peer_log("*** UT_METADATA [ ALREADY HAVE METADATA ]"); #endif m_torrent.add_redundant_bytes(size, torrent::piece_unknown); @@ -553,7 +553,7 @@ namespace libtorrent { namespace // verify the total_size if (total_size <= 0 || total_size > m_torrent.session().settings().get_int(settings_pack::max_metadata_size)) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING source.m_pc.peer_log("*** UT_METADATA [ metadata size too big: %d ]", total_size); #endif // #error post alert @@ -567,7 +567,7 @@ namespace libtorrent { namespace if (piece < 0 || piece >= int(m_requested_metadata.size())) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING source.m_pc.peer_log("*** UT_METADATA [ piece: %d INVALID ]", piece); #endif return false; @@ -575,7 +575,7 @@ namespace libtorrent { namespace if (total_size != m_metadata_size) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING source.m_pc.peer_log("*** UT_METADATA [ total_size: %d INCONSISTENT WITH: %d ]" , total_size, m_metadata_size); #endif diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 3ce2027ff..a25f4f5ff 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -56,7 +56,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/extensions/ut_pex.hpp" -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING #include "libtorrent/lazy_entry.hpp" #endif @@ -311,7 +311,7 @@ namespace libtorrent { namespace lazy_entry const* p = pex_msg.dict_find_string("dropped"); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING int num_dropped = 0; int num_added = 0; if (p) num_dropped += p->string_length()/6; @@ -333,7 +333,7 @@ namespace libtorrent { namespace p = pex_msg.dict_find_string("added"); lazy_entry const* pf = pex_msg.dict_find_string("added.f"); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING if (p) num_added += p->string_length() / 6; #endif if (p != 0 @@ -367,7 +367,7 @@ namespace libtorrent { namespace #if TORRENT_USE_IPV6 lazy_entry const* p6 = pex_msg.dict_find("dropped6"); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING if (p6) num_dropped += p6->string_length() / 18; #endif if (p6 != 0 && p6->type() == lazy_entry::string_t) @@ -385,7 +385,7 @@ namespace libtorrent { namespace } p6 = pex_msg.dict_find("added6"); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING if (p6) num_added += p6->string_length() / 18; #endif lazy_entry const* p6f = pex_msg.dict_find("added6.f"); @@ -417,7 +417,7 @@ namespace libtorrent { namespace } } #endif -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("<== PEX [ dropped: %d added: %d ]" , num_dropped, num_added); #endif @@ -436,7 +436,7 @@ namespace libtorrent { namespace ptime now = time_now(); if (now - seconds(60) < m_last_msg) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("*** PEX [ waiting: %d seconds to next msg ]" , total_seconds(seconds(60) - (now - m_last_msg))); #endif @@ -454,7 +454,7 @@ namespace libtorrent { namespace if (now - milliseconds(delay) < global_last) { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("*** PEX [ global-wait: %d ]", total_seconds(milliseconds(delay) - (now - global_last))); #endif return; @@ -499,7 +499,7 @@ namespace libtorrent { namespace m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_extended); m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_pex); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING lazy_entry m; error_code ec; int ret = lazy_bdecode(&pex_msg[0], &pex_msg[0] + pex_msg.size(), m, ec); @@ -607,7 +607,7 @@ namespace libtorrent { namespace m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_extended); m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_pex); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING m_pc.peer_log("==> PEX_FULL [ added: %d msg_size: %d ]", num_added, int(pex_msg.size())); #endif } diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 8fb3db265..3decb18f1 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -654,7 +654,7 @@ struct utp_socket_impl bool m_stalled:1; }; -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING int socket_impl_size() { return sizeof(utp_socket_impl); } #endif diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 2615d23f6..c50fb233c 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -97,7 +97,7 @@ web_peer_connection::web_peer_connection(peer_connection_args const& pack // into single larger ones request_large_blocks(true); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** web_peer_connection %s", m_url.c_str()); #endif } @@ -369,7 +369,7 @@ void web_peer_connection::write_request(peer_request const& r) } } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("==> %s", request.c_str()); #endif @@ -488,7 +488,7 @@ void web_peer_connection::on_receive(error_code const& error if (error) { received_bytes(0, bytes_transferred); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** web_peer_connection error: %s", error.message().c_str()); #endif #ifdef TORRENT_DEBUG @@ -526,7 +526,7 @@ void web_peer_connection::on_receive(error_code const& error if (failed) { received_bytes(0, bytes_transferred); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** %s", std::string(recv_buffer.begin, recv_buffer.end).c_str()); #endif disconnect(errors::http_parse_error, op_bittorrent, 2); @@ -583,7 +583,7 @@ void web_peer_connection::on_receive(error_code const& error m_web->supports_keepalive = false; } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** STATUS: %d %s", m_parser.status_code(), m_parser.message().c_str()); std::multimap const& headers = m_parser.headers(); for (std::multimap::const_iterator i = headers.begin() @@ -681,7 +681,7 @@ void web_peer_connection::on_receive(error_code const& error location = resolve_redirect_location(m_url, location); } -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** LOCATION: %s", location.c_str()); #endif t->add_web_seed(location, web_seed_entry::url_seed, m_external_auth, m_extra_headers); @@ -790,7 +790,7 @@ void web_peer_connection::on_receive(error_code const& error } else { -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size); #endif TORRENT_ASSERT(int(bytes_transferred) >= header_size - m_partial_chunk_header); @@ -840,7 +840,7 @@ void web_peer_connection::on_receive(error_code const& error TORRENT_ASSERT(m_block_pos >= 0); -#ifdef TORRENT_VERBOSE_LOGGING +#ifdef TORRENT_LOGGING peer_log("*** payload_transferred: %d [ %d:%d = %d ]" , payload_transferred, front_request.piece , front_request.start, front_request.length); diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index 629a67bdb..0568b05c2 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -63,7 +63,7 @@ struct mock_peer_connection : peer_connection_interface for (int i = 0; i < 20; ++i) m_id[i] = rand(); } virtual ~mock_peer_connection() {} -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING virtual void peer_log(char const* fmt, ...) const { va_list v; @@ -114,7 +114,7 @@ struct mock_torrent return true; } -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_LOGGING void debug_log(const char* fmt, ...) const { va_list v;