Update: Preliminary work for su3 router updates:

- new ROUTER_SIGNED_SU3 UpdateType
   - Add support for torrent and HTTP
   - Refactor UpdateRunners to return actual UpdateType
   - Deal with signed/su3 conflicts
   - unpack/verify stubbed only
This commit is contained in:
zzz
2013-09-22 18:03:56 +00:00
parent 6fede7f524
commit f47ec65b8f
17 changed files with 205 additions and 66 deletions

View File

@@ -69,6 +69,7 @@ public class ConsoleUpdateManager implements UpdateManager {
private final Map<UpdateItem, Version> _downloaded;
/** downloaded AND installed */
private final Map<UpdateItem, Version> _installed;
private final boolean _allowTorrent;
private static final DecimalFormat _pct = new DecimalFormat("0.0%");
private volatile String _status;
@@ -90,6 +91,13 @@ public class ConsoleUpdateManager implements UpdateManager {
_downloaded = new ConcurrentHashMap();
_installed = new ConcurrentHashMap();
_status = "";
// DEBUG slow start for snark updates
// For 0.9.4 update, only for dev builds
// For 0.9.5 update, only for dev builds and 1% more
// For 0.9.6 update, only for dev builds and 3% more
// For 0.9.8 update, only for dev builds and 30% more
// Remove this for 100%
_allowTorrent = RouterVersion.BUILD != 0 || _context.random().nextInt(100) < 30;
}
public static ConsoleUpdateManager getInstance() {
@@ -99,6 +107,7 @@ public class ConsoleUpdateManager implements UpdateManager {
public void start() {
notifyInstalled(NEWS, "", Long.toString(NewsHelper.lastUpdated(_context)));
notifyInstalled(ROUTER_SIGNED, "", RouterVersion.VERSION);
notifyInstalled(ROUTER_SIGNED_SU3, "", RouterVersion.VERSION);
// hack to init from the current news file... do this before we register Updaters
// This will not kick off any Updaters as none are yet registered
(new NewsFetcher(_context, this, Collections.EMPTY_LIST)).checkForUpdates();
@@ -122,6 +131,10 @@ public class ConsoleUpdateManager implements UpdateManager {
register(c, ROUTER_SIGNED, HTTP, 0); // news is an update checker for the router
Updater u = new UpdateHandler(_context, this);
register(u, ROUTER_SIGNED, HTTP, 0);
if (ConfigUpdateHandler.USE_SU3_UPDATE) {
register(c, ROUTER_SIGNED_SU3, HTTP, 0);
register(u, ROUTER_SIGNED_SU3, HTTP, 0);
}
// TODO see NewsFetcher
//register(u, ROUTER_SIGNED, HTTPS_CLEARNET, -5);
//register(u, ROUTER_SIGNED, HTTP_CLEARNET, -10);
@@ -558,18 +571,18 @@ public class ConsoleUpdateManager implements UpdateManager {
* Call once for each type/method pair.
*/
public void register(Updater updater, UpdateType type, UpdateMethod method, int priority) {
if ((type == ROUTER_SIGNED || type == ROUTER_UNSIGNED) && NewsHelper.dontInstall(_context)) {
if ((type == ROUTER_SIGNED || type == ROUTER_UNSIGNED || type == ROUTER_SIGNED_SU3) &&
NewsHelper.dontInstall(_context)) {
if (_log.shouldLog(Log.WARN))
_log.warn("Ignoring registration for " + type + ", router updates disabled");
return;
}
// DEBUG slow start for snark updates
// For 0.9.4 update, only for dev builds
// For 0.9.5 update, only for dev builds and 1% more
// For 0.9.6 update, only for dev builds and 3% more
// For 0.9.8 update, only for dev builds and 30% more
// Remove this for 100%
if (method == TORRENT && RouterVersion.BUILD == 0 && _context.random().nextInt(100) > 29) {
if (type == ROUTER_SIGNED_SU3 && !ConfigUpdateHandler.USE_SU3_UPDATE) {
if (_log.shouldLog(Log.WARN))
_log.warn("Ignoring registration for " + type + ", SU3 updates disabled");
return;
}
if (method == TORRENT && !_allowTorrent) {
if (_log.shouldLog(Log.WARN))
_log.warn("Ignoring torrent registration");
return;
@@ -723,8 +736,10 @@ public class ConsoleUpdateManager implements UpdateManager {
// fall through
case ROUTER_SIGNED:
case ROUTER_SIGNED_SU3:
if (shouldInstall() &&
!(isUpdateInProgress(ROUTER_SIGNED) ||
isUpdateInProgress(ROUTER_SIGNED_SU3) ||
isUpdateInProgress(ROUTER_UNSIGNED))) {
if (_log.shouldLog(Log.INFO))
_log.info("Updating " + ui + " after notify");
@@ -761,6 +776,7 @@ public class ConsoleUpdateManager implements UpdateManager {
switch (task.getType()) {
case NEWS:
case ROUTER_SIGNED:
case ROUTER_SIGNED_SU3:
case ROUTER_UNSIGNED:
// ConfigUpdateHandler, SummaryHelper, SummaryBarRenderer handle status display
break;
@@ -877,6 +893,12 @@ public class ConsoleUpdateManager implements UpdateManager {
notifyDownloaded(task.getType(), task.getID(), actualVersion);
break;
case ROUTER_SIGNED_SU3:
rv = handleSu3File(task.getURI(), actualVersion, file);
if (rv)
notifyDownloaded(task.getType(), task.getID(), actualVersion);
break;
case ROUTER_UNSIGNED:
rv = handleUnsignedFile(task.getURI(), actualVersion, file);
if (rv) {
@@ -932,10 +954,30 @@ public class ConsoleUpdateManager implements UpdateManager {
_log.info(ui + " " + ver + " downloaded");
_downloaded.put(ui, ver);
// one trumps the other
if (type == ROUTER_SIGNED)
if (type == ROUTER_SIGNED) {
_downloaded.remove(new UpdateItem(ROUTER_UNSIGNED, ""));
else if (type == ROUTER_UNSIGNED)
_downloaded.remove(new UpdateItem(ROUTER_SIGNED_SU3, ""));
// remove available from other type
UpdateItem altui = new UpdateItem(ROUTER_SIGNED_SU3, id);
Version old = _available.get(altui);
if (old != null && old.compareTo(ver) <= 0)
_available.remove(altui);
// ... and declare the alt downloaded as well
_downloaded.put(altui, ver);
} else if (type == ROUTER_SIGNED_SU3) {
_downloaded.remove(new UpdateItem(ROUTER_SIGNED, ""));
_downloaded.remove(new UpdateItem(ROUTER_UNSIGNED, ""));
// remove available from other type
UpdateItem altui = new UpdateItem(ROUTER_SIGNED, id);
Version old = _available.get(altui);
if (old != null && old.compareTo(ver) <= 0)
_available.remove(altui);
// ... and declare the alt downloaded as well
_downloaded.put(altui, ver);
} else if (type == ROUTER_UNSIGNED) {
_downloaded.remove(new UpdateItem(ROUTER_SIGNED, ""));
_downloaded.remove(new UpdateItem(ROUTER_SIGNED_SU3, ""));
}
Version old = _available.get(ui);
if (old != null && old.compareTo(ver) <= 0)
_available.remove(ui);
@@ -969,6 +1011,7 @@ public class ConsoleUpdateManager implements UpdateManager {
break;
case ROUTER_SIGNED:
{ // avoid dup variables in next case
String URLs = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL, ConfigUpdateHandler.DEFAULT_UPDATE_URL);
StringTokenizer tok = new StringTokenizer(URLs, " ,\r\n");
List<URI> rv = new ArrayList();
@@ -979,6 +1022,21 @@ public class ConsoleUpdateManager implements UpdateManager {
}
Collections.shuffle(rv, _context.random());
return rv;
}
case ROUTER_SIGNED_SU3:
{
String URLs = ConfigUpdateHandler.SU3_UPDATE_URLS;
StringTokenizer tok = new StringTokenizer(URLs, " ,\r\n");
List<URI> rv = new ArrayList();
while (tok.hasMoreTokens()) {
try {
rv.add(new URI(tok.nextToken().trim()));
} catch (URISyntaxException use) {}
}
Collections.shuffle(rv, _context.random());
return rv;
}
case ROUTER_UNSIGNED:
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
@@ -1011,12 +1069,35 @@ public class ConsoleUpdateManager implements UpdateManager {
* @return success
*/
private boolean handleSudFile(URI uri, String actualVersion, File f) {
return handleRouterFile(uri, actualVersion, f, false);
}
/**
* @return success
* @since 0.9.9
*/
private boolean handleSu3File(URI uri, String actualVersion, File f) {
return handleRouterFile(uri, actualVersion, f, true);
}
/**
* Process sud, su2, or su3
* @return success
* @since 0.9.9
*/
private boolean handleRouterFile(URI uri, String actualVersion, File f, boolean isSU3) {
String url = uri.toString();
// Process the .sud/.su2 file
updateStatus("<b>" + _("Update downloaded") + "</b>");
TrustedUpdate up = new TrustedUpdate(_context);
File to = new File(_context.getRouterDir(), Router.UPDATE_FILE);
String err = up.migrateVerified(RouterVersion.VERSION, f, to);
String err;
// Process the file
if (isSU3) {
err = "todo";
} else {
TrustedUpdate up = new TrustedUpdate(_context);
err = up.migrateVerified(RouterVersion.VERSION, f, to);
}
///////////
// caller must delete now.. why?
//f.delete();
@@ -1277,6 +1358,8 @@ public class ConsoleUpdateManager implements UpdateManager {
@Override
public String toString() {
if ("".equals(id))
return "UpdateItem " + type;
return "UpdateItem " + type + ' ' + id;
}
}