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.
2012-06-18 22:09:45 +00:00
|
|
|
package net.i2p.router.update;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.i2p.router.Router;
|
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
import net.i2p.router.util.RFC822Date;
|
|
|
|
import net.i2p.router.web.ConfigUpdateHandler;
|
|
|
|
import net.i2p.router.web.NewsHelper;
|
|
|
|
import net.i2p.update.*;
|
|
|
|
import net.i2p.util.EepGet;
|
|
|
|
import net.i2p.util.FileUtil;
|
|
|
|
import net.i2p.util.I2PAppThread;
|
|
|
|
import net.i2p.util.Log;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Handles the request to update the router by firing off an
|
|
|
|
* {@link net.i2p.util.EepGet} call to download the latest unsigned zip file
|
|
|
|
* and displaying the status to anyone who asks.
|
|
|
|
* </p>
|
|
|
|
* <p>After the download completes the signed update file is copied to the
|
|
|
|
* router directory, and if configured the router is restarted to complete
|
|
|
|
* the update process.
|
|
|
|
* </p>
|
|
|
|
*/
|
2012-10-17 22:24:15 +00:00
|
|
|
class UnsignedUpdateHandler implements Checker, Updater {
|
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.
2012-06-18 22:09:45 +00:00
|
|
|
private final RouterContext _context;
|
|
|
|
|
|
|
|
public UnsignedUpdateHandler(RouterContext ctx) {
|
|
|
|
_context = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param currentVersion ignored, we use time stored in a property
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public UpdateTask check(UpdateType type, UpdateMethod method,
|
|
|
|
String id, String currentVersion, long maxTime) {
|
|
|
|
if (type != UpdateType.ROUTER_UNSIGNED || method != UpdateMethod.HTTP)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
|
|
|
|
if (url == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
List<URI> updateSources;
|
|
|
|
try {
|
|
|
|
updateSources = Collections.singletonList(new URI(url));
|
|
|
|
} catch (URISyntaxException use) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
String lastUpdate = _context.getProperty(NewsHelper.PROP_LAST_UPDATE_TIME);
|
|
|
|
if (lastUpdate == null) {
|
|
|
|
// we don't know what version you have, so stamp it with the current time,
|
|
|
|
// and we'll look for something newer next time around.
|
|
|
|
_context.router().saveConfig(NewsHelper.PROP_LAST_UPDATE_TIME,
|
|
|
|
Long.toString(_context.clock().now()));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
long ms = 0;
|
|
|
|
try {
|
|
|
|
ms = Long.parseLong(lastUpdate);
|
|
|
|
} catch (NumberFormatException nfe) {}
|
|
|
|
if (ms <= 0) {
|
|
|
|
// we don't know what version you have, so stamp it with the current time,
|
|
|
|
// and we'll look for something newer next time around.
|
|
|
|
_context.router().saveConfig(NewsHelper.PROP_LAST_UPDATE_TIME,
|
|
|
|
Long.toString(_context.clock().now()));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateRunner update = new UnsignedUpdateChecker(_context, updateSources, ms);
|
|
|
|
update.start();
|
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start a download and return a handle to the download task.
|
|
|
|
* Should not block.
|
|
|
|
*
|
|
|
|
* @param id plugin name or ignored
|
|
|
|
* @param maxTime how long you have
|
|
|
|
* @return active task or null if unable to download
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public UpdateTask update(UpdateType type, UpdateMethod method, List<URI> updateSources,
|
|
|
|
String id, String newVersion, long maxTime) {
|
|
|
|
if (type != UpdateType.ROUTER_UNSIGNED || method != UpdateMethod.HTTP || updateSources.isEmpty())
|
|
|
|
return null;
|
|
|
|
UpdateRunner update = new UnsignedUpdateRunner(_context, updateSources);
|
|
|
|
update.start();
|
|
|
|
return update;
|
|
|
|
}
|
|
|
|
}
|