From a98376a2f79e96890f2216aa933cec2e88218a6e Mon Sep 17 00:00:00 2001 From: Elizabeth Fong Date: Thu, 17 Aug 2006 12:44:15 +0000 Subject: [PATCH] fix the Ice 404 and production 247,143,675,456 percent complete bugs; get bittorrent fully working --- .../getdown/launcher/HTTPDownloader.java | 11 +++++++ .../getdown/launcher/TorrentDownloader.java | 32 +++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/java/com/threerings/getdown/launcher/HTTPDownloader.java b/src/java/com/threerings/getdown/launcher/HTTPDownloader.java index ae6986f..e2d124c 100644 --- a/src/java/com/threerings/getdown/launcher/HTTPDownloader.java +++ b/src/java/com/threerings/getdown/launcher/HTTPDownloader.java @@ -20,6 +20,17 @@ public class HTTPDownloader extends Downloader super(resources, obs); } + /** + * A method of instantiating a downloader to take over the job partway. + */ + public HTTPDownloader (List resources, Observer obs, + long totalSize) + { + super(resources, obs); + _totalSize = totalSize; + _start = System.currentTimeMillis(); + } + /** * Issues a HEAD request for the specified resource and notes the * amount of data we will be downloading to account for it. diff --git a/src/java/com/threerings/getdown/launcher/TorrentDownloader.java b/src/java/com/threerings/getdown/launcher/TorrentDownloader.java index 79947d7..25a45e5 100644 --- a/src/java/com/threerings/getdown/launcher/TorrentDownloader.java +++ b/src/java/com/threerings/getdown/launcher/TorrentDownloader.java @@ -54,7 +54,7 @@ public class TorrentDownloader extends Downloader SnarkShutdown stopper = _stoppermap.get(rsrc); stopper.run(); Runtime.getRuntime().removeShutdownHook(stopper); - _fallback = new HTTPDownloader(_resources, _obs); + fallback(); if (_metaDownload && rsrc.getPath().equals("full")) { length = 0; } else { @@ -87,19 +87,39 @@ public class TorrentDownloader extends Downloader long now = System.currentTimeMillis(); if ((now - _lastUpdate) >= UPDATE_DELAY) { _currentSize = snark.coordinator.getDownloaded(); - if (_currentSize < SIZE_THRESHOLD && - (now - _start) >= TIME_THRESHOLD) { + if ((_currentSize < SIZE_THRESHOLD && + (now - _start) >= TIME_THRESHOLD) || + (_currentSize == 0 && + (now - _start) >= TIME_THRESHOLD / 4)) { + Log.info("Torrenting too slow, falling back to HTTP."); // The download isn't going as planned, abort; snarkStopper.run(); Runtime.getRuntime().removeShutdownHook(snarkStopper); - _fallback = new HTTPDownloader(_resources, _obs); - _fallback.doDownload(rsrc); + snarkStopper = null; + _stoppermap.remove(rsrc); + if (_metaDownload) { + _metaDownload = false; + } + fallback(); return; } } updateObserver(); } - snarkStopper.run(); + if (snarkStopper != null) { + snarkStopper.run(); + Runtime.getRuntime().removeShutdownHook(snarkStopper); + _stoppermap.remove(rsrc); + } + } + + /** + * If torrent downloading either bugs out or is too slow, switch to a + * different method by creating the fallback downloader. + */ + protected void fallback () + { + _fallback = new HTTPDownloader(_resources, _obs, _totalSize); } /** Keeps a mapping of resource names to torrent downloaders */