forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 52d5a19210a344e0de43f6fe4d898d34f6c41829)
to branch 'i2p.i2p.zzz.update' (head d88c6abf9b4988ba892e435594cd74917ab9ab7f)
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;
|
||||
@ -989,4 +990,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