Skip to content

Commit ff6eaf5

Browse files
committed
do a live check to validate throttle names (closes #53)
1 parent 4ed6b4a commit ff6eaf5

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

debian/changelog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
pyrocore (0.5.3) precise; urgency=medium
22

3+
* issue#53: Use a live check to validate throttle names
34
* issue#52: Fixed version detection when installed from PyPI
45
* Include install path and Python release in version info
56

6-
-- pyroscope <[email protected]> Sun, 11 Jun 2017 11:50:19 +0200
7+
-- pyroscope <[email protected]> Sun, 11 Jun 2017 14:17:47 +0200
78

89
pyrocore (0.5.2) precise; urgency=high
910

src/pyrocore/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def map_announce2alias(url):
6868
scgi_local = ""
6969
scgi_port = ""
7070
scgi_url = ""
71-
throttle_names = set(("NONE", "NULL"))
7271
engine = Bunch(open=lambda: None)
7372
fast_query = 0
7473
formats = {}

src/pyrocore/torrent/rtorrent.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,13 @@ def set_throttle(self, name):
289289
if name.lower() == "null":
290290
name = "NULL"
291291
if name.lower() == "none":
292-
name = ""
292+
name = ''
293293

294-
if (name or "NONE") not in config.throttle_names:
295-
raise error.UserError("Unknown throttle name %r" % (name or "NONE",))
294+
if name not in self._engine.known_throttle_names:
295+
if self._engine._rpc.throttle.up.max(xmlrpc.NOHASH, name) == -1:
296+
if self._engine._rpc.throttle.down.max(xmlrpc.NOHASH, name) == -1:
297+
raise error.UserError("Unknown throttle name '{}'".format(name))
298+
self._engine.known_throttle_names.add(name)
296299

297300
if (name or "NONE") == self.throttle:
298301
self._engine.LOG.debug("Keeping throttle %r on torrent #%s" % (self.throttle, self._fields["hash"]))
@@ -507,20 +510,14 @@ def flush(self):
507510
class RtorrentEngine(engine.TorrentEngine):
508511
""" The rTorrent backend proxy.
509512
"""
510-
# throttling config keys
511-
RTORRENT_RC_THROTTLE_KEYS = ("throttle_up", "throttle_down", "throttle_ip", )
512-
513513
# keys we read from rTorrent's configuration
514-
RTORRENT_RC_KEYS = ("scgi_local", "scgi_port", "log.execute") + RTORRENT_RC_THROTTLE_KEYS
514+
RTORRENT_RC_KEYS = ("scgi_local", "scgi_port", "log.execute")
515515

516516
# mapping from new to old commands, and thus our config keys
517517
RTORRENT_RC_ALIASES = {
518518
"network.scgi.open_local": "scgi_local",
519519
"network.scgi.open_port": "scgi_port",
520520
#"log.execute": "",
521-
"throttle.up": "throttle_up",
522-
"throttle.down": "throttle_down",
523-
"throttle.ip": "throttle_ip",
524521
}
525522

526523
# rTorrent names of fields that never change
@@ -572,6 +569,7 @@ def __init__(self):
572569
self._session_dir = None
573570
self._download_dir = None
574571
self._item_cache = {}
572+
self.known_throttle_names = {'', 'NULL'}
575573

576574

577575
def load_config(self, namespace=None, rcfile=None):
@@ -615,11 +613,7 @@ def cfgkey(key):
615613
key = self.RTORRENT_RC_ALIASES.get(key, key)
616614

617615
# Copy values we're interested in
618-
if key in self.RTORRENT_RC_THROTTLE_KEYS:
619-
val = val.split(',')[0].strip()
620-
self.LOG.debug("rtorrent.rc: added throttle %r" % (val,))
621-
namespace.throttle_names.add(val)
622-
elif key in self.RTORRENT_RC_KEYS and not getattr(namespace, cfgkey(key), None):
616+
if key in self.RTORRENT_RC_KEYS and not getattr(namespace, cfgkey(key), None):
623617
self.LOG.debug("rtorrent.rc: %s = %s" % (key, val))
624618
setattr(namespace, cfgkey(key), val)
625619

0 commit comments

Comments
 (0)