* Fixed the hashing so it properly starts and stops. When

DownloadList::pause is called it clears the "hashing" variable.

* Added convenience functions for retriving torrent::Object key's of
specific types.

* Iterate to the first visible transfer in the chunks seen view. Patch
by Josef Drexler.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@732 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-06-28 22:50:58 +00:00
parent ee353bfc9f
commit 4b79a7c47f
6 changed files with 27 additions and 18 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ Download::enable_udp_trackers(bool state) {
uint32_t
Download::priority() {
return bencode()->get_key("rtorrent").get_key("priority").as_value();
return bencode()->get_key("rtorrent").get_key_value("priority");
}
void
+4 -4
View File
@@ -55,10 +55,10 @@ public:
typedef download_type::ConnectionType connection_type;
typedef utils::VariableMap variable_map_type;
static const int64_t variable_hashing_stopped = 0;
static const int64_t variable_hashing_initial = 1;
static const int64_t variable_hashing_last = 2;
static const int64_t variable_hashing_rehash = 3;
static const int variable_hashing_stopped = 0;
static const int variable_hashing_initial = 1;
static const int variable_hashing_last = 2;
static const int variable_hashing_rehash = 3;
Download(download_type d);
~Download();
+6 -6
View File
@@ -232,12 +232,12 @@ DownloadFactory::receive_failed(const std::string& msg) {
void
DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorrent) {
if (!rtorrent->has_key_value("state") || rtorrent->get_key("state").as_value() > 1) {
if (!rtorrent->has_key_value("state") || rtorrent->get_key_value("state") > 1) {
rtorrent->insert_key("state", (int64_t)m_start);
rtorrent->insert_key("state_changed", cachedTime.seconds());
} else if (!rtorrent->has_key_value("state_changed") ||
rtorrent->get_key("state_changed").as_value() > cachedTime.seconds() || rtorrent->get_key("state_changed").as_value() == 0) {
rtorrent->get_key_value("state_changed") > cachedTime.seconds() || rtorrent->get_key_value("state_changed") == 0) {
rtorrent->insert_key("state_changed", cachedTime.seconds());
}
@@ -245,18 +245,18 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre
rtorrent->insert_key("complete", (int64_t)0);
if (!rtorrent->has_key_value("hashing"))
rtorrent->insert_key("hashing", Download::variable_hashing_stopped);
rtorrent->insert_key("hashing", (int64_t)Download::variable_hashing_stopped);
if (!rtorrent->has_key_string("tied_to_file"))
rtorrent->insert_key("tied_to_file", std::string());
if (rtorrent->has_key_value("priority"))
download->variable()->set("priority", rtorrent->get_key("priority").as_value() % 4);
download->variable()->set("priority", rtorrent->get_key_value("priority") % 4);
else
download->variable()->set("priority", (int64_t)2);
if (rtorrent->has_key_value("key")) {
download->tracker_list()->set_key(rtorrent->get_key("key").as_value());
download->tracker_list()->set_key(rtorrent->get_key_value("key"));
} else {
download->tracker_list()->set_key(random() % (std::numeric_limits<uint32_t>::max() - 1) + 1);
@@ -264,7 +264,7 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre
}
if (rtorrent->has_key_value("total_uploaded"))
download->download()->up_rate()->set_total(rtorrent->get_key("total_uploaded").as_value());
download->download()->up_rate()->set_total(rtorrent->get_key_value("total_uploaded"));
if (!rtorrent->has_key_value("ignore_ratio"))
rtorrent->insert_key("ignore_ratio", (int64_t)0);
+12 -7
View File
@@ -221,9 +221,7 @@ DownloadList::close_throw(Download* download) {
download->download()->close();
if (!download->is_hash_failed() &&
download->variable()->get_value("state") != 0 &&
download->variable()->get_value("hashing") != Download::variable_hashing_stopped)
if (!download->is_hash_failed() && download->variable()->get_value("hashing") != Download::variable_hashing_stopped)
throw torrent::client_error("DownloadList::close_throw(...) called but we're going into a hashing loop.");
std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download));
@@ -246,6 +244,12 @@ void
DownloadList::start_try(Download* download) {
check_contains(download);
// Also don't start if the state is one of those that indicate we
// were manually stopped?
if (download->is_hash_failed())
return;
// Don't clear the hash failed as this function is used by scripts,
// etc.
download->variable()->set("state", (int64_t)1);
@@ -321,9 +325,9 @@ DownloadList::pause(Download* download) {
try {
// Clear initial hashing, but retain the other types.
if (download->variable()->get_value("hashing") == Download::variable_hashing_initial)
download->variable()->set("hashing", Download::variable_hashing_stopped);
// Always clear hashing on pause. When a hashing request is added,
// it should have cleared the hash resume data.
download->variable()->set_value("hashing", Download::variable_hashing_stopped);
if (!download->download()->is_active())
return;
@@ -388,7 +392,7 @@ DownloadList::hash_done(Download* download) {
// ReiserFS bug with >4GB files.
int64_t hashing = download->variable()->get_value("hashing");
download->variable()->set("hashing", Download::variable_hashing_stopped);
download->variable()->set_value("hashing", Download::variable_hashing_stopped);
switch (hashing) {
case Download::variable_hashing_initial:
@@ -442,6 +446,7 @@ DownloadList::hash_queue(Download* download, int type) {
download->download()->hash_resume_clear();
download->set_hash_failed(false);
download->variable()->set_value("hashing", type);
if (download->is_open())
throw torrent::internal_error("DownloadList::hash_clear(...) download still open.");
@@ -99,6 +99,9 @@ WindowDownloadChunksSeen::redraw() {
std::vector<torrent::BlockList*>::const_iterator itrTransfer = transferChunks.begin();
while (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) > (*itrTransfer)->index())
itrTransfer++;
for (int y = 1; y < m_canvas->get_height() && chunk < last; ++y) {
m_canvas->print(0, y, "%5u ", (int)(chunk - seen));
+1
View File
@@ -72,6 +72,7 @@ public:
void set(const std::string& key, const mapped_type& arg);
void set_string(const std::string& key, const std::string& arg) { set(key, mapped_type(arg)); }
void set_value(const std::string& key, mapped_value_type arg) { set(key, mapped_type(arg)); }
// Relocate.
void process_command(const std::string& command);