diff --git a/Jamfile b/Jamfile index e7a5daf99..790ccbe22 100755 --- a/Jamfile +++ b/Jamfile @@ -257,6 +257,7 @@ rule warnings ( properties * ) { result += -Wall ; result += -Wextra ; + result += -Wno-format-zero-length ; # enable these warnings again, once the other ones are dealt with result += -Wno-sign-compare ; diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index a44104efd..019f02404 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2160,16 +2160,34 @@ namespace libtorrent // default it is disabled as a build configuration. struct TORRENT_EXPORT peer_log_alert : peer_alert { + // describes whether this log refers to in-flow or out-flow of the + // peer. The exception is ``info`` which is neither incoming or outgoing. + enum direction_t + { + incoming_message, + outgoing_message, + incoming, + outgoing, + info, + }; + // internal peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h - , tcp::endpoint const& i - , peer_id const& pi, char const* log); + , tcp::endpoint const& i, peer_id const& pi + , peer_log_alert::direction_t dir + , char const* event, char const* log); TORRENT_DEFINE_ALERT(peer_log_alert, 81) static const int static_category = alert::peer_log_notification; virtual std::string message() const; + // string literal indicating the kind of event. For messages, this is the + // message name. + char const* event_type; + + direction_t direction; + // returns the log message char const* msg() const; diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index d9948343c..6ea30754f 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -413,13 +413,7 @@ namespace libtorrent void set_upload_only(bool u); bool upload_only() const { return m_upload_only; } - void set_holepunch_mode() - { - m_holepunch_mode = true; -#ifndef TORRENT_DISABLE_LOGGING - peer_log("*** HOLEPUNCH MODE ***"); -#endif - } + void set_holepunch_mode(); // will send a keep-alive message to the peer void keep_alive(); @@ -553,9 +547,10 @@ namespace libtorrent int est_reciprocation_rate() const { return m_est_reciprocation_rate; } #ifndef TORRENT_DISABLE_LOGGING - virtual void peer_log(char const* fmt, ...) const + void peer_log(peer_log_alert::direction_t direction + , char const* event, char const* fmt = "", ...) const #if defined __GNUC__ || defined __clang__ - __attribute__((format(printf, 2, 3))) + __attribute__((format(printf, 4, 5))) #endif ; #endif @@ -654,13 +649,7 @@ namespace libtorrent // a piece for the moment, the boost::optional // will be invalid. virtual boost::optional - downloading_piece_progress() const - { -#ifndef TORRENT_DISABLE_LOGGING - peer_log("*** downloading_piece_progress() dispatched to the base class!"); -#endif - return boost::optional(); - } + downloading_piece_progress() const; enum message_type_flags { message_type_request = 1 }; void send_buffer(char const* begin, int size, int flags = 0); diff --git a/include/libtorrent/peer_connection_interface.hpp b/include/libtorrent/peer_connection_interface.hpp index 9d9060381..30cc0dcb6 100644 --- a/include/libtorrent/peer_connection_interface.hpp +++ b/include/libtorrent/peer_connection_interface.hpp @@ -63,7 +63,12 @@ namespace libtorrent virtual stat const& statistics() const = 0; virtual void get_peer_info(peer_info& p) const = 0; #ifndef TORRENT_DISABLE_LOGGING - virtual void peer_log(char const* fmt, ...) const = 0; + virtual void peer_log(peer_log_alert::direction_t direction + , char const* event, char const* fmt = "", ...) const +#if defined __GNUC__ || defined __clang__ + __attribute__((format(printf, 4, 5))) +#endif + = 0; #endif protected: ~peer_connection_interface() {} diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 73cc31619..690be6cf2 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1028,6 +1028,7 @@ namespace libtorrent __attribute__((format(printf, 2, 3))) #endif ; + void log_to_all_peers(char const* message); time_point m_dht_start_time; #endif diff --git a/src/alert.cpp b/src/alert.cpp index a2af39352..c0524e0cb 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1559,10 +1559,16 @@ namespace libtorrent { return torrent_alert::message() + ": " + msg(); } - peer_log_alert::peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h + peer_log_alert::peer_log_alert(aux::stack_allocator& alloc + , torrent_handle const& h , tcp::endpoint const& i - , peer_id const& pi, char const* log) + , peer_id const& pi + , direction_t dir + , char const* event + , char const* log) : peer_alert(alloc, h, i, pi) + , event_type(event) + , direction(dir) , m_str_idx(alloc.copy_string(log)) {} @@ -1573,7 +1579,10 @@ namespace libtorrent { std::string peer_log_alert::message() const { - return torrent_alert::message() + " [" + print_endpoint(ip) + "] " + msg(); + static char const* mode[] = + { "<==", "==>", "<<<", ">>>", "***" }; + return torrent_alert::message() + " [" + print_endpoint(ip) + "] " + + mode[direction] + " " + event_type + " [ " + msg() + " ]"; } lsd_error_alert::lsd_error_alert(aux::stack_allocator&, error_code const& ec) diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 654386cdf..075c10b47 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/version.hpp" #include "libtorrent/extensions.hpp" #include "libtorrent/aux_/session_interface.hpp" -//#include "libtorrent/aux_/escape_string.hpp" +#include "libtorrent/alert_types.hpp" #include "libtorrent/broadcast_socket.hpp" #include "libtorrent/peer_info.hpp" #include "libtorrent/random.hpp" @@ -126,7 +126,7 @@ namespace libtorrent #endif { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** bt_peer_connection"); + peer_log(peer_log_alert::info, "CONSTRUCT", "bt_peer_connection"); #endif #if TORRENT_USE_ASSERTS @@ -174,7 +174,7 @@ namespace libtorrent if (t->graceful_pause()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ON_CONNECTED [ graceful-paused ]"); + peer_log(peer_log_alert::info, "ON_CONNECTED", "graceful-paused"); #endif disconnect(error_code(errors::torrent_paused), op_bittorrent); return; @@ -195,7 +195,8 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING char const* policy_name[] = {"forced", "enabled", "disabled"}; - peer_log("*** outgoing encryption policy: %s", policy_name[out_enc_policy]); + peer_log(peer_log_alert::info, "ENCRYPTION" + , "outgoing encryption policy: %s", policy_name[out_enc_policy]); #endif if (out_enc_policy == settings_pack::pe_forced) @@ -255,7 +256,7 @@ namespace libtorrent void bt_peer_connection::on_metadata() { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ON_METADATA"); + peer_log(peer_log_alert::info, "ON_METADATA"); #endif disconnect_if_redundant(); @@ -287,7 +288,7 @@ namespace libtorrent TORRENT_ASSERT(m_sent_handshake && m_sent_bitfield); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> DHT_PORT [ %d ]", listen_port); + peer_log(peer_log_alert::outgoing_message, "DHT_PORT", "%d", listen_port); #endif char msg[] = {0,0,0,3, msg_dht_port, 0, 0}; char* ptr = msg + 5; @@ -303,7 +304,7 @@ namespace libtorrent TORRENT_ASSERT(m_sent_handshake); m_sent_bitfield = true; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> HAVE_ALL"); + peer_log(peer_log_alert::outgoing_message, "HAVE_ALL"); #endif char msg[] = {0,0,0,1, msg_have_all}; send_buffer(msg, sizeof(msg)); @@ -317,7 +318,7 @@ namespace libtorrent TORRENT_ASSERT(m_sent_handshake); m_sent_bitfield = true; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> HAVE_NONE"); + peer_log(peer_log_alert::outgoing_message, "HAVE_NONE"); #endif char msg[] = {0,0,0,1, msg_have_none}; send_buffer(msg, sizeof(msg)); @@ -334,8 +335,8 @@ namespace libtorrent if (!m_supports_fast) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REJECT_PIECE [ piece: %d | s: %d | l: %d ]" - , r.piece, r.start, r.length); + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE" + , "piece: %d | s: %d | l: %d", r.piece, r.start, r.length); #endif TORRENT_ASSERT(m_sent_handshake && m_sent_bitfield); TORRENT_ASSERT(associated_torrent().lock()->valid_metadata()); @@ -380,7 +381,8 @@ namespace libtorrent TORRENT_ASSERT(t->valid_metadata()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> SUGGEST [ piece: %d num_peers: %d ]", piece + peer_log(peer_log_alert::outgoing_message, "SUGGEST" + , "piece: %d num_peers: %d", piece , t->has_picker() ? t->picker().get_availability(piece) : -1); #endif @@ -448,7 +450,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING if (is_outgoing()) - peer_log("*** initiating encrypted handshake"); + peer_log(peer_log_alert::info, "ENCRYPTION", "initiating encrypted handshake"); #endif m_dh_key_exchange.reset(new (std::nothrow) dh_key_exchange); @@ -461,7 +463,7 @@ namespace libtorrent int pad_size = random() % 512; #ifndef TORRENT_DISABLE_LOGGING - peer_log(" pad size: %d", pad_size); + peer_log(peer_log_alert::info, "ENCRYPTION", "pad size: %d", pad_size); #endif char msg[dh_key_len + 512]; @@ -475,7 +477,7 @@ namespace libtorrent send_buffer(msg, buf_size); #ifndef TORRENT_DISABLE_LOGGING - peer_log(" sent DH key"); + peer_log(peer_log_alert::info, "ENCRYPTION", "sent DH key"); #endif } @@ -540,8 +542,8 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING char const* level[] = {"plaintext", "rc4", "plaintext rc4"}; - peer_log(" crypto provide : [ %s ]" - , level[crypto_provide-1]); + peer_log(peer_log_alert::info, "ENCRYPTION" + , "%s", level[crypto_provide-1]); #endif write_pe_vc_cryptofield(ptr, encrypt_size, crypto_provide, pad_size); @@ -579,7 +581,7 @@ namespace libtorrent m_rc4_encrypted = false; #ifndef TORRENT_DISABLE_LOGGING - peer_log(" crypto select : [ %s ]" + peer_log(peer_log_alert::info, "ENCRYPTION", " crypto select: %s" , (crypto_select == 0x01) ? "plaintext" : "rc4"); #endif } @@ -657,7 +659,7 @@ namespace libtorrent m_rc4->set_outgoing_key(&local_key[0], 20); #ifndef TORRENT_DISABLE_LOGGING - peer_log(" computed RC4 keys"); + peer_log(peer_log_alert::info, "ENCRYPTION", "computed RC4 keys"); #endif } @@ -800,7 +802,8 @@ namespace libtorrent else bitmask += '0'; } } - peer_log("==> EXTENSIONS [ %s ]", bitmask.c_str()); + peer_log(peer_log_alert::outgoing_message, "EXTENSIONS" + , "%s", bitmask.c_str()); #endif ptr += 8; @@ -826,10 +829,12 @@ namespace libtorrent char hex_pid[41]; to_hex((char const*)&m_our_peer_id[0], 20, hex_pid); hex_pid[40] = 0; - peer_log(">>> sent peer_id: %s client: %s" + peer_log(peer_log_alert::outgoing, "HANDSHAKE" + , "sent peer_id: %s client: %s" , hex_pid, identify_client(m_our_peer_id).c_str()); } - peer_log("==> HANDSHAKE [ ih: %s ]", to_hex(ih.to_string()).c_str()); + peer_log(peer_log_alert::outgoing_message, "HANDSHAKE" + , "ih: %s", to_hex(ih.to_string()).c_str()); #endif send_buffer(handshake, sizeof(handshake)); @@ -905,7 +910,7 @@ namespace libtorrent INVARIANT_CHECK; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== KEEPALIVE"); + peer_log(peer_log_alert::incoming_message, "KEEPALIVE"); #endif incoming_keepalive(); } @@ -1245,7 +1250,7 @@ namespace libtorrent if (recv_pos < header_size) return; #ifndef TORRENT_DISABLE_LOGGING -// peer_log("<== PIECE_FRAGMENT p: %d start: %d length: %d" +// peer_log(peer_log_alert::incoming_message, "PIECE_FRAGMENT", "p: %d start: %d length: %d" // , p.piece, p.start, p.length); #endif @@ -1265,7 +1270,8 @@ namespace libtorrent if (merkle && list_size > 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HASHPIECE [ piece: %d list: %d ]", p.piece, list_size); + peer_log(peer_log_alert::incoming_message, "HASHPIECE" + , "piece: %d list: %d", p.piece, list_size); #endif bdecode_node hash_list; error_code ec; @@ -1518,7 +1524,8 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING error_code ec; static const char* hp_msg_name[] = {"rendezvous", "connect", "failed"}; - peer_log("<== HOLEPUNCH [ msg: %s from %s to: unknown address type ]" + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg: %s from %s to: unknown address type" , (msg_type >= 0 && msg_type < 3 ? hp_msg_name[msg_type] : "unknown message type") , print_address(remote().address()).c_str()); #endif @@ -1534,8 +1541,8 @@ namespace libtorrent case hp_rendezvous: // rendezvous { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HOLEPUNCH [ msg: rendezvous to: %s ]" - , print_address(ep.address()).c_str()); + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg: rendezvous to: %s", print_address(ep.address()).c_str()); #endif // this peer is asking us to introduce it to // the peer at 'ep'. We need to find which of @@ -1568,7 +1575,8 @@ namespace libtorrent if (p == 0 || p->connection) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HOLEPUNCH [ msg:connect to: %s error: failed to add peer ]" + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg:connect to: %s error: failed to add peer" , print_address(ep.address()).c_str()); #endif // we either couldn't add this peer, or it's @@ -1578,12 +1586,11 @@ namespace libtorrent if (p->banned) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HOLEPUNCH [ msg:connect to: %s error: peer banned ]" - , print_address(ep.address()).c_str()); + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg:connect to: %s error: peer banned", print_address(ep.address()).c_str()); #endif // this peer is banned, don't connect to it break; - } // to make sure we use the uTP protocol p->supports_utp = true; @@ -1597,7 +1604,8 @@ namespace libtorrent if (p->connection) p->connection->set_holepunch_mode(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HOLEPUNCH [ msg:connect to: %s ]" + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg:connect to: %s" , print_address(ep.address()).c_str()); #endif } break; @@ -1607,7 +1615,8 @@ namespace libtorrent #ifndef TORRENT_DISABLE_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 + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg:failed error: %d msg: %s", error , ((error > 0 && error < 5)?err_msg[error-1]:"unknown message id")); #endif // #error deal with holepunch errors @@ -1617,7 +1626,8 @@ namespace libtorrent default: { error_code ec; - peer_log("<== HOLEPUNCH [ msg: unknown message type (%d) to: %s ]" + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH" + , "msg: unknown message type (%d) to: %s" , msg_type, print_address(ep.address()).c_str()); } #endif @@ -1637,7 +1647,8 @@ namespace libtorrent 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"}; - peer_log("==> HOLEPUNCH [ msg: %s to: %s error: %s ]" + peer_log(peer_log_alert::outgoing_message, "HOLEPUNCH" + , "msg: %s to: %s error: %s" , (type >= 0 && type < 3 ? hp_msg_name[type] : "unknown message type") , print_address(ep.address()).c_str() , hp_error_string[error]); @@ -1705,13 +1716,15 @@ namespace libtorrent if (m_recv_buffer.packet_size() != 3) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== UPLOAD_ONLY [ ERROR: unexpected packet size: %d ]", m_recv_buffer.packet_size()); + peer_log(peer_log_alert::incoming_message, "UPLOAD_ONLY" + , "ERROR: unexpected packet size: %d", m_recv_buffer.packet_size()); #endif return; } bool ul = detail::read_uint8(recv_buffer.begin) != 0; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== UPLOAD_ONLY [ %s ]", (ul?"true":"false")); + peer_log(peer_log_alert::incoming_message, "UPLOAD_ONLY" + , "%s", (ul?"true":"false")); #endif set_upload_only(ul); return; @@ -1723,13 +1736,15 @@ namespace libtorrent if (m_recv_buffer.packet_size() != 3) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== SHARE_MODE [ ERROR: unexpected packet size: %d ]", m_recv_buffer.packet_size()); + peer_log(peer_log_alert::incoming_message, "SHARE_MODE" + , "ERROR: unexpected packet size: %d", m_recv_buffer.packet_size()); #endif return; } bool sm = detail::read_uint8(recv_buffer.begin) != 0; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== SHARE_MODE [ %s ]", (sm?"true":"false")); + peer_log(peer_log_alert::incoming_message, "SHARE_MODE" + , "%s", (sm?"true":"false")); #endif set_share_mode(sm); return; @@ -1739,7 +1754,7 @@ namespace libtorrent { if (!m_recv_buffer.packet_finished()) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HOLEPUNCH"); + peer_log(peer_log_alert::incoming_message, "HOLEPUNCH"); #endif on_holepunch(); return; @@ -1751,7 +1766,8 @@ namespace libtorrent if (m_recv_buffer.packet_size() != 6) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== DONT_HAVE [ ERROR: unexpected packet size: %d ]", m_recv_buffer.packet_size()); + peer_log(peer_log_alert::incoming_message, "DONT_HAVE" + , "ERROR: unexpected packet size: %d", m_recv_buffer.packet_size()); #endif return; } @@ -1762,8 +1778,8 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING if (m_recv_buffer.packet_finished()) - peer_log("<== EXTENSION MESSAGE [ msg: %d size: %d ]" - , extended_id, m_recv_buffer.packet_size()); + peer_log(peer_log_alert::incoming_message, "EXTENSION_MESSAGE" + , "msg: %d size: %d", extended_id, m_recv_buffer.packet_size()); #endif for (extension_list_t::iterator i = m_extensions.begin() @@ -1794,14 +1810,16 @@ namespace libtorrent if (ret != 0 || ec || root.type() != bdecode_node::dict_t) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** invalid extended handshake: %s pos: %d" + peer_log(peer_log_alert::info, "EXTENSION_MESSAGE" + , "invalid extended handshake: %s pos: %d" , ec.message().c_str(), pos); #endif return; } #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== EXTENDED HANDSHAKE: %s", print_entry(root).c_str()); + peer_log(peer_log_alert::incoming_message, "EXTENDED_HANDSHAKE" + , "%s", print_entry(root).c_str()); #endif for (extension_list_t::iterator i = m_extensions.begin(); @@ -1843,13 +1861,7 @@ namespace libtorrent if (!client_info.empty()) m_client_version = client_info; int reqq = int(root.dict_find_int_value("reqq")); - if (reqq > 0) - { - max_out_request_queue(reqq); -#ifdef TORRENT_VERBOSE_LOGGING - peer_log("*** MAX OUT REQUEST QUEUE [ %d ]", reqq); -#endif - } + if (reqq > 0) max_out_request_queue(reqq); if (root.dict_find_int_value("upload_only", 0)) set_upload_only(true); @@ -1992,7 +2004,7 @@ namespace libtorrent if (!m_settings.get_bool(settings_pack::close_redundant_connections)) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> UPLOAD_ONLY [ %d ]" + peer_log(peer_log_alert::outgoing_message, "UPLOAD_ONLY", "%d" , int(t->is_upload_only() && !t->super_seeding())); #endif @@ -2093,7 +2105,7 @@ namespace libtorrent if (t->super_seeding()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log(" *** NOT SENDING BITFIELD, super seeding"); + peer_log(peer_log_alert::info, "BITFIELD", "not sending bitfield, super seeding"); #endif if (m_supports_fast) write_have_none(); @@ -2124,7 +2136,7 @@ namespace libtorrent { // don't send a bitfield if we don't have any pieces #ifndef TORRENT_DISABLE_LOGGING - peer_log(" *** NOT SENDING BITFIELD"); + peer_log(peer_log_alert::info, "BITFIELD", "not sending bitfield, have none"); #endif m_sent_bitfield = true; return; @@ -2203,7 +2215,8 @@ namespace libtorrent if (msg[5 + k / 8] & (0x80 >> (k % 8))) bitfield_string[k] = '1'; else bitfield_string[k] = '0'; } - peer_log("==> BITFIELD [ %s ]", bitfield_string.c_str()); + peer_log(peer_log_alert::outgoing_message, "BITFIELD" + , "%s", bitfield_string.c_str()); #endif m_sent_bitfield = true; @@ -2216,7 +2229,8 @@ namespace libtorrent for (int i = 0; i < num_lazy_pieces; ++i) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> HAVE [ piece: %d ]", lazy_pieces[i]); + peer_log(peer_log_alert::outgoing_message, "HAVE" + , "piece: %d", lazy_pieces[i]); #endif write_have(lazy_pieces[i]); } @@ -2335,7 +2349,8 @@ namespace libtorrent stats_counters().inc_stats_counter(counters::num_outgoing_ext_handshake); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> EXTENDED HANDSHAKE: %s", handshake.to_string().c_str()); + peer_log(peer_log_alert::outgoing_message, "EXTENDED_HANDSHAKE" + , "%s", handshake.to_string().c_str()); #endif } #endif @@ -2556,7 +2571,8 @@ namespace libtorrent int consumed = m_enc_handler.decrypt(m_recv_buffer, bytes_transferred); #ifndef TORRENT_DISABLE_LOGGING if (consumed + bytes_transferred > 0) - peer_log("<== decrypted block [ s = %d ]", int(consumed + bytes_transferred)); + peer_log(peer_log_alert::incoming_message, "ENCRYPTION" + , "decrypted block s = %d", int(consumed + bytes_transferred)); #endif if (bytes_transferred == SIZE_MAX) { @@ -2627,7 +2643,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** received DH key"); + peer_log(peer_log_alert::info, "ENCRYPTION", "received DH key"); #endif // PadA/B can be a max of 512 bytes, and 20 bytes more for @@ -2726,7 +2742,8 @@ namespace libtorrent { std::size_t bytes_processed = syncoffset + 20; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** sync point (hash) found at offset %d" + peer_log(peer_log_alert::info, "ENCRYPTION" + , "sync point (hash) found at offset %d" , int(m_sync_bytes_read + bytes_processed - 20)); #endif m_state = read_pe_skey_vc; @@ -2775,7 +2792,7 @@ namespace libtorrent init_pe_rc4_handler(m_dh_key_exchange->get_secret(), ti->info_hash()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** stream key found, torrent located"); + peer_log(peer_log_alert::info, "ENCRYPTION", "stream key found, torrent located"); #endif } @@ -2798,7 +2815,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** verification constant found"); + peer_log(peer_log_alert::info, "ENCRYPTION", "verification constant found"); #endif m_state = read_pe_cryptofield; m_recv_buffer.reset(4 + 2); @@ -2862,7 +2879,8 @@ namespace libtorrent { std::size_t bytes_processed = syncoffset + 8; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** sync point (verification constant) found at offset %d" + peer_log(peer_log_alert::info, "ENCRYPTION" + , "sync point (verification constant) found at offset %d" , int(m_sync_bytes_read + bytes_processed - 8)); #endif int transferred_used = bytes_processed - recv_buffer.left() + bytes_transferred; @@ -2897,7 +2915,7 @@ namespace libtorrent boost::uint32_t crypto_field = detail::read_uint32(recv_buffer.begin); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** crypto %s : [%s%s ]" + peer_log(peer_log_alert::info, "ENCRYPTION", "crypto %s : [%s%s ]" , is_outgoing() ? "select" : "provide" , (crypto_field & 1) ? " plaintext" : "" , (crypto_field & 2) ? " rc4" : ""); @@ -3011,7 +3029,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** len(IA) : %d", len_ia); + peer_log(peer_log_alert::info, "ENCRYPTION", "len(IA) : %d", len_ia); #endif if (len_ia == 0) { @@ -3057,7 +3075,8 @@ namespace libtorrent rc4_decrypt(wr_buf.begin, m_recv_buffer.packet_size()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** decrypted ia : %d bytes", m_recv_buffer.packet_size()); + peer_log(peer_log_alert::info, "ENCRYPTION" + , "decrypted ia : %d bytes", m_recv_buffer.packet_size()); #endif // everything that arrives after this is encrypted @@ -3106,7 +3125,8 @@ namespace libtorrent rc4_decrypt(wr_buf.begin, wr_buf.left()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** decrypted remaining %d bytes", wr_buf.left()); + peer_log(peer_log_alert::info, "ENCRYPTION" + , "decrypted remaining %d bytes", wr_buf.left()); #endif } m_rc4.reset(); @@ -3147,14 +3167,16 @@ namespace libtorrent { #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** unrecognized protocol header"); + peer_log(peer_log_alert::info, "ENCRYPTION" + , "unrecognized protocol header"); #endif #ifdef TORRENT_USE_OPENSSL if (is_ssl(*get_socket())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SSL peers are not allowed to use any other encryption"); + peer_log(peer_log_alert::info, "ENCRYPTION" + , "SSL peers are not allowed to use any other encryption"); #endif disconnect(errors::invalid_info_hash, op_bittorrent, 1); return; @@ -3180,7 +3202,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** attempting encrypted connection"); + peer_log(peer_log_alert::info, "ENCRYPTION", "attempting encrypted connection"); #endif m_state = read_pe_dhkey; m_recv_buffer.cut(0, dh_key_len); @@ -3208,7 +3230,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== BitTorrent protocol"); + peer_log(peer_log_alert::incoming_message, "HANDSHAKE", "BitTorrent protocol"); #endif } @@ -3238,7 +3260,7 @@ namespace libtorrent else extensions[i*8+j] = '0'; } } - peer_log("<== EXTENSIONS [ %s ext: %s%s%s]" + peer_log(peer_log_alert::incoming_message, "EXTENSIONS", "%s ext: %s%s%s" , extensions.c_str() , (recv_buffer[7] & 0x01) ? "DHT " : "" , (recv_buffer[7] & 0x04) ? "FAST " : "" @@ -3278,14 +3300,14 @@ namespace libtorrent , (const char*)t->torrent_file().info_hash().begin())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** received invalid info_hash"); + peer_log(peer_log_alert::info, "ERROR", "received invalid info_hash"); #endif disconnect(errors::invalid_info_hash, op_bittorrent, 1); return; } #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< info_hash received"); + peer_log(peer_log_alert::incoming, "HANDSHAKE", "info_hash received"); #endif } @@ -3332,7 +3354,7 @@ namespace libtorrent if (is_print(recv_buffer.begin[i])) ascii_pid[i] = recv_buffer.begin[i]; else ascii_pid[i] = '.'; } - peer_log("<<< received peer_id: %s client: %s ascii: \"%s\"" + peer_log(peer_log_alert::incoming, "HANDSHAKE", "received peer_id: %s client: %s ascii: \"%s\"" , hex_pid, identify_client(peer_id(recv_buffer.begin)).c_str(), ascii_pid); } #endif @@ -3403,7 +3425,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HANDSHAKE"); + peer_log(peer_log_alert::incoming_message, "HANDSHAKE"); #endif // consider this a successful connection, reset the failcount if (peer_info_struct()) @@ -3520,7 +3542,8 @@ namespace libtorrent int next_barrier = m_enc_handler.encrypt(iovec); #ifndef TORRENT_DISABLE_LOGGING if (next_barrier != 0) - peer_log("==> encrypted block [ s = %d ]", next_barrier); + peer_log(peer_log_alert::outgoing_message, "SEND_BARRIER" + , "encrypted block s = %d", next_barrier); #endif return next_barrier; } diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 8d65291f4..1148b50db 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -79,7 +79,7 @@ namespace libtorrent prefer_contiguous_blocks(blocks_per_piece); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** http_seed_connection"); + peer_log(peer_log_alert::info, "CONNECT", "http_seed_connection"); #endif } @@ -195,7 +195,7 @@ namespace libtorrent m_first_request = false; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> %s", request.c_str()); + peer_log(peer_log_alert::outgoing_message, "REQUEST", "%s", request.c_str()); #endif send_buffer(request.c_str(), request.size(), message_type_request); @@ -214,7 +214,8 @@ namespace libtorrent { received_bytes(0, bytes_transferred); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** http_seed_connection error: %s", error.message().c_str()); + peer_log(peer_log_alert::info, "ERROR" + , "http_seed_connection error: %s", error.message().c_str()); #endif return; } @@ -377,7 +378,8 @@ namespace libtorrent else { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** parsed chunk: %" PRId64 " header_size: %d" + peer_log(peer_log_alert::info, "CHUNKED_ENCODING" + , "parsed chunk: %" PRId64 " header_size: %d" , chunk_size, header_size); #endif TORRENT_ASSERT(bytes_transferred >= size_t(header_size - m_partial_chunk_header)); @@ -416,7 +418,7 @@ namespace libtorrent int retry_time = atol(std::string(recv_buffer.begin, recv_buffer.end).c_str()); if (retry_time <= 0) retry_time = 60; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** retrying in %d seconds", retry_time); + peer_log(peer_log_alert::info, "CONNECT", "retrying in %d seconds", retry_time); #endif received_bytes(0, bytes_transferred); diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index 96181c6e2..c2bf18756 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -206,7 +206,8 @@ namespace libtorrent { namespace if (added == 0) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log(" <== LT_TEX [ NOT A DICTIONARY ]"); + m_pc.peer_log(peer_log_alert::incoming_message, "LT_TEX" + , "NOT A DICTIONARY"); #endif return true; } @@ -214,16 +215,15 @@ namespace libtorrent { namespace if (m_tp.num_tex_trackers() >= 50) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log(" <== LT_TEX [ we already have %d trackers " - "from tex, don't add any more", m_tp.num_tex_trackers()); + m_pc.peer_log(peer_log_alert::incoming_message, "LT_TEX" + , "we already have %d trackers from tex, don't add any more" + , m_tp.num_tex_trackers()); #endif return true; } #ifndef TORRENT_DISABLE_LOGGING - std::stringstream log_line; - log_line << " <== LT_TEX [ " - "added: "; + m_pc.peer_log(peer_log_alert::incoming_message, "LT_TEX"); #endif for (int i = 0; i < added.list_size(); ++i) @@ -254,12 +254,7 @@ namespace libtorrent { namespace continue; if (m_tp.num_tex_trackers() >= 50) - { -#ifndef TORRENT_DISABLE_LOGGING - log_line << "**reached-limit** "; -#endif break; - } e.fail_limit = 1; e.send_stats = false; @@ -268,13 +263,9 @@ namespace libtorrent { namespace m_tp.increment_tracker_counter(); #ifndef TORRENT_DISABLE_LOGGING - log_line << e.url << " "; + m_pc.peer_log(peer_log_alert::info, "LT_TEX", "added: %s", e.url.c_str()); #endif } -#ifndef TORRENT_DISABLE_LOGGING - log_line << "]\n"; - m_pc.peer_log("%s", log_line.str().c_str()); -#endif return true; } @@ -326,9 +317,7 @@ namespace libtorrent { namespace return false; #ifndef TORRENT_DISABLE_LOGGING - std::stringstream log_line; - log_line << " ==> LT_TEX [ " - "added: "; + m_pc.peer_log(peer_log_alert::outgoing_message, "LT_TEX"); #endif entry tex; entry::list_type& added = tex["added"].list(); @@ -338,17 +327,13 @@ namespace libtorrent { namespace if (!send_tracker(*i)) continue; added.push_back(i->url); #ifndef TORRENT_DISABLE_LOGGING - log_line << i->url << " "; + m_pc.peer_log(peer_log_alert::info, "LT_TEX" + , "sending: %s", i->url.c_str()); #endif } std::vector tex_msg; bencode(std::back_inserter(tex_msg), tex); -#ifndef TORRENT_DISABLE_LOGGING - log_line << "]"; - m_pc.peer_log("%s", log_line.str().c_str()); -#endif - char msg[6]; char* ptr = msg; diff --git a/src/metadata_transfer.cpp b/src/metadata_transfer.cpp index f7726a50b..bf2d62c6e 100644 --- a/src/metadata_transfer.cpp +++ b/src/metadata_transfer.cpp @@ -301,8 +301,8 @@ namespace libtorrent { namespace if (m_message_index == 0) return; #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("==> METADATA_REQUEST [ start: %d | size: %d ]\n" - , start, size); + m_pc.peer_log(peer_log_alert::outgoing_message, "METADATA_REQUEST" + , "start: %d size: %d", start, size); #endif char msg[9]; @@ -339,7 +339,8 @@ namespace libtorrent { namespace char* ptr = msg; #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("==> METADATA [ start: %d | total_size: %d | offset: %d | data_size: %d ]" + m_pc.peer_log(peer_log_alert::outgoing_message, "METADATA" + , "start: %d total_size: %d offset: %d data_size: %d" , req.first, req.second, offset.first, offset.second); #endif // yes, we have metadata, send it @@ -360,7 +361,8 @@ namespace libtorrent { namespace else { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("==> DONT HAVE METADATA\n"); + m_pc.peer_log(peer_log_alert::outgoing_message, "METADATA" + , "don't have metadata"); #endif char msg[4+3]; char* ptr = msg; @@ -401,8 +403,8 @@ namespace libtorrent { namespace int size = detail::read_uint8(body.begin) + 1; #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== METADATA_REQUEST [ start: %d | size: %d ]\n" - , start, size); + m_pc.peer_log(peer_log_alert::incoming_message, "METADATA_REQUEST" + , "start: %d size: %d", start, size); #endif if (length != 3) @@ -424,7 +426,8 @@ namespace libtorrent { namespace int data_size = length - 9; #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== METADATA [ total_size: %d | offset: %d | data_size: %d ]" + m_pc.peer_log(peer_log_alert::incoming_message, "METADATA" + , "total_size: %d | offset: %d | data_size: %d" ,total_size, offset, data_size); #endif @@ -467,7 +470,8 @@ namespace libtorrent { namespace m_tp.cancel_metadata_request(m_last_metadata_request); m_waiting_metadata_request = false; #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== DONT HAVE METADATA\n"); + m_pc.peer_log(peer_log_alert::incoming_message, "METADATA" + , "don't have metadata"); #endif break; default: diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 76d882cdc..026917088 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -251,8 +251,10 @@ namespace libtorrent error_code ec; TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec); tcp::endpoint local_ep = m_socket->local_endpoint(ec); - peer_log("%s [ ep: %s type: %s seed: %d p: %p local: %s]" - , m_outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" + + peer_log(m_outgoing ? peer_log_alert::outgoing : peer_log_alert::incoming + , m_outgoing ? "OUTGOING_CONNECTION" : "INCOMING_CONNECTION" + , "ep: %s type: %s seed: %d p: %p local: %s" , print_endpoint(m_remote).c_str() , m_socket->type_name() , m_peer_info ? m_peer_info->seed : 0, m_peer_info @@ -355,7 +357,8 @@ namespace libtorrent { m_socket->set_option(type_of_service(m_settings.get_int(settings_pack::peer_tos)), ec); #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> SET_TOS[ tos: %d e: %s ]", m_settings.get_int(settings_pack::peer_tos), ec.message().c_str()); + peer_log(peer_log_alert::outgoing, "SET_TOS", "tos: %d e: %s" + , m_settings.get_int(settings_pack::peer_tos), ec.message().c_str()); #endif } #if TORRENT_USE_IPV6 && defined IPV6_TCLASS @@ -367,7 +370,8 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SET_PEER_CLASS [ a: %s ]", print_address(m_remote.address()).c_str()); + peer_log(peer_log_alert::info, "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()); @@ -375,7 +379,8 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING for (int i = 0; i < num_classes(); ++i) { - peer_log("*** CLASS [ %s ]", m_ses.peer_classes().at(class_at(i))->label.c_str()); + peer_log(peer_log_alert::info, "CLASS", "%s" + , m_ses.peer_classes().at(class_at(i))->label.c_str()); } #endif @@ -388,7 +393,8 @@ namespace libtorrent if (!m_connecting) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> OPEN [ protocol: %s ]", (m_remote.address().is_v4()?"IPv4":"IPv6")); + peer_log(peer_log_alert::outgoing, "OPEN", "protocol: %s" + , (m_remote.address().is_v4()?"IPv4":"IPv6")); #endif error_code ec; m_socket->open(m_remote.protocol(), ec); @@ -401,7 +407,8 @@ namespace libtorrent tcp::endpoint bound_ip = m_ses.bind_outgoing_socket(*m_socket , m_remote.address(), ec); #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> BIND [ dst: %s ec: %s ]", print_endpoint(bound_ip).c_str() + peer_log(peer_log_alert::outgoing, "BIND", "dst: %s ec: %s" + , print_endpoint(bound_ip).c_str() , ec.message().c_str()); #endif if (ec) @@ -411,7 +418,8 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> ASYNC_CONNECT [ dst: %s ]", print_endpoint(m_remote).c_str()); + peer_log(peer_log_alert::outgoing, "ASYNC_CONNECT", "dst: %s" + , print_endpoint(m_remote).c_str()); #endif #if defined TORRENT_ASIO_DEBUGGING add_outstanding_async("peer_connection::on_connection_complete"); @@ -434,7 +442,8 @@ namespace libtorrent t->get_handle(), remote(), pid(), m_socket->type()); } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** LOCAL ENDPOINT[ e: %s ]", print_endpoint(m_socket->local_endpoint(ec)).c_str()); + peer_log(peer_log_alert::info, "LOCAL ENDPOINT", "e: %s" + , print_endpoint(m_socket->local_endpoint(ec)).c_str()); #endif } @@ -469,14 +478,14 @@ namespace libtorrent if (m_have_piece.size() == 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** UPDATE_INTEREST [ connections not initialized ]"); + peer_log(peer_log_alert::info, "UPDATE_INTEREST", "connections not initialized"); #endif return; } if (!t->ready_for_connections()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** UPDATE_INTEREST [ not ready for connections ]"); + peer_log(peer_log_alert::info, "UPDATE_INTEREST", "not ready for connections"); #endif return; } @@ -495,7 +504,7 @@ namespace libtorrent { interested = true; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** UPDATE_INTEREST [ interesting, piece: %d ]", j); + peer_log(peer_log_alert::info, "UPDATE_INTEREST", "interesting, piece: %d", j); #endif break; } @@ -504,7 +513,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING if (!interested) - peer_log("*** UPDATE_INTEREST [ not interesting ]"); + peer_log(peer_log_alert::info, "UPDATE_INTEREST", "not interesting"); #endif if (!interested) send_not_interested(); @@ -517,9 +526,10 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING #if defined __GNUC__ || defined __clang__ - __attribute__((format(printf, 2, 3))) + __attribute__((format(printf, 4, 5))) #endif - void peer_connection::peer_log(char const* fmt, ...) const + void peer_connection::peer_log(peer_log_alert::direction_t direction + , char const* event, char const* fmt, ...) const { TORRENT_ASSERT(is_single_thread()); @@ -528,6 +538,8 @@ namespace libtorrent va_list v; va_start(v, fmt); + // TODO: it would be neat to be able to print this straight into the + // alert's stack allocator char buf[512]; vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); @@ -537,7 +549,7 @@ namespace libtorrent if (t) h = t->get_handle(); m_ses.alerts().emplace_alert( - h, m_remote, m_peer_id, buf); + h, m_remote, m_peer_id, direction, event, buf); } #endif @@ -571,7 +583,7 @@ namespace libtorrent if (t->super_seeding()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SKIPPING ALLOWED SET BECAUSE OF SUPER SEEDING"); + peer_log(peer_log_alert::info, "ALLOWED", "skipping allowed set because of super seeding"); #endif return; } @@ -579,7 +591,7 @@ namespace libtorrent if (upload_only()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SKIPPING ALLOWED SET BECAUSE PEER IS UPLOAD ONLY"); + peer_log(peer_log_alert::info, "ALLOWED", "skipping allowed set because peer is upload only"); #endif return; } @@ -601,7 +613,7 @@ namespace libtorrent if (has_piece(i)) continue; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> ALLOWED_FAST [ %d ]", i); + peer_log(peer_log_alert::outgoing_message, "ALLOWED_FAST", "%d", i); #endif write_allow_fast(i); TORRENT_ASSERT(std::find(m_accept_fast.begin() @@ -645,7 +657,7 @@ namespace libtorrent == m_accept_fast.end()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> ALLOWED_FAST [ %d ]", piece); + peer_log(peer_log_alert::outgoing_message, "ALLOWED_FAST", "%d", piece); #endif write_allow_fast(piece); if (m_accept_fast.empty()) @@ -723,7 +735,7 @@ namespace libtorrent if (m_num_pieces == int(m_have_piece.size())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); + peer_log(peer_log_alert::info, "INIT", "this is a seed p: %p", m_peer_info); #endif TORRENT_ASSERT(m_have_piece.all_set()); @@ -827,7 +839,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** CONNECTION CLOSED"); + peer_log(peer_log_alert::info, "CONNECTION CLOSED"); #endif TORRENT_ASSERT(m_request_queue.empty()); TORRENT_ASSERT(m_download_queue.empty()); @@ -911,7 +923,7 @@ namespace libtorrent if (in_handshake()) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< RECEIVED [ piece: %d ]", index); + peer_log(peer_log_alert::incoming, "RECEIVED", "piece: %d", index); #endif // remove suggested pieces once we have them @@ -954,7 +966,7 @@ namespace libtorrent if (!m_settings.get_bool(settings_pack::send_redundant_have)) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> HAVE [ piece: %d ] SUPRESSED", index); + peer_log(peer_log_alert::outgoing_message, "HAVE", "piece: %d SUPRESSED", index); #endif return; } @@ -963,7 +975,7 @@ namespace libtorrent if (disconnect_if_redundant()) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> HAVE [ piece: %d ]", index); + peer_log(peer_log_alert::outgoing_message, "HAVE", "piece: %d", index); #endif write_have(index); #if TORRENT_USE_ASSERTS @@ -1182,7 +1194,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING m_connect_time = clock_type::now(); - peer_log("*** attached to torrent"); + peer_log(peer_log_alert::info, "ATTACH", "attached to torrent"); #endif TORRENT_ASSERT(!m_disconnecting); @@ -1193,7 +1205,7 @@ namespace libtorrent if (t && t->is_aborted()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** the torrent has been aborted"); + peer_log(peer_log_alert::info, "ATTACH", "the torrent has been aborted"); #endif t.reset(); } @@ -1203,7 +1215,8 @@ namespace libtorrent t = m_ses.delay_load_torrent(ih, this); #ifndef TORRENT_DISABLE_LOGGING if (t) - peer_log("*** Delay loaded torrent: %s:", to_hex(ih.to_string()).c_str()); + peer_log(peer_log_alert::info, "ATTACH" + , "Delay loaded torrent: %s:", to_hex(ih.to_string()).c_str()); #endif } @@ -1211,7 +1224,9 @@ namespace libtorrent { // we couldn't find the torrent! #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** couldn't find a torrent with the given info_hash: %s torrents:", to_hex(ih.to_string()).c_str()); + peer_log(peer_log_alert::info, "ATTACH" + , "couldn't find a torrent with the given info_hash: %s torrents:" + , to_hex(ih.to_string()).c_str()); #endif #ifndef TORRENT_DISABLE_DHT @@ -1243,7 +1258,7 @@ namespace libtorrent // torrents that have errors should always reject // incoming peers #ifndef TORRENT_DISABLE_LOGGING - peer_log("rejected connection to paused torrent"); + peer_log(peer_log_alert::info, "ATTACH", "rejected connection to paused torrent"); #endif disconnect(errors::torrent_paused, op_bittorrent, 2); return; @@ -1257,7 +1272,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. #ifndef TORRENT_DISABLE_LOGGING - peer_log("rejected regular connection to i2p torrent"); + peer_log(peer_log_alert::info, "ATTACH", "rejected regular connection to i2p torrent"); #endif disconnect(errors::peer_banned, op_bittorrent, 2); return; @@ -1338,7 +1353,7 @@ namespace libtorrent INVARIANT_CHECK; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== KEEPALIVE"); + peer_log(peer_log_alert::incoming_message, "KEEPALIVE"); #endif } @@ -1372,7 +1387,7 @@ namespace libtorrent if (is_disconnecting()) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== CHOKE"); + peer_log(peer_log_alert::incoming_message, "CHOKE"); #endif if (m_peer_choked == false) m_counters.inc_stats_counter(counters::num_peers_down_unchoked, -1); @@ -1434,7 +1449,7 @@ namespace libtorrent TORRENT_ASSERT(t); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== REJECT_PIECE [ piece: %d | s: %x | l: %x ]" + peer_log(peer_log_alert::incoming_message, "REJECT_PIECE", "piece: %d s: %x l: %x" , r.piece, r.start, r.length); #endif @@ -1485,7 +1500,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING else { - peer_log("*** PIECE NOT IN REQUEST QUEUE"); + peer_log(peer_log_alert::info, "REJECT_PIECE", "piece not in request queue"); } #endif if (has_peer_choked()) @@ -1523,7 +1538,8 @@ namespace libtorrent INVARIANT_CHECK; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== SUGGEST_PIECE [ piece: %d ]", index); + peer_log(peer_log_alert::incoming_message, "SUGGEST_PIECE" + , "piece: %d", index); #endif boost::shared_ptr t = m_torrent.lock(); if (!t) return; @@ -1540,7 +1556,8 @@ namespace libtorrent if (index < 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== INVALID_SUGGEST_PIECE [ %d ]", index); + peer_log(peer_log_alert::incoming_message, "INVALID_SUGGEST_PIECE" + , "%d", index); #endif return; } @@ -1550,8 +1567,8 @@ namespace libtorrent if (index >= int(m_have_piece.size())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== INVALID_SUGGEST [ %d | s: %d ]" - , index, int(m_have_piece.size())); + peer_log(peer_log_alert::incoming_message, "INVALID_SUGGEST" + , "%d s: %d", index, int(m_have_piece.size())); #endif return; } @@ -1568,7 +1585,8 @@ namespace libtorrent m_suggested_pieces.push_back(index); #ifndef TORRENT_DISABLE_LOGGING - peer_log("** SUGGEST_PIECE [ piece: %d added to set: %d ]", index, int(m_suggested_pieces.size())); + peer_log(peer_log_alert::info, "SUGGEST_PIECE", "piece: %d added to set: %d" + , index, int(m_suggested_pieces.size())); #endif } @@ -1598,7 +1616,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== UNCHOKE"); + peer_log(peer_log_alert::incoming_message, "UNCHOKE"); #endif if (m_peer_choked) m_counters.inc_stats_counter(counters::num_peers_down_unchoked); @@ -1636,7 +1654,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== INTERESTED"); + peer_log(peer_log_alert::incoming_message, "INTERESTED"); #endif if (m_peer_interested == false) m_counters.inc_stats_counter(counters::num_peers_up_interested); @@ -1653,7 +1671,8 @@ namespace libtorrent if (t->graceful_pause()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("DID NOT UNCHOKE [ graceful pause mode ]"); + peer_log(peer_log_alert::info, "UNCHOKE" + , "did not unchoke, graceful pause mode"); #endif return; } @@ -1669,7 +1688,7 @@ namespace libtorrent // has this problem, sending another unchoke here will kick it // to react to the fact that it's unchoked. #ifndef TORRENT_DISABLE_LOGGING - peer_log("SENDING REDUNDANT UNCHOKE"); + peer_log(peer_log_alert::info, "UNCHOKE", "sending redundant unchoke"); #endif write_unchoke(); return; @@ -1684,7 +1703,7 @@ namespace libtorrent if (ignore_unchoke_slots()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("ABOUT TO UNCHOKE [ peer ignores unchoke slots ]"); + peer_log(peer_log_alert::info, "UNCHOKE", "about to unchoke, peer ignores unchoke slots"); #endif // if this peer is expempted from the choker // just unchoke it immediately @@ -1711,8 +1730,8 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING else { - peer_log("DID NOT UNCHOKE [ the number of uploads (%d) " - "is more than or equal to the limit (%d) ]" + peer_log(peer_log_alert::info, "UNCHOKE", "did not unchoke, the number of uploads (%d) " + "is more than or equal to the limit (%d)" , m_ses.num_uploads(), m_settings.get_int(settings_pack::unchoke_slots_limit)); } #endif @@ -1738,7 +1757,7 @@ namespace libtorrent m_became_uninterested = aux::time_now(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== NOT_INTERESTED"); + peer_log(peer_log_alert::incoming_message, "NOT_INTERESTED"); #endif if (m_peer_interested) m_counters.inc_stats_counter(counters::num_peers_up_interested, -1); @@ -1802,7 +1821,7 @@ namespace libtorrent if (!m_bitfield_received) incoming_have_none(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HAVE [ piece: %d ]", index); + peer_log(peer_log_alert::incoming_message, "HAVE", "piece: %d", index); #endif if (is_disconnecting()) return; @@ -1829,7 +1848,7 @@ namespace libtorrent if (index >= int(m_have_piece.size()) || index < 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ERROR: [ have-metadata have_piece: %d size: %d ]" + peer_log(peer_log_alert::info, "ERROR", "have-metadata have_piece: %d size: %d" , index, int(m_have_piece.size())); #endif disconnect(errors::invalid_have, op_bittorrent, 2); @@ -1853,7 +1872,8 @@ namespace libtorrent if (m_have_piece[index]) { #ifndef TORRENT_DISABLE_LOGGING - peer_log(" got redundant HAVE message for index: %d", index); + peer_log(peer_log_alert::incoming, "HAVE" + , "got redundant HAVE message for index: %d", index); #endif return; } @@ -1889,7 +1909,7 @@ namespace libtorrent if (is_seed()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); + peer_log(peer_log_alert::info, "SEED", "this is a seed. p: %p", m_peer_info); #endif TORRENT_ASSERT(m_have_piece.all_set()); @@ -1959,7 +1979,7 @@ namespace libtorrent if (is_disconnecting()) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== DONT_HAVE [ piece: %d ]", index); + peer_log(peer_log_alert::incoming_message, "DONT_HAVE", "piece: %d", index); #endif // if we got an invalid message, abort @@ -1972,7 +1992,8 @@ namespace libtorrent if (!m_have_piece[index]) { #ifndef TORRENT_DISABLE_LOGGING - peer_log(" got redundant DONT_HAVE message for index: %d", index); + peer_log(peer_log_alert::incoming, "DONT_HAVE" + , "got redundant DONT_HAVE message for index: %d", index); #endif return; } @@ -2021,7 +2042,8 @@ namespace libtorrent bitfield_str.resize(bits.size()); for (int i = 0; i < int(bits.size()); ++i) bitfield_str[i] = bits[i] ? '1' : '0'; - peer_log("<== BITFIELD [ %s ]", bitfield_str.c_str()); + peer_log(peer_log_alert::incoming_message, "BITFIELD" + , "%s", bitfield_str.c_str()); #endif // if we don't have the metedata, we cannot @@ -2055,7 +2077,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING if (m_num_pieces == int(bits.size())) - peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); + peer_log(peer_log_alert::info, "SEED", "this is a seed. p: %p", m_peer_info); #endif m_have_piece = bits; m_num_pieces = bits.count(); @@ -2074,7 +2096,7 @@ namespace libtorrent if (num_pieces == int(m_have_piece.size())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); + peer_log(peer_log_alert::info, "SEED", "this is a seed. p: %p", m_peer_info); #endif t->set_seed(m_peer_info, true); @@ -2138,7 +2160,7 @@ namespace libtorrent && can_disconnect(error_code(errors::upload_upload_connection, get_libtorrent_category()))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** the peer is upload-only and our torrent is also upload-only"); + peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and our torrent is also upload-only"); #endif disconnect(errors::upload_upload_connection, op_bittorrent); return true; @@ -2151,7 +2173,7 @@ namespace libtorrent && can_disconnect(error_code(errors::uninteresting_upload_peer, get_libtorrent_category()))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** the peer is upload-only and we're not interested in it"); + peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and we're not interested in it"); #endif disconnect(errors::uninteresting_upload_peer, op_bittorrent); return true; @@ -2188,8 +2210,8 @@ namespace libtorrent m_counters.inc_stats_counter(counters::piece_requests); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== REQUEST [ piece: %d s: %x l: %x ]" - , r.piece, r.start, r.length); + peer_log(peer_log_alert::incoming_message, "REQUEST" + , "piece: %d s: %x l: %x", r.piece, r.start, r.length); #endif if (t->super_seeding() @@ -2198,8 +2220,8 @@ namespace libtorrent m_counters.inc_stats_counter(counters::invalid_piece_requests); ++m_num_invalid_requests; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** INVALID_REQUEST [ piece not superseeded " - "i: %d t: %d n: %d h: %d ss1: %d ss2: %d ]" + peer_log(peer_log_alert::info, "INVALID_REQUEST", "piece not superseeded " + "i: %d t: %d n: %d h: %d ss1: %d ss2: %d" , m_peer_interested , int(t->torrent_file().piece_size(r.piece)) , t->torrent_file().num_pieces() @@ -2242,8 +2264,8 @@ namespace libtorrent // if we don't have valid metadata yet, // we shouldn't get a request #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** INVALID_REQUEST [ we don't have metadata yet ]"); - peer_log("==> REJECT_PIECE [ piece: %d | s: %x | l: %x ] no metadata" + peer_log(peer_log_alert::info, "INVALID_REQUEST", "we don't have metadata yet"); + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE", "piece: %d s: %x l: %x no metadata" , r.piece, r.start, r.length); #endif write_reject_request(r); @@ -2258,9 +2280,9 @@ namespace libtorrent // ignore requests if the client // is making too many of them. #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** INVALID_REQUEST [ incoming request queue full %d ]" + peer_log(peer_log_alert::info, "INVALID_REQUEST", "incoming request queue full %d" , int(m_requests.size())); - peer_log("==> REJECT_PIECE [ piece: %d | s: %x | l: %x ] too many requests" + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE", "piece: %d s: %x l: %x too many requests" , r.piece, r.start, r.length); #endif write_reject_request(r); @@ -2275,13 +2297,13 @@ namespace libtorrent if (!m_peer_interested) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** INVALID_REQUEST [ peer is not interested " - " t: %d n: %d h: %d block_limit: %d ]" + peer_log(peer_log_alert::info, "INVALID_REQUEST", "peer is not interested " + " t: %d n: %d h: %d block_limit: %d" , int(t->torrent_file().piece_size(r.piece)) , t->torrent_file().num_pieces() , t->has_piece_passed(r.piece) , t->block_size()); - peer_log("*** artificial INTERESTED message"); + peer_log(peer_log_alert::info, "INTERESTED", "artificial incoming INTERESTED message"); #endif if (t->alerts().should_post()) { @@ -2314,15 +2336,16 @@ namespace libtorrent m_counters.inc_stats_counter(counters::invalid_piece_requests); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** INVALID_REQUEST [ " - "i: %d t: %d n: %d h: %d block_limit: %d ]" + peer_log(peer_log_alert::info, "INVALID_REQUEST" + , "i: %d t: %d n: %d h: %d block_limit: %d" , m_peer_interested , int(t->torrent_file().piece_size(r.piece)) , t->torrent_file().num_pieces() , t->has_piece_passed(r.piece) , t->block_size()); - peer_log("==> REJECT_PIECE [ piece: %d | s: %d | l: %d ] invalid request" + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE" + , "piece: %d s: %d l: %d invalid request" , r.piece , r.start , r.length); #endif @@ -2354,7 +2377,7 @@ namespace libtorrent return; } #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> CHOKE"); + peer_log(peer_log_alert::outgoing_message, "CHOKE"); #endif write_choke(); } @@ -2379,8 +2402,8 @@ namespace libtorrent if (m_choked && fast_idx == -1) { #ifndef TORRENT_DISABLE_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" + peer_log(peer_log_alert::info, "REJECTING REQUEST", "peer choked and piece not in allowed fast set"); + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE", "piece: %d s: %d l: %d peer choked" , r.piece, r.start, r.length); #endif m_counters.inc_stats_counter(counters::choked_piece_requests); @@ -2471,7 +2494,7 @@ namespace libtorrent if (!verify_piece(r)) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** INVALID_PIECE [ piece: %d s: %d l: %d ]" + peer_log(peer_log_alert::info, "INVALID_PIECE", "piece: %d s: %d l: %d" , r.piece, r.start, r.length); #endif disconnect(errors::invalid_piece, op_bittorrent, 2); @@ -2518,7 +2541,8 @@ namespace libtorrent , m_remote, m_peer_id, int(b.block_index), int(b.piece_index)); } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** The block we just got was not in the request queue ***"); + peer_log(peer_log_alert::info, "INVALID_REQUEST" + , "The block we just got was not in the request queue"); #endif TORRENT_ASSERT(m_download_queue.front().block == b); m_download_queue.front().not_wanted = true; @@ -2580,7 +2604,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_down_disk); m_channel_state[download_channel] |= peer_info::bw_disk; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** exceeded disk buffer watermark"); + peer_log(peer_log_alert::info, "DISK", "exceeded disk buffer watermark"); #endif } @@ -2644,7 +2668,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_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 ]" + peer_log(peer_log_alert::incoming_message, "PIECE", "piece: %d s: %x l: %x ds: %d qs: %d q: %d hash: %s" , p.piece, p.start, p.length, statistics().download_rate() , int(m_desired_queue_size), int(m_download_queue.size()) , to_hex(h.final().to_string()).c_str()); @@ -2704,7 +2728,7 @@ namespace libtorrent , int(block_finished.piece_index)); } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** The block we just got was not in the request queue ***"); + peer_log(peer_log_alert::info, "INVALID_REQUEST", "The block we just got was not in the request queue"); #endif #if TORRENT_USE_ASSERTS TORRENT_ASSERT_VAL(m_received_in_piece == p.length, m_received_in_piece); @@ -2747,7 +2771,7 @@ namespace libtorrent m_request_time.add_sample(total_milliseconds(now - m_requested)); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** REQUEST-TIME (%d +- %d ms)" + peer_log(peer_log_alert::info, "REQUEST_TIME", "%d +- %d ms" , m_request_time.mean(), m_request_time.avg_deviation()); #endif @@ -2781,7 +2805,7 @@ namespace libtorrent t->debug_log("PIECE [%p] (%d ms) (%d)", this , int(total_milliseconds(clock_type::now() - m_unchoke_time)), t->num_have()); - peer_log("*** FILE ASYNC WRITE [ piece: %d | s: %x | l: %x ]" + peer_log(peer_log_alert::info, "FILE_ASYNC_WRITE", "piece: %d s: %x l: %x" , p.piece, p.start, p.length); #endif m_download_queue.erase(b); @@ -2817,7 +2841,7 @@ namespace libtorrent m_request_time.add_sample(total_milliseconds(now - m_requested)); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** REQUEST-TIME (%d +- %d ms)" + peer_log(peer_log_alert::info, "REQUEST_TIME", "%d +- %d ms" , m_request_time.mean(), m_request_time.avg_deviation()); #endif @@ -2915,7 +2939,7 @@ namespace libtorrent if (t) t->dec_refcount("async_write"); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** FILE ASYNC WRITE COMPLETE [ ret: %d | piece: %d | s: %x | l: %x | e: %s ]" + peer_log(peer_log_alert::info, "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 @@ -3023,7 +3047,8 @@ namespace libtorrent if (is_disconnecting()) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== CANCEL [ piece: %d | s: %x | l: %x ]", r.piece, r.start, r.length); + peer_log(peer_log_alert::incoming_message, "CANCEL" + , "piece: %d s: %x l: %x", r.piece, r.start, r.length); #endif std::vector::iterator i @@ -3038,7 +3063,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_up_requests, -1); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REJECT_PIECE [ piece: %d s: %x l: %x ] cancelled" + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE", "piece: %d s: %x l: %x cancelled" , r.piece , r.start , r.length); #endif write_reject_request(r); @@ -3051,7 +3076,7 @@ namespace libtorrent // disk and once the disk job comes back, discard it if it has // been cancelled. Maybe even be able to cancel disk jobs? #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** GOT CANCEL NOT IN THE QUEUE"); + peer_log(peer_log_alert::info, "INVALID_CANCEL", "got cancel not in the queue"); #endif } } @@ -3066,7 +3091,7 @@ namespace libtorrent INVARIANT_CHECK; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== DHT_PORT [ p: %d ]", listen_port); + peer_log(peer_log_alert::incoming_message, "DHT_PORT", "p: %d", listen_port); #endif #ifndef TORRENT_DISABLE_DHT m_ses.add_dht_node(udp::endpoint( @@ -3091,7 +3116,7 @@ namespace libtorrent TORRENT_ASSERT(m_in_constructor == false); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HAVE_ALL"); + peer_log(peer_log_alert::incoming_message, "HAVE_ALL"); #endif #ifndef TORRENT_DISABLE_EXTENSIONS @@ -3109,7 +3134,7 @@ namespace libtorrent m_have_all = true; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** THIS IS A SEED [ p: %p ]", m_peer_info); + peer_log(peer_log_alert::info, "SEED", "this is a seed p: %p", m_peer_info); #endif t->set_seed(m_peer_info, true); @@ -3167,7 +3192,7 @@ namespace libtorrent INVARIANT_CHECK; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== HAVE_NONE"); + peer_log(peer_log_alert::incoming_message, "HAVE_NONE"); #endif boost::shared_ptr t = m_torrent.lock(); @@ -3223,7 +3248,7 @@ namespace libtorrent t->debug_log("ALLOW FAST [%p] (%d ms)", this, int(total_milliseconds(now - m_connect_time))); if (m_peer_choked) m_unchoke_time = now; } - peer_log("<== ALLOWED_FAST [ %d ]", index); + peer_log(peer_log_alert::incoming_message, "ALLOWED_FAST", "%d", index); #endif #ifndef TORRENT_DISABLE_EXTENSIONS @@ -3234,10 +3259,12 @@ namespace libtorrent } #endif if (is_disconnecting()) return; + if (index < 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== INVALID_ALLOWED_FAST [ %d ]", index); + peer_log(peer_log_alert::incoming_message, "INVALID_ALLOWED_FAST" + , "%d", index); #endif return; } @@ -3247,8 +3274,8 @@ namespace libtorrent if (index >= int(m_have_piece.size())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== INVALID_ALLOWED_FAST [ %d | s: %d ]" - , index, int(m_have_piece.size())); + peer_log(peer_log_alert::incoming_message, "INVALID_ALLOWED_FAST" + , "%d s: %d", index, int(m_have_piece.size())); #endif return; } @@ -3350,7 +3377,8 @@ namespace libtorrent if (t->upload_mode()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** PIECE_PICKER [ not_picking: %d,%d upload_mode ]" + peer_log(peer_log_alert::info, "PIECE_PICKER" + , "not_picking: %d,%d upload_mode" , block.piece_index, block.block_index); #endif return false; @@ -3358,7 +3386,8 @@ namespace libtorrent if (m_disconnecting) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** PIECE_PICKER [ not_picking: %d,%d disconnecting ]" + peer_log(peer_log_alert::info, "PIECE_PICKER" + , "not_picking: %d,%d disconnecting" , block.piece_index, block.block_index); #endif return false; @@ -3378,7 +3407,8 @@ namespace libtorrent if (i->busy) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** PIECE_PICKER [ not_picking: %d,%d already in download queue & busy ]" + peer_log(peer_log_alert::info, "PIECE_PICKER" + , "not_picking: %d,%d already in download queue & busy" , block.piece_index, block.block_index); #endif return false; @@ -3391,7 +3421,8 @@ namespace libtorrent if (i->busy) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** PIECE_PICKER [ not_picking: %d,%d already in request queue & busy ]" + peer_log(peer_log_alert::info, "PIECE_PICKER" + , "not_picking: %d,%d already in request queue & busy" , block.piece_index, block.block_index); #endif return false; @@ -3403,7 +3434,8 @@ namespace libtorrent , picker_options())) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** PIECE_PICKER [ not_picking: %d,%d failed to mark_as_downloading ]" + peer_log(peer_log_alert::info, "PIECE_PICKER" + , "not_picking: %d,%d failed to mark_as_downloading" , block.piece_index, block.block_index); #endif return false; @@ -3442,7 +3474,7 @@ namespace libtorrent TORRENT_ASSERT(t->valid_metadata()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** CANCEL ALL REQUESTS"); + peer_log(peer_log_alert::info, "CANCEL_ALL_REQUESTS"); #endif while (!m_request_queue.empty()) @@ -3478,7 +3510,8 @@ namespace libtorrent r.length = block_size; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> CANCEL [ piece: %d s: %d l: %d b: %d ]" + peer_log(peer_log_alert::outgoing_message, "CANCEL" + , "piece: %d s: %d l: %d b: %d" , b.piece_index, block_offset, block_size, b.block_index); #endif write_cancel(r); @@ -3546,7 +3579,8 @@ namespace libtorrent r.length = block_size; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> CANCEL [ piece: %d s: %d l: %d b: %d ]" + peer_log(peer_log_alert::outgoing_message, "CANCEL" + , "piece: %d s: %d l: %d b: %d" , block.piece_index, block_offset, block_size, block.block_index); #endif write_cancel(r); @@ -3571,7 +3605,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> CHOKE"); + peer_log(peer_log_alert::outgoing_message, "CHOKE"); #endif write_choke(); m_counters.inc_stats_counter(counters::num_peers_up_unchoked_all, -1); @@ -3596,7 +3630,8 @@ namespace libtorrent peer_request const& r = *i; m_counters.inc_stats_counter(counters::choked_piece_requests); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REJECT_PIECE [ piece: %d s: %d l: %d ] choking" + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE" + , "piece: %d s: %d l: %d choking" , r.piece , r.start , r.length); #endif write_reject_request(r); @@ -3645,7 +3680,7 @@ namespace libtorrent m_uploaded_at_last_unchoke = m_statistics.total_payload_upload(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> UNCHOKE"); + peer_log(peer_log_alert::outgoing_message, "UNCHOKE"); #endif return true; } @@ -3661,7 +3696,7 @@ namespace libtorrent write_interested(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> INTERESTED"); + peer_log(peer_log_alert::outgoing_message, "INTERESTED"); #endif } @@ -3691,7 +3726,7 @@ namespace libtorrent m_became_uninteresting = aux::time_now(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> NOT_INTERESTED"); + peer_log(peer_log_alert::outgoing_message, "NOT_INTERESTED"); #endif } @@ -3742,7 +3777,7 @@ namespace libtorrent if (t->graceful_pause() && m_outstanding_bytes == 0) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** GRACEFUL PAUSE [ NO MORE DOWNLOAD ]"); + peer_log(peer_log_alert::info, "GRACEFUL_PAUSE", "NO MORE DOWNLOAD"); #endif disconnect(errors::torrent_paused, op_bittorrent); return; @@ -3831,7 +3866,8 @@ namespace libtorrent if (m_queued_time_critical) --m_queued_time_critical; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** MERGING REQUEST [ piece: %d block: %d ]" + peer_log(peer_log_alert::info, "MERGING_REQUEST" + , "piece: %d block: %d" , block.block.piece_index, block.block.block_index); #endif @@ -3868,8 +3904,8 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REQUEST [ piece: %d | s: %x | l: %x | ds: %d B/s | " - "dqs: %d rqs: %d blk: %s ]" + peer_log(peer_log_alert::outgoing_message, "REQUEST" + , "piece: %d s: %x l: %x ds: %dB/s dqs: %d rqs: %d blk: %s" , r.piece, r.start, r.length, statistics().download_rate() , int(m_desired_queue_size), int(m_download_queue.size()) , m_request_large_blocks?"large":"single"); @@ -3897,10 +3933,11 @@ namespace libtorrent TORRENT_ASSERT(e); #ifndef TORRENT_DISABLE_LOGGING - peer_log("CONNECTION FAILED: %s", print_endpoint(m_remote).c_str()); + peer_log(peer_log_alert::info, "CONNECTION FAILED" + , "%s", print_endpoint(m_remote).c_str()); #endif #ifndef TORRENT_DISABLE_LOGGING - m_ses.session_log(" CONNECTION FAILED: %s", print_endpoint(m_remote).c_str()); + m_ses.session_log("CONNECTION FAILED: %s", print_endpoint(m_remote).c_str()); #endif m_counters.inc_stats_counter(counters::connect_timeouts); @@ -3972,7 +4009,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING if (close_reason != 0) { - peer_log("*** CLOSE REASON [ %d ]", int(close_reason)); + peer_log(peer_log_alert::info, "CLOSE_REASON", "%d", int(close_reason)); } #endif @@ -3985,13 +4022,16 @@ namespace libtorrent switch (error) { case 0: - peer_log("*** CONNECTION CLOSED [op: %d] %s", op, ec.message().c_str()); + peer_log(peer_log_alert::info, "CONNECTION_CLOSED", "op: %d error: %s" + , op, ec.message().c_str()); break; case 1: - peer_log("*** CONNECTION FAILED [op: %d] %s", op, ec.message().c_str()); + peer_log(peer_log_alert::info, "CONNECTION_FAILED", "op: %d error: %s" + , op, ec.message().c_str()); break; case 2: - peer_log("*** PEER ERROR [op: %d] %s", op, ec.message().c_str()); + peer_log(peer_log_alert::info, "PEER_ERROR" ,"op: %d error: %s" + , op, ec.message().c_str()); break; } #endif @@ -4451,7 +4491,7 @@ namespace libtorrent if (exceeded) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** exceeded disk buffer watermark"); + peer_log(peer_log_alert::info, "DISK", "exceeded disk buffer watermark"); #endif if ((m_channel_state[download_channel] & peer_info::bw_disk) == 0) m_counters.inc_stats_counter(counters::num_peers_down_disk); @@ -4471,7 +4511,7 @@ namespace libtorrent m_superseed_piece[1] = -1; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ending super seed mode"); + peer_log(peer_log_alert::info, "SUPER_SEEDING", "ending"); #endif boost::shared_ptr t = m_torrent.lock(); assert(t); @@ -4487,7 +4527,8 @@ namespace libtorrent assert(!has_piece(new_piece)); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> HAVE [ piece: %d ] (super seed)", new_piece); + peer_log(peer_log_alert::outgoing_message, "HAVE", "piece: %d (super seed)" + , new_piece); #endif write_have(new_piece); @@ -4505,7 +4546,7 @@ namespace libtorrent void peer_connection::max_out_request_queue(int s) { #ifdef TORRENT_VERBOSE_LOGGING - peer_log("*** MAX OUT QUEUE SIZE [ %d -> %d ]" + peer_log(peer_log_alert::info, "MAX_OUT_QUEUE_SIZE", "%d -> %d" , m_max_out_request_queue, s); #endif m_max_out_request_queue = s; @@ -4548,7 +4589,8 @@ namespace libtorrent m_desired_queue_size = min_request_queue; #ifdef TORRENT_VERBOSE_LOGGING - peer_log("*** UPDATE_QUEUE_SIZE [ dqs: %d max: %d dl: %d qt: %d snubbed: %d ]" + peer_log(peer_log_alert::info, "UPDATE_QUEUE_SIZE" + , "dqs: %d max: %d dl: %d qt: %d snubbed: %d" , m_desired_queue_size, m_max_out_request_queue , download_rate, queue_time, int(m_snubbed)); #endif @@ -4665,7 +4707,8 @@ namespace libtorrent && can_disconnect(error_code(errors::timed_out, get_libtorrent_category()))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** CONNECT FAILED [ waited %d seconds ] ***", int(total_seconds(d))); + peer_log(peer_log_alert::info, "CONNECT_FAILED", "waited %d seconds" + , int(total_seconds(d))); #endif connect_failed(errors::timed_out); return; @@ -4685,7 +4728,8 @@ namespace libtorrent && can_disconnect(error_code(errors::timed_out_inactivity, get_libtorrent_category()))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** LAST ACTIVITY [ %d seconds ago ] ***", int(total_seconds(d))); + peer_log(peer_log_alert::info, "LAST_ACTIVITY", "%d seconds ago" + , int(total_seconds(d))); #endif disconnect(errors::timed_out_inactivity, op_bittorrent); return; @@ -4698,7 +4742,8 @@ namespace libtorrent && d > seconds(m_settings.get_int(settings_pack::handshake_timeout))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** NO HANDSHAKE [ waited %d seconds ] ***", int(total_seconds(d))); + peer_log(peer_log_alert::info, "NO_HANDSHAKE", "waited %d seconds" + , int(total_seconds(d))); #endif disconnect(errors::timed_out_no_handshake, op_bittorrent); return; @@ -4719,7 +4764,8 @@ namespace libtorrent && can_disconnect(error_code(errors::timed_out_no_request, get_libtorrent_category()))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** NO REQUEST [ waited %d seconds ] ***", int(total_seconds(d))); + peer_log(peer_log_alert::info, "NO_REQUEST", "waited %d seconds" + , int(total_seconds(d))); #endif disconnect(errors::timed_out_no_request, op_bittorrent); return; @@ -4748,7 +4794,7 @@ namespace libtorrent && can_disconnect(error_code(errors::timed_out_no_interest))) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** MUTUAL NO INTEREST [ t1: %d t2: %d ]" + peer_log(peer_log_alert::info, "MUTUAL_NO_INTEREST", "t1: %d t2: %d" , int(total_seconds(d1)), int(total_seconds(d2))); #endif disconnect(errors::timed_out_no_interest, op_bittorrent); @@ -4800,7 +4846,8 @@ namespace libtorrent // in this case we'll clear our download queue and // re-request the blocks. #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** PIECE_REQUEST TIMED OUT [ %d time: %d to: %d ]" + peer_log(peer_log_alert::info, "PIECE_REQUEST_TIMED_OUT" + , "%d time: %d to: %d" , int(m_download_queue.size()), int(total_seconds(now - m_last_piece)) , piece_timeout); #endif @@ -4977,7 +5024,8 @@ namespace libtorrent } #ifdef TORRENT_VERBOSE_LOGGING - peer_log(">>> SEND_BUFFER_WATERMARK [ %d max: %d min: %d factor: %d ]" + peer_log(peer_log_alert::outgoing, "SEND_BUFFER_WATERMARK" + , "%d max: %d min: %d factor: %d" , buffer_size_watermark, m_ses.settings().send_buffer_watermark , m_ses.settings().send_buffer_low_watermark, m_ses.settings().send_buffer_watermark_factor); #endif @@ -5001,7 +5049,8 @@ namespace libtorrent if (t->is_deleted()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REJECT_PIECE [ piece: %d s: %x l: %x ] torrent deleted" + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE" + , "piece: %d s: %x l: %x torrent deleted" , r.piece , r.start , r.length); #endif write_reject_request(r); @@ -5020,7 +5069,8 @@ namespace libtorrent ++m_outstanding_piece_verification; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SEED-MODE FILE ASYNC HASH [ piece: %d ]", r.piece); + peer_log(peer_log_alert::info, "SEED_MODE_FILE_ASYNC_HASH" + , "piece: %d", r.piece); #endif // this means we're in seed mode and we haven't yet // verified this piece (r.piece) @@ -5044,7 +5094,8 @@ namespace libtorrent // we will reject this request if (t->is_predictive_piece(r.piece)) continue; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REJECT_PIECE [ piece: %d s: %x l: %x ] piece not passed hash check" + peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE" + , "piece: %d s: %x l: %x piece not passed hash check" , r.piece , r.start , r.length); #endif write_reject_request(r); @@ -5052,8 +5103,8 @@ namespace libtorrent else { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** FILE ASYNC READ [ piece: %d | s: %x | l: %x ]" - , r.piece, r.start, r.length); + peer_log(peer_log_alert::info, "FILE_ASYNC_READ" + , "piece: %d s: %x l: %x", r.piece, r.start, r.length); #endif m_reading_bytes += r.length; sent_a_piece = true; @@ -5107,7 +5158,8 @@ namespace libtorrent && sha1_hash(j->d.piece_hash) != t->torrent_file().hash_for_piece(j->piece)) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SEED-MODE FILE HASH [ piece: %d failed ]", j->piece); + peer_log(peer_log_alert::info, "SEED_MODE_FILE_HASH" + , "piece: %d failed", j->piece); #endif t->leave_seed_mode(false); @@ -5118,7 +5170,8 @@ namespace libtorrent if (t->seed_mode()) t->verified(j->piece); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SEED-MODE FILE HASH [ piece: %d passed ]", j->piece); + peer_log(peer_log_alert::info, "SEED_MODE_FILE_HASH" + , "piece: %d passed", j->piece); #endif if (t) { @@ -5143,8 +5196,8 @@ namespace libtorrent int disk_rtt = int(total_microseconds(clock_type::now() - issue_time)); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** FILE ASYNC READ COMPLETE [ ret: %d | piece: %d | s: %x | l: %x" - " | b: %p | c: %s | e: %s | rtt: %d us ]" + peer_log(peer_log_alert::info, "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 , (j->flags & disk_io_job::cache_hit ? "cache hit" : "cache miss") , j->error.ec.message().c_str(), disk_rtt); @@ -5209,8 +5262,8 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> PIECE [ piece: %d s: %x l: %x ]" - , r.piece, r.start, r.length); + peer_log(peer_log_alert::outgoing_message + , "PIECE", "piece: %d s: %x l: %x", r.piece, r.start, r.length); #endif m_counters.blend_stats_counter(counters::request_latency, disk_rtt, 5); @@ -5230,8 +5283,9 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("%s ASSIGN BANDWIDHT [ bytes: %d ]" - , channel == upload_channel ? ">>>" : "<<<", amount); + peer_log(channel == upload_channel + ? peer_log_alert::outgoing : peer_log_alert::incoming + , "ASSIGN BANDWIDHT", "bytes: %d", amount); #endif TORRENT_ASSERT(amount > 0 || is_disconnecting()); @@ -5323,10 +5377,12 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_LOGGING - peer_log("%s REQUEST_BANDWIDTH [ bytes: %d quota: %d wanted_transfer: %d " - "prio: %d num_channels: %d ]" - , channel == download_channel ? "<<<" : ">>>", bytes - , m_quota[channel], wanted_transfer(channel), priority, c); + peer_log( + channel == download_channel ? peer_log_alert::incoming + : peer_log_alert::outgoing, + "REQUEST_BANDWIDTH", "bytes: %d quota: %d wanted_transfer: %d " + "prio: %d num_channels: %d", bytes, m_quota[channel] + , wanted_transfer(channel), priority, c); #endif TORRENT_ASSERT((m_channel_state[channel] & peer_info::bw_limit) == 0); @@ -5336,12 +5392,17 @@ namespace libtorrent int ret = manager->request_bandwidth(self() , bytes, priority, channels, c); - if (ret == 0) m_channel_state[channel] |= peer_info::bw_limit; + if (ret == 0) + { + m_channel_state[channel] |= peer_info::bw_limit; + } else { #ifndef TORRENT_DISABLE_LOGGING - peer_log("%s ASSIGN BANDWIDTH [ bytes: %d ]" - , channel == download_channel ? "<<<" : ">>>", ret); + peer_log( + channel == download_channel ? peer_log_alert::incoming + : peer_log_alert::outgoing + , "ASSIGN_BANDWIDTH", "bytes: %d", ret); #endif m_quota[channel] += ret; } @@ -5401,7 +5462,8 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_up_disk); m_channel_state[upload_channel] |= peer_info::bw_disk; #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> waiting for disk [outstanding: %d]", m_reading_bytes); + peer_log(peer_log_alert::outgoing, "WAITING_FOR_DISK", "outstanding: %d" + , m_reading_bytes); #endif if (!m_connecting @@ -5439,16 +5501,16 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING if (m_send_buffer.empty()) { - peer_log(">>> SEND BUFFER DEPLETED [" - " quota: %d buf: %d connecting: %s disconnecting: %s pending_disk: %d ]" + peer_log(peer_log_alert::outgoing, "SEND_BUFFER_DEPLETED" + , "quota: %d buf: %d connecting: %s disconnecting: %s pending_disk: %d" , m_quota[upload_channel] , int(m_send_buffer.size()), m_connecting?"yes":"no" , m_disconnecting?"yes":"no", m_reading_bytes); } else { - peer_log(">>> CANNOT WRITE [" - " quota: %d buf: %d connecting: %s disconnecting: %s pending_disk: %d ]" + peer_log(peer_log_alert::outgoing, "CANNOT_WRITE" + , "quota: %d buf: %d connecting: %s disconnecting: %s pending_disk: %d" , m_quota[upload_channel] , int(m_send_buffer.size()), m_connecting?"yes":"no" , m_disconnecting?"yes":"no", m_reading_bytes); @@ -5469,14 +5531,15 @@ namespace libtorrent if (m_corked) { #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> CORKED WRITE [ bytes: %d ]", amount_to_send); + peer_log(peer_log_alert::outgoing, "CORKED_WRITE", "bytes: %d" + , amount_to_send); #endif return; } TORRENT_ASSERT((m_channel_state[upload_channel] & peer_info::bw_network) == 0); #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> ASYNC_WRITE [ bytes: %d ]", amount_to_send); + peer_log(peer_log_alert::outgoing, "ASYNC_WRITE", "bytes: %d", amount_to_send); #endif std::vector const& vec = m_send_buffer.build_iovec(amount_to_send); #if defined TORRENT_ASIO_DEBUGGING @@ -5513,7 +5576,7 @@ namespace libtorrent boost::shared_ptr me(self()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** dropped below disk buffer watermark"); + peer_log(peer_log_alert::info, "DISK", "dropped below disk buffer watermark"); #endif m_counters.inc_stats_counter(counters::num_peers_down_disk, -1); m_channel_state[download_channel] &= ~peer_info::bw_disk; @@ -5556,9 +5619,9 @@ namespace libtorrent if (!can_read()) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< CANNOT READ [ quota: %d " + peer_log(peer_log_alert::incoming, "CANNOT_READ", "quota: %d " "can-write-to-disk: %s queue-limit: %d disconnecting: %s " - " connecting: %s ]" + " connecting: %s" , m_quota[download_channel] , ((m_channel_state[download_channel] & peer_info::bw_disk)?"no":"yes") , m_settings.get_int(settings_pack::max_queued_disk_bytes) @@ -5611,7 +5674,7 @@ namespace libtorrent TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0); m_channel_state[download_channel] |= peer_info::bw_network; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< ASYNC_READ [ ]"); + peer_log(peer_log_alert::incoming, "ASYNC_READ"); #endif #if defined TORRENT_ASIO_DEBUGGING @@ -5641,7 +5704,8 @@ namespace libtorrent TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0); m_channel_state[download_channel] |= peer_info::bw_network; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< ASYNC_READ [ max: %d bytes ]", max_receive); + peer_log(peer_log_alert::incoming, "ASYNC_READ" + , "max: %d bytes", max_receive); #endif // utp sockets aren't thread safe... @@ -5701,7 +5765,7 @@ namespace libtorrent if (ret == 0 && !ec) ec = asio::error::eof; #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]" + peer_log(peer_log_alert::incoming, "SYNC_READ", "max: %d ret: %d e: %s" , max_receive, int(ret), ec ? ec.message().c_str() : ""); #endif return ret; @@ -5725,12 +5789,22 @@ namespace libtorrent , userdata, ref); } - namespace { - void session_free_buffer(char* buffer, void* userdata, block_cache_reference) + boost::optional + peer_connection::downloading_piece_progress() const { - aux::session_interface* ses = (aux::session_interface*)userdata; - ses->free_buffer(buffer); +#ifndef TORRENT_DISABLE_LOGGING + peer_log(peer_log_alert::info, "ERROR" + , "downloading_piece_progress() dispatched to the base class!"); +#endif + return boost::optional(); } + + namespace { + void session_free_buffer(char* buffer, void* userdata, block_cache_reference) + { + aux::session_interface* ses = (aux::session_interface*)userdata; + ses->free_buffer(buffer); + } } void peer_connection::send_buffer(char const* buf, int size, int flags) @@ -5803,7 +5877,7 @@ namespace libtorrent if (error) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ERROR [ in peer_connection::on_receive_data_nb error: %s ]" + peer_log(peer_log_alert::info, "ERROR", "in peer_connection::on_receive_data_nb error: %s" , error.message().c_str()); #endif on_receive(error, bytes_transferred); @@ -5820,7 +5894,8 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< READ_AVAILABLE [ bytes: %d ]", int(buffer_size)); + peer_log(peer_log_alert::incoming, "READ_AVAILABLE" + , "bytes: %d", int(buffer_size)); #endif // at this point the ioctl told us the socket doesn't have any @@ -5927,7 +6002,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" + peer_log(peer_log_alert::incoming, "ON_RECEIVE_DATA", "bytes: %d error: %s" , int(bytes_transferred), error.message().c_str()); #endif @@ -5950,7 +6025,8 @@ namespace libtorrent if (error) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ERROR [ in peer_connection::on_receive_data_impl error: %s ]" + peer_log(peer_log_alert::info, "ERROR" + , "in peer_connection::on_receive_data_impl error: %s" , error.message().c_str()); #endif trancieve_ip_packet(bytes_in_loop, m_remote.address().is_v6()); @@ -5965,7 +6041,8 @@ namespace libtorrent m_ses.received_buffer(bytes_transferred); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" + peer_log(peer_log_alert::incoming, "ON_RECEIVE_DATA" + , "bytes: %d error: %s" , int(bytes_transferred), error.message().c_str()); #endif @@ -5976,7 +6053,8 @@ namespace libtorrent do { #ifndef TORRENT_DISABLE_LOGGING - peer_log("<<< read %d bytes", int(bytes_transferred)); + peer_log(peer_log_alert::incoming, "READ" + , "%d bytes", int(bytes_transferred)); #endif // correct the dl quota usage, if not all of the buffer was actually read TORRENT_ASSERT(int(bytes_transferred) <= m_quota[download_channel]); @@ -6106,7 +6184,7 @@ namespace libtorrent const_cast(this)->m_channel_state[download_channel] |= peer_info::bw_disk; #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** exceeded disk buffer watermark"); + peer_log(peer_log_alert::info, "DISK", "exceeded disk buffer watermark"); #endif return false; } @@ -6210,14 +6288,15 @@ namespace libtorrent TORRENT_ASSERT(m_socket); #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> COMPLETED [ ep: %s ]", print_endpoint(m_remote).c_str()); + peer_log(peer_log_alert::outgoing, "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); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SET NON-BLOCKING"); + peer_log(peer_log_alert::info, "SET_NON_BLOCKING"); #endif m_socket->io_control(ioc, ec); if (ec) @@ -6240,7 +6319,8 @@ namespace libtorrent error_code ec; m_socket->set_option(type_of_service(m_settings.get_int(settings_pack::peer_tos)), ec); #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> SET_TOS[ tos: %d e: %s ]", m_settings.get_int(settings_pack::peer_tos), ec.message().c_str()); + peer_log(peer_log_alert::outgoing, "SET_TOS", "tos: %d e: %s" + , m_settings.get_int(settings_pack::peer_tos), ec.message().c_str()); #endif } #if TORRENT_USE_IPV6 && defined IPV6_TCLASS @@ -6284,7 +6364,7 @@ namespace libtorrent m_ses.deferred_submit_jobs(); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** ON_SEND_DATA [ bytes: %d error: %s ]" + peer_log(peer_log_alert::info, "ON_SEND_DATA", "bytes: %d error: %s" , int(bytes_transferred), error.message().c_str()); #endif @@ -6326,13 +6406,15 @@ namespace libtorrent m_send_barrier -= bytes_transferred; #ifndef TORRENT_DISABLE_LOGGING - peer_log(">>> wrote %d bytes", int(bytes_transferred)); + peer_log(peer_log_alert::outgoing, "WROTE" + , "%d bytes", int(bytes_transferred)); #endif if (error) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("**ERROR**: %s [in peer_connection::on_send_data]", error.message().c_str()); + peer_log(peer_log_alert::info, "ERROR" + , "%s in peer_connection::on_send_data", error.message().c_str()); #endif disconnect(error, op_sock_write); return; @@ -6630,6 +6712,14 @@ namespace libtorrent } #endif + void peer_connection::set_holepunch_mode() + { + m_holepunch_mode = true; +#ifndef TORRENT_DISABLE_LOGGING + peer_log(peer_log_alert::info, "HOLEPUNCH_MODE", "[ on ]"); +#endif + } + void peer_connection::keep_alive() { TORRENT_ASSERT(is_single_thread()); @@ -6649,7 +6739,7 @@ namespace libtorrent if (m_channel_state[upload_channel] & peer_info::bw_network) return; #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> KEEPALIVE"); + peer_log(peer_log_alert::outgoing_message, "KEEPALIVE"); #endif m_last_sent = aux::time_now(); diff --git a/src/peer_list.cpp b/src/peer_list.cpp index f0539a640..2ea79cf46 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -617,7 +617,7 @@ namespace libtorrent TORRENT_ASSERT(i->address() == c.remote().address()); #ifndef TORRENT_DISABLE_LOGGING - c.peer_log("*** DUPLICATE PEER [ this: \"%s\" that: \"%s\" ]" + c.peer_log(peer_log_alert::info, "DUPLICATE PEER [ this: \"%s\" that: \"%s\" ]" , print_address(c.remote().address()).c_str() , print_address(i->address()).c_str()); #endif @@ -675,8 +675,10 @@ namespace libtorrent if (our_port < other_port) { #ifndef TORRENT_DISABLE_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); + c.peer_log(peer_log_alert::info, "DUPLICATE_PEER_RESOLUTION" + , "\"%d\" < \"%d\"", our_port, other_port); + i->connection->peer_log(peer_log_alert::info, "DUPLICATE_PEER_RESOLUTION" + , "\"%d\" < \"%d\"", our_port, other_port); #endif // we should keep our outgoing connection @@ -693,8 +695,10 @@ namespace libtorrent else { #ifndef TORRENT_DISABLE_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); + c.peer_log(peer_log_alert::info, "DUPLICATE_PEER_RESOLUTION" + , "\"%d\" >= \"%d\"", our_port, other_port); + i->connection->peer_log(peer_log_alert::info, "DUPLICATE_PEER_RESOLUTION" + , "\"%d\" >= \"%d\"", our_port, other_port); #endif // they should keep their outgoing connection if (outgoing1) diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index 937b1da51..5c7fecca2 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -88,7 +88,8 @@ namespace libtorrent - (int)c.request_queue().size(); #ifndef TORRENT_DISABLE_LOGGING - c.peer_log("*** PIECE_PICKER [ dlq: %d rqq: %d target: %d req: %d engame: %d ]" + c.peer_log(peer_log_alert::info, "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()); #endif @@ -160,7 +161,8 @@ namespace libtorrent , ses.stats_counters()); #ifndef TORRENT_DISABLE_LOGGING - c.peer_log("*** PIECE_PICKER [ prefer_contiguous: %d picked: %d ]" + c.peer_log(peer_log_alert::info, "PIECE_PICKER" + , "prefer_contiguous: %d picked: %d" , prefer_contiguous_blocks, int(interesting_pieces.size())); #endif @@ -225,7 +227,8 @@ namespace libtorrent if (j != dq.end()) TORRENT_ASSERT(j->timed_out || j->not_wanted); #endif #ifndef TORRENT_DISABLE_LOGGING - c.peer_log("*** PIECE_PICKER [ not_picking: %d,%d already in queue ]" + c.peer_log(peer_log_alert::info, "PIECE_PICKER" + , "not_picking: %d,%d already in queue" , i->piece_index, i->block_index); #endif continue; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index eb5804c28..aff2874c9 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3476,7 +3476,7 @@ retry: --type_limit; #ifndef TORRENT_DISABLE_LOGGING if (!t->allows_peers()) - t->log_to_all_peers("AUTO MANAGER STARTING TORRENT"); + t->log_to_all_peers("auto manager starting torrent"); #endif t->set_allow_peers(true); } @@ -3484,7 +3484,7 @@ retry: { #ifndef TORRENT_DISABLE_LOGGING if (t->allows_peers()) - t->log_to_all_peers("AUTO MANAGER PAUSING TORRENT"); + t->log_to_all_peers("auto manager pausing torrent"); #endif // use graceful pause for auto-managed torrents t->set_allow_peers(false, true); diff --git a/src/torrent.cpp b/src/torrent.cpp index d781e1a98..39e357eaf 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4264,7 +4264,7 @@ namespace libtorrent , end(m_connections.end()); p != end; ++p) { #ifndef TORRENT_DISABLE_LOGGING - (*p)->peer_log(">>> PREDICTIVE_HAVE [ piece: %d expected in %d ms]" + (*p)->peer_log(peer_log_alert::outgoing, "PREDICTIVE_HAVE", "piece: %d expected in %d ms" , index, milliseconds); #endif (*p)->announce_piece(index); @@ -4410,7 +4410,7 @@ namespace libtorrent , print_endpoint(p->ip()).c_str()); #endif #ifndef TORRENT_DISABLE_LOGGING - peer->peer_log("*** BANNING PEER: Too many corrupt pieces"); + peer->peer_log(peer_log_alert::info, "BANNING_PEER", "Too many corrupt pieces"); #endif peer->disconnect(errors::too_many_corrupt_pieces, op_bittorrent); } @@ -4768,7 +4768,7 @@ namespace libtorrent m_inactivity_timer.cancel(ec); #ifndef TORRENT_DISABLE_LOGGING - log_to_all_peers("ABORTING TORRENT"); + log_to_all_peers("aborting"); #endif // disconnect all peers and close all @@ -8054,7 +8054,7 @@ namespace libtorrent if (p->upload_only()) { #ifndef TORRENT_DISABLE_LOGGING - p->peer_log("*** SEED, CLOSING CONNECTION"); + p->peer_log(peer_log_alert::info, "SEED", "CLOSING CONNECTION"); #endif seeds.push_back(p); } @@ -8295,7 +8295,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - pc->peer_log("*** ON_FILES_CHECKED"); + pc->peer_log(peer_log_alert::info, "ON_FILES_CHECKED"); #endif if (pc->is_interesting() && !pc->has_peer_choked()) { @@ -8781,7 +8781,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); #ifndef TORRENT_DISABLE_LOGGING - log_to_all_peers("DELETING FILES IN TORRENT"); + log_to_all_peers("deleting files"); #endif disconnect_all(errors::torrent_removed, op_bittorrent); @@ -8857,7 +8857,7 @@ namespace libtorrent if (ec) { char buf[1024]; - snprintf(buf, sizeof(buf), "TORRENT ERROR: %s: %s", ec.message().c_str() + snprintf(buf, sizeof(buf), "error %s: %s", ec.message().c_str() , resolve_filename(error_file).c_str()); log_to_all_peers(buf); } @@ -9199,7 +9199,7 @@ namespace libtorrent update_want_scrape(); #ifndef TORRENT_DISABLE_LOGGING - log_to_all_peers("PAUSING TORRENT"); + log_to_all_peers("pausing"); #endif // when checking and being paused in graceful pause mode, we @@ -9256,7 +9256,7 @@ namespace libtorrent if (p->outstanding_bytes() > 0) { #ifndef TORRENT_DISABLE_LOGGING - p->peer_log("*** CHOKING PEER: torrent graceful paused"); + p->peer_log(peer_log_alert::info, "CHOKING_PEER", "torrent graceful paused"); #endif // remove any un-sent requests from the queue p->clear_request_queue(); @@ -9266,7 +9266,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING - p->peer_log("*** CLOSING CONNECTION: torrent_paused"); + p->peer_log(peer_log_alert::info, "CLOSING_CONNECTION", "torrent_paused"); #endif p->disconnect(errors::torrent_paused, op_bittorrent); i = j; @@ -9291,13 +9291,11 @@ namespace libtorrent void torrent::log_to_all_peers(char const* message) { TORRENT_ASSERT(is_single_thread()); -#ifndef TORRENT_DISABLE_LOGGING for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i) { - (*i)->peer_log("*** %s", message); + (*i)->peer_log(peer_log_alert::info, "TORRENT", "%s", message); } -#endif debug_log("%s", message); } @@ -9748,7 +9746,7 @@ namespace libtorrent TORRENT_DECLARE_DUMMY(std::exception, e); (void)e; #ifndef TORRENT_DISABLE_LOGGING - p->peer_log("*** ERROR %s", e.what()); + p->peer_log(peer_log_alert::info, "ERROR", "%s", e.what()); #endif p->disconnect(errors::no_error, op_bittorrent, 1); } diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 91a808eb3..a8ae389bc 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -264,7 +264,8 @@ namespace libtorrent { namespace char const* names[] = {"request", "data", "dont-have"}; char const* n = ""; if (type >= 0 && type < 3) n = names[type]; - m_pc.peer_log("==> UT_METADATA [ type: %d (%s) | piece: %d ]", type, n, piece); + m_pc.peer_log(peer_log_alert::outgoing_message, "UT_METADATA" + , "type: %d (%s) piece: %d", type, n, piece); #endif // abort if the peer doesn't support the metadata extension @@ -327,7 +328,8 @@ namespace libtorrent { namespace if (length > 17 * 1024) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== UT_METADATA [ packet too big %d ]", length); + m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" + , "packet too big %d", length); #endif m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2); return true; @@ -340,7 +342,8 @@ namespace libtorrent { namespace if (msg.type() != entry::dictionary_t) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== UT_METADATA [ not a dictionary ]"); + m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" + , "not a dictionary"); #endif m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2); return true; @@ -352,7 +355,8 @@ namespace libtorrent { namespace || piece_ent == 0 || piece_ent->type() != entry::int_t) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== UT_METADATA [ missing or invalid keys ]"); + m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" + , "missing or invalid keys"); #endif m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2); return true; @@ -361,7 +365,8 @@ namespace libtorrent { namespace int piece = piece_ent->integer(); #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== UT_METADATA [ type: %d | piece: %d ]", type, piece); + m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" + , "type: %d piece: %d", type, piece); #endif switch (type) @@ -372,7 +377,8 @@ namespace libtorrent { namespace || piece < 0 || piece >= int(m_tp.get_metadata_size() + 16 * 1024 - 1)/(16*1024)) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("*** UT_METADATA [ have: %d invalid piece %d metadata size: %d ]" + m_pc.peer_log(peer_log_alert::info, "UT_METADATA" + , "have: %d invalid piece %d metadata size: %d" , int(m_torrent.valid_metadata()), piece , int(m_tp.get_metadata_size())); #endif @@ -396,7 +402,8 @@ namespace libtorrent { namespace if (i == m_sent_requests.end()) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("*** UT_METADATA [ UNWANTED / TIMED OUT ]"); + m_pc.peer_log(peer_log_alert::info, "UT_METADATA" + , "UNWANTED / TIMED OUT"); #endif return true; } @@ -544,7 +551,8 @@ namespace libtorrent { namespace if (m_torrent.valid_metadata()) { #ifndef TORRENT_DISABLE_LOGGING - source.m_pc.peer_log("*** UT_METADATA [ ALREADY HAVE METADATA ]"); + source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA" + , "already have metadata"); #endif m_torrent.add_redundant_bytes(size, torrent::piece_unknown); return false; @@ -556,7 +564,8 @@ namespace libtorrent { namespace if (total_size <= 0 || total_size > m_torrent.session().settings().get_int(settings_pack::max_metadata_size)) { #ifndef TORRENT_DISABLE_LOGGING - source.m_pc.peer_log("*** UT_METADATA [ metadata size too big: %d ]", total_size); + source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA" + , "metadata size too big: %d", total_size); #endif // #error post alert return false; @@ -570,7 +579,8 @@ namespace libtorrent { namespace if (piece < 0 || piece >= int(m_requested_metadata.size())) { #ifndef TORRENT_DISABLE_LOGGING - source.m_pc.peer_log("*** UT_METADATA [ piece: %d INVALID ]", piece); + source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA" + , "piece: %d INVALID", piece); #endif return false; } @@ -578,7 +588,8 @@ namespace libtorrent { namespace if (total_size != m_metadata_size) { #ifndef TORRENT_DISABLE_LOGGING - source.m_pc.peer_log("*** UT_METADATA [ total_size: %d INCONSISTENT WITH: %d ]" + source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA" + , "total_size: %d INCONSISTENT WITH: %d" , total_size, m_metadata_size); #endif // they disagree about the size! diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index a42bccb9f..9525aac25 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -413,7 +413,7 @@ namespace libtorrent { namespace } #endif #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("<== PEX [ dropped: %d added: %d ]" + m_pc.peer_log(peer_log_alert::incoming_message, "PEX", "dropped: %d added: %d" , num_dropped, num_added); #endif @@ -432,7 +432,7 @@ namespace libtorrent { namespace if (now - seconds(60) < m_last_msg) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("*** PEX [ waiting: %d seconds to next msg ]" + m_pc.peer_log(peer_log_alert::info, "PEX", "waiting: %d seconds to next msg" , int(total_seconds(seconds(60) - (now - m_last_msg)))); #endif return; @@ -450,7 +450,7 @@ namespace libtorrent { namespace if (now - milliseconds(delay) < global_last) { #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("*** PEX [ global-wait: %d ]" + m_pc.peer_log(peer_log_alert::info, "PEX", "global-wait: %d" , int(total_seconds(milliseconds(delay) - (now - global_last)))); #endif return; @@ -511,7 +511,7 @@ namespace libtorrent { namespace if (e) num_added += e.string_length() / 18; e = m.dict_find_string("dropped6"); if (e) num_dropped += e.string_length() / 18; - m_pc.peer_log("==> PEX_DIFF [ dropped: %d added: %d msg_size: %d ]" + m_pc.peer_log(peer_log_alert::outgoing_message, "PEX_DIFF", "dropped: %d added: %d msg_size: %d" , num_dropped, num_added, int(pex_msg.size())); #endif } @@ -604,7 +604,8 @@ namespace libtorrent { namespace m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_pex); #ifndef TORRENT_DISABLE_LOGGING - m_pc.peer_log("==> PEX_FULL [ added: %d msg_size: %d ]", num_added, int(pex_msg.size())); + m_pc.peer_log(peer_log_alert::outgoing_message, "PEX_FULL" + , "added: %d msg_size: %d", num_added, int(pex_msg.size())); #endif } diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index abde31da0..1c0adefff 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -100,7 +100,7 @@ web_peer_connection::web_peer_connection(peer_connection_args const& pack request_large_blocks(true); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** web_peer_connection %s", m_url.c_str()); + peer_log(peer_log_alert::info, "URL", "web_peer_connection %s", m_url.c_str()); #endif } @@ -130,7 +130,7 @@ void web_peer_connection::disconnect(error_code const& ec // us bailing out and failing the entire request just because our // write-end was closed, ignore it and keep reading until the read-end // also is closed. - peer_log("*** WRITE-DIRECTION CLOSED"); + peer_log(peer_log_alert::info, "WRITE_DIRECTION", "CLOSED"); #endif // prevent the peer from trying to send anything more @@ -158,7 +158,8 @@ void web_peer_connection::disconnect(error_code const& ec && !m_piece.empty() && m_web) { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** SAVE-RESTART-DATA: [ data: %d req: %d off: %d ]" + peer_log(peer_log_alert::info, "SAVE_RESTART_DATA" + , "data: %d req: %d off: %d" , int(m_piece.size()), int(m_requests.front().piece) , int(m_requests.front().start)); #endif @@ -278,7 +279,7 @@ void web_peer_connection::write_request(peer_request const& r) m_requests.push_back(pr); #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> REQUESTING [ piece: %d start: %d len: %d ]" + peer_log(peer_log_alert::outgoing_message, "REQUESTING", "piece: %d start: %d len: %d" , pr.piece, pr.start, pr.length); #endif @@ -290,7 +291,7 @@ void web_peer_connection::write_request(peer_request const& r) TORRENT_ASSERT(front.length > int(m_piece.size())); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** RESTART-DATA: [ data: %d req: (%d, %d) size: %d ]" + peer_log(peer_log_alert::info, "RESTART_DATA", "data: %d req: (%d, %d) size: %d" , int(m_piece.size()), int(front.piece), int(front.start) , int (front.start + front.length - 1)); #endif @@ -397,7 +398,7 @@ void web_peer_connection::write_request(peer_request const& r) } #ifndef TORRENT_DISABLE_LOGGING - peer_log("==> %s", request.c_str()); + peer_log(peer_log_alert::outgoing_message, "REQUEST", "%s", request.c_str()); #endif // in case the first file on this series of requests is a padfile @@ -443,7 +444,8 @@ bool web_peer_connection::maybe_harvest_block() incoming_piece(front_request, &m_piece[0]); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== POP REQUEST [ piece: %d start: %d len: %d ]" + peer_log(peer_log_alert::incoming_message, "POP_REQUEST" + , "piece: %d start: %d len: %d" , front_request.piece, front_request.start, front_request.length); #endif m_requests.pop_front(); @@ -520,7 +522,8 @@ void web_peer_connection::on_receive(error_code const& error { received_bytes(0, bytes_transferred); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** web_peer_connection error: %s", error.message().c_str()); + peer_log(peer_log_alert::info, "ERROR" + , "web_peer_connection error: %s", error.message().c_str()); #endif #ifdef TORRENT_DEBUG TORRENT_ASSERT(statistics().last_payload_downloaded() @@ -558,7 +561,8 @@ void web_peer_connection::on_receive(error_code const& error { received_bytes(0, bytes_transferred); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** %s", std::string(recv_buffer.begin, recv_buffer.end).c_str()); + peer_log(peer_log_alert::info, "RECEIVE_BYTES" + , "%s", std::string(recv_buffer.begin, recv_buffer.end).c_str()); #endif disconnect(errors::http_parse_error, op_bittorrent, 2); #ifdef TORRENT_DEBUG @@ -615,11 +619,12 @@ void web_peer_connection::on_receive(error_code const& error } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** STATUS: %d %s", m_parser.status_code(), m_parser.message().c_str()); + peer_log(peer_log_alert::info, "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() , end(headers.end()); i != end; ++i) - peer_log(" %s: %s", i->first.c_str(), i->second.c_str()); + peer_log(peer_log_alert::info, "STATUS", " %s: %s", i->first.c_str(), i->second.c_str()); #endif // if the status code is not one of the accepted ones, abort if (!is_ok_status(m_parser.status_code())) @@ -713,7 +718,7 @@ void web_peer_connection::on_receive(error_code const& error } #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** LOCATION: %s", location.c_str()); + peer_log(peer_log_alert::info, "LOCATION", "%s", location.c_str()); #endif t->add_web_seed(location, web_seed_entry::url_seed, m_external_auth, m_extra_headers); t->remove_web_seed(this, errors::redirecting, op_bittorrent, 2); @@ -823,7 +828,8 @@ void web_peer_connection::on_receive(error_code const& error else { #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** parsed chunk: %" PRId64 " header_size: %d" + peer_log(peer_log_alert::info, "PARSE" + , "parsed chunk: %" PRId64 " header_size: %d" , chunk_size, header_size); #endif TORRENT_ASSERT(int(bytes_transferred) >= header_size - m_partial_chunk_header); @@ -874,7 +880,8 @@ void web_peer_connection::on_receive(error_code const& error TORRENT_ASSERT(m_block_pos >= 0); #ifndef TORRENT_DISABLE_LOGGING - peer_log("*** payload_transferred: %d [ %d:%d = %d ]" + peer_log(peer_log_alert::info, "TRAMSFER" + , "payload_transferred: %d [ %d:%d = %d ]" , payload_transferred, front_request.piece , front_request.start, front_request.length); #endif @@ -922,8 +929,8 @@ void web_peer_connection::on_receive(error_code const& error std::vector sl = info.orig_files().map_block( front_request.piece, front_request.start, front_request.start + front_request.length); - peer_log("INVALID HTTP RESPONSE [ in=(%d, %" PRId64 "-%" PRId64 ") " - "expected=(%d, %" PRId64 "-%" PRId64 ") piece: %d ]" + peer_log(peer_log_alert::incoming, "INVALID HTTP RESPONSE" + , "in=(%d, %" PRId64 "-%" PRId64 ") expected=(%d, %" PRId64 "-%" PRId64 ") piece: %d ]" , file_index, range_start, range_end, sl[0].file_index , sl[0].offset, sl[0].offset + sl[0].size, front_request.piece); #endif @@ -985,7 +992,8 @@ void web_peer_connection::on_receive(error_code const& error incoming_piece(r, recv_buffer.begin); #ifndef TORRENT_DISABLE_LOGGING - peer_log("<== POP REQUEST [ piece: %d start: %d len: %d ]" + peer_log(peer_log_alert::incoming_message, "POP_REQUEST" + , "piece: %d start: %d len: %d" , r.piece, r.start, r.length); #endif m_requests.pop_front(); diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index 4031ea294..57dff3e85 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -72,7 +72,8 @@ struct mock_peer_connection : peer_connection_interface virtual ~mock_peer_connection() {} #if !defined TORRENT_DISABLE_LOGGING - virtual void peer_log(char const* fmt, ...) const + virtual void peer_log(peer_log_alert::direction_t dir, char const* event + , char const* fmt, ...) const { va_list v; va_start(v, fmt);