forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 2da3b585b42d058e25909bc303d72277ae2463b5)
to branch 'i2p.i2p.zzz.update' (head ebbad994215dc2822e9a1776399864ed77a0e5a0)
This commit is contained in:
@ -81,14 +81,15 @@
|
||||
</target>
|
||||
|
||||
<!-- unit tests -->
|
||||
<target name="scalatest.compileTest" depends="jar, scala.init">
|
||||
<target name="scalatest.compileTest" depends="compile, scala.init">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj_scala" />
|
||||
<scalac srcdir="./test/scalatest" destdir="./build/obj_scala" deprecation="on" >
|
||||
<classpath>
|
||||
<pathelement location="${classpath}" />
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${scalatest.jar}" />
|
||||
<pathelement location="./build/i2p.jar" />
|
||||
<pathelement location="./build/obj" />
|
||||
</classpath>
|
||||
</scalac>
|
||||
</target>
|
||||
@ -102,6 +103,23 @@
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
<!-- jars with tests -->
|
||||
<target name="jarScalaTest" depends="scalatest.compileTest">
|
||||
<mkdir dir="./build/obj_scala_jar" />
|
||||
<copy todir="./build/obj_scala_jar">
|
||||
<fileset dir="./build/">
|
||||
<include name="obj/**/*.class"/>
|
||||
</fileset>
|
||||
<mapper type="glob" from="obj/*" to="*" />
|
||||
</copy>
|
||||
<copy todir="./build/obj_scala_jar">
|
||||
<fileset dir="./build/">
|
||||
<include name="obj_scala/**/*.class"/>
|
||||
</fileset>
|
||||
<mapper type="glob" from="obj_scala/*" to="*" />
|
||||
</copy>
|
||||
<jar destfile="./build/i2pscalatest.jar" basedir="./build/obj_scala_jar" includes="**/*.class" />
|
||||
</target>
|
||||
<target name="jarTest" depends="junit.compileTest">
|
||||
<jar destfile="./build/i2ptest.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
</target>
|
||||
|
@ -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;
|
||||
@ -991,4 +992,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