wire things so both patches and full installs try bittorrent first
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
||||
-injars lib/jRegistryKey.jar(!META-INF/*)
|
||||
-injars lib/samskivert.jar(!META-INF/*,!**/velocity/**,!**/xml/**)
|
||||
-injars lib/commons-io.jar(!META-INF/*)
|
||||
# -injars lib/snark.jar(!META-INF/*)
|
||||
-injars lib/snark.jar(!META-INF/*)
|
||||
|
||||
-libraryjars <java.home>/lib/rt.jar
|
||||
-dontskipnonpubliclibraryclasses
|
||||
|
||||
@@ -181,6 +181,18 @@ public class Application
|
||||
return _resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the {@link Resource} objects used by
|
||||
* this application.
|
||||
*/
|
||||
public List<Resource> getAllResources ()
|
||||
{
|
||||
List<Resource> allResources = new ArrayList<Resource>();
|
||||
allResources.addAll(getCodeResources());
|
||||
allResources.addAll(getActiveResources());
|
||||
return allResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all auxiliary resource groups defined by the
|
||||
* application. An auxiliary resource group is a collection of resource
|
||||
@@ -266,6 +278,24 @@ public class Application
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a resource that can be used to download an archive containing
|
||||
* all files belonging to the application.
|
||||
*/
|
||||
public Resource getFullResource ()
|
||||
{
|
||||
String file = "full";
|
||||
try {
|
||||
URL remote = new URL(createVAppBase(_targetVersion), file);
|
||||
return new Resource(file, remote, getLocalPath(file), false);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to create full resource path [file=" + file +
|
||||
", appbase=" + _appbase + ", tvers=" + _targetVersion +
|
||||
", error=" + e + "].");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the application to parse its <code>getdown.txt</code>
|
||||
* configuration and prepare itself for operation. The application
|
||||
@@ -757,10 +787,8 @@ public class Application
|
||||
*/
|
||||
public List<Resource> verifyResources (ProgressObserver obs)
|
||||
{
|
||||
ArrayList<Resource> rsrcs = new ArrayList<Resource>();
|
||||
ArrayList<Resource> failures = new ArrayList<Resource>();
|
||||
rsrcs.addAll(getCodeResources());
|
||||
rsrcs.addAll(getActiveResources());
|
||||
List<Resource> rsrcs = getAllResources();
|
||||
List<Resource> failures = new ArrayList<Resource>();
|
||||
|
||||
// total up the file size of the resources to validate
|
||||
long totalSize = 0L;
|
||||
@@ -806,8 +834,7 @@ public class Application
|
||||
*/
|
||||
public void clearValidationMarkers ()
|
||||
{
|
||||
clearValidationMarkers(getCodeResources().iterator());
|
||||
clearValidationMarkers(getActiveResources().iterator());
|
||||
clearValidationMarkers(getAllResources().iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -504,13 +504,18 @@ public abstract class Getdown extends Thread
|
||||
}
|
||||
};
|
||||
|
||||
// Torrent downloading is disabled by default until the kinks are out
|
||||
Downloader dl;
|
||||
// if (false) {
|
||||
// dl = new TorrentDownloader(resources, obs);
|
||||
// } else {
|
||||
if (resources.equals(_app.getAllResources())) {
|
||||
ArrayList<Resource> full = new ArrayList<Resource>();
|
||||
full.add(_app.getFullResource());
|
||||
full.addAll(resources);
|
||||
dl = new TorrentDownloader(full, obs);
|
||||
} else if (resources.size() == 1 &&
|
||||
resources.get(0).getPath().startsWith("patch")) {
|
||||
dl = new TorrentDownloader(resources, obs);
|
||||
} else {
|
||||
dl = new HTTPDownloader(resources, obs);
|
||||
// }
|
||||
}
|
||||
dl.start();
|
||||
|
||||
// now wait for it to complete
|
||||
|
||||
@@ -27,6 +27,10 @@ public class TorrentDownloader extends Downloader
|
||||
Runtime.getRuntime().addShutdownHook(snarkStopper);
|
||||
_torrentmap.put(resource, snark);
|
||||
_stoppermap.put(resource, snarkStopper);
|
||||
if (resource.getPath().equals("full")) {
|
||||
_metaDownload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +38,12 @@ public class TorrentDownloader extends Downloader
|
||||
protected long checkSize(Resource rsrc)
|
||||
throws IOException
|
||||
{
|
||||
if (_metaDownload && !rsrc.getPath().equals("full")) {
|
||||
return 0;
|
||||
}
|
||||
if (_fallback != null) {
|
||||
return _fallback.checkSize(rsrc);
|
||||
}
|
||||
Snark snark = _torrentmap.get(rsrc);
|
||||
long length = -1;
|
||||
try {
|
||||
@@ -41,9 +51,16 @@ public class TorrentDownloader extends Downloader
|
||||
length = snark.meta.getTotalLength();
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Bittorrent failed, falling back to HTTP");
|
||||
_stoppermap.get(rsrc).run();
|
||||
SnarkShutdown stopper = _stoppermap.get(rsrc);
|
||||
stopper.run();
|
||||
Runtime.getRuntime().removeShutdownHook(stopper);
|
||||
_fallback = new HTTPDownloader(_resources, _obs);
|
||||
length = _fallback.checkSize(rsrc);
|
||||
if (_metaDownload && rsrc.getPath().equals("full")) {
|
||||
length = 0;
|
||||
} else {
|
||||
length = _fallback.checkSize(rsrc);
|
||||
}
|
||||
_metaDownload = false;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
@@ -52,10 +69,17 @@ public class TorrentDownloader extends Downloader
|
||||
protected void doDownload(Resource rsrc)
|
||||
throws IOException
|
||||
{
|
||||
if (_fallback != null) {
|
||||
_fallback.doDownload(rsrc);
|
||||
if (_metaDownload && !rsrc.getPath().equals("full")) {
|
||||
return;
|
||||
}
|
||||
if (_fallback != null) {
|
||||
if (rsrc.getPath().equals("full")) {
|
||||
return;
|
||||
} else {
|
||||
_fallback.doDownload(rsrc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Snark snark = _torrentmap.get(rsrc);
|
||||
SnarkShutdown snarkStopper = _stoppermap.get(rsrc);
|
||||
snark.collectPieces();
|
||||
@@ -67,6 +91,7 @@ public class TorrentDownloader extends Downloader
|
||||
(now - _start) >= TIME_THRESHOLD) {
|
||||
// The download isn't going as planned, abort;
|
||||
snarkStopper.run();
|
||||
Runtime.getRuntime().removeShutdownHook(snarkStopper);
|
||||
_fallback = new HTTPDownloader(_resources, _obs);
|
||||
_fallback.doDownload(rsrc);
|
||||
return;
|
||||
@@ -91,6 +116,12 @@ public class TorrentDownloader extends Downloader
|
||||
/** The length of time before we check for adequate progress*/
|
||||
protected static final long TIME_THRESHOLD = 60 * 1000l;
|
||||
|
||||
/**
|
||||
* Whether we are downloading an artificially-generated metafile
|
||||
* representing all of the {@link Resource}s at the end of the file.
|
||||
*/
|
||||
protected boolean _metaDownload = false;
|
||||
|
||||
/**
|
||||
* The minimum amount of data that must be downloaded within the
|
||||
* initial period in order to continue using BitTorrent
|
||||
|
||||
Reference in New Issue
Block a user