forked from I2P_Developers/i2p.i2p
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:
@ -26,6 +26,7 @@ import net.i2p.data.Base64;
|
||||
import net.i2p.data.RoutingKeyGenerator;
|
||||
import net.i2p.internal.InternalClientManager;
|
||||
import net.i2p.stat.StatManager;
|
||||
import net.i2p.update.UpdateManager;
|
||||
import net.i2p.util.Clock;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.FileUtil;
|
||||
@ -984,4 +985,13 @@ public class I2PAppContext {
|
||||
_simpleTimer2Initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The controller of router, plugin, and other updates.
|
||||
* @return always null in I2PAppContext, the update manager if in RouterContext and it is registered
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public UpdateManager updateManager() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
79
core/java/src/net/i2p/update/UpdateManager.java
Normal file
79
core/java/src/net/i2p/update/UpdateManager.java
Normal file
@ -0,0 +1,79 @@
|
||||
package net.i2p.update;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.List;;
|
||||
|
||||
/**
|
||||
* The central resource coordinating updates.
|
||||
* This must be registered with the context.
|
||||
*
|
||||
* The UpdateManager starts and stops all updates,
|
||||
* and controls notification to the user.
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public interface UpdateManager {
|
||||
|
||||
/**
|
||||
* Call multiple times for each type/method pair.
|
||||
* The UpdateManager will then call start()
|
||||
*/
|
||||
public void register(Updater updater, UpdateType type, UpdateMethod method, int priority);
|
||||
|
||||
public void unregister(Updater updater, UpdateType type, UpdateMethod method);
|
||||
|
||||
public void start();
|
||||
|
||||
public void shutdown();
|
||||
|
||||
/**
|
||||
* Called by the Updater, either after check() was called, or it found out on its own.
|
||||
*
|
||||
* @param newsSource who told us
|
||||
* @param id plugin name for plugins, ignored otherwise
|
||||
* @param method How to get the new version
|
||||
* @param updateSourcew Where to get the new version
|
||||
* @param newVersion The new version available
|
||||
* @param minVersion The minimum installed version to be able to update to newVersion
|
||||
* @return true if we didn't know already
|
||||
*/
|
||||
public boolean notifyVersionAvailable(UpdateTask task, URI newsSource,
|
||||
UpdateType type, String id,
|
||||
UpdateMethod method, List<URI> updateSources,
|
||||
String newVersion, String minVersion);
|
||||
|
||||
/**
|
||||
* Called by the Updater after check() was called and all notifyVersionAvailable() callbacks are finished
|
||||
* @param newer notifyVersionAvailable was called
|
||||
* @param success check succeeded (newer or not)
|
||||
*/
|
||||
public void notifyCheckComplete(UpdateTask task, boolean newer, boolean success);
|
||||
|
||||
public void notifyProgress(UpdateTask task, String status);
|
||||
public void notifyProgress(UpdateTask task, String status, long downloaded, long totalSize);
|
||||
|
||||
/**
|
||||
* Not necessarily the end if there are more URIs to try.
|
||||
* @param t may be null
|
||||
*/
|
||||
public void notifyAttemptFailed(UpdateTask task, String reason, Throwable t);
|
||||
|
||||
/**
|
||||
* The task has finished and failed.
|
||||
* @param t may be null
|
||||
*/
|
||||
public void notifyTaskFailed(UpdateTask task, String reason, Throwable t);
|
||||
|
||||
/**
|
||||
* An update has been downloaded but not verified.
|
||||
* The manager will verify it.
|
||||
* Caller should delete the file upon return, unless it will share it with others,
|
||||
* e.g. on a torrent.
|
||||
*
|
||||
* @param actualVersion may be higher (or lower?) than the version requested
|
||||
* @param file a valid format for the task's UpdateType
|
||||
* @return true if valid, false if corrupt
|
||||
*/
|
||||
public boolean notifyComplete(UpdateTask task, String actualVersion, File file);
|
||||
}
|
15
core/java/src/net/i2p/update/UpdateMethod.java
Normal file
15
core/java/src/net/i2p/update/UpdateMethod.java
Normal file
@ -0,0 +1,15 @@
|
||||
package net.i2p.update;
|
||||
|
||||
/**
|
||||
* Transport mechanism for getting something.
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public enum UpdateMethod {
|
||||
METHOD_DUMMY,
|
||||
HTTP, // .i2p or via outproxy
|
||||
HTTP_CLEARNET, // direct non-.i2p
|
||||
TORRENT,
|
||||
GNUTELLA, IMULE, TAHOE_LAFS,
|
||||
DEBIAN
|
||||
}
|
30
core/java/src/net/i2p/update/UpdateTask.java
Normal file
30
core/java/src/net/i2p/update/UpdateTask.java
Normal file
@ -0,0 +1,30 @@
|
||||
package net.i2p.update;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* A running check or download. Cannot be restarted.
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public interface UpdateTask {
|
||||
|
||||
public void shutdown();
|
||||
|
||||
public boolean isRunning();
|
||||
|
||||
public UpdateType getType();
|
||||
|
||||
public UpdateMethod getMethod();
|
||||
|
||||
/**
|
||||
* The current URI being checked or downloaded from.
|
||||
* Can change if there are multiple URIs to try.
|
||||
*/
|
||||
public URI getURI();
|
||||
|
||||
/**
|
||||
* Valid for plugins
|
||||
*/
|
||||
public String getID();
|
||||
}
|
16
core/java/src/net/i2p/update/UpdateType.java
Normal file
16
core/java/src/net/i2p/update/UpdateType.java
Normal file
@ -0,0 +1,16 @@
|
||||
package net.i2p.update;
|
||||
|
||||
/**
|
||||
* What to update
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public enum UpdateType {
|
||||
TYPE_DUMMY,
|
||||
NEWS,
|
||||
ROUTER_SIGNED,
|
||||
ROUTER_SIGNED_PACK200, // unused, use ROUTER_SIGNED for both
|
||||
ROUTER_UNSIGNED,
|
||||
PLUGIN, PLUGIN_INSTALL,
|
||||
GEOIP, BLOCKLIST, RESEED
|
||||
}
|
36
core/java/src/net/i2p/update/Updater.java
Normal file
36
core/java/src/net/i2p/update/Updater.java
Normal file
@ -0,0 +1,36 @@
|
||||
package net.i2p.update;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controls one or more types of updates.
|
||||
* This must be registered with the UpdateManager.
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public interface Updater {
|
||||
|
||||
/**
|
||||
* Check for updates.
|
||||
* Should not block.
|
||||
* If any are found, call back to UpdateManager.notifyUpdateAvailable().
|
||||
*
|
||||
* @param id plugin name or ignored
|
||||
* @param maxTime how long you have
|
||||
* @return active task or null if unable to check
|
||||
*/
|
||||
public UpdateTask check(UpdateType type, UpdateMethod method,
|
||||
String id, String currentVersion, long maxTime);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public UpdateTask update(UpdateType type, UpdateMethod method, List<URI> updateSources,
|
||||
String id, String newVersion, long maxTime);
|
||||
}
|
8
core/java/src/net/i2p/update/package.html
Normal file
8
core/java/src/net/i2p/update/package.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
Interfaces for classes to assist in the update process without
|
||||
needing the router context.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
@ -22,7 +22,7 @@ public class VersionComparator implements Comparator<String> {
|
||||
while (lTokens.hasMoreTokens() && rTokens.hasMoreTokens()) {
|
||||
String lNumber = lTokens.nextToken();
|
||||
String rNumber = rTokens.nextToken();
|
||||
int diff = intCompare(lNumber, rNumber);
|
||||
int diff = longCompare(lNumber, rNumber);
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
}
|
||||
@ -34,19 +34,24 @@ public class VersionComparator implements Comparator<String> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final int intCompare(String lop, String rop) {
|
||||
int left, right;
|
||||
private static final int longCompare(String lop, String rop) {
|
||||
long left, right;
|
||||
try {
|
||||
left = Integer.parseInt(lop);
|
||||
left = Long.parseLong(lop);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
right = Integer.parseInt(rop);
|
||||
right = Long.parseLong(rop);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return 1;
|
||||
}
|
||||
return left - right;
|
||||
long diff = left - right;
|
||||
if (diff < 0)
|
||||
return -1;
|
||||
if (diff > 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final String VALID_SEPARATOR_CHARS = ".-_";
|
||||
|
Reference in New Issue
Block a user