Author: toad
Date: 2009-04-18 13:45:11 +0000 (Sat, 18 Apr 2009)
New Revision: 26961

Modified:
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/client/async/USKManager.java
Log:
Fetch content in temporary background fetcher, hence fix regression.
FIXME: priorities are set to IMMEDIATE_SPLITFILE for easy testing, should be 
reverted when current changes finished.


Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2009-04-18 13:34:54 UTC (rev 26960)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2009-04-18 13:45:11 UTC (rev 26961)
@@ -1078,7 +1078,7 @@
                        long edition = context.uskManager.lookupKnownGood(usk);
                        if(edition <= usk.suggestedEdition) {
                                // Background fetch - start background fetch 
first so can pick up updates in the datastore during registration.
-                               
context.uskManager.startTemporaryBackgroundFetcher(usk, context);
+                               
context.uskManager.startTemporaryBackgroundFetcher(usk, context, ctx, true);
                                edition = 
context.uskManager.lookupKnownGood(usk);
                                if(edition > usk.suggestedEdition) {
                                        if(logMINOR) 
Logger.minor(SingleFileFetcher.class, "Redirecting to edition "+edition);

Modified: trunk/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKManager.java      2009-04-18 
13:34:54 UTC (rev 26960)
+++ trunk/freenet/src/freenet/client/async/USKManager.java      2009-04-18 
13:45:11 UTC (rev 26961)
@@ -9,6 +9,11 @@
 import com.db4o.ObjectContainer;
 
 import freenet.client.FetchContext;
+import freenet.client.FetchException;
+import freenet.client.HighLevelSimpleClient;
+import freenet.client.NullClientCallback;
+import freenet.clients.http.FProxyToadlet;
+import freenet.keys.FreenetURI;
 import freenet.keys.USK;
 import freenet.node.NodeClientCore;
 import freenet.node.RequestClient;
@@ -16,6 +21,7 @@
 import freenet.support.Executor;
 import freenet.support.LRUQueue;
 import freenet.support.Logger;
+import freenet.support.io.NullBucket;
 
 /**
  * Tracks the latest version of every known USK.
@@ -45,14 +51,20 @@
        final LRUQueue<USK> temporaryBackgroundFetchersLRU;
        
        final FetchContext backgroundFetchContext;
+       /** This one actually fetches data */
+       final FetchContext realFetchContext;
        
        final Executor executor;
        
        private ClientContext context;
        
        public USKManager(NodeClientCore core) {
-               backgroundFetchContext = 
core.makeClient(RequestStarter.UPDATE_PRIORITY_CLASS).getFetchContext();
+               HighLevelSimpleClient client = 
core.makeClient(RequestStarter.UPDATE_PRIORITY_CLASS);
+               client.setMaxIntermediateLength(FProxyToadlet.MAX_LENGTH);
+               client.setMaxLength(FProxyToadlet.MAX_LENGTH);
+               backgroundFetchContext = client.getFetchContext();
                backgroundFetchContext.followRedirects = false;
+               realFetchContext = client.getFetchContext();
                latestKnownGoodByClearUSK = new HashMap<USK, Long>();
                latestSlotByClearUSK = new HashMap<USK, Long>();
                subscribersByClearUSK = new HashMap<USK, USKCallback[]>();
@@ -114,7 +126,7 @@
                return getFetcher(usk, persistent ? new 
FetchContext(backgroundFetchContext, FetchContext.IDENTICAL_MASK, false, null) 
: backgroundFetchContext, true, client.persistent(), cb, true, container, 
context);
        }
 
-       public void startTemporaryBackgroundFetcher(USK usk, ClientContext 
context) {
+       public void startTemporaryBackgroundFetcher(USK usk, ClientContext 
context, final FetchContext fctx, boolean prefetchContent) {
                USK clear = usk.clearCopy();
                USKFetcher sched = null;
                Vector<USKFetcher> toCancel = null;
@@ -127,10 +139,41 @@
 //                     }
                        USKFetcher f = backgroundFetchersByClearUSK.get(clear);
                        if(f == null) {
-                               f = new USKFetcher(usk, this, 
backgroundFetchContext, new USKFetcherWrapper(usk, 
RequestStarter.UPDATE_PRIORITY_CLASS, this), 3, false, false);
+                               f = new USKFetcher(usk, this, 
backgroundFetchContext, new USKFetcherWrapper(usk, 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS, this), 3, false, false);
                                sched = f;
                                backgroundFetchersByClearUSK.put(clear, f);
                        }
+                       if(prefetchContent)
+                               f.addCallback(new USKFetcherCallback() {
+
+                                       public void onCancelled(ObjectContainer 
container, ClientContext context) {
+                                               // Ok
+                                       }
+
+                                       public void onFailure(ObjectContainer 
container, ClientContext context) {
+                                               // Ok
+                                       }
+
+                                       public void onFoundEdition(long l, USK 
key, ObjectContainer container, ClientContext context, boolean metadata, short 
codec, byte[] data, boolean newKnownGood, boolean newSlotToo) {
+                                               FreenetURI uri = 
key.copy(l).getURI();
+                                               final ClientGetter get = new 
ClientGetter(new NullClientCallback(), uri, new FetchContext(fctx, 
FetchContext.IDENTICAL_MASK, false, null), 
RequestStarter.UPDATE_PRIORITY_CLASS, USKManager.this, new NullBucket(), null);
+                                               try {
+                                                       get.start(null, 
context);
+                                               } catch (FetchException e) {
+                                                       // Ignore
+                                               }
+                                       }
+
+                                       public short getPollingPriorityNormal() 
{
+                                               return 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+                                       }
+
+                                       public short 
getPollingPriorityProgress() {
+                                               return 
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+                                       }
+                                       
+                                       
+                               });
                        temporaryBackgroundFetchersLRU.push(clear);
                        while(temporaryBackgroundFetchersLRU.size() > 
NodeClientCore.maxBackgroundUSKFetchers) {
                                USK del = temporaryBackgroundFetchersLRU.pop();

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

Reply via email to