Added per torrent max connections and max upload slots preferences.

This commit is contained in:
Alex Dedul 2007-08-08 19:59:46 +00:00
parent b9a5b1c7a3
commit 758b5d8851
7 changed files with 647 additions and 519 deletions

File diff suppressed because it is too large Load Diff

View File

@ -33,11 +33,13 @@ LOCATION_KEYS = [
"auto_end_seeding",
"auto_seed_ratio",
"end_seed_ratio",
"max_connections",
"max_connections_global",
"max_connections_per_torrent",
"max_download_rate",
"max_download_rate_bps",
"max_number_downloads",
"max_number_uploads",
"max_upload_slots_global",
"max_upload_slots_per_torrent",
"max_upload_rate",
"max_upload_rate_bps",
"max_uploads",

View File

@ -69,9 +69,9 @@ DHT_FILENAME = "dht.state"
PREF_FUNCTIONS = {
"listen_on" : deluge_core.set_listen_on,
"max_connections" : deluge_core.set_max_connections,
"max_connections_global" : deluge_core.set_max_connections_global,
"max_active_torrents" : None, # no need for a function, applied constantly
"max_number_uploads" : deluge_core.set_max_uploads,
"max_upload_slots_global" : deluge_core.set_max_upload_slots_global,
"auto_seed_ratio" : None, # no need for a function, applied constantly
"max_download_speed_bps" : deluge_core.set_download_rate_limit,
"max_upload_speed_bps" : deluge_core.set_upload_rate_limit,
@ -903,10 +903,14 @@ class Manager:
else:
PREF_FUNCTIONS[pref](self.get_pref(pref))
# We need to reapply priorities to files after preferences were
# changed
# We need to reapply priorities to files and per torrent options after
# preferences were changed.
for unique_ID in self.unique_IDs:
self.prioritize_files(unique_ID, self.get_priorities(unique_ID))
self.set_max_connections_per_torrent(unique_ID,
self.get_pref("max_connections_per_torrent"))
self.set_max_upload_slots_per_torrent(unique_ID,
self.get_pref("max_upload_slots_per_torrent"))
def set_DHT(self, start=False):
if start == True and self.dht_running != True:
@ -957,12 +961,17 @@ class Manager:
def replace_trackers(self, unique_ID, trackers):
return deluge_core.replace_trackers(unique_ID, trackers)
def set_flp(self, unique_ID, num):
return deluge_core.set_flp(unique_ID, int(num))
def set_priv(self, unique_ID, on_off):
return deluge_core.set_priv(unique_ID, on_off)
def set_max_connections_per_torrent(self, unique_ID, max_connections):
return deluge_core.set_max_connections_per_torrent(unique_ID,
max_connections)
def set_max_upload_slots_per_torrent(self, unique_ID, max_upload_slots):
return deluge_core.set_max_upload_slots_per_torrent(unique_ID,
max_upload_slots)
def set_per_upload_rate_limit(self, unique_ID, speed):
if speed != -1:
speed = speed * 1024

View File

@ -551,7 +551,7 @@ static PyObject *torrent_listening_port(PyObject *self, PyObject *args)
}
static PyObject *torrent_set_max_uploads(PyObject *self, PyObject *args)
static PyObject *torrent_set_max_upload_slots_global(PyObject *self, PyObject *args)
{
python_long max_up;
if (!PyArg_ParseTuple(args, "i", &max_up))
@ -563,7 +563,7 @@ static PyObject *torrent_set_max_uploads(PyObject *self, PyObject *args)
}
static PyObject *torrent_set_max_connections(PyObject *self, PyObject *args)
static PyObject *torrent_set_max_connections_global(PyObject *self, PyObject *args)
{
python_long max_conn;
if (!PyArg_ParseTuple(args, "i", &max_conn))
@ -1720,28 +1720,6 @@ static PyObject *torrent_replace_trackers(PyObject *self, PyObject *args)
h.force_reannounce();
return Py_None;
}
static PyObject *torrent_set_flp(PyObject *self, PyObject *args)
{
python_long unique_ID;
int num;
if (!PyArg_ParseTuple(args, "ii", &unique_ID, &num))
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
torrent_t &t = M_torrents->at(index);
torrent_status s = t.handle.status();
const torrent_info &i = t.handle.get_torrent_info();
int npieces = i.num_pieces() - 1;
t.handle.piece_priority(0, num);
t.handle.piece_priority(npieces, num);
return Py_None;
}
static PyObject *torrent_prioritize_files(PyObject *self, PyObject *args)
{
python_long unique_ID;
@ -1883,65 +1861,98 @@ static PyObject *torrent_set_priv(PyObject *self, PyObject *args)
return Py_None;
}
static PyObject *torrent_set_max_connections_per_torrent(PyObject *self, PyObject *args)
{
python_long unique_ID, max_connections;
if (!PyArg_ParseTuple(args, "ii", &unique_ID, &max_connections))
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
torrent_t &t = M_torrents->at(index);
t.handle.set_max_connections(max_connections);
return Py_None;
}
static PyObject *torrent_set_max_upload_slots_per_torrent(PyObject *self, PyObject *args)
{
python_long unique_ID, max_upload_slots;
if (!PyArg_ParseTuple(args, "ii", &unique_ID, &max_upload_slots))
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
torrent_t &t = M_torrents->at(index);
t.handle.set_max_uploads(max_upload_slots);
return Py_None;
}
//====================
// Python Module data
//====================
static PyMethodDef deluge_core_methods[] =
{
{"pe_settings", torrent_pe_settings, METH_VARARGS, "."},
{"pre_init", torrent_pre_init, METH_VARARGS, "."},
{"init", torrent_init, METH_VARARGS, "."},
{"quit", torrent_quit, METH_VARARGS, "."},
{"save_fastresume", torrent_save_fastresume, METH_VARARGS, "."},
{"set_max_half_open", torrent_set_max_half_open, METH_VARARGS, "."},
{"set_download_rate_limit", torrent_set_download_rate_limit, METH_VARARGS, "."},
{"set_upload_rate_limit", torrent_set_upload_rate_limit, METH_VARARGS, "."},
{"set_per_upload_rate_limit", torrent_set_per_upload_rate_limit, METH_VARARGS, "."},
{"set_per_download_rate_limit", torrent_set_per_download_rate_limit, METH_VARARGS, "."},
{"set_listen_on", torrent_set_listen_on, METH_VARARGS, "."},
{"is_listening", torrent_is_listening, METH_VARARGS, "."},
{"listening_port", torrent_listening_port, METH_VARARGS, "."},
{"set_max_uploads", torrent_set_max_uploads, METH_VARARGS, "."},
{"set_max_connections", torrent_set_max_connections, METH_VARARGS, "."},
{"add_torrent", torrent_add_torrent, METH_VARARGS, "."},
{"move_storage", torrent_move_storage, METH_VARARGS, "."},
{"remove_torrent", torrent_remove_torrent, METH_VARARGS, "."},
{"get_num_torrents", torrent_get_num_torrents, METH_VARARGS, "."},
{"reannounce", torrent_reannounce, METH_VARARGS, "."},
{"pause", torrent_pause, METH_VARARGS, "."},
{"resume", torrent_resume, METH_VARARGS, "."},
{"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."},
{"pop_event", torrent_pop_event, METH_VARARGS, "."},
{"get_session_info", torrent_get_session_info, METH_VARARGS, "."},
{"get_peer_info", torrent_get_peer_info, METH_VARARGS, "."},
{"get_file_info", torrent_get_file_info, METH_VARARGS, "."},
{"dump_file_info", torrent_dump_file_info, METH_VARARGS, "."},
{"constants", torrent_constants, METH_VARARGS, "."},
{"start_DHT", torrent_start_DHT, METH_VARARGS, "."},
{"stop_DHT", torrent_stop_DHT, METH_VARARGS, "."},
{"get_DHT_info", torrent_get_DHT_info, METH_VARARGS, "."},
{"create_torrent", torrent_create_torrent, METH_VARARGS, "."},
{"reset_IP_filter", torrent_reset_IP_filter, METH_VARARGS, "."},
{"add_range_to_IP_filter", torrent_add_range_to_IP_filter, METH_VARARGS, "."},
{"set_IP_filter", torrent_set_IP_filter, METH_VARARGS, "."},
{"use_upnp", torrent_use_upnp, METH_VARARGS, "."},
{"use_natpmp", torrent_use_natpmp, METH_VARARGS, "."},
{"use_utpex", torrent_use_utpex, METH_VARARGS, "."},
{"set_ratio", torrent_set_ratio, METH_VARARGS, "."},
{"proxy_settings", torrent_proxy_settings, METH_VARARGS, "."},
{"get_trackers", torrent_get_trackers, METH_VARARGS, "."},
{"dump_trackers", torrent_dump_trackers, METH_VARARGS, "."},
{"replace_trackers", torrent_replace_trackers, METH_VARARGS, "."},
{"set_flp", torrent_set_flp, METH_VARARGS, "."},
{"prioritize_files", torrent_prioritize_files, METH_VARARGS, "."},
{"prioritize_first_last_pieces", torrent_prioritize_first_last_pieces, METH_VARARGS, "."},
{"set_priv", torrent_set_priv, METH_VARARGS, "."},
{"test_duplicate", torrent_test_duplicate, METH_VARARGS, "."},
{"has_piece", torrent_has_piece, METH_VARARGS, "."},
{"get_piece_info", torrent_get_piece_info, METH_VARARGS, "."},
{"get_all_piece_info", torrent_get_all_piece_info, METH_VARARGS, "."},
{"get_file_piece_range", torrent_get_file_piece_range, METH_VARARGS, "."},
{"pe_settings", torrent_pe_settings, METH_VARARGS, "."},
{"pre_init", torrent_pre_init, METH_VARARGS, "."},
{"init", torrent_init, METH_VARARGS, "."},
{"quit", torrent_quit, METH_VARARGS, "."},
{"save_fastresume", torrent_save_fastresume, METH_VARARGS, "."},
{"set_max_half_open", torrent_set_max_half_open, METH_VARARGS, "."},
{"set_download_rate_limit", torrent_set_download_rate_limit, METH_VARARGS, "."},
{"set_upload_rate_limit", torrent_set_upload_rate_limit, METH_VARARGS, "."},
{"set_per_upload_rate_limit", torrent_set_per_upload_rate_limit, METH_VARARGS, "."},
{"set_per_download_rate_limit", torrent_set_per_download_rate_limit, METH_VARARGS, "."},
{"set_listen_on", torrent_set_listen_on, METH_VARARGS, "."},
{"is_listening", torrent_is_listening, METH_VARARGS, "."},
{"listening_port", torrent_listening_port, METH_VARARGS, "."},
{"set_max_upload_slots_global", torrent_set_max_upload_slots_global, METH_VARARGS, "."},
{"set_max_upload_slots_per_torrent",torrent_set_max_upload_slots_per_torrent, METH_VARARGS, "."},
{"set_max_connections_global", torrent_set_max_connections_global, METH_VARARGS, "."},
{"set_max_connections_per_torrent", torrent_set_max_connections_per_torrent, METH_VARARGS, "."},
{"add_torrent", torrent_add_torrent, METH_VARARGS, "."},
{"move_storage", torrent_move_storage, METH_VARARGS, "."},
{"remove_torrent", torrent_remove_torrent, METH_VARARGS, "."},
{"get_num_torrents", torrent_get_num_torrents, METH_VARARGS, "."},
{"reannounce", torrent_reannounce, METH_VARARGS, "."},
{"pause", torrent_pause, METH_VARARGS, "."},
{"resume", torrent_resume, METH_VARARGS, "."},
{"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."},
{"pop_event", torrent_pop_event, METH_VARARGS, "."},
{"get_session_info", torrent_get_session_info, METH_VARARGS, "."},
{"get_peer_info", torrent_get_peer_info, METH_VARARGS, "."},
{"get_file_info", torrent_get_file_info, METH_VARARGS, "."},
{"dump_file_info", torrent_dump_file_info, METH_VARARGS, "."},
{"constants", torrent_constants, METH_VARARGS, "."},
{"start_DHT", torrent_start_DHT, METH_VARARGS, "."},
{"stop_DHT", torrent_stop_DHT, METH_VARARGS, "."},
{"get_DHT_info", torrent_get_DHT_info, METH_VARARGS, "."},
{"create_torrent", torrent_create_torrent, METH_VARARGS, "."},
{"reset_IP_filter", torrent_reset_IP_filter, METH_VARARGS, "."},
{"add_range_to_IP_filter", torrent_add_range_to_IP_filter, METH_VARARGS, "."},
{"set_IP_filter", torrent_set_IP_filter, METH_VARARGS, "."},
{"use_upnp", torrent_use_upnp, METH_VARARGS, "."},
{"use_natpmp", torrent_use_natpmp, METH_VARARGS, "."},
{"use_utpex", torrent_use_utpex, METH_VARARGS, "."},
{"set_ratio", torrent_set_ratio, METH_VARARGS, "."},
{"proxy_settings", torrent_proxy_settings, METH_VARARGS, "."},
{"get_trackers", torrent_get_trackers, METH_VARARGS, "."},
{"dump_trackers", torrent_dump_trackers, METH_VARARGS, "."},
{"replace_trackers", torrent_replace_trackers, METH_VARARGS, "."},
{"prioritize_files", torrent_prioritize_files, METH_VARARGS, "."},
{"prioritize_first_last_pieces", torrent_prioritize_first_last_pieces, METH_VARARGS, "."},
{"set_priv", torrent_set_priv, METH_VARARGS, "."},
{"test_duplicate", torrent_test_duplicate, METH_VARARGS, "."},
{"has_piece", torrent_has_piece, METH_VARARGS, "."},
{"get_piece_info", torrent_get_piece_info, METH_VARARGS, "."},
{"get_all_piece_info", torrent_get_all_piece_info, METH_VARARGS, "."},
{"get_file_piece_range", torrent_get_file_piece_range, METH_VARARGS, "."},
{NULL}
};

View File

@ -95,9 +95,11 @@ class PreferencesDlg:
self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on")[0])
self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on")[1])
self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_speed"))
self.glade.get_widget("spin_num_upload").set_value(float(self.preferences.get("max_number_uploads")))
self.glade.get_widget("spin_max_upload_slots_global").set_value(float(self.preferences.get("max_upload_slots_global")))
self.glade.get_widget("spin_max_upload_slots_per_torrent").set_value(float(self.preferences.get("max_upload_slots_per_torrent")))
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_speed"))
self.glade.get_widget("spin_max_connections").set_value(self.preferences.get("max_connections"))
self.glade.get_widget("spin_max_connections_global").set_value(self.preferences.get("max_connections_global"))
self.glade.get_widget("spin_max_connections_per_torrent").set_value(self.preferences.get("max_connections_per_torrent"))
self.glade.get_widget("spin_peer_proxy_port").set_value(self.preferences.get("peer_proxy_port"))
self.glade.get_widget("spin_tracker_proxy_port").set_value(self.preferences.get("tracker_proxy_port"))
self.glade.get_widget("spin_dht_proxy_port").set_value(self.preferences.get("dht_proxy_port"))
@ -199,13 +201,15 @@ class PreferencesDlg:
self.preferences.set("use_compact_storage", self.glade.get_widget("chk_compact").get_active())
self.preferences.set("listen_on", [self.glade.get_widget("spin_port_min").get_value(), self.glade.get_widget("spin_port_max").get_value()])
self.preferences.set("max_upload_speed", self.glade.get_widget("spin_max_upload").get_value())
self.preferences.set("max_number_uploads", int(self.glade.get_widget("spin_num_upload").get_value()))
self.preferences.set("max_upload_slots_global", int(self.glade.get_widget("spin_max_upload_slots_global").get_value()))
self.preferences.set("max_upload_slots_per_torrent", int(self.glade.get_widget("spin_max_upload_slots_per_torrent").get_value()))
self.preferences.set("max_download_speed", self.glade.get_widget("spin_max_download").get_value())
self.preferences.set("peer_proxy_port", self.glade.get_widget("spin_peer_proxy_port").get_value())
self.preferences.set("dht_proxy_port", self.glade.get_widget("spin_dht_proxy_port").get_value())
self.preferences.set("web_proxy_port", self.glade.get_widget("spin_web_proxy_port").get_value())
self.preferences.set("tracker_proxy_port", self.glade.get_widget("spin_tracker_proxy_port").get_value())
self.preferences.set("max_connections", int(self.glade.get_widget("spin_max_connections").get_value()))
self.preferences.set("max_connections_global", int(self.glade.get_widget("spin_max_connections_global").get_value()))
self.preferences.set("max_connections_per_torrent", int(self.glade.get_widget("spin_max_connections_per_torrent").get_value()))
self.preferences.set("max_active_torrents", int(self.glade.get_widget("spin_torrents").get_value()))
self.preferences.set("queue_seeds_to_bottom", self.glade.get_widget("chk_seedbottom").get_active())
self.preferences.set("enable_dht", self.glade.get_widget("chk_dht").get_active())

View File

@ -943,10 +943,10 @@ class DelugeGTK:
def update_statusbar_and_tray(self):
core_state = self.manager.get_state()
connections = core_state['num_peers']
if self.config.get("max_connections") < 0 :
if self.config.get("max_connections_global") < 0 :
max_connections = _("Unlimited")
else:
max_connections = int(self.config.get("max_connections"))
max_connections = int(self.config.get("max_connections_global"))
dlspeed = common.fspeed(core_state['download_rate'])
ulspeed = common.fspeed(core_state['upload_rate'])
dltotal = common.fsize(core_state['total_downloaded'])

View File

@ -62,10 +62,12 @@ DEFAULT_PREFS = {
"listen_on" : [6881,6889],
"lock_tray" : False,
"max_active_torrents" : 8,
"max_connections" : 200,
"max_connections_global" : 200,
"max_connections_per_torrent" : -1,
"max_download_speed" : -1,
"max_download_speed_bps": -1,
"max_number_uploads" : 10,
"max_upload_slots_global" : 15,
"max_upload_slots_per_torrent" : -1,
"max_upload_speed" : -1,
"max_upload_speed_bps" : -1,
"pref_rc4" : True,