From da4ea77c2a50e4ceefad6066e80b0c7eca64e7ef Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 18 Oct 2012 02:20:39 +0000
Subject: [PATCH] more fixes

---
 .../router/update/ConsoleUpdateManager.java   | 16 ++++++++++++----
 .../net/i2p/router/update/NewsTimerTask.java  | 19 ++++++++++++++-----
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java
index 33e83eee7b..4873c920c5 100644
--- a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java
+++ b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java
@@ -106,14 +106,15 @@ public class ConsoleUpdateManager implements UpdateManager {
         }
 
         _context.registerUpdateManager(this);
-        Updater u = new DummyHandler(_context);
-        register(u, TYPE_DUMMY, HTTP, 0);
+        DummyHandler dh = new DummyHandler(_context);
+        register((Checker)dh, TYPE_DUMMY, HTTP, 0);
+        register((Updater)dh, TYPE_DUMMY, HTTP, 0);
         // register news before router, so we don't fire off an update
         // right at instantiation if the news is already indicating a new version
         Checker c = new NewsHandler(_context);
         register(c, NEWS, HTTP, 0);
         register(c, ROUTER_SIGNED, HTTP, 0);  // news is an update checker for the router
-        u = new UpdateHandler(_context);
+        Updater u = new UpdateHandler(_context);
         register(u, ROUTER_SIGNED, HTTP, 0);
         UnsignedUpdateHandler uuh = new UnsignedUpdateHandler(_context);
         register((Checker)uuh, ROUTER_UNSIGNED, HTTP, 0);
@@ -182,6 +183,14 @@ public class ConsoleUpdateManager implements UpdateManager {
         return null;
     }
 
+    /**
+     *  Fire off a checker task
+     *  Non-blocking.
+     */
+    public void check(UpdateType type) {
+        check(type, "");
+    }
+
     /**
      *  Fire off a checker task
      *  Non-blocking.
@@ -645,7 +654,6 @@ public class ConsoleUpdateManager implements UpdateManager {
         synchronized(task) {
             task.notifyAll();
         }
-// TODO
     }
 
     public void notifyProgress(UpdateTask task, String status, long downloaded, long totalSize) {
diff --git a/apps/routerconsole/java/src/net/i2p/router/update/NewsTimerTask.java b/apps/routerconsole/java/src/net/i2p/router/update/NewsTimerTask.java
index 56fb6000c0..ae1aadd813 100644
--- a/apps/routerconsole/java/src/net/i2p/router/update/NewsTimerTask.java
+++ b/apps/routerconsole/java/src/net/i2p/router/update/NewsTimerTask.java
@@ -55,16 +55,22 @@ class NewsTimerTask implements SimpleTimer.TimedEvent {
 
     public void timeReached() {
         if (shouldFetchNews()) {
+            // blocking
             fetchNews();
-            if (shouldFetchUnsigned())
-                fetchUnsignedHead();
+            if (shouldFetchUnsigned()) {
+                // give it a sec for the download to kick in, if it's going to
+                try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
+                if (!_mgr.isCheckInProgress() && !_mgr.isUpdateInProgress())
+                    // nonblocking
+                    fetchUnsignedHead();
+            }
         }
     }
     
     private boolean shouldFetchNews() {
         if (_context.router().gracefulShutdownInProgress())
             return false;
-        if (NewsHelper.isUpdateInProgress())
+        if (_mgr.isCheckInProgress() || _mgr.isUpdateInProgress())
             return false;
         long lastFetch = NewsHelper.lastChecked(_context);
         String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY,
@@ -88,8 +94,9 @@ class NewsTimerTask implements SimpleTimer.TimedEvent {
         }
     }
 
+    /** blocking */
     private void fetchNews() {
-        _mgr.check(NEWS, "");
+        _mgr.checkAvailable(NEWS, 60*1000);
     }
     
     private boolean shouldFetchUnsigned() {
@@ -102,8 +109,10 @@ class NewsTimerTask implements SimpleTimer.TimedEvent {
     /**
      * HEAD the update url, and if the last-mod time is newer than the last update we
      * downloaded, as stored in the properties, then we download it using eepget.
+     *
+     * Non-blocking
      */
     private void fetchUnsignedHead() {
-        _mgr.check(ROUTER_UNSIGNED, "");
+        _mgr.check(ROUTER_UNSIGNED);
     }
 }
-- 
GitLab