diff options
author | Sebastian Hahn <sebastian@torproject.org> | 2009-08-16 22:21:11 +0200 |
---|---|---|
committer | Sebastian Hahn <sebastian@torproject.org> | 2009-08-25 20:10:54 +0200 |
commit | 4c383af36602612be745764463dd76fee17ae205 (patch) | |
tree | 0986176d08d51c17d83d387fdacd8ee23e8f13c4 /lib/thandy/ClientCLI.py | |
parent | aa0d32f4b675e155e6e004604bf8b6ee4e607873 (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/ClientCLI.py')
-rw-r--r-- | lib/thandy/ClientCLI.py | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/lib/thandy/ClientCLI.py b/lib/thandy/ClientCLI.py index 73c96df..bcbdfc7 100644 --- a/lib/thandy/ClientCLI.py +++ b/lib/thandy/ClientCLI.py @@ -68,7 +68,8 @@ def update(args): options, args = getopt.getopt(args, "", [ "repo=", "no-download", "loop", "no-packagesys", "install", "socks-port=", "debug", "info", - "warn", "force-check", "controller-log-format" + "warn", "force-check", "controller-log-format", + "download-method=" ]) download = True keep_looping = False @@ -76,6 +77,7 @@ def update(args): install = False socksPort = None forceCheck = False + downloadMethod = "direct" for o, v in options: if o == '--repo': @@ -92,12 +94,20 @@ def update(args): socksPort = int(v) elif o == '--force-check': forceCheck = True + elif o == '--download-method': + downloadMethod = v configureLogs(options) if socksPort: thandy.socksurls.setSocksProxy("127.0.0.1", socksPort) + if downloadMethod == "bittorrent": + thandy.bt_compat.BtCompat.setUseBt(True) + elif downloadMethod != "direct": + usage() + sys.exit() + repo = thandy.repository.LocalRepository(repoRoot) downloader = thandy.download.DownloadManager() downloader.start() @@ -109,11 +119,15 @@ def update(args): hashes = {} lengths = {} installable = {} + btMetadata = {} logging.info("Checking for files to update.") - files = repo.getFilesToUpdate(trackingBundles=args, hashDict=hashes, - lengthDict=lengths, - usePackageSystem=use_packagesys, - installableDict=installable) + files, downloadingFiles = repo.getFilesToUpdate( + trackingBundles=args, + hashDict=hashes, + lengthDict=lengths, + usePackageSystem=use_packagesys, + installableDict=installable, + btMetadataDict=btMetadata) if forceCheck: files.add("/meta/timestamp.txt") @@ -183,13 +197,23 @@ def update(args): logging.info("Waiting a while before we fetch %s", f) continue - dj = thandy.download.ThandyDownloadJob( - f, repo.getFilename(f), - mirrorlist, - wantHash=hashes.get(f), - wantLength=lengths.get(f), - repoFile=repo.getRequestedFile(f), - useTor=(socksPort!=None)) + dj = None + if thandy.bt_compat.BtCompat.shouldUseBt() and downloadingFiles: + dj = thandy.download.ThandyBittorrentDownloadJob( + repo.getFilename(btMetadata[f]), f, + repo.getFilename(f), + wantHash=hashes.get(f), + wantLength=lengths.get(f), + repoFile=repo.getRequestedFile(f)) + + else: + dj = thandy.download.ThandyDownloadJob( + f, repo.getFilename(f), + mirrorlist, + wantHash=hashes.get(f), + wantLength=lengths.get(f), + repoFile=repo.getRequestedFile(f), + useTor=(socksPort!=None)) def successCb(rp=f): rf = repo.getRequestedFile(rp) @@ -219,6 +243,7 @@ def usage(): print " [--no-packagesys] [--install] [--socks-port=port]" print " [--debug|--info|--warn] [--force-check]" print " [--controller-log-format]" + print " [--download-method=direct|bittorrent]" print " bundle1, bundle2, ..." print " json2xml file" sys.exit(1) |