Author: jflesch
Date: 2006-10-29 13:47:43 +0000 (Sun, 29 Oct 2006)
New Revision: 10731

Modified:
   trunk/freenet/src/freenet/client/async/BaseClientGetter.java
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/ClientRequester.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/clients/http/NinjaSpider.java
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/GetRequestStatusMessage.java
Log:
Fix https://bugs.freenetproject.org/view.php?id=651

Modified: trunk/freenet/src/freenet/client/async/BaseClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/BaseClientGetter.java        
2006-10-29 00:00:48 UTC (rev 10730)
+++ trunk/freenet/src/freenet/client/async/BaseClientGetter.java        
2006-10-29 13:47:43 UTC (rev 10731)
@@ -9,6 +9,4 @@
        protected BaseClientGetter(short priorityClass, ClientRequestScheduler 
chkScheduler, ClientRequestScheduler sskScheduler, Object client) {
                super(priorityClass, chkScheduler, sskScheduler, client);
        }
-
-       
 }

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-10-29 
00:00:48 UTC (rev 10730)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-10-29 
13:47:43 UTC (rev 10731)
@@ -44,8 +44,8 @@
         * write the data directly to the bucket, or copy it and free the 
original temporary bucket. Preferably the
         * former, obviously!
         */
-       public ClientGetter(ClientCallback client, ClientRequestScheduler 
chkSched, ClientRequestScheduler sskSched, 
-                       FreenetURI uri, FetcherContext ctx, short 
priorityClass, Object clientContext, Bucket returnBucket) {
+       public ClientGetter(ClientCallback client, ClientRequestScheduler 
chkSched, ClientRequestScheduler sskSched,
+                           FreenetURI uri, FetcherContext ctx, short 
priorityClass, Object clientContext, Bucket returnBucket) {
                super(priorityClass, chkSched, sskSched, clientContext);
                this.client = client;
                this.returnBucket = returnBucket;
@@ -55,11 +55,11 @@
                this.actx = new ArchiveContext(ctx.maxArchiveLevels);
                archiveRestarts = 0;
        }
-       
+
        public void start() throws FetchException {
                start(false);
        }
-       
+
        public boolean start(boolean restart) throws FetchException {
                try {
                        // FIXME synchronization is probably unnecessary.
@@ -136,7 +136,7 @@
                        return;
                }
        }
-       
+
        public void cancel() {
                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                if(logMINOR) Logger.minor(this, "Cancelling "+this);
@@ -178,7 +178,7 @@
                                Logger.minor(this, "Ignoring transition: 
"+oldState+" -> "+newState+" because current = "+currentState);
                }
                // TODO Auto-generated method stub
-               
+
        }

        public boolean canRestart() {

Modified: trunk/freenet/src/freenet/client/async/ClientRequester.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequester.java 2006-10-29 
00:00:48 UTC (rev 10730)
+++ trunk/freenet/src/freenet/client/async/ClientRequester.java 2006-10-29 
13:47:43 UTC (rev 10731)
@@ -8,7 +8,7 @@

 /** A high level client request. A request (either fetch or put) started
  * by a Client. Has a suitable context and a URI; is fulfilled only when
- * we have followed all the redirects etc, or have an error. Can be 
+ * we have followed all the redirects etc, or have an error. Can be
  * retried.
  */
 public abstract class ClientRequester {
@@ -19,30 +19,30 @@
        final ClientRequestScheduler chkScheduler;
        final ClientRequestScheduler sskScheduler;
        protected final Object client;
-       
+
        public short getPriorityClass() {
                return priorityClass;
        }
-       
+
        protected ClientRequester(short priorityClass, ClientRequestScheduler 
chkScheduler, ClientRequestScheduler sskScheduler, Object client) {
                this.priorityClass = priorityClass;
                this.chkScheduler = chkScheduler;
                this.sskScheduler = sskScheduler;
                this.client = client;
        }
-       
+
        public void cancel() {
                cancelled = true;
        }
-       
+
        public boolean isCancelled() {
                return cancelled;
        }
-       
+
        public abstract FreenetURI getURI();
-       
+
        public abstract boolean isFinished();
-       
+
        /** Total number of blocks this request has tried to fetch/put. */
        protected int totalBlocks;
        /** Number of blocks we have successfully completed a fetch/put for. */
@@ -55,7 +55,7 @@
        protected int minSuccessBlocks;
        /** Has totalBlocks stopped growing? */
        protected boolean blockSetFinalized;
-       
+
        public void blockSetFinalized() {
                synchronized(this) {
                        if(blockSetFinalized) return;
@@ -65,7 +65,7 @@
                        Logger.minor(this, "Finalized set of blocks for "+this, 
new Exception("debug"));
                notifyClients();
        }
-       
+
        public synchronized void addBlock() {
                if(blockSetFinalized)
                        if(Logger.globalGetThreshold() > Logger.MINOR)
@@ -74,7 +74,7 @@
                                Logger.error(this, "addBlock() but set 
finalized! on "+this, new Exception("error"));
                totalBlocks++;
        }
-       
+
        public synchronized void addBlocks(int num) {
                if(blockSetFinalized)
                        if(Logger.globalGetThreshold() > Logger.MINOR)
@@ -83,7 +83,7 @@
                                Logger.error(this, "addBlocks() but set 
finalized! on "+this, new Exception("error"));
                totalBlocks+=num;
        }
-       
+
        public void completedBlock(boolean dontNotify) {
                if(Logger.shouldLog(Logger.MINOR, this))
                        Logger.minor(this, "Completed block ("+dontNotify+")");
@@ -93,25 +93,25 @@
                }
                notifyClients();
        }
-       
+
        public void failedBlock() {
                synchronized(this) {
                        failedBlocks++;
                }
                notifyClients();
        }
-       
+
        public void fatallyFailedBlock() {
                synchronized(this) {
                        fatallyFailedBlocks++;
                }
                notifyClients();
        }
-       
+
        public synchronized void addMustSucceedBlocks(int blocks) {
                minSuccessBlocks += blocks;
        }
-       
+
        public abstract void notifyClients();

        /** Get client context object */

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-10-29 00:00:48 UTC (rev 10730)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-10-29 13:47:43 UTC (rev 10731)
@@ -51,16 +51,16 @@
        private final boolean dontTellClientGet;
        private Object token;
        private final Bucket returnBucket;
-       
+
        /** Create a new SingleFileFetcher and register self.
         * Called when following a redirect, or direct from ClientGet.
-        * @param token 
-        * @param dontTellClientGet 
+        * @param token
+        * @param dontTellClientGet
         */
-       public SingleFileFetcher(BaseClientGetter get, GetCompletionCallback 
cb, ClientMetadata metadata, 
-                       ClientKey key, LinkedList metaStrings, FetcherContext 
ctx, 
-                       ArchiveContext actx, int maxRetries, int 
recursionLevel, 
-                       boolean dontTellClientGet, Object token, boolean 
isEssential, 
+       public SingleFileFetcher(BaseClientGetter get, GetCompletionCallback 
cb, ClientMetadata metadata,
+                       ClientKey key, LinkedList metaStrings, FetcherContext 
ctx,
+                       ArchiveContext actx, int maxRetries, int recursionLevel,
+                       boolean dontTellClientGet, Object token, boolean 
isEssential,
                        Bucket returnBucket) throws FetchException {
                super(key, maxRetries, ctx, get);
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
@@ -645,4 +645,4 @@

        }

-}
\ No newline at end of file
+}

Modified: trunk/freenet/src/freenet/clients/http/NinjaSpider.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/NinjaSpider.java     2006-10-29 
00:00:48 UTC (rev 10730)
+++ trunk/freenet/src/freenet/clients/http/NinjaSpider.java     2006-10-29 
13:47:43 UTC (rev 10731)
@@ -62,7 +62,7 @@
  * This name comes from my flatmate, David Anderson. It originated in the 
following discussion over dinner:
  *   him> I've just thought of something weird...
  *   me> oO
- *   him> The term "spider" for indexing software comes from the analogy "a 
spider one the web", right ?
+ *   him> The term "spider" for indexing software comes from the analogy "a 
spider on the web", right ?
  *   me> Yeeess... ?
  *   him> So, if you're writing a spider for a darknet, isn't it a .... *Ninja 
Spider* ? :D
  *
@@ -448,7 +448,7 @@

                        Element fileElement = xmlDoc.createElement("file");

-                       fileElement.setAttribute("id", (new 
Integer(i)).toString());
+                       fileElement.setAttribute("id", Integer.toString(i));
                        fileElement.setAttribute("key", 
uris[i].toString(false));

                        Long size = 
(Long)sizeOfURIs.get(uris[i].toString(false));

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java   2006-10-29 00:00:48 UTC 
(rev 10730)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java   2006-10-29 13:47:43 UTC 
(rev 10731)
@@ -43,10 +43,10 @@
        private final File tempFile;
        /** Bucket passed in to the ClientGetter to return data in. Null unless 
returntype=disk */
        private Bucket returnBucket;
-       
+
        // Verbosity bitmasks
        private int VERBOSITY_SPLITFILE_PROGRESS = 1;
-       
+
        // Stuff waiting for reconnection
        /** Did the request succeed? Valid if finished. */
        private boolean succeeded;
@@ -67,15 +67,16 @@

        /**
         * Create one for a global-queued request not made by FCP.
-        * @throws IdentifierCollisionException 
+        * @throws IdentifierCollisionException
         */
-       public ClientGet(FCPClient globalClient, FreenetURI uri, boolean 
dsOnly, boolean ignoreDS, 
-                       int maxSplitfileRetries, int maxNonSplitfileRetries, 
long maxOutputLength, 
+       public ClientGet(FCPClient globalClient, FreenetURI uri, boolean 
dsOnly, boolean ignoreDS,
+                       int maxSplitfileRetries, int maxNonSplitfileRetries, 
long maxOutputLength,
                        short returnType, boolean persistRebootOnly, String 
identifier, int verbosity, short prioClass,
                        File returnFilename, File returnTempFilename) throws 
IdentifierCollisionException {
-               super(uri, identifier, verbosity, null, globalClient, 
prioClass, 
+               super(uri, identifier, verbosity, null, globalClient, prioClass,
                                (persistRebootOnly ? 
ClientRequest.PERSIST_REBOOT : ClientRequest.PERSIST_FOREVER),
                                                null, true);
+
                fctx = new FetcherContext(client.defaultFetchContext, 
FetcherContext.IDENTICAL_MASK, false);
                fctx.eventProducer.addEventListener(this);
                fctx.localRequestOnly = dsOnly;
@@ -123,8 +124,8 @@
                        client.queueClientRequestMessage(msg, 0);
                }
        }
-       
-       
+
+
        public ClientGet(FCPConnectionHandler handler, ClientGetMessage 
message) throws IdentifierCollisionException {
                super(message.uri, message.identifier, message.verbosity, 
handler, message.priorityClass,
                                message.persistenceType, message.clientToken, 
message.global);
@@ -185,12 +186,13 @@

        /**
         * Create a ClientGet from a request serialized to a SimpleFieldSet.
-        * Can throw, and does minimal verification, as is dealing with data 
+        * Can throw, and does minimal verification, as is dealing with data
         * supposedly serialized out by the node.
-        * @throws IOException 
+        * @throws IOException
         */
        public ClientGet(SimpleFieldSet fs, FCPClient client2) throws 
IOException {
                super(fs, client2);
+
                returnType = 
ClientGetMessage.parseValidReturnType(fs.get("ReturnType"));
                String f = fs.get("Filename");
                if(f != null)
@@ -254,14 +256,20 @@
                        }
                }
                returnBucket = ret;
-               
+
                getter = new ClientGetter(this, 
client.core.requestStarters.chkFetchScheduler, 
client.core.requestStarters.sskFetchScheduler, uri, fctx, priorityClass, 
client.lowLevelClient, returnBucket);
+
                if(persistenceType != PERSIST_CONNECTION) {
                        FCPMessage msg = persistentTagMessage();
                        client.queueClientRequestMessage(msg, 0);
                }
-               if(finished && !succeeded)
+               if(finished && !succeeded) {
                        started = true;
+               }
+
+               if (finished && succeeded) {
+                       allDataPending = new AllDataMessage(returnBucket, 
identifier);
+               }
        }

        public void start() {
@@ -277,13 +285,13 @@
                        onFailure(e, null);
                }
        }
-       
+
        public void onLostConnection() {
                if(persistenceType == PERSIST_CONNECTION)
                        cancel();
                // Otherwise ignore
        }
-       
+
        public void onSuccess(FetchResult result, ClientGetter state) {
                Logger.minor(this, "Succeeded: "+identifier);
                Bucket data = result.asBucket();
@@ -343,6 +351,7 @@
                        finished = true;
                }
                trySendDataFoundOrGetFailed(null);
+
                if(adm != null)
                        trySendAllDataMessage(adm, null);
                if(!dontFree)
@@ -351,9 +360,9 @@
        }

        private void trySendDataFoundOrGetFailed(FCPConnectionOutputHandler 
handler) {
-               
+
                FCPMessage msg;
-               
+
                // Don't need to lock. succeeded is only ever set, never unset.
                // and succeeded and getFailedMessage are both atomic.
                if(succeeded) {
@@ -382,14 +391,14 @@
                        client.queueClientRequestMessage(msg, 0);
                }
        }
-       
+
        private void trySendProgress(SimpleProgressMessage msg, 
FCPConnectionOutputHandler handler) {
                if(persistenceType != ClientRequest.PERSIST_CONNECTION) {
                        progressPending = msg;
                }
                client.queueClientRequestMessage(msg, 
VERBOSITY_SPLITFILE_PROGRESS);
        }
-       
+
        public void sendPendingMessages(FCPConnectionOutputHandler handler, 
boolean includePersistentRequest, boolean includeData, boolean onlyData) {
                if(persistenceType == ClientRequest.PERSIST_CONNECTION) {
                        Logger.error(this, "WTF? 
persistenceType="+persistenceType, new Exception("error"));
@@ -405,6 +414,11 @@
                        if(finished)
                                trySendDataFoundOrGetFailed(handler);
                }
+
+               if (onlyData && allDataPending  == null) {
+                       Logger.error(this, "No data pending !");
+               }
+
                if(includeData && (allDataPending != null))
                        handler.queue(allDataPending);
        }
@@ -445,7 +459,7 @@
                if(!(((verbosity & VERBOSITY_SPLITFILE_PROGRESS) == 
VERBOSITY_SPLITFILE_PROGRESS) &&
                                (ce instanceof SplitfileProgressEvent)))
                        return;
-               SimpleProgressMessage progress = 
+               SimpleProgressMessage progress =
                        new SimpleProgressMessage(identifier, 
(SplitfileProgressEvent)ce);
                trySendProgress(progress, null);
        }
@@ -540,35 +554,35 @@
                } else
                        return -1;
        }
-       
+
        public double getTotalBlocks() {
                if(progressPending != null) {
                        return progressPending.getTotalBlocks();
                } else
                        return 1;
        }
-       
+
        public double getMinBlocks() {
                if(progressPending != null) {
                        return progressPending.getMinBlocks();
                } else
                        return 1;
        }
-       
+
        public double getFailedBlocks() {
                if(progressPending != null) {
                        return progressPending.getFailedBlocks();
                } else
                        return 0;
        }
-       
+
        public double getFatalyFailedBlocks() {
                if(progressPending != null) {
                        return progressPending.getFatalyFailedBlocks();
                } else
                        return 0;
        }
-       
+
        public double getFetchedBlocks() {
                if(progressPending != null) {
                        return progressPending.getFetchedBlocks();
@@ -593,7 +607,7 @@

        /**
         * Returns the {@link Bucket} that contains the downloaded data.
-        * 
+        *
         * @return The data in a {@link Bucket}, or <code>null</code> if this
         *         isn&rsquo;t applicable
         */

Modified: trunk/freenet/src/freenet/node/fcp/GetRequestStatusMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/GetRequestStatusMessage.java     
2006-10-29 00:00:48 UTC (rev 10730)
+++ trunk/freenet/src/freenet/node/fcp/GetRequestStatusMessage.java     
2006-10-29 13:47:43 UTC (rev 10731)
@@ -33,9 +33,9 @@
        public void run(FCPConnectionHandler handler, Node node)
                        throws MessageInvalidException {
                ClientRequest req;
-               if(global)
+               if(global) {
                        req = 
handler.server.globalClient.getRequest(identifier);
-               else
+               } else
                        req = handler.getClient().getRequest(identifier);
                if(req == null) {
                        ProtocolErrorMessage msg = new 
ProtocolErrorMessage(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, false, null, 
identifier);


Reply via email to