summaryrefslogtreecommitdiff
path: root/lib/thandy/download.py
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2009-08-16 22:21:11 +0200
committerSebastian Hahn <sebastian@torproject.org>2009-08-25 20:10:54 +0200
commit4c383af36602612be745764463dd76fee17ae205 (patch)
tree0986176d08d51c17d83d387fdacd8ee23e8f13c4 /lib/thandy/download.py
parentaa0d32f4b675e155e6e004604bf8b6ee4e607873 (diff)
Add the ability to download files via BitTorrent
The Client has learned a new option, --download-method, too specify whether we're downloading directly or via BitTorrent. This implementation has a few remaining issues, the biggest one is that seeding isn't implemented at all (when the download stops, Thandy stops sharing). Failure to download due to no available peers also doesn't work.
Diffstat (limited to 'lib/thandy/download.py')
-rw-r--r--lib/thandy/download.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/thandy/download.py b/lib/thandy/download.py
index fb1b9f3..8e774ec 100644
--- a/lib/thandy/download.py
+++ b/lib/thandy/download.py
@@ -634,6 +634,53 @@ class ThandyDownloadJob(DownloadJob):
def getMirror(self):
return self._usingMirror
+class ThandyBittorrentDownloadJob(DownloadJob):
+ """Thandy's subtype of DownloadJob with BitTorrent support. Makes sure the
+ file downloaded via BitTorrent is the file we wanted, and moves
+ it into the right place.
+ """
+ def __init__(self, metaFile, relPath, destPath, wantHash=None,
+ supportedURLTypes=None, useTor=None, repoFile=None,
+ downloadStatusLog=None, wantLength=None):
+
+ DownloadJob.__init__(self, destPath, None, wantHash=wantHash,
+ wantLength=wantLength,
+ useTor=useTor, repoFile=repoFile)
+ self._relPath = relPath
+ self._metaFile = metaFile
+
+ tmppath = thandy.util.userFilename("tmp")
+ if relPath.startswith("/"):
+ relPath = relPath[1:]
+ self._tmpPath = os.path.join(tmppath, relPath)
+
+ d = os.path.dirname(self._tmpPath)
+ if not os.path.exists(d):
+ os.makedirs(d, 0700)
+
+ self._downloadStatusLog = downloadStatusLog
+
+ def setDownloadStatusLog(self, log):
+ self._downloadStatusLog = log
+
+ def getRelativePath(self):
+ return self._relPath
+
+ def _download(self):
+
+ btcomp = thandy.bt_compat.BtCompat()
+ btcomp.download(self._metaFile, self._tmpPath)
+
+ try:
+ self._checkTmpFile()
+ except (thandy.FormatException, thandy.DownloadError), err:
+ self._removeTmpFile()
+ if haveStalled:
+ raise BadCompoundData(err)
+ else:
+ raise
+ thandy.util.ensureParentDir(self._destPath)
+ thandy.util.moveFile(self._tmpPath, self._destPath)
_socks_opener = thandy.socksurls.build_socks_opener()