mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-09 07:39:21 +00:00
* Enable custom throttles, both per-download or per-IP. See http://libtorrent.rakshasa.no/ticket/20 for info and instructions. Patch by Josef Drexler.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1091 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -6,6 +6,7 @@ libsub_ui_a_SOURCES = \
|
||||
download_list.cc \
|
||||
download_list.h \
|
||||
element_base.h \
|
||||
element_base.cc \
|
||||
element_chunks_seen.cc \
|
||||
element_chunks_seen.h \
|
||||
element_download_list.cc \
|
||||
|
||||
@@ -42,12 +42,14 @@
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/chunk_manager.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/throttle.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
#include <torrent/data/file_list.h>
|
||||
#include <torrent/peer/connection_list.h>
|
||||
|
||||
#include "core/download.h"
|
||||
#include "core/manager.h"
|
||||
#include "input/manager.h"
|
||||
#include "display/window_title.h"
|
||||
#include "display/window_download_statusbar.h"
|
||||
@@ -179,6 +181,15 @@ Download::create_info() {
|
||||
element->push_column("Send buffer:", te_command("cat=$to_kb=$get_send_buffer_size=,\" KB\""));
|
||||
element->push_column("Receive buffer:", te_command("cat=$to_kb=$get_receive_buffer_size=,\" KB\""));
|
||||
|
||||
// TODO: Define a custom command for this and use $argument.0 instead of looking up the name multiple times?
|
||||
element->push_column("Throttle:", te_command("branch=d.get_throttle_name=,\""
|
||||
"cat=$d.get_throttle_name=,\\\" [Max \\\","
|
||||
"$to_throttle=$get_throttle_up_max=$d.get_throttle_name=,\\\"/\\\","
|
||||
"$to_throttle=$get_throttle_down_max=$d.get_throttle_name=,\\\" KB] [Rate \\\","
|
||||
"$to_kb=$get_throttle_up_rate=$d.get_throttle_name=,\\\"/\\\","
|
||||
"$to_kb=$get_throttle_down_rate=$d.get_throttle_name=,\\\" KB]\\\"\","
|
||||
"cat=\"global\""));
|
||||
|
||||
element->push_back("");
|
||||
element->push_column("Upload:", te_command("cat=$to_kb=$d.get_up_rate=,\" KB / \",$to_xb=$d.get_up_total="));
|
||||
element->push_column("Download:", te_command("cat=$to_kb=$d.get_down_rate=,\" KB / \",$to_xb=$d.get_down_total="));
|
||||
@@ -315,6 +326,32 @@ Download::receive_prev_priority() {
|
||||
m_download->set_priority((m_download->priority() - 1) % 4);
|
||||
}
|
||||
|
||||
void
|
||||
Download::adjust_down_throttle(int throttle) {
|
||||
core::ThrottleMap::iterator itr = control->core()->throttles().find(m_download->bencode()->get_key("rtorrent").get_key_string("throttle_name"));
|
||||
|
||||
if (itr == control->core()->throttles().end() || itr->second.second == NULL || itr->first == "NULL")
|
||||
control->ui()->adjust_down_throttle(throttle);
|
||||
else
|
||||
itr->second.second->set_max_rate(std::max<int>((itr->second.second->is_throttled() ? itr->second.second->max_rate() : 0) + throttle * 1024, 0));
|
||||
|
||||
if (m_uiArray[DISPLAY_INFO]->is_active())
|
||||
m_uiArray[DISPLAY_INFO]->mark_dirty();
|
||||
}
|
||||
|
||||
void
|
||||
Download::adjust_up_throttle(int throttle) {
|
||||
core::ThrottleMap::iterator itr = control->core()->throttles().find(m_download->bencode()->get_key("rtorrent").get_key_string("throttle_name"));
|
||||
|
||||
if (itr == control->core()->throttles().end() || itr->second.first == NULL || itr->first == "NULL")
|
||||
control->ui()->adjust_up_throttle(throttle);
|
||||
else
|
||||
itr->second.first->set_max_rate(std::max<int>((itr->second.first->is_throttled() ? itr->second.first->max_rate() : 0) + throttle * 1024, 0));
|
||||
|
||||
if (m_uiArray[DISPLAY_INFO]->is_active())
|
||||
m_uiArray[DISPLAY_INFO]->mark_dirty();
|
||||
}
|
||||
|
||||
void
|
||||
Download::bind_keys() {
|
||||
m_bindings['1'] = sigc::bind(sigc::mem_fun(this, &Download::receive_max_uploads), -1);
|
||||
@@ -328,6 +365,23 @@ Download::bind_keys() {
|
||||
|
||||
m_bindings['t'] = sigc::bind(sigc::mem_fun(m_download->tracker_list(), &torrent::TrackerList::manual_request), false);
|
||||
m_bindings['T'] = sigc::bind(sigc::mem_fun(m_download->tracker_list(), &torrent::TrackerList::manual_request), true);
|
||||
|
||||
const char* keys = control->ui()->get_throttle_keys();
|
||||
|
||||
m_bindings[keys[ 0]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_up_throttle), 1);
|
||||
m_bindings[keys[ 1]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_up_throttle), -1);
|
||||
m_bindings[keys[ 2]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_down_throttle), 1);
|
||||
m_bindings[keys[ 3]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_down_throttle), -1);
|
||||
|
||||
m_bindings[keys[ 4]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_up_throttle), 5);
|
||||
m_bindings[keys[ 5]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_up_throttle), -5);
|
||||
m_bindings[keys[ 6]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_down_throttle), 5);
|
||||
m_bindings[keys[ 7]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_down_throttle), -5);
|
||||
|
||||
m_bindings[keys[ 8]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_up_throttle), 50);
|
||||
m_bindings[keys[ 9]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_up_throttle), -50);
|
||||
m_bindings[keys[10]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_down_throttle), 50);
|
||||
m_bindings[keys[11]] = sigc::bind(sigc::mem_fun(this, &Download::adjust_down_throttle), -50);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,6 +87,9 @@ public:
|
||||
void receive_next_priority();
|
||||
void receive_prev_priority();
|
||||
|
||||
void adjust_up_throttle(int throttle);
|
||||
void adjust_down_throttle(int throttle);
|
||||
|
||||
display::Window* window() { return NULL; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2007, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "display/frame.h"
|
||||
#include "display/window.h"
|
||||
|
||||
#include "element_base.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
void
|
||||
ElementBase::mark_dirty() {
|
||||
if (is_active())
|
||||
m_frame->window()->mark_dirty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,6 +62,8 @@ public:
|
||||
|
||||
void slot_exit(const slot_type& s) { m_slotExit = s; }
|
||||
|
||||
void mark_dirty();
|
||||
|
||||
protected:
|
||||
display::Frame* m_frame;
|
||||
bool m_focus;
|
||||
|
||||
@@ -72,6 +72,7 @@ ElementDownloadList::ElementDownloadList() :
|
||||
|
||||
m_bindings['+'] = sigc::mem_fun(*this, &ElementDownloadList::receive_next_priority);
|
||||
m_bindings['-'] = sigc::mem_fun(*this, &ElementDownloadList::receive_prev_priority);
|
||||
m_bindings['T'-'@']= sigc::mem_fun(*this, &ElementDownloadList::receive_cycle_throttle);
|
||||
m_bindings['I'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command),
|
||||
"branch=d.get_ignore_commands=,"
|
||||
"{d.set_ignore_commands=0, print=\"Torrent set to heed commands.\"},"
|
||||
@@ -185,6 +186,27 @@ ElementDownloadList::receive_prev_priority() {
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
|
||||
void
|
||||
ElementDownloadList::receive_cycle_throttle() {
|
||||
if (m_view->focus() == m_view->end_visible())
|
||||
return;
|
||||
|
||||
core::Download* download = *m_view->focus();
|
||||
if (download->is_active()) {
|
||||
control->core()->push_log("Cannot change throttle on active download.");
|
||||
return;
|
||||
}
|
||||
|
||||
core::ThrottleMap::const_iterator itr = control->core()->throttles().find(download->bencode()->get_key("rtorrent").get_key_string("throttle_name"));
|
||||
if (itr == control->core()->throttles().end())
|
||||
itr = control->core()->throttles().begin();
|
||||
else
|
||||
++itr;
|
||||
|
||||
download->set_throttle_name(itr == control->core()->throttles().end() ? std::string() : itr->first);
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
|
||||
void
|
||||
ElementDownloadList::receive_change_view(const std::string& name) {
|
||||
core::ViewManager::iterator itr = control->view_manager()->find(name);
|
||||
|
||||
@@ -73,6 +73,8 @@ public:
|
||||
void receive_next_priority();
|
||||
void receive_prev_priority();
|
||||
|
||||
void receive_cycle_throttle();
|
||||
|
||||
void receive_change_view(const std::string& name);
|
||||
|
||||
private:
|
||||
|
||||
+27
-46
@@ -120,59 +120,40 @@ Root::cleanup() {
|
||||
m_control = NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
Root::get_throttle_keys() {
|
||||
const std::string& keyLayout = rpc::call_command_string("get_key_layout");
|
||||
|
||||
if (strcasecmp(keyLayout.c_str(), "azerty") == 0)
|
||||
return "qwQWsxSXdcDC";
|
||||
else if (strcasecmp(keyLayout.c_str(), "qwertz") == 0)
|
||||
return "ayAYsxSXdcDC";
|
||||
else if (strcasecmp(keyLayout.c_str(), "dvorak") == 0)
|
||||
return "a;A:oqOQejEJ";
|
||||
else
|
||||
return "azAZsxSXdcDC";
|
||||
}
|
||||
|
||||
void
|
||||
Root::setup_keys() {
|
||||
m_control->input()->push_back(&m_bindings);
|
||||
|
||||
const std::string& keyLayout = rpc::call_command_string("get_key_layout");
|
||||
const char* keys = get_throttle_keys();
|
||||
|
||||
if (strcasecmp(keyLayout.c_str(), "azerty") == 0) {
|
||||
m_bindings['q'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1);
|
||||
m_bindings['w'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -1);
|
||||
m_bindings['Q'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 1);
|
||||
m_bindings['W'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -1);
|
||||
m_bindings[keys[ 0]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1);
|
||||
m_bindings[keys[ 1]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -1);
|
||||
m_bindings[keys[ 2]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 1);
|
||||
m_bindings[keys[ 3]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -1);
|
||||
|
||||
} else if (strcasecmp(keyLayout.c_str(), "qwertz") == 0) {
|
||||
m_bindings['a'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1);
|
||||
m_bindings['y'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -1);
|
||||
m_bindings['A'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 1);
|
||||
m_bindings['Y'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -1);
|
||||
m_bindings[keys[ 4]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 5);
|
||||
m_bindings[keys[ 5]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -5);
|
||||
m_bindings[keys[ 6]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 5);
|
||||
m_bindings[keys[ 7]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -5);
|
||||
|
||||
} else if (strcasecmp(keyLayout.c_str(), "dvorak") == 0) {
|
||||
m_bindings['a'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1);
|
||||
m_bindings[';'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -1);
|
||||
m_bindings['A'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 1);
|
||||
m_bindings[':'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -1);
|
||||
|
||||
} else {
|
||||
m_bindings['a'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1);
|
||||
m_bindings['z'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -1);
|
||||
m_bindings['A'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 1);
|
||||
m_bindings['Z'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -1);
|
||||
}
|
||||
|
||||
if (strcasecmp(keyLayout.c_str(), "dvorak") != 0) {
|
||||
m_bindings['s'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 5);
|
||||
m_bindings['x'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -5);
|
||||
m_bindings['S'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 5);
|
||||
m_bindings['X'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -5);
|
||||
|
||||
m_bindings['d'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 50);
|
||||
m_bindings['c'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -50);
|
||||
m_bindings['D'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 50);
|
||||
m_bindings['C'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -50);
|
||||
|
||||
} else {
|
||||
m_bindings['o'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 5);
|
||||
m_bindings['q'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -5);
|
||||
m_bindings['O'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 5);
|
||||
m_bindings['Q'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -5);
|
||||
|
||||
m_bindings['e'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 50);
|
||||
m_bindings['j'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -50);
|
||||
m_bindings['E'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 50);
|
||||
m_bindings['J'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -50);
|
||||
}
|
||||
m_bindings[keys[ 8]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 50);
|
||||
m_bindings[keys[ 9]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), -50);
|
||||
m_bindings[keys[10]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), 50);
|
||||
m_bindings[keys[11]] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_down_throttle), -50);
|
||||
|
||||
m_bindings['\x0C'] = sigc::mem_fun(m_control->display(), &display::Manager::force_redraw); // ^L
|
||||
m_bindings['\x11'] = sigc::mem_fun(m_control, &Control::receive_normal_shutdown); // ^Q
|
||||
|
||||
@@ -86,6 +86,8 @@ public:
|
||||
void adjust_down_throttle(int throttle);
|
||||
void adjust_up_throttle(int throttle);
|
||||
|
||||
const char* get_throttle_keys();
|
||||
|
||||
void enable_input(const std::string& title, input::TextInput* input);
|
||||
void disable_input();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user