forked from premiere/premiere-libtorrent
made lsd work
This commit is contained in:
parent
633f174947
commit
ea45641c8b
|
@ -616,6 +616,10 @@ namespace libtorrent
|
|||
, std::vector<tcp::endpoint> const& peers);
|
||||
void on_dht_announce_response(std::vector<tcp::endpoint> const& peers);
|
||||
bool should_announce_dht() const;
|
||||
|
||||
// the time when the DHT was last announced of our
|
||||
// presence on this torrent
|
||||
ptime m_last_dht_announce;
|
||||
#endif
|
||||
|
||||
// this is the upload and download statistics for the whole torrent.
|
||||
|
|
36
src/lsd.cpp
36
src/lsd.cpp
|
@ -99,11 +99,7 @@ void lsd::rebind(address const& listen_interface)
|
|||
|
||||
m_socket.set_option(join_group(lsd_multicast_address));
|
||||
m_socket.set_option(outbound_interface(local_ip));
|
||||
#ifdef NDEBUG
|
||||
m_socket.set_option(enable_loopback(false));
|
||||
#else
|
||||
m_socket.set_option(enable_loopback(true));
|
||||
#endif
|
||||
m_socket.set_option(hops(255));
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
@ -171,10 +167,6 @@ catch (std::exception&)
|
|||
void lsd::on_announce(asio::error_code const& e
|
||||
, std::size_t bytes_transferred)
|
||||
{
|
||||
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||
m_log << time_now_string()
|
||||
<< " <== on_announce" << std::endl;
|
||||
#endif
|
||||
using namespace libtorrent::detail;
|
||||
if (e) return;
|
||||
|
||||
|
@ -182,11 +174,15 @@ void lsd::on_announce(asio::error_code const& e
|
|||
char* end = m_receive_buffer + bytes_transferred;
|
||||
char* line = std::find(p, end, '\n');
|
||||
for (char* i = p; i < line; ++i) *i = std::tolower(*i);
|
||||
if (line == end || std::strcmp("bt-search", p))
|
||||
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||
m_log << time_now_string()
|
||||
<< " <== announce: " << std::string(p, line) << std::endl;
|
||||
#endif
|
||||
if (line == end || (line - p >= 9 && std::memcmp("bt-search", p, 9)))
|
||||
{
|
||||
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||
m_log << time_now_string()
|
||||
<< " <== Got incorrect method in announce" << std::string(p, line) << std::endl;
|
||||
<< " *** assumed 'bt-search', ignoring" << std::endl;
|
||||
#endif
|
||||
setup_receive();
|
||||
return;
|
||||
|
@ -200,13 +196,19 @@ void lsd::on_announce(asio::error_code const& e
|
|||
if (line == end) break;
|
||||
*line = 0;
|
||||
for (char* i = p; i < line; ++i) *i = std::tolower(*i);
|
||||
if (!strcmp(p, "port:"))
|
||||
if (line - p >= 5 && memcmp(p, "port:", 5) == 0)
|
||||
{
|
||||
port = atoi(p + 5);
|
||||
p += 5;
|
||||
while (*p == ' ') ++p;
|
||||
port = atoi(p);
|
||||
}
|
||||
else if (!strcmp(p, "infohash:"))
|
||||
else if (line - p >= 9 && memcmp(p, "infohash:", 9) == 0)
|
||||
{
|
||||
ih = boost::lexical_cast<sha1_hash>(p + 9);
|
||||
p += 9;
|
||||
while (*p == ' ') ++p;
|
||||
if (line - p > 40) p[40] = 0;
|
||||
try { ih = boost::lexical_cast<sha1_hash>(p); }
|
||||
catch (std::exception&) {}
|
||||
}
|
||||
p = line + 1;
|
||||
}
|
||||
|
@ -215,7 +217,7 @@ void lsd::on_announce(asio::error_code const& e
|
|||
{
|
||||
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||
m_log << time_now_string()
|
||||
<< " <== Got incoming local announce " << m_remote.address()
|
||||
<< " *** incoming local announce " << m_remote.address()
|
||||
<< ":" << port << " ih: " << ih << std::endl;
|
||||
#endif
|
||||
// we got an announce, pass it on through the callback
|
||||
|
@ -227,10 +229,6 @@ void lsd::on_announce(asio::error_code const& e
|
|||
|
||||
void lsd::setup_receive() try
|
||||
{
|
||||
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
|
||||
m_log << time_now_string()
|
||||
<< " *** setup_receive" << std::endl;
|
||||
#endif
|
||||
assert(m_socket.is_open());
|
||||
m_socket.async_receive_from(asio::buffer(m_receive_buffer
|
||||
, sizeof(m_receive_buffer)), m_remote, bind(&lsd::on_announce, this, _1, _2));
|
||||
|
|
|
@ -201,6 +201,7 @@ namespace libtorrent
|
|||
, m_resolve_countries(false)
|
||||
#endif
|
||||
, m_announce_timer(ses.m_io_service)
|
||||
, m_last_dht_announce(time_now() - minutes(15))
|
||||
, m_policy()
|
||||
, m_ses(ses)
|
||||
, m_checker(checker)
|
||||
|
@ -284,6 +285,7 @@ namespace libtorrent
|
|||
, m_resolve_countries(false)
|
||||
#endif
|
||||
, m_announce_timer(ses.m_io_service)
|
||||
, m_last_dht_announce(time_now() - minutes(15))
|
||||
, m_policy()
|
||||
, m_ses(ses)
|
||||
, m_checker(checker)
|
||||
|
@ -439,7 +441,8 @@ namespace libtorrent
|
|||
{
|
||||
boost::weak_ptr<torrent> self(shared_from_this());
|
||||
|
||||
m_announce_timer.expires_from_now(minutes(30));
|
||||
// announce on local network every 5 minutes
|
||||
m_announce_timer.expires_from_now(minutes(5));
|
||||
m_announce_timer.async_wait(m_ses.m_strand.wrap(
|
||||
bind(&torrent::on_announce_disp, self, _1)));
|
||||
|
||||
|
@ -448,8 +451,10 @@ namespace libtorrent
|
|||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
if (!m_ses.m_dht) return;
|
||||
if (should_announce_dht())
|
||||
ptime now = time_now();
|
||||
if (should_announce_dht() && now - m_last_dht_announce > minutes(14))
|
||||
{
|
||||
m_last_dht_announce = now;
|
||||
// TODO: There should be a way to abort an announce operation on the dht.
|
||||
// when the torrent is destructed
|
||||
assert(m_ses.m_external_listen_port > 0);
|
||||
|
@ -2017,6 +2022,8 @@ namespace libtorrent
|
|||
// only start the announce if we want to announce with the dht
|
||||
if (should_announce_dht())
|
||||
{
|
||||
// force the DHT to reannounce
|
||||
m_last_dht_announce = time_now() - minutes(15);
|
||||
boost::weak_ptr<torrent> self(shared_from_this());
|
||||
m_announce_timer.expires_from_now(seconds(1));
|
||||
m_announce_timer.async_wait(m_ses.m_strand.wrap(
|
||||
|
|
Loading…
Reference in New Issue