small lsd, dht, webseed, and socks fixes
This commit is contained in:
parent
3fb3bd9233
commit
edb20e0c05
@ -273,6 +273,9 @@ namespace libtorrent { namespace dht
|
|||||||
udp::endpoint ep(listen_interface, listen_port);
|
udp::endpoint ep(listen_interface, listen_port);
|
||||||
m_socket.open(ep.protocol());
|
m_socket.open(ep.protocol());
|
||||||
m_socket.bind(ep);
|
m_socket.bind(ep);
|
||||||
|
m_socket.async_receive_from(asio::buffer(&m_in_buf[m_buffer][0]
|
||||||
|
, m_in_buf[m_buffer].size()), m_remote_endpoint[m_buffer]
|
||||||
|
, m_strand.wrap(bind(&dht_tracker::on_receive, self(), _1, _2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dht_tracker::tick(asio::error_code const& e)
|
void dht_tracker::tick(asio::error_code const& e)
|
||||||
|
|||||||
@ -43,7 +43,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +55,8 @@ namespace libtorrent
|
|||||||
if (i == tcp::resolver::iterator())
|
if (i == tcp::resolver::iterator())
|
||||||
{
|
{
|
||||||
asio::error_code ec = asio::error::operation_not_supported;
|
asio::error_code ec = asio::error::operation_not_supported;
|
||||||
(*h)(e);
|
(*h)(ec);
|
||||||
close();
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +95,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +110,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +123,9 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (reply_version != 0)
|
if (reply_version != 0)
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
asio::error_code ec = asio::error::operation_not_supported;
|
||||||
close();
|
(*h)(ec);
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +145,7 @@ namespace libtorrent
|
|||||||
case 93: ec = asio::error::no_permission; break;
|
case 93: ec = asio::error::no_permission; break;
|
||||||
}
|
}
|
||||||
(*h)(ec);
|
(*h)(ec);
|
||||||
close();
|
close(ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,7 +44,8 @@ namespace libtorrent
|
|||||||
if (e || i == tcp::resolver::iterator())
|
if (e || i == tcp::resolver::iterator())
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +58,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +88,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +103,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +117,8 @@ namespace libtorrent
|
|||||||
if (version < 5)
|
if (version < 5)
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +131,8 @@ namespace libtorrent
|
|||||||
if (m_user.empty())
|
if (m_user.empty())
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +150,8 @@ namespace libtorrent
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +162,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +178,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,14 +192,16 @@ namespace libtorrent
|
|||||||
if (version != 1)
|
if (version != 1)
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +233,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +248,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +261,8 @@ namespace libtorrent
|
|||||||
if (version < 5)
|
if (version < 5)
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int response = read_uint8(p);
|
int response = read_uint8(p);
|
||||||
@ -267,7 +281,8 @@ namespace libtorrent
|
|||||||
case 8: e = asio::error::address_family_not_supported; break;
|
case 8: e = asio::error::address_family_not_supported; break;
|
||||||
}
|
}
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
p += 1; // reserved
|
p += 1; // reserved
|
||||||
@ -291,7 +306,8 @@ namespace libtorrent
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
(*h)(asio::error::operation_not_supported);
|
(*h)(asio::error::operation_not_supported);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_buffer.resize(skip_bytes);
|
m_buffer.resize(skip_bytes);
|
||||||
@ -305,7 +321,8 @@ namespace libtorrent
|
|||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
(*h)(e);
|
(*h)(e);
|
||||||
close();
|
asio::error_code ec;
|
||||||
|
close(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -287,6 +287,9 @@ namespace libtorrent
|
|||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
bool torrent::should_announce_dht() const
|
bool torrent::should_announce_dht() const
|
||||||
{
|
{
|
||||||
|
if (m_ses.m_listen_sockets.empty()) return false;
|
||||||
|
|
||||||
|
if (!m_ses.m_dht) return false;
|
||||||
// don't announce private torrents
|
// don't announce private torrents
|
||||||
if (m_torrent_file->is_valid() && m_torrent_file->priv()) return false;
|
if (m_torrent_file->is_valid() && m_torrent_file->priv()) return false;
|
||||||
|
|
||||||
@ -434,7 +437,8 @@ namespace libtorrent
|
|||||||
bind(&torrent::on_announce_disp, self, _1)));
|
bind(&torrent::on_announce_disp, self, _1)));
|
||||||
|
|
||||||
// announce with the local discovery service
|
// announce with the local discovery service
|
||||||
m_ses.announce_lsd(m_torrent_file->info_hash());
|
if (!m_paused)
|
||||||
|
m_ses.announce_lsd(m_torrent_file->info_hash());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -444,13 +448,12 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
if (m_paused) return;
|
||||||
if (!m_ses.m_dht) return;
|
if (!m_ses.m_dht) return;
|
||||||
ptime now = time_now();
|
ptime now = time_now();
|
||||||
if (should_announce_dht() && now - m_last_dht_announce > minutes(14))
|
if (should_announce_dht() && now - m_last_dht_announce > minutes(14))
|
||||||
{
|
{
|
||||||
m_last_dht_announce = now;
|
m_last_dht_announce = now;
|
||||||
// TODO: There should be a way to abort an announce operation on the dht.
|
|
||||||
// when the torrent is destructed
|
|
||||||
if (m_ses.m_listen_sockets.empty()) return;
|
if (m_ses.m_listen_sockets.empty()) return;
|
||||||
m_ses.m_dht->announce(m_torrent_file->info_hash()
|
m_ses.m_dht->announce(m_torrent_file->info_hash()
|
||||||
, m_ses.m_listen_sockets.front().external_port
|
, m_ses.m_listen_sockets.front().external_port
|
||||||
@ -2250,15 +2253,15 @@ namespace libtorrent
|
|||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
// only start the announce if we want to announce with the dht
|
// only start the announce if we want to announce with the dht
|
||||||
if (should_announce_dht())
|
ptime now = time_now();
|
||||||
|
if (should_announce_dht() && now - m_last_dht_announce > minutes(14))
|
||||||
{
|
{
|
||||||
if (m_abort) return;
|
|
||||||
// force the DHT to reannounce
|
// force the DHT to reannounce
|
||||||
m_last_dht_announce = time_now() - minutes(15);
|
m_last_dht_announce = now;
|
||||||
boost::weak_ptr<torrent> self(shared_from_this());
|
boost::weak_ptr<torrent> self(shared_from_this());
|
||||||
m_announce_timer.expires_from_now(seconds(1));
|
m_ses.m_dht->announce(m_torrent_file->info_hash()
|
||||||
m_announce_timer.async_wait(m_ses.m_strand.wrap(
|
, m_ses.m_listen_sockets.front().external_port
|
||||||
bind(&torrent::on_announce_disp, self, _1)));
|
, m_ses.m_strand.wrap(bind(&torrent::on_dht_announce_response_disp, self, _1)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -306,10 +306,12 @@ namespace libtorrent
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool range_contains(peer_request const& range, peer_request const& req)
|
bool range_contains(peer_request const& range, peer_request const& req, int piece_size)
|
||||||
{
|
{
|
||||||
return range.start <= req.start
|
size_type range_start = size_type(range.piece) * piece_size + range.start;
|
||||||
&& range.start + range.length >= req.start + req.length;
|
size_type req_start = size_type(req.piece) * piece_size + req.start;
|
||||||
|
return range_start <= req_start
|
||||||
|
&& range_start + range.length >= req_start + req.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,6 +472,9 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// std::cerr << "REQUESTS: m_requests: " << m_requests.size()
|
||||||
|
// << " file_requests: " << m_file_requests.size() << std::endl;
|
||||||
|
|
||||||
torrent_info const& info = t->torrent_file();
|
torrent_info const& info = t->torrent_file();
|
||||||
|
|
||||||
if (m_requests.empty() || m_file_requests.empty())
|
if (m_requests.empty() || m_file_requests.empty())
|
||||||
@ -480,16 +485,16 @@ namespace libtorrent
|
|||||||
, range_end - range_start);
|
, range_end - range_start);
|
||||||
|
|
||||||
peer_request front_request = m_requests.front();
|
peer_request front_request = m_requests.front();
|
||||||
|
/*
|
||||||
size_type rs = size_type(in_range.piece) * info.piece_length() + in_range.start;
|
size_type rs = size_type(in_range.piece) * info.piece_length() + in_range.start;
|
||||||
size_type re = rs + in_range.length;
|
size_type re = rs + in_range.length;
|
||||||
size_type fs = size_type(front_request.piece) * info.piece_length() + front_request.start;
|
size_type fs = size_type(front_request.piece) * info.piece_length() + front_request.start;
|
||||||
size_type fe = fs + front_request.length;
|
size_type fe = fs + front_request.length;
|
||||||
if (fs < rs || fe > re)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("invalid range in HTTP response");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
std::cerr << "RANGE: r = (" << rs << ", " << re << " ) "
|
||||||
|
"f = (" << fs << ", " << fe << ") "
|
||||||
|
"file_index = " << file_index << " received_body = " << m_received_body << std::endl;
|
||||||
|
*/
|
||||||
// skip the http header and the blocks we've already read. The
|
// skip the http header and the blocks we've already read. The
|
||||||
// http_body.begin is now in sync with the request at the front
|
// http_body.begin is now in sync with the request at the front
|
||||||
// of the request queue
|
// of the request queue
|
||||||
@ -504,11 +509,16 @@ namespace libtorrent
|
|||||||
bool range_overlaps_request = in_range.start + in_range.length
|
bool range_overlaps_request = in_range.start + in_range.length
|
||||||
> front_request.start + int(m_piece.size());
|
> front_request.start + int(m_piece.size());
|
||||||
|
|
||||||
|
if (!range_overlaps_request)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("invalid range in HTTP response");
|
||||||
|
}
|
||||||
|
|
||||||
// if the request is contained in the range (i.e. the entire request
|
// if the request is contained in the range (i.e. the entire request
|
||||||
// fits in the range) we should not start a partial piece, since we soon
|
// fits in the range) we should not start a partial piece, since we soon
|
||||||
// will receive enough to call incoming_piece() and pass the read buffer
|
// will receive enough to call incoming_piece() and pass the read buffer
|
||||||
// directly (in the next loop below).
|
// directly (in the next loop below).
|
||||||
if (range_overlaps_request && !range_contains(in_range, front_request))
|
if (range_overlaps_request && !range_contains(in_range, front_request, info.piece_length()))
|
||||||
{
|
{
|
||||||
// the start of the next block to receive is stored
|
// the start of the next block to receive is stored
|
||||||
// in m_piece. We need to append the rest of that
|
// in m_piece. We need to append the rest of that
|
||||||
@ -549,7 +559,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
// report all received blocks to the bittorrent engine
|
// report all received blocks to the bittorrent engine
|
||||||
while (!m_requests.empty()
|
while (!m_requests.empty()
|
||||||
&& range_contains(in_range, m_requests.front())
|
&& range_contains(in_range, m_requests.front(), info.piece_length())
|
||||||
&& recv_buffer.left() >= m_requests.front().length)
|
&& recv_buffer.left() >= m_requests.front().length)
|
||||||
{
|
{
|
||||||
peer_request r = m_requests.front();
|
peer_request r = m_requests.front();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user