diff --git a/src/kademlia/get_peers.cpp b/src/kademlia/get_peers.cpp index 4c856b872..c8c638250 100644 --- a/src/kademlia/get_peers.cpp +++ b/src/kademlia/get_peers.cpp @@ -80,7 +80,7 @@ void get_peers_observer::reply(msg const& m) , print_endpoint(m.addr).c_str() , to_hex(id.string_value()).c_str() , distance_exp(m_algorithm->target(), node_id(id.string_ptr())) - , (end - peers) / 6); + , int((end - peers) / 6)); } #endif while (end - peers >= 6) @@ -102,7 +102,7 @@ void get_peers_observer::reply(msg const& m) , print_endpoint(m.addr).c_str() , to_hex(id.string_value()).c_str() , distance_exp(m_algorithm->target(), node_id(id.string_ptr())) - , n.list_size()); + , int(n.list_size())); } #endif } diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 03969dbe5..0c71b339a 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -125,8 +125,11 @@ bool node::verify_token(std::string const& token, char const* info_hash if (token.length() != 4) { #ifndef TORRENT_DISABLE_LOGGING - m_observer->log(dht_logger::node, "token of incorrect length: %d" - , token.length()); + if (m_observer) + { + m_observer->log(dht_logger::node, "token of incorrect length: %d" + , int(token.length())); + } #endif return false; } @@ -138,11 +141,11 @@ bool node::verify_token(std::string const& token, char const* info_hash h1.update(&address[0], address.length()); h1.update((char*)&m_secret[0], sizeof(m_secret[0])); h1.update((char*)info_hash, sha1_hash::size); - + sha1_hash h = h1.final(); if (std::equal(token.begin(), token.end(), (char*)&h[0])) return true; - + hasher h2; h2.update(&address[0], address.length()); h2.update((char*)&m_secret[1], sizeof(m_secret[1])); @@ -192,12 +195,13 @@ void node::bootstrap(std::vector const& nodes #endif r->add_entry(node_id(0), *i, observer::flag_initial); } - + // make us start as far away from our node ID as possible r->trim_seed_nodes(); #ifndef TORRENT_DISABLE_LOGGING - m_observer->log(dht_logger::node, "bootstrapping with %d nodes", count); + if (m_observer) + m_observer->log(dht_logger::node, "bootstrapping with %d nodes", count); #endif r->start(); } @@ -284,7 +288,7 @@ void node::incoming(msg const& m) { #ifndef TORRENT_DISABLE_LOGGING bdecode_node err = m.message.dict_find_list("e"); - if (err && err.list_size() >= 2) + if (err && err.list_size() >= 2 && m_observer) { m_observer->log(dht_logger::node, "INCOMING ERROR: %s" , err.list_string_value_at(1).c_str()); @@ -303,13 +307,16 @@ namespace , node& node, int listen_port, sha1_hash const& ih, int flags) { #ifndef TORRENT_DISABLE_LOGGING - char hex_ih[41]; - to_hex(reinterpret_cast(&ih[0]), 20, hex_ih); - node.observer()->log(dht_logger::node, "sending announce_peer [ ih: %s " - " p: %d nodes: %d ]", hex_ih, listen_port, int(v.size())); + if (node.observer()) + { + char hex_ih[41]; + to_hex(reinterpret_cast(&ih[0]), 20, hex_ih); + node.observer()->log(dht_logger::node, "sending announce_peer [ ih: %s " + " p: %d nodes: %d ]", hex_ih, listen_port, int(v.size())); + } #endif - // create a dummy traversal_algorithm + // create a dummy traversal_algorithm boost::intrusive_ptr algo( new traversal_algorithm(node, (node_id::min)())); @@ -318,8 +325,11 @@ namespace , end(v.end()); i != end; ++i) { #ifndef TORRENT_DISABLE_LOGGING - node.observer()->log(dht_logger::node, "announce-distance: %d" - , (160 - distance_exp(ih, i->first.id))); + if (node.observer()) + { + node.observer()->log(dht_logger::node, "announce-distance: %d" + , (160 - distance_exp(ih, i->first.id))); + } #endif void* ptr = node.m_rpc.allocate_observer(); @@ -346,8 +356,11 @@ namespace void node::add_router_node(udp::endpoint router) { #ifndef TORRENT_DISABLE_LOGGING - m_observer->log(dht_logger::node, "adding router node: %s" - , print_endpoint(router).c_str()); + if (m_observer) + { + m_observer->log(dht_logger::node, "adding router node: %s" + , print_endpoint(router).c_str()); + } #endif m_table.add_router_node(router); } @@ -363,10 +376,13 @@ void node::announce(sha1_hash const& info_hash, int listen_port, int flags , boost::function const&)> f) { #ifndef TORRENT_DISABLE_LOGGING - char hex_ih[41]; - to_hex(reinterpret_cast(&info_hash[0]), 20, hex_ih); - m_observer->log(dht_logger::node, "announcing [ ih: %s p: %d ]" - , hex_ih, listen_port); + if (m_observer) + { + char hex_ih[41]; + to_hex(reinterpret_cast(&info_hash[0]), 20, hex_ih); + m_observer->log(dht_logger::node, "announcing [ ih: %s p: %d ]" + , hex_ih, listen_port); + } #endif // search for nodes with ids close to id or with peers // for info-hash id. then send announce_peer to them. @@ -392,10 +408,13 @@ void node::get_item(sha1_hash const& target , boost::function f) { #ifndef TORRENT_DISABLE_LOGGING - char hex_target[41]; - to_hex(reinterpret_cast(&target[0]), 20, hex_target); - m_observer->log(dht_logger::node, "starting get for [ hash: %s ]" - , hex_target); + if (m_observer) + { + char hex_target[41]; + to_hex(reinterpret_cast(&target[0]), 20, hex_target); + m_observer->log(dht_logger::node, "starting get for [ hash: %s ]" + , hex_target); + } #endif boost::intrusive_ptr ta; @@ -407,9 +426,12 @@ void node::get_item(char const* pk, std::string const& salt , boost::function f) { #ifndef TORRENT_DISABLE_LOGGING - char hex_key[65]; - to_hex(pk, 32, hex_key); - m_observer->log(dht_logger::node, "starting get for [ key: %s ]", hex_key); + if (m_observer) + { + char hex_key[65]; + to_hex(pk, 32, hex_key); + m_observer->log(dht_logger::node, "starting get for [ key: %s ]", hex_key); + } #endif boost::intrusive_ptr ta; @@ -434,9 +456,12 @@ struct ping_observer : observer if (!r) { #ifndef TORRENT_DISABLE_LOGGING - m_algorithm->get_node().observer()->log(dht_logger::node - , "[%p] missing response dict" - , m_algorithm.get()); + if (m_algorithm->get_node().observer()) + { + m_algorithm->get_node().observer()->log(dht_logger::node + , "[%p] missing response dict" + , m_algorithm.get()); + } #endif return; } @@ -900,7 +925,7 @@ void node::incoming_request(msg const& m, entry& e) if (msg_keys[2] && msg_keys[2].int_value() != 0) scrape = true; lookup_peers(info_hash, reply, noseed, scrape); #ifndef TORRENT_DISABLE_LOGGING - if (reply.find_key("values")) + if (reply.find_key("values") && m_observer) { m_observer->log(dht_logger::node, "values: %d" , int(reply["values"].list().size())); diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 7fa361a8c..26610eca2 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -278,7 +278,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id { #ifndef TORRENT_DISABLE_LOGGING m_log->log(dht_logger::rpc_manager, "reply with unknown transaction id size: %d from %s" - , transaction_id.size(), print_endpoint(m.addr).c_str()); + , int(transaction_id.size()), print_endpoint(m.addr).c_str()); #endif // this isn't necessarily because the other end is doing // something wrong. This can also happen when we restart @@ -336,7 +336,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id #ifndef TORRENT_DISABLE_LOGGING m_log->log(dht_logger::rpc_manager, "[%p] reply with transaction id: %d from %s" - , o->m_algorithm.get(), transaction_id.size() + , o->m_algorithm.get(), int(transaction_id.size()) , print_endpoint(m.addr).c_str()); #endif o->reply(m); diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index 737144d68..38258fd7f 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -440,8 +440,8 @@ bool traversal_algorithm::add_requests() , "[%p] INVOKE nodes-left: %d top-invoke-count: %d " "invoke-count: %d branch-factor: %d " "distance: %d id: %s addr: %s type: %s" - , this, m_results.end() - i, outstanding, m_invoke_count - , m_branch_factor, distance_exp(m_target, o->id()), hex_id + , this, int(m_results.end() - i), outstanding, int(m_invoke_count) + , int(m_branch_factor), distance_exp(m_target, o->id()), hex_id , print_address(o->target_addr()).c_str(), name()); #endif @@ -561,7 +561,7 @@ void traversal_observer::reply(msg const& m) { #ifndef TORRENT_DISABLE_LOGGING m_algorithm->get_node().observer()->log(dht_logger::traversal, "[%p] invalid id in response" - , m_algorithm.get(), m_algorithm->name()); + , m_algorithm.get()); #endif return; } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 3df71686d..d349c7b23 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6502,18 +6502,21 @@ retry: offset += vsnprintf(&buf[offset], sizeof(buf) - offset, fmt, v); va_end(v); - bdecode_node print; - error_code ec; - int ret = bdecode(pkt, pkt + len, print, ec, NULL, 100, 100); + if (offset < sizeof(buf) - 1) + { + buf[offset++] = ' '; - // TODO: 3 there should be a separate dht_log_alert for messages that - // contains the raw packet separately. This printing should be moved - // down to the ::message() function of that alert - std::string msg = print_entry(print, true); + bdecode_node print; + error_code ec; + int ret = bdecode(pkt, pkt + len, print, ec, NULL, 100, 100); - if (offset < sizeof(buf)) buf[offset++] = ' '; + // TODO: 3 there should be a separate dht_log_alert for messages that + // contains the raw packet separately. This printing should be moved + // down to the ::message() function of that alert + std::string msg = print_entry(print, true); - strncpy(&buf[offset], msg.c_str(), sizeof(buf) - offset); + strncpy(&buf[offset], msg.c_str(), sizeof(buf) - offset); + } m_alerts.emplace_alert(dht_log_alert::tracker, buf); }