Author: toad
Date: 2009-04-15 19:46:22 +0000 (Wed, 15 Apr 2009)
New Revision: 26853

Modified:
   trunk/freenet/src/freenet/client/async/USKManager.java
   trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java
   trunk/freenet/src/freenet/client/async/USKRetriever.java
   trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java
   trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
   trunk/freenet/src/freenet/node/PeerNode.java
   trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java
   trunk/freenet/src/freenet/node/fcp/SubscribedUSKUpdate.java
Log:
Only update bookmarks when data has actually been fetched. Various related 
bugfixes and minor refactorings. Add a couple of debugging fields to 
SubscribedUSKUpdate.


Modified: trunk/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKManager.java      2009-04-15 
19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/client/async/USKManager.java      2009-04-15 
19:46:22 UTC (rev 26853)
@@ -232,6 +232,7 @@
         * checked on a regular basis, unless runBackgroundFetch=true.
         */
        public void subscribe(USK origUSK, USKCallback cb, boolean 
runBackgroundFetch, RequestClient client) {
+               if(Logger.shouldLog(Logger.MINOR, this)) Logger.minor(this, 
"Subscribing to "+origUSK+" for "+cb);
                if(client.persistent()) throw new 
UnsupportedOperationException("USKManager subscriptions cannot be persistent");
                USKFetcher sched = null;
                long ed = origUSK.suggestedEdition;
@@ -337,7 +338,7 @@
         * @return
         */
        public USKRetriever subscribeContent(USK origUSK, USKRetrieverCallback 
cb, boolean runBackgroundFetch, FetchContext fctx, short prio, RequestClient 
client) {
-               USKRetriever ret = new USKRetriever(fctx, prio, client, cb);
+               USKRetriever ret = new USKRetriever(fctx, prio, client, cb, 
origUSK);
                subscribe(origUSK, ret, runBackgroundFetch, client);
                return ret;
        }

Modified: trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java      
2009-04-15 19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java      
2009-04-15 19:46:22 UTC (rev 26853)
@@ -39,6 +39,11 @@
        }
 
        public void onFailure(FetchException e, ClientGetState state, 
ObjectContainer container, ClientContext context) {
+               switch(e.mode) {
+               case FetchException.NOT_ENOUGH_PATH_COMPONENTS:
+               case FetchException.PERMANENT_REDIRECT:
+                       context.uskManager.updateKnownGood(usk, 
usk.suggestedEdition, context);
+               }
                if(persistent) {
                        container.activate(cb, 1);
                        container.activate(usk, 5);

Modified: trunk/freenet/src/freenet/client/async/USKRetriever.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKRetriever.java    2009-04-15 
19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/client/async/USKRetriever.java    2009-04-15 
19:46:22 UTC (rev 26853)
@@ -8,10 +8,9 @@
 import com.db4o.ObjectContainer;
 
 import freenet.client.ArchiveContext;
-import freenet.client.ClientMetadata;
+import freenet.client.FetchContext;
 import freenet.client.FetchException;
 import freenet.client.FetchResult;
-import freenet.client.FetchContext;
 import freenet.keys.FreenetURI;
 import freenet.keys.USK;
 import freenet.node.RequestClient;
@@ -25,13 +24,15 @@
        /** Context for fetching data */
        final FetchContext ctx;
        final USKRetrieverCallback cb;
+       final USK origUSK;
        
        public USKRetriever(FetchContext fctx, short prio,  
-                       RequestClient client, USKRetrieverCallback cb) {
+                       RequestClient client, USKRetrieverCallback cb, USK 
origUSK) {
                super(prio, client);
                if(client.persistent()) throw new 
UnsupportedOperationException("USKRetriever cannot be persistent");
                this.ctx = fctx;
                this.cb = cb;
+               this.origUSK = origUSK;
        }
 
        public void onFoundEdition(long l, USK key, ObjectContainer container, 
ClientContext context, boolean metadata, short codec, byte[] data, boolean 
newKnownGood, boolean newSlotToo) {
@@ -59,10 +60,17 @@
        public void onSuccess(FetchResult result, ClientGetState state, 
ObjectContainer container, ClientContext context) {
                if(Logger.shouldLog(Logger.MINOR, this))
                        Logger.minor(this, "Success on "+this+" from "+state+" 
: length "+result.size()+" mime type "+result.getMimeType());
-               cb.onFound(state.getToken(), result);
+               cb.onFound(origUSK, state.getToken(), result);
+               context.uskManager.updateKnownGood(origUSK, state.getToken(), 
context);
        }
 
        public void onFailure(FetchException e, ClientGetState state, 
ObjectContainer container, ClientContext context) {
+               switch(e.mode) {
+               case FetchException.NOT_ENOUGH_PATH_COMPONENTS:
+               case FetchException.PERMANENT_REDIRECT:
+                       context.uskManager.updateKnownGood(origUSK, 
state.getToken(), context);
+                       return;
+               }
                Logger.error(this, "Found edition "+state.getToken()+" but 
failed to fetch edition: "+e, e);
        }
 

Modified: trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java    
2009-04-15 19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java    
2009-04-15 19:46:22 UTC (rev 26853)
@@ -4,6 +4,7 @@
 package freenet.client.async;
 
 import freenet.client.FetchResult;
+import freenet.keys.USK;
 
 /**
  * Interface implemented by USKRetriever clients.
@@ -15,7 +16,7 @@
         * @param edition The USK edition number.
         * @param data The retrieved data.
         */
-       void onFound(long edition, FetchResult data);
+       void onFound(USK origUSK, long edition, FetchResult data);
 
        /**
         * Priority at which the polling should run normally.

Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java   2009-04-15 
19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java   2009-04-15 
19:46:22 UTC (rev 26853)
@@ -60,7 +60,7 @@
        // ?force= links become invalid after 2 hours.
        private static final long FORCE_GRAIN_INTERVAL = 60*60*1000;
        /** Maximum size for transparent pass-through, should be a config 
option */
-       static long MAX_LENGTH = 2*1024*1024; // 2MB
+       public static long MAX_LENGTH = 2*1024*1024; // 2MB
        
        static final URI welcome;
        static {

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2009-04-15 19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2009-04-15 19:46:22 UTC (rev 26853)
@@ -3,6 +3,7 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.clients.http.bookmark;
 
+import freenet.client.async.USKRetriever;
 import freenet.keys.FreenetURI;
 import freenet.keys.USK;
 import freenet.l10n.L10n;
@@ -26,6 +27,7 @@
     private final BookmarkUpdatedUserAlert alert;
     private final UserAlertManager alerts;
     protected String desc;
+       USKRetriever retriever;
 
     public BookmarkItem(FreenetURI k, String n, String d, boolean 
hasAnActivelink, UserAlertManager uam)
             throws MalformedURLException {

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2009-04-15 19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2009-04-15 19:46:22 UTC (rev 26853)
@@ -15,8 +15,11 @@
 
 import java.util.List;
 
+import freenet.client.FetchResult;
 import freenet.client.async.ClientContext;
 import freenet.client.async.USKCallback;
+import freenet.client.async.USKRetrieverCallback;
+import freenet.clients.http.FProxyToadlet;
 import freenet.keys.FreenetURI;
 import freenet.keys.USK;
 import freenet.l10n.L10n;
@@ -98,6 +101,11 @@
        private class USKUpdatedCallback implements USKCallback {
 
                public void onFoundEdition(long edition, USK key, 
ObjectContainer container, ClientContext context, boolean wasMetadata, short 
codec, byte[] data, boolean newKnownGood, boolean newSlotToo) {
+                       if(!newKnownGood) {
+                               FreenetURI uri = key.copy(edition).getURI();
+                               node.makeClient(PRIORITY).prefetch(uri, 
60*60*1000, FProxyToadlet.MAX_LENGTH, null, PRIORITY);
+                               return;
+                       }
                        List<BookmarkItem> items = MAIN_CATEGORY.getAllItems();
                        for(int i = 0; i < items.size(); i++) {
                                if(!"USK".equals(items.get(i).getKeyType()))
@@ -108,7 +116,7 @@
                                        USK usk = USK.create(furi);
 
                                        if(usk.equals(key, false)) {
-                                               
items.get(i).setEdition(key.suggestedEdition, node);
+                                               
items.get(i).setEdition(edition, node);
                                                break;
                                        }
                                } catch(MalformedURLException mue) {
@@ -118,11 +126,11 @@
                }
 
                public short getPollingPriorityNormal() {
-                       return RequestStarter.PREFETCH_PRIORITY_CLASS;
+                       return PRIORITY;
                }
 
                public short getPollingPriorityProgress() {
-                       return RequestStarter.UPDATE_PRIORITY_CLASS;
+                       return PRIORITY;
                }
        }
 
@@ -293,6 +301,8 @@
                _innerReadBookmarks("", category, sfs);
        }
        
+       static final short PRIORITY = 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+       
        private void subscribeToUSK(BookmarkItem item) {
                if("USK".equals(item.getKeyType()))
                        try {

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2009-04-15 19:44:45 UTC 
(rev 26852)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2009-04-15 19:46:22 UTC 
(rev 26853)
@@ -3321,7 +3321,7 @@
                        om.dropExcessPeers();
        }
 
-       public void onFound(long edition, FetchResult result) {
+       public void onFound(USK origUSK, long edition, FetchResult result) {
                if(isConnected() || myARK.suggestedEdition > edition) {
                        result.asBucket().free();
                        return;

Modified: trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java        2009-04-15 
19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java        2009-04-15 
19:46:22 UTC (rev 26853)
@@ -36,8 +36,8 @@
                        core.uskManager.unsubscribe(key, this, !dontPoll);
                        return;
                }
-               if(newKnownGood && !newSlotToo) return;
-               FCPMessage msg = new SubscribedUSKUpdate(identifier, l, key);
+               //if(newKnownGood && !newSlotToo) return;
+               FCPMessage msg = new SubscribedUSKUpdate(identifier, l, key, 
newKnownGood, newSlotToo);
                handler.outputHandler.queue(msg);
        }
 

Modified: trunk/freenet/src/freenet/node/fcp/SubscribedUSKUpdate.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/SubscribedUSKUpdate.java 2009-04-15 
19:44:45 UTC (rev 26852)
+++ trunk/freenet/src/freenet/node/fcp/SubscribedUSKUpdate.java 2009-04-15 
19:46:22 UTC (rev 26853)
@@ -14,13 +14,17 @@
        final String identifier;
        final long edition;
        final USK key;
+       final boolean newKnownGood;
+       final boolean newSlotToo;
        
        static final String name = "SubscribedUSKUpdate";
        
-       public SubscribedUSKUpdate(String identifier, long l, USK key) {
+       public SubscribedUSKUpdate(String identifier, long l, USK key, boolean 
newKnownGood, boolean newSlotToo) {
                this.identifier = identifier;
                this.edition = l;
                this.key = key;
+               this.newKnownGood = newKnownGood;
+               this.newSlotToo = newSlotToo;
        }
 
        @Override
@@ -29,6 +33,8 @@
                fs.putSingle("Identifier", identifier);
                fs.put("Edition", edition);
                fs.putSingle("URI", key.getURI().toString());
+               fs.put("NewKnownGood", newKnownGood);
+               fs.put("NewSlotToo", newSlotToo);
                return fs;
        }
 

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to