-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added commands to update choke queue.
- Loading branch information
Showing
2 changed files
with
61 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,9 @@ | ||
// rTorrent - BitTorrent client | ||
// Copyright (C) 2005-2011, 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 <[email protected]> | ||
// | ||
// Skomakerveien 33 | ||
// 3185 Skoppum, NORWAY | ||
|
||
#include "config.h" | ||
|
||
#include <torrent/download/resource_manager.h> | ||
#include <torrent/download/choke_group.h> | ||
#include <torrent/download/choke_queue.h> | ||
#include <torrent/utils/log.h> | ||
#include <torrent/utils/option_strings.h> | ||
|
||
#include "ui/root.h" | ||
|
@@ -52,6 +17,9 @@ | |
// For cg_d_group. | ||
#include "core/download.h" | ||
|
||
#define LT_LOG_SUBSYSTEM(log_fmt, ...) \ | ||
lt_log_print_subsystem(torrent::LOG_TORRENT_INFO, "choke_queue", log_fmt, __VA_ARGS__); | ||
|
||
// A hack to allow testing of the new choke_group API without the | ||
// working parts present. | ||
#define USE_CHOKE_GROUP 0 | ||
|
@@ -122,6 +90,22 @@ apply_cg_insert(const std::string& arg) { | |
return torrent::Object(); | ||
} | ||
|
||
torrent::Object | ||
apply_cg_all_update_balance(bool is_up) { | ||
LT_LOG_SUBSYSTEM("apply update balance: resource_manager is_up:%i", (int)is_up); | ||
|
||
for (torrent::ResourceManager::group_iterator | ||
itr = torrent::resource_manager()->group_begin(), | ||
last = torrent::resource_manager()->group_end(); itr != last; itr++) { | ||
if (is_up) | ||
itr->up_queue()->balance(); | ||
else | ||
itr->down_queue()->balance(); | ||
} | ||
|
||
return torrent::Object(); | ||
} | ||
|
||
// | ||
// The hacked version: | ||
// | ||
|
@@ -182,6 +166,11 @@ apply_cg_list() { | |
return torrent::Object::from_list(result); | ||
} | ||
|
||
int | ||
cg_get_can_unchoke(torrent::choke_queue* cq) { | ||
return cq->max_unchoked_signed() - (int)cq->size_unchoked(); | ||
} | ||
|
||
torrent::Object | ||
apply_cg_insert(const std::string& arg) { | ||
int64_t dummy; | ||
|
@@ -214,6 +203,20 @@ apply_cg_index_of(const std::string& arg) { | |
return std::distance(cg_list_hack.begin(), itr); | ||
} | ||
|
||
torrent::Object | ||
apply_cg_all_update_balance(bool is_up) { | ||
LT_LOG_SUBSYSTEM("apply update balance: hack is_up:%i", (int)is_up); | ||
|
||
for (auto itr : cg_list_hack) { | ||
if (is_up) | ||
itr->up_queue()->balance(); | ||
else | ||
itr->down_queue()->balance(); | ||
} | ||
|
||
return torrent::Object(); | ||
} | ||
|
||
// | ||
// End of choke group hack. | ||
// | ||
|
@@ -356,6 +359,9 @@ initialize_command_groups() { | |
std::bind(&torrent::choke_group::tracker_mode, CG_GROUP_AT()))); | ||
CMD2_ANY_LIST ("choke_group.tracker.mode.set", std::bind(&apply_cg_tracker_mode_set, std::placeholders::_2)); | ||
|
||
CMD2_ANY ("choke_group.all.up.update_balance", std::bind(&apply_cg_all_update_balance, true)); | ||
CMD2_ANY ("choke_group.all.down.update_balance", std::bind(&apply_cg_all_update_balance, false)); | ||
|
||
CMD2_ANY ("choke_group.up.rate", std::bind(&torrent::choke_group::up_rate, CG_GROUP_AT())); | ||
CMD2_ANY ("choke_group.down.rate", std::bind(&torrent::choke_group::down_rate, CG_GROUP_AT())); | ||
|
||
|