- Lots of fixes for notifying when updates and checks are complete

- Fixes for NewsHelper stored timestamps
- Add getProperty(String, long) to context for sanity
- New methods and types
- Logging improvements
- Add failsafe TaskCleaner
This commit is contained in:
zzz
2012-10-18 14:28:14 +00:00
parent 2b50c5aaf4
commit 0b4401e64b
13 changed files with 145 additions and 76 deletions

View File

@ -75,6 +75,8 @@ public class ConsoleUpdateManager implements UpdateManager {
private static final long DEFAULT_MAX_TIME = 3*60*60*1000L; private static final long DEFAULT_MAX_TIME = 3*60*60*1000L;
private static final long DEFAULT_CHECK_TIME = 60*1000; private static final long DEFAULT_CHECK_TIME = 60*1000;
private static final long STATUS_CLEAN_TIME = 20*60*1000;
private static final long TASK_CLEANER_TIME = 15*60*1000;
public ConsoleUpdateManager(RouterContext ctx) { public ConsoleUpdateManager(RouterContext ctx) {
_context = ctx; _context = ctx;
@ -124,6 +126,7 @@ public class ConsoleUpdateManager implements UpdateManager {
register((Checker)puh, PLUGIN_INSTALL, HTTP, 0); register((Checker)puh, PLUGIN_INSTALL, HTTP, 0);
register((Updater)puh, PLUGIN_INSTALL, HTTP, 0); register((Updater)puh, PLUGIN_INSTALL, HTTP, 0);
new NewsTimerTask(_context); new NewsTimerTask(_context);
_context.simpleScheduler().addPeriodicEvent(new TaskCleaner(), TASK_CLEANER_TIME);
} }
public void shutdown() { public void shutdown() {
@ -167,8 +170,11 @@ public class ConsoleUpdateManager implements UpdateManager {
UpdateTask t; UpdateTask t;
synchronized(_activeCheckers) { synchronized(_activeCheckers) {
t = r.checker.check(type, r.method, id, current, maxWait); t = r.checker.check(type, r.method, id, current, maxWait);
if (t != null) if (t != null) {
if (_log.shouldLog(Log.INFO))
_log.info("Starting " + r);
_activeCheckers.add(t); _activeCheckers.add(t);
}
} }
if (t != null) { if (t != null) {
synchronized(t) { synchronized(t) {
@ -198,7 +204,7 @@ public class ConsoleUpdateManager implements UpdateManager {
public void check(UpdateType type, String id) { public void check(UpdateType type, String id) {
if (isCheckInProgress(type, id)) { if (isCheckInProgress(type, id)) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Check or update already in progress for: " + type + ' ' + id); _log.warn("Check already in progress for: " + type + ' ' + id);
return; return;
} }
for (RegisteredChecker r : _registeredCheckers) { for (RegisteredChecker r : _registeredCheckers) {
@ -207,6 +213,8 @@ public class ConsoleUpdateManager implements UpdateManager {
synchronized(_activeCheckers) { synchronized(_activeCheckers) {
UpdateTask t = r.checker.check(type, r.method, id, current, DEFAULT_CHECK_TIME); UpdateTask t = r.checker.check(type, r.method, id, current, DEFAULT_CHECK_TIME);
if (t != null) { if (t != null) {
if (_log.shouldLog(Log.INFO))
_log.info("Starting " + r);
_activeCheckers.add(t); _activeCheckers.add(t);
break; break;
} }
@ -489,6 +497,8 @@ public class ConsoleUpdateManager implements UpdateManager {
if (t != null) { if (t != null) {
// race window here // race window here
// store the remaining ones for retrying // store the remaining ones for retrying
if (_log.shouldLog(Log.INFO))
_log.info("Starting " + r);
_downloaders.put(t, toTry); _downloaders.put(t, toTry);
return t; return t;
} }
@ -624,7 +634,7 @@ public class ConsoleUpdateManager implements UpdateManager {
*/ */
public void notifyCheckComplete(UpdateTask task, boolean newer, boolean success) { public void notifyCheckComplete(UpdateTask task, boolean newer, boolean success) {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info(task.toString() + " complete"); _log.info("Checker " + task + " for " + task.getType() + " complete");
synchronized(_activeCheckers) { synchronized(_activeCheckers) {
_activeCheckers.remove(task); _activeCheckers.remove(task);
} }
@ -688,7 +698,8 @@ public class ConsoleUpdateManager implements UpdateManager {
* @param t may be null * @param t may be null
*/ */
public void notifyAttemptFailed(UpdateTask task, String reason, Throwable t) { public void notifyAttemptFailed(UpdateTask task, String reason, Throwable t) {
_log.warn("Attempt failed " + task + ": " + reason, t); if (_log.shouldLog(Log.WARN))
_log.warn("Attempt failed " + task + " for " + task.getType() + ": " + reason, t);
} }
/** /**
@ -697,7 +708,7 @@ public class ConsoleUpdateManager implements UpdateManager {
*/ */
public void notifyTaskFailed(UpdateTask task, String reason, Throwable t) { public void notifyTaskFailed(UpdateTask task, String reason, Throwable t) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Failed " + task + ": " + reason, t); _log.warn("Failed " + task + " for " + task.getType() + ": " + reason, t);
List<RegisteredUpdater> toTry = _downloaders.get(task); List<RegisteredUpdater> toTry = _downloaders.get(task);
if (toTry != null) { if (toTry != null) {
UpdateItem ui = new UpdateItem(task.getType(), task.getID()); UpdateItem ui = new UpdateItem(task.getType(), task.getID());
@ -711,6 +722,7 @@ public class ConsoleUpdateManager implements UpdateManager {
} }
} }
_downloaders.remove(task); _downloaders.remove(task);
_activeCheckers.remove(task);
///// for certain types only ///// for certain types only
finishStatus("<b>" + _("Transfer failed from {0}", linkify(task.getURI().toString())) + "</b>"); finishStatus("<b>" + _("Transfer failed from {0}", linkify(task.getURI().toString())) + "</b>");
} }
@ -729,7 +741,7 @@ public class ConsoleUpdateManager implements UpdateManager {
*/ */
public boolean notifyComplete(UpdateTask task, String actualVersion, File file) { public boolean notifyComplete(UpdateTask task, String actualVersion, File file) {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info(task.toString() + " complete"); _log.info("Updater " + task + " for " + task.getType() + " complete");
boolean rv = false; boolean rv = false;
switch (task.getType()) { switch (task.getType()) {
case TYPE_DUMMY: case TYPE_DUMMY:
@ -1004,12 +1016,12 @@ public class ConsoleUpdateManager implements UpdateManager {
private void finishStatus(String msg) { private void finishStatus(String msg) {
updateStatus(msg); updateStatus(msg);
_context.simpleScheduler().addEvent(new Cleaner(msg), 20*60*1000); _context.simpleScheduler().addEvent(new StatusCleaner(msg), STATUS_CLEAN_TIME);
} }
private class Cleaner implements SimpleTimer.TimedEvent { private class StatusCleaner implements SimpleTimer.TimedEvent {
private final String _msg; private final String _msg;
public Cleaner(String msg) { public StatusCleaner(String msg) {
_msg = msg; _msg = msg;
} }
public void timeReached() { public void timeReached() {
@ -1018,6 +1030,36 @@ public class ConsoleUpdateManager implements UpdateManager {
} }
} }
/**
* Failsafe
*/
private class TaskCleaner implements SimpleTimer.TimedEvent {
public void timeReached() {
if (!_activeCheckers.isEmpty()) {
synchronized(_activeCheckers) {
for (Iterator<UpdateTask> iter = _activeCheckers.iterator(); iter.hasNext(); ) {
UpdateTask t = iter.next();
if (!t.isRunning()) {
if (_log.shouldLog(Log.WARN))
_log.warn("Failsafe remove checker " + t);
iter.remove();
}
}
}
}
if (!_downloaders.isEmpty()) {
for (Iterator<UpdateTask> iter = _downloaders.keySet().iterator(); iter.hasNext(); ) {
UpdateTask t = iter.next();
if (!t.isRunning()) {
if (_log.shouldLog(Log.WARN))
_log.warn("Failsafe remove downloader " + t);
iter.remove();
}
}
}
}
}
/** /**
* Equals on updater, type and method only * Equals on updater, type and method only
*/ */

View File

@ -37,6 +37,9 @@ class NewsFetcher extends UpdateRunner {
private String _lastModified; private String _lastModified;
private final File _newsFile; private final File _newsFile;
private final File _tempFile; private final File _tempFile;
/** is the news newer */
private boolean _isNewer;
private boolean _success;
private static final String TEMP_NEWS_FILE = "news.xml.temp"; private static final String TEMP_NEWS_FILE = "news.xml.temp";
@ -65,8 +68,14 @@ class NewsFetcher extends UpdateRunner {
} }
@Override @Override
public void update() { public void run() {
fetchNews(); _isRunning = true;
try {
fetchNews();
} finally {
_mgr.notifyCheckComplete(this, _isNewer, _success);
_isRunning = false;
}
} }
public void fetchNews() { public void fetchNews() {
@ -93,8 +102,9 @@ class NewsFetcher extends UpdateRunner {
if (lastMod != null) { if (lastMod != null) {
_lastModified = lastMod; _lastModified = lastMod;
long lm = RFC822Date.parse822Date(lastMod); long lm = RFC822Date.parse822Date(lastMod);
if (lm > 0) if (lm == 0)
_context.router().saveConfig(NewsHelper.PROP_LAST_CHECKED, Long.toString(lm)); lm = _context.clock().now();
_context.router().saveConfig(NewsHelper.PROP_LAST_CHECKED, Long.toString(lm));
} }
return; return;
} }
@ -107,8 +117,6 @@ class NewsFetcher extends UpdateRunner {
private static final String VERSION_STRING = "version=\"" + RouterVersion.VERSION + "\""; private static final String VERSION_STRING = "version=\"" + RouterVersion.VERSION + "\"";
private static final String VERSION_PREFIX = "version=\""; private static final String VERSION_PREFIX = "version=\"";
///// move to UpdateManager?
/** /**
* Parse the installed (not the temp) news file for the latest version. * Parse the installed (not the temp) news file for the latest version.
* TODO: Real XML parsing, different update methods, * TODO: Real XML parsing, different update methods,
@ -181,6 +189,7 @@ class NewsFetcher extends UpdateRunner {
_context.router().saveConfig(NewsHelper.PROP_LAST_UPDATED, newVer); _context.router().saveConfig(NewsHelper.PROP_LAST_UPDATED, newVer);
_mgr.notifyVersionAvailable(this, _currentURI, NEWS, "", HTTP, _mgr.notifyVersionAvailable(this, _currentURI, NEWS, "", HTTP,
null, newVer, ""); null, newVer, "");
_isNewer = true;
checkForUpdates(); checkForUpdates();
} else { } else {
if (_log.shouldLog(Log.ERROR)) if (_log.shouldLog(Log.ERROR))
@ -190,6 +199,7 @@ class NewsFetcher extends UpdateRunner {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Transfer complete, but no file? - probably 304 Not Modified"); _log.warn("Transfer complete, but no file? - probably 304 Not Modified");
} }
_success = true;
} }
/** override to prevent status update */ /** override to prevent status update */

View File

@ -8,11 +8,15 @@ import java.util.List;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import net.i2p.router.web.ConfigUpdateHelper; import net.i2p.router.web.ConfigUpdateHelper;
import net.i2p.update.*; import net.i2p.update.*;
import static net.i2p.update.UpdateType.*;
import static net.i2p.update.UpdateMethod.*;
/** /**
* Task to periodically look for updates to the news.xml, and to keep * Task to periodically look for updates to the news.xml, and to keep
* track of whether that has an announcement for a new version. * track of whether that has an announcement for a new version.
* *
* Overrides UpdateRunner for convenience, this is not an Updater
*
* @since 0.9.4 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
class NewsHandler extends UpdateHandler implements Checker { class NewsHandler extends UpdateHandler implements Checker {
@ -31,8 +35,8 @@ class NewsHandler extends UpdateHandler implements Checker {
*/ */
public UpdateTask check(UpdateType type, UpdateMethod method, public UpdateTask check(UpdateType type, UpdateMethod method,
String id, String currentVersion, long maxTime) { String id, String currentVersion, long maxTime) {
if ((type != UpdateType.ROUTER_SIGNED && type != UpdateType.ROUTER_SIGNED_PACK200 && type != UpdateType.NEWS) || if ((type != ROUTER_SIGNED && type != ROUTER_SIGNED_PACK200 && type != NEWS) ||
method != UpdateMethod.HTTP) method != HTTP)
return null; return null;
List<URI> updateSources = new ArrayList(2); List<URI> updateSources = new ArrayList(2);
try { try {

View File

@ -43,9 +43,18 @@ class PluginUpdateChecker extends UpdateRunner {
_oldVersion = oldVersion; _oldVersion = oldVersion;
} }
@Override @Override
public UpdateType getType() { return UpdateType.PLUGIN; } public UpdateType getType() { return UpdateType.PLUGIN; }
@Override
public void run() {
_isRunning = true;
try {
update();
} finally {
_isRunning = false;
}
}
@Override @Override
protected void update() { protected void update() {

View File

@ -46,9 +46,9 @@ class UnsignedUpdateChecker extends UpdateRunner {
try { try {
success = fetchUnsignedHead(); success = fetchUnsignedHead();
} finally { } finally {
_mgr.notifyCheckComplete(this, _unsignedUpdateAvailable, success);
_isRunning = false; _isRunning = false;
} }
_mgr.notifyCheckComplete(this, _unsignedUpdateAvailable, success);
} }

View File

@ -12,6 +12,8 @@ import net.i2p.router.util.RFC822Date;
import net.i2p.router.web.ConfigUpdateHandler; import net.i2p.router.web.ConfigUpdateHandler;
import net.i2p.router.web.NewsHelper; import net.i2p.router.web.NewsHelper;
import net.i2p.update.*; import net.i2p.update.*;
import static net.i2p.update.UpdateType.*;
import static net.i2p.update.UpdateMethod.*;
import net.i2p.util.EepGet; import net.i2p.util.EepGet;
import net.i2p.util.FileUtil; import net.i2p.util.FileUtil;
import net.i2p.util.I2PAppThread; import net.i2p.util.I2PAppThread;
@ -54,18 +56,7 @@ class UnsignedUpdateHandler implements Checker, Updater {
return null; return null;
} }
String lastUpdate = _context.getProperty(NewsHelper.PROP_LAST_UPDATE_TIME); long ms = _context.getProperty(NewsHelper.PROP_LAST_UPDATE_TIME, 0L);
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) { if (ms <= 0) {
// we don't know what version you have, so stamp it with the current time, // 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. // and we'll look for something newer next time around.
@ -90,7 +81,7 @@ class UnsignedUpdateHandler implements Checker, Updater {
@Override @Override
public UpdateTask update(UpdateType type, UpdateMethod method, List<URI> updateSources, public UpdateTask update(UpdateType type, UpdateMethod method, List<URI> updateSources,
String id, String newVersion, long maxTime) { String id, String newVersion, long maxTime) {
if (type != UpdateType.ROUTER_UNSIGNED || method != UpdateMethod.HTTP || updateSources.isEmpty()) if (type != ROUTER_UNSIGNED || method != HTTP || updateSources.isEmpty())
return null; return null;
UpdateRunner update = new UnsignedUpdateRunner(_context, updateSources); UpdateRunner update = new UnsignedUpdateRunner(_context, updateSources);
update.start(); update.start();

View File

@ -9,6 +9,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.util.RFC822Date; import net.i2p.router.util.RFC822Date;
import net.i2p.router.web.ConfigUpdateHandler; import net.i2p.router.web.ConfigUpdateHandler;
import net.i2p.update.*; import net.i2p.update.*;
import static net.i2p.update.UpdateType.*;
import net.i2p.util.EepGet; import net.i2p.util.EepGet;
import net.i2p.util.FileUtil; import net.i2p.util.FileUtil;
import net.i2p.util.I2PAppThread; import net.i2p.util.I2PAppThread;
@ -31,7 +32,7 @@ class UnsignedUpdateRunner extends UpdateRunner {
@Override @Override
public UpdateType getType() { return UpdateType.ROUTER_UNSIGNED; } public UpdateType getType() { return ROUTER_UNSIGNED; }
/** Get the file */ /** Get the file */

View File

@ -83,6 +83,8 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
_isRunning = true; _isRunning = true;
try { try {
update(); update();
} catch (Throwable t) {
_mgr.notifyTaskFailed(this, "", t);
} finally { } finally {
_isRunning = false; _isRunning = false;
} }
@ -207,6 +209,7 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
_log.error("Update from " + url + " did not download completely (" + _log.error("Update from " + url + " did not download completely (" +
bytesRemaining + " remaining after " + currentAttempt + " tries)"); bytesRemaining + " remaining after " + currentAttempt + " tries)");
updateStatus("<b>" + _("Transfer failed from {0}", linkify(url)) + "</b>"); updateStatus("<b>" + _("Transfer failed from {0}", linkify(url)) + "</b>");
_mgr.notifyTaskFailed(this, "", null);
} }
public void headerReceived(String url, int attemptNum, String key, String val) {} public void headerReceived(String url, int attemptNum, String key, String val) {}

View File

@ -101,10 +101,14 @@ public class ConfigUpdateHandler extends FormHandler {
addFormError("Update manager not registered, cannot check"); addFormError("Update manager not registered, cannot check");
return; return;
} }
boolean a1 = mgr.checkAvailable(NEWS, 60*1000) != null; if (mgr.isUpdateInProgress() || mgr.isCheckInProgress()) {
addFormError(_("Update or check already in progress"));
return;
}
boolean a1 = mgr.checkAvailable(NEWS, 30*1000) != null;
boolean a2 = false; boolean a2 = false;
if ((!a1) && _updateUnsigned && _zipURL != null && _zipURL.length() > 0) if ((!a1) && _updateUnsigned && _zipURL != null && _zipURL.length() > 0)
a2 = mgr.checkAvailable(ROUTER_UNSIGNED, 60*1000) != null; a2 = mgr.checkAvailable(ROUTER_UNSIGNED, 30*1000) != null;
if (a1 || a2) { if (a1 || a2) {
if ( (_updatePolicy == null) || (!_updatePolicy.equals("notify")) ) if ( (_updatePolicy == null) || (!_updatePolicy.equals("notify")) )
addFormNotice(_("Update available, attempting to download now")); addFormNotice(_("Update available, attempting to download now"));

View File

@ -20,15 +20,15 @@ public class NewsHelper extends ContentHelper {
public static final String PROP_LAST_UPDATE_TIME = "router.updateLastDownloaded"; public static final String PROP_LAST_UPDATE_TIME = "router.updateLastDownloaded";
/** @since 0.8.12 */ /** @since 0.8.12 */
private static final String PROP_LAST_HIDDEN = "routerconsole.newsLastHidden"; private static final String PROP_LAST_HIDDEN = "routerconsole.newsLastHidden";
/** @since 0.9.2 */ /** @since 0.9.4 */
public static final String PROP_LAST_CHECKED = "routerconsole.newsLastChecked"; public static final String PROP_LAST_CHECKED = "routerconsole.newsLastChecked";
/** @since 0.9.2 */ /** @since 0.9.4 */
public static final String PROP_LAST_UPDATED = "routerconsole.newsLastUpdated"; public static final String PROP_LAST_UPDATED = "routerconsole.newsLastUpdated";
public static final String NEWS_FILE = "docs/news.xml"; public static final String NEWS_FILE = "docs/news.xml";
/** /**
* If ANY update is in progress. * If ANY update is in progress.
* @since 0.9.2 was stored in system properties * @since 0.9.4 was stored in system properties
*/ */
public static boolean isAnyUpdateInProgress() { public static boolean isAnyUpdateInProgress() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -39,7 +39,7 @@ public class NewsHelper extends ContentHelper {
/** /**
* If a signed or unsigned router update is in progress. * If a signed or unsigned router update is in progress.
* Does NOT cover plugins, news, etc. * Does NOT cover plugins, news, etc.
* @since 0.9.2 was stored in system properties * @since 0.9.4 was stored in system properties
*/ */
public static boolean isUpdateInProgress() { public static boolean isUpdateInProgress() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -50,7 +50,7 @@ public class NewsHelper extends ContentHelper {
} }
/** /**
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public static boolean isUpdateAvailable() { public static boolean isUpdateAvailable() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -60,7 +60,7 @@ public class NewsHelper extends ContentHelper {
/** /**
* @return null if none * @return null if none
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public static String updateVersion() { public static String updateVersion() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -69,7 +69,7 @@ public class NewsHelper extends ContentHelper {
} }
/** /**
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public static boolean isUnsignedUpdateAvailable() { public static boolean isUnsignedUpdateAvailable() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -79,7 +79,7 @@ public class NewsHelper extends ContentHelper {
/** /**
* @return null if none * @return null if none
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public static String unsignedUpdateVersion() { public static String unsignedUpdateVersion() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -97,7 +97,7 @@ public class NewsHelper extends ContentHelper {
/** /**
* @return "" if none * @return "" if none
* @since 0.9.2 moved from UpdateHelper * @since 0.9.4 moved from UpdateHelper
*/ */
public static String getUpdateStatus() { public static String getUpdateStatus() {
ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance(); ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
@ -122,19 +122,13 @@ public class NewsHelper extends ContentHelper {
} }
/** /**
* @since 0.9.2 * @since 0.9.4
*/ */
public static boolean shouldShowNews(RouterContext ctx) { public static boolean shouldShowNews(RouterContext ctx) {
long lastUpdated = lastUpdated(ctx); long lastUpdated = lastUpdated(ctx);
if (lastUpdated <= 0) if (lastUpdated <= 0)
return true; return true;
String h = ctx.getProperty(PROP_LAST_HIDDEN); long last = ctx.getProperty(PROP_LAST_HIDDEN, 0L);
if (h == null)
return true;
long last = 0;
try {
last = Long.parseLong(h);
} catch (NumberFormatException nfe) {}
return lastUpdated > last; return lastUpdated > last;
} }
@ -148,18 +142,16 @@ public class NewsHelper extends ContentHelper {
/** /**
* Save config with the timestamp of the current news to hide, or 0 to show * Save config with the timestamp of the current news to hide, or 0 to show
* @since 0.9.2 * @since 0.9.4
*/ */
public static void showNews(RouterContext ctx, boolean yes) { public static void showNews(RouterContext ctx, boolean yes) {
long lastUpdated = 0; long stamp = yes ? 0 : lastUpdated(ctx);
/////// FIME from props, or from last mod time?
long stamp = yes ? 0 : lastUpdated;
ctx.router().saveConfig(PROP_LAST_HIDDEN, Long.toString(stamp)); ctx.router().saveConfig(PROP_LAST_HIDDEN, Long.toString(stamp));
} }
/** /**
* @return HTML * @return HTML
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public String status() { public String status() {
return status(_context); return status(_context);
@ -167,7 +159,7 @@ public class NewsHelper extends ContentHelper {
/** /**
* @return HTML * @return HTML
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public static String status(RouterContext ctx) { public static String status(RouterContext ctx) {
StringBuilder buf = new StringBuilder(128); StringBuilder buf = new StringBuilder(128);
@ -202,7 +194,7 @@ public class NewsHelper extends ContentHelper {
} }
/** /**
* @since 0.9.2 moved from NewsFetcher * @since 0.9.4 moved from NewsFetcher
*/ */
public static boolean dontInstall(RouterContext ctx) { public static boolean dontInstall(RouterContext ctx) {
File test = new File(ctx.getBaseDir(), "history.txt"); File test = new File(ctx.getBaseDir(), "history.txt");
@ -212,31 +204,22 @@ public class NewsHelper extends ContentHelper {
} }
/** /**
* @since 0.9.2 * @since 0.9.4
*/ */
public static long lastChecked(RouterContext ctx) { public static long lastChecked(RouterContext ctx) {
String lc = ctx.getProperty(PROP_LAST_CHECKED); return ctx.getProperty(PROP_LAST_CHECKED, 0L);
if (lc == null) {
try {
return Long.parseLong(lc);
} catch (NumberFormatException nfe) {}
}
return 0;
} }
/** /**
* When the news was last downloaded * When the news was last downloaded
* @since 0.9.2 * @since 0.9.4
*/ */
public static long lastUpdated(RouterContext ctx) { public static long lastUpdated(RouterContext ctx) {
String lc = ctx.getProperty(PROP_LAST_UPDATED); long rv = ctx.getProperty(PROP_LAST_UPDATED, 0L);
if (lc == null) { if (rv > 0)
try { return rv;
return Long.parseLong(lc);
} catch (NumberFormatException nfe) {}
}
File newsFile = new File(ctx.getRouterDir(), NEWS_FILE); File newsFile = new File(ctx.getRouterDir(), NEWS_FILE);
long rv = newsFile.lastModified(); rv = newsFile.lastModified();
ctx.router().saveConfig(PROP_LAST_UPDATED, Long.toString(rv)); ctx.router().saveConfig(PROP_LAST_UPDATED, Long.toString(rv));
return rv; return rv;
} }

View File

@ -479,6 +479,26 @@ public class I2PAppContext {
return ival; return ival;
} }
/**
* Return a long with a long default
* @since 0.9.4
*/
public long getProperty(String propName, long defaultVal) {
String val = null;
if (_overrideProps != null) {
val = _overrideProps.getProperty(propName);
if (val == null)
val = System.getProperty(propName);
}
long rv = defaultVal;
if (val != null) {
try {
rv = Long.parseLong(val);
} catch (NumberFormatException nfe) {}
}
return rv;
}
/** /**
* Return a boolean with a boolean default * Return a boolean with a boolean default
* @since 0.7.12 * @since 0.7.12

View File

@ -9,6 +9,7 @@ public enum UpdateMethod {
METHOD_DUMMY, METHOD_DUMMY,
HTTP, // .i2p or via outproxy HTTP, // .i2p or via outproxy
HTTP_CLEARNET, // direct non-.i2p HTTP_CLEARNET, // direct non-.i2p
HTTPS_CLEARNET, // direct non-.i2p
TORRENT, TORRENT,
GNUTELLA, IMULE, TAHOE_LAFS, GNUTELLA, IMULE, TAHOE_LAFS,
DEBIAN DEBIAN

View File

@ -12,5 +12,6 @@ public enum UpdateType {
ROUTER_SIGNED_PACK200, // unused, use ROUTER_SIGNED for both ROUTER_SIGNED_PACK200, // unused, use ROUTER_SIGNED for both
ROUTER_UNSIGNED, ROUTER_UNSIGNED,
PLUGIN, PLUGIN_INSTALL, PLUGIN, PLUGIN_INSTALL,
GEOIP, BLOCKLIST, RESEED GEOIP, BLOCKLIST, RESEED,
HOMEPAGE
} }