From 7af7927f5d6b9b195242fc66aa87cedbfebe2802 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sun, 11 Aug 2013 21:45:45 -0300 Subject: [PATCH] some more debuging to make sure new dht announce x torrent peers is working --- libtorrent/src/kademlia/node.cpp | 2 ++ libtorrent/src/torrent.cpp | 26 +++++++++++++++++++++++++- src/twister.cpp | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/libtorrent/src/kademlia/node.cpp b/libtorrent/src/kademlia/node.cpp index c567387c..3b1bb992 100644 --- a/libtorrent/src/kademlia/node.cpp +++ b/libtorrent/src/kademlia/node.cpp @@ -423,6 +423,8 @@ void node_impl::announce(std::string const& trackerName, sha1_hash const& info_h #ifdef TORRENT_DHT_VERBOSE_LOGGING TORRENT_LOG(node) << "announcing [ ih: " << info_hash << " p: " << listen_port << " ]" ; #endif + printf("node_impl::announce '%s' host: %s:%d myself=%d\n", trackerName.c_str(), addr.to_string().c_str(), listen_port, myself); + add_peer( trackerName, info_hash, addr, listen_port, seed ); // do not announce other peers, just add them to our local m_map. diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index b57f98aa..2dae99a9 100644 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -88,6 +88,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif // BOOST_VERSION #endif // TORRENT_USE_OPENSSL +#include "../../src/util.h" #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING #include "libtorrent/struct_debug.hpp" #endif @@ -201,6 +202,8 @@ namespace peer_id const& pid; }; + + void nop() {} } namespace libtorrent @@ -2239,6 +2242,22 @@ namespace libtorrent TORRENT_ASSERT(m_allow_peers); + // [MF] use m_dht->announce with myself=false to update dht tracker with other peers + { + policy::const_iterator i = get_policy().begin_peer(); + policy::const_iterator end = get_policy().end_peer(); + for (; i != end; ++i) + { + policy::peer const* p = *i; + + if( p->connectable && !p->banned ) { + m_ses.m_dht->announce(*m_name, m_torrent_file->info_hash() + , p->address(), p->port, p->seed, false + , boost::bind(&nop)); + } + } + } + #ifdef TORRENT_USE_OPENSSL int port = is_ssl_torrent() ? m_ses.ssl_listen_port() : m_ses.listen_port(); #else @@ -2284,6 +2303,9 @@ namespace libtorrent localpeer.port(port); BOOST_FOREACH(tcp::endpoint const& p, peers) { +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING + debug_log("on_dht_announce_response %s:%d (local=%d)", p.address().to_string().c_str(), p.port(), p==localpeer); +#endif if( p != localpeer ) { m_policy.add_peer(p, peer_id(0), peer_info::dht, 0); } @@ -8982,7 +9004,9 @@ namespace libtorrent char buf[1280]; snprintf(buf, sizeof(buf), "%s: %s: %s\n", time_now_string() , to_hex(info_hash().to_string()).substr(0, 6).c_str(), usr); - (*m_ses.m_logger) << buf; + //(*m_ses.m_logger) << buf; + // [MF] + printf(buf); } #endif diff --git a/src/twister.cpp b/src/twister.cpp index 0ac23d3e..a51309d9 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -184,6 +184,8 @@ void ThreadWaitExtIP() // settings to test local connections settings.allow_multiple_connections_per_ip = true; settings.enable_outgoing_utp = false; // test (netstat display) + //settings.dht_announce_interval = 60; // test + //settings.min_announce_interval = 60; // test ses->set_settings(settings); printf("libtorrent + dht started\n");