Author: toad
Date: 2006-08-17 16:21:41 +0000 (Thu, 17 Aug 2006)
New Revision: 10166

Modified:
   trunk/freenet/src/freenet/client/async/USKChecker.java
   trunk/freenet/src/freenet/client/async/USKFetcher.java
   trunk/freenet/src/freenet/client/async/USKManager.java
   trunk/freenet/src/freenet/node/updater/NodeUpdater.java
   
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java
Log:
Lots of fixes/improvements related to updating and USKs.
Boost priority of background USK fetches the first time they run, and when they 
have moved forward in the last cycle.
If a background fetcher falls out of the LRU, kill it as soon as all its 
clients have unsubscribed.
If we successfully fetch an update, and start to fetch a later update, let the 
user update to the new update rather than the newest update if they want to.
Don't indefinitely re-fetch the same update version.

Modified: trunk/freenet/src/freenet/client/async/USKChecker.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKChecker.java      2006-08-17 
16:19:51 UTC (rev 10165)
+++ trunk/freenet/src/freenet/client/async/USKChecker.java      2006-08-17 
16:21:41 UTC (rev 10166)
@@ -75,4 +75,7 @@
                return "USKChecker for "+key.getURI();
        }

+       public short getPriorityClass() {
+               return cb.getPriority();
+       }
 }

Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java      2006-08-17 
16:19:51 UTC (rev 10165)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java      2006-08-17 
16:21:41 UTC (rev 10166)
@@ -76,6 +76,9 @@

        /** Cancelled? */
        private boolean cancelled;
+
+       /** Kill a background poll fetcher when it has lost its last 
subscriber? */
+       private boolean killOnLoseSubscribers;

        final ClientRequester parent;

@@ -151,9 +154,13 @@
                }

                public short getPriority() {
-                       if(backgroundPoll)
+                       if(backgroundPoll) {
+                               if(minFailures == origMinFailures && 
minFailures != maxMinFailures) {
+                                       // Either just started, or just 
advanced, either way boost the priority.
+                                       return 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+                               }
                                return RequestStarter.UPDATE_PRIORITY_CLASS;
-                       else
+                       } else
                                return parent.getPriorityClass();
                }
        }
@@ -312,10 +319,11 @@
                        Logger.minor(this, "Latest: "+curLatest);
                        long addTo = curLatest + minFailures;
                        long addFrom = Math.max(lastAddedEdition + 1, curLatest 
+ 1);
+                       Logger.minor(this, "Adding from "+addFrom+" to 
"+addTo+" for "+origUSK);
                        if(addTo >= addFrom) {
                                l = new LinkedList();
                                for(long i=addFrom;i<=addTo;i++) {
-                                       Logger.minor(this, "Adding checker for 
edition "+i);
+                                       Logger.minor(this, "Adding checker for 
edition "+i+" for "+origUSK);
                                        l.add(add(i));
                                }
                        }
@@ -383,12 +391,15 @@
                Logger.minor(this, "Adding USKAttempt for "+i+" for 
"+origUSK.getURI());
                if(!runningAttempts.isEmpty()) {
                        USKAttempt last = (USKAttempt) 
runningAttempts.lastElement();
-                       if(last.number >= i)
+                       if(last.number >= i) {
+                               Logger.minor(this, "Returning because 
last.number="+i+" for "+origUSK.getURI());
                                return null;
+                       }
                }
                USKAttempt a = new USKAttempt(i);
                runningAttempts.add(a);
                lastAddedEdition = i;
+               Logger.minor(this, "Added "+a+" for "+origUSK);
                return a;
        }

@@ -448,8 +459,12 @@
                return !subscribers.isEmpty();
        }

-       public synchronized void removeSubscriber(USKCallback cb) {
-               subscribers.remove(cb);
+       public void removeSubscriber(USKCallback cb) {
+               synchronized(this) {
+                       subscribers.remove(cb);
+                       if(!(subscribers.isEmpty() && killOnLoseSubscribers)) 
return;
+               }
+               cancel();
        }

        public synchronized boolean hasLastData() {
@@ -474,4 +489,8 @@
                lastRequestData = null;
        }

+       public synchronized void killOnLoseSubscribers() {
+               this.killOnLoseSubscribers = true;
+       }
+       
 }

Modified: trunk/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKManager.java      2006-08-17 
16:19:51 UTC (rev 10165)
+++ trunk/freenet/src/freenet/client/async/USKManager.java      2006-08-17 
16:21:41 UTC (rev 10166)
@@ -118,6 +118,7 @@
                                } else {
                                        Logger.minor(this, "Allowing temporary 
background fetcher to continue as it has subscribers... "+fetcher);
                                        // It will burn itself out anyway as 
it's a temp fetcher, so no big harm here.
+                                       fetcher.killOnLoseSubscribers();
                                }
                        }
                }

Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2006-08-17 
16:19:51 UTC (rev 10165)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2006-08-17 
16:21:41 UTC (rev 10166)
@@ -57,6 +57,7 @@
        private final int currentVersion;
        private int availableVersion;
        private int fetchingVersion;
+       private int fetchedVersion;

        private String revocationMessage;
        private boolean hasBeenBlown;
@@ -143,6 +144,8 @@
                        try{
                                Logger.minor(this, "maybeUpdate: 
isFetching="+isFetching+", isRunning="+isRunning+", 
isUpdatable="+isUpdatable()+", availableVersion="+availableVersion);
                                if(isFetching || (!isRunning) || 
(!isUpdatable())) return;
+                               if(availableVersion == fetchedVersion) return;
+                               fetchingVersion = availableVersion;
                        }catch (PrivkeyHasBeenBlownException e){
                                // Handled in blow().
                                isRunning=false;
@@ -150,8 +153,7 @@
                        }


-                       fetchingVersion = availableVersion;
-                       alert.set(availableVersion,fetchingVersion,result != 
null && result.asBucket() != null && result.asBucket().size() > 0);
+                       alert.set(availableVersion,fetchedVersion,result != 
null && result.asBucket() != null && result.asBucket().size() > 0);
                        alert.isValid(true);
                        Logger.normal(this,"Starting the update process 
("+availableVersion+")");
                        System.err.println("Starting the update process: found 
the update ("+availableVersion+"), now fetching it.");
@@ -420,6 +422,7 @@
                                }
                                return;
                        }
+                       this.fetchedVersion = fetchingVersion;
                        System.out.println("Found "+fetchingVersion);
                        Logger.normal(this, "Found a new version! (" + 
fetchingVersion + ", setting up a new UpdatedVersionAviableUserAlert");
                        alert.set(availableVersion,fetchingVersion,true);

Modified: 
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java
===================================================================
--- 
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java 
    2006-08-17 16:19:51 UTC (rev 10165)
+++ 
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java 
    2006-08-17 16:21:41 UTC (rev 10166)
@@ -54,8 +54,13 @@
                        if (isReady) {
                                alertNode.addChild("#", " Updating to " + 
version + " is advised.");
                                alertNode.addChild("form", new String[] { 
"action", "method" }, new String[] { "/", "post" }).addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "submit", "update", 
"Update to " + readyVersion + " now" });
+                               if(readyVersion < version)
+                                       alertNode.addChild("#", "The node is 
currently fetching version "+version+" but you can update to "+readyVersion+" 
now, or wait for the node to fetch "+version+".");
                        } else {
-                               alertNode.addChild("#", " Your node is 
currently fetching the update and will ask you whether you want to update or 
not when it's ready.");
+                               if(updater.isAutoUpdateAllowed)
+                                       alertNode.addChild("#", " Your node is 
currently fetching the update and will automatically restart when it's ready 
(as configured).");
+                               else
+                                       alertNode.addChild("#", " Your node is 
currently fetching the update and will ask you whether you want to update or 
not when it's ready.");
                        }
                }
                return alertNode;


Reply via email to