[Core] Move add tracker merge into Torrent method

This commit is contained in:
Calum Lind 2015-10-01 19:15:02 +01:00
parent 50200326a9
commit cb8e9d3018
2 changed files with 16 additions and 10 deletions

View File

@ -591,6 +591,20 @@ class Torrent(object):
"""
self.tracker_status = status
def merge_trackers(self, torrent_info):
"""Merges new trackers in torrent_info into torrent"""
log.info("Adding any new trackers to torrent (%s) already in session...", self.torrent_id)
if not torrent_info:
return
# Don't merge trackers if either torrent has private flag set.
if torrent_info.priv() or self.get_status(["private"])["private"]:
log.info("Adding trackers aborted: Torrent has private flag set.")
else:
for tracker in torrent_info.trackers():
self.handle.add_tracker({"url": tracker.url, "tier": tracker.tier})
# Update torrent.trackers from libtorrent handle.
self.set_trackers()
def update_state(self):
"""Updates the state, based on libtorrent's torrent state"""
status = self.handle.status()

View File

@ -337,16 +337,8 @@ class TorrentManager(component.Component):
# Check for existing torrent in session.
if torrent_id in self.get_torrent_list():
log.warning("Unable to add torrent (%s), already in session", torrent_id)
if torrent_info:
log.info("Adding any new trackers to torrent (%s) already in session...", torrent_id)
# Don't merge trackers if either torrent has private flag set.
if torrent_info.priv() or self[torrent_id].get_status(["private"])["private"]:
log.info("Adding trackers aborted: Torrent has private flag set.")
else:
for tracker in torrent_info.trackers():
self[torrent_id].handle.add_tracker({"url": tracker.url, "tier": tracker.tier})
# Update torrent.trackers from lt.
self[torrent_id].set_trackers()
# Attempt merge trackers before returning.
self.torrents[torrent_id].merge_trackers(torrent_info)
return
# Load default options and update if needed.