summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcos Pinto <markybob@dipconsultants.com>2007-11-26 00:26:45 +0000
committerMarcos Pinto <markybob@dipconsultants.com>2007-11-26 00:26:45 +0000
commitedb20e0c054ce82fe29be63151b267b0ee01f137 (patch)
tree370106961b2c83f609c2c0ccefac21f8c367ebaf
parent3fb3bd9233b3f2f8bce22ca15ed656b8756a07b9 (diff)
downloaddeluge-edb20e0c054ce82fe29be63151b267b0ee01f137.tar.gz
deluge-edb20e0c054ce82fe29be63151b267b0ee01f137.tar.bz2
deluge-edb20e0c054ce82fe29be63151b267b0ee01f137.zip
small lsd, dht, webseed, and socks fixes
-rw-r--r--libtorrent/src/kademlia/dht_tracker.cpp3
-rw-r--r--libtorrent/src/socks4_stream.cpp23
-rw-r--r--libtorrent/src/socks5_stream.cpp51
-rwxr-xr-xlibtorrent/src/torrent.cpp21
-rwxr-xr-xlibtorrent/src/web_peer_connection.cpp30
5 files changed, 83 insertions, 45 deletions
diff --git a/libtorrent/src/kademlia/dht_tracker.cpp b/libtorrent/src/kademlia/dht_tracker.cpp
index f32db06d4..1c693b0f3 100644
--- a/libtorrent/src/kademlia/dht_tracker.cpp
+++ b/libtorrent/src/kademlia/dht_tracker.cpp
@@ -273,6 +273,9 @@ namespace libtorrent { namespace dht
udp::endpoint ep(listen_interface, listen_port);
m_socket.open(ep.protocol());
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)
diff --git a/libtorrent/src/socks4_stream.cpp b/libtorrent/src/socks4_stream.cpp
index 3a31b2375..c96dde85b 100644
--- a/libtorrent/src/socks4_stream.cpp
+++ b/libtorrent/src/socks4_stream.cpp
@@ -43,7 +43,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -54,8 +55,8 @@ namespace libtorrent
if (i == tcp::resolver::iterator())
{
asio::error_code ec = asio::error::operation_not_supported;
- (*h)(e);
- close();
+ (*h)(ec);
+ close(ec);
return;
}
@@ -68,7 +69,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -93,7 +95,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -107,7 +110,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -119,8 +123,9 @@ namespace libtorrent
if (reply_version != 0)
{
- (*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec = asio::error::operation_not_supported;
+ (*h)(ec);
+ close(ec);
return;
}
@@ -140,7 +145,7 @@ namespace libtorrent
case 93: ec = asio::error::no_permission; break;
}
(*h)(ec);
- close();
+ close(ec);
}
}
diff --git a/libtorrent/src/socks5_stream.cpp b/libtorrent/src/socks5_stream.cpp
index a40cd33d0..26d87ab09 100644
--- a/libtorrent/src/socks5_stream.cpp
+++ b/libtorrent/src/socks5_stream.cpp
@@ -44,7 +44,8 @@ namespace libtorrent
if (e || i == tcp::resolver::iterator())
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -57,7 +58,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -86,7 +88,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -100,7 +103,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -113,7 +117,8 @@ namespace libtorrent
if (version < 5)
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -126,7 +131,8 @@ namespace libtorrent
if (m_user.empty())
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -144,7 +150,8 @@ namespace libtorrent
else
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
}
@@ -155,7 +162,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -170,7 +178,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -183,14 +192,16 @@ namespace libtorrent
if (version != 1)
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
if (status != 0)
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -222,7 +233,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -236,7 +248,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
@@ -248,7 +261,8 @@ namespace libtorrent
if (version < 5)
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
int response = read_uint8(p);
@@ -267,7 +281,8 @@ namespace libtorrent
case 8: e = asio::error::address_family_not_supported; break;
}
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
p += 1; // reserved
@@ -291,7 +306,8 @@ namespace libtorrent
else
{
(*h)(asio::error::operation_not_supported);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
m_buffer.resize(skip_bytes);
@@ -305,7 +321,8 @@ namespace libtorrent
if (e)
{
(*h)(e);
- close();
+ asio::error_code ec;
+ close(ec);
return;
}
diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp
index 33a73d1f3..d74a7b053 100755
--- a/libtorrent/src/torrent.cpp
+++ b/libtorrent/src/torrent.cpp
@@ -287,6 +287,9 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_DHT
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
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)));
// 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
{
@@ -444,13 +448,12 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_DHT
+ if (m_paused) return;
if (!m_ses.m_dht) return;
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
if (m_ses.m_listen_sockets.empty()) return;
m_ses.m_dht->announce(m_torrent_file->info_hash()
, m_ses.m_listen_sockets.front().external_port
@@ -2250,15 +2253,15 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_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
- m_last_dht_announce = time_now() - minutes(15);
+ m_last_dht_announce = now;
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(
- bind(&torrent::on_announce_disp, self, _1)));
+ m_ses.m_dht->announce(m_torrent_file->info_hash()
+ , m_ses.m_listen_sockets.front().external_port
+ , m_ses.m_strand.wrap(bind(&torrent::on_dht_announce_response_disp, self, _1)));
}
#endif
diff --git a/libtorrent/src/web_peer_connection.cpp b/libtorrent/src/web_peer_connection.cpp
index 21208454e..b91401171 100755
--- a/libtorrent/src/web_peer_connection.cpp
+++ b/libtorrent/src/web_peer_connection.cpp
@@ -306,10 +306,12 @@ namespace libtorrent
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
- && range.start + range.length >= req.start + req.length;
+ size_type range_start = size_type(range.piece) * piece_size + range.start;
+ 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();
if (m_requests.empty() || m_file_requests.empty())
@@ -480,16 +485,16 @@ namespace libtorrent
, range_end - range_start);
peer_request front_request = m_requests.front();
-
+/*
size_type rs = size_type(in_range.piece) * info.piece_length() + in_range.start;
size_type re = rs + in_range.length;
size_type fs = size_type(front_request.piece) * info.piece_length() + front_request.start;
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
// http_body.begin is now in sync with the request at the front
// of the request queue
@@ -504,11 +509,16 @@ namespace libtorrent
bool range_overlaps_request = in_range.start + in_range.length
> 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
// 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
// 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
// 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
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)
{
peer_request r = m_requests.front();