Big refactor of the router console update subsystem, in preparation for

implementing out-of-console updaters like i2psnark.

- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
  (router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
  I2PAppContext, identifying the type of update item and
  update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
  obtained from the UpdateManager. No more use of System properties
  to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
  no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
  and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
  All helper methods that are still required are moved to NewsHelper.

The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.

For each update type, there's several parts:
    - The xxxUpdateHandler implements the Updater
    - The xxxUpdateChecker implements the UpdateTask for checking
    - The xxxUpdateRunner implements the UpdateTask for downloading

New and moved classes:

web/				update/
----				-------
new				ConsoleUpdateManager.java

new				PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker 		-> PluginUpdateHandler.java
PluginUpdateHandler.java	-> PluginUpdateRunner

new				UnsignedUpdateHandler.java
UnsignedUpdateHandler		->  UnsignedUpdateRunner.java
new				UnsignedUpdateChecker from NewsFetcher

UpdateHandler.java remains
new				UpdateHandler.java
new				UpdateRunner.java from UpdateHandler

move				NewsHandler from NewsFetcher
new				NewsFetcher
new				NewsTimerTask

new				DummyHandler


Initial checkin. Unfinished, untested, unpolished.
This commit is contained in:
zzz
2012-06-18 22:09:45 +00:00
parent 273d7399a0
commit e62b76d2cc
39 changed files with 2836 additions and 1235 deletions
@@ -0,0 +1,94 @@
package net.i2p.router.update;
import java.io.File;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Date;
import net.i2p.router.RouterContext;
import net.i2p.router.util.RFC822Date;
import net.i2p.router.web.ConfigUpdateHandler;
import net.i2p.router.web.Messages;
import net.i2p.update.*;
import net.i2p.util.EepHead;
import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
/**
* Does a simple EepHead to get the last-modified header.
* Moved from NewsFetcher and turned into an UpdateTask.
*
* Overrides UpdateRunner for convenience, does not use super's Eepget StatusListener
*
* @since 0.9.2
*/
class UnsignedUpdateChecker extends UpdateRunner {
private final long _ms;
private boolean _unsignedUpdateAvailable;
protected static final String SIGNED_UPDATE_FILE = "i2pupdate.sud";
public UnsignedUpdateChecker(RouterContext ctx, List<URI> uris, long lastUpdateTime) {
super(ctx, uris);
_ms = lastUpdateTime;
}
//////// begin UpdateTask methods
@Override
public UpdateType getType() { return UpdateType.ROUTER_UNSIGNED; }
//////// end UpdateTask methods
@Override
public void run() {
_isRunning = true;
boolean success = false;
try {
success = fetchUnsignedHead();
} finally {
_isRunning = false;
}
_mgr.notifyCheckComplete(this, _unsignedUpdateAvailable, success);
}
/**
* HEAD the update url, and if the last-mod time is newer than the last update we
* downloaded, as stored in the properties, then we download it using eepget.
*/
private boolean fetchUnsignedHead() {
if (_urls.isEmpty())
return false;
_currentURI = _urls.get(0);
String url = _currentURI.toString();
// assume always proxied for now
//boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
int proxyPort = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT);
try {
EepHead get = new EepHead(_context, proxyHost, proxyPort, 0, url);
if (get.fetch()) {
String lastmod = get.getLastModified();
if (lastmod != null) {
long modtime = RFC822Date.parse822Date(lastmod);
if (modtime <= 0) return false;
if (_ms <= 0) return false;
if (modtime > _ms) {
_unsignedUpdateAvailable = true;
// '07-Jul 21:09 UTC' with month name in the system locale
String unsignedUpdateVersion = (new SimpleDateFormat("dd-MMM HH:mm")).format(new Date(modtime)) + " UTC";
_mgr.notifyVersionAvailable(this, _urls.get(0), getType(), "", getMethod(), _urls,
unsignedUpdateVersion, "");
}
}
return true;
}
} catch (Throwable t) {
_log.error("Error fetching the unsigned update", t);
}
return false;
}
}