Author: toad
Date: 2006-03-04 22:02:57 +0000 (Sat, 04 Mar 2006)
New Revision: 8163

Modified:
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/ClientPut.java
   trunk/freenet/src/freenet/node/fcp/FCPClient.java
   trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
   trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
   trunk/freenet/src/freenet/support/io/FileBucket.java
Log:
496:
Persistence bugfixes.

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-03-04 
20:56:02 UTC (rev 8162)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2006-03-04 
22:02:57 UTC (rev 8163)
@@ -72,7 +72,8 @@
                                BucketTools.copy(from, to);
                                from.free();
                        } catch (IOException e) {
-                               onFailure(new 
FetchException(FetchException.BUCKET_ERROR), state /* not strictly to blame, 
but we're not ako ClientGetState... */);
+                               Logger.error(this, "Error copying from "+from+" 
to "+to+" : "+e.toString(), e);
+                               onFailure(new 
FetchException(FetchException.BUCKET_ERROR, e.toString()), state /* not 
strictly to blame, but we're not ako ClientGetState... */);
                        }
                        result = new FetchResult(result, to);
                } else {

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-03-04 20:56:02 UTC (rev 
8162)
+++ trunk/freenet/src/freenet/node/Version.java 2006-03-04 22:02:57 UTC (rev 
8163)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 495;
+       private static final int buildNumber = 496;

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 475;

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java   2006-03-04 20:56:02 UTC 
(rev 8162)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java   2006-03-04 22:02:57 UTC 
(rev 8163)
@@ -127,6 +127,8 @@
                        }
                }
                returnBucket = ret;
+               if(persistenceType != PERSIST_CONNECTION)
+                       client.register(this);
                getter = new ClientGetter(this, client.node.fetchScheduler, 
uri, fctx, priorityClass, client, returnBucket);
                if(persistenceType != PERSIST_CONNECTION && handler != null)
                        sendPendingMessages(handler.outputHandler, true);

Modified: trunk/freenet/src/freenet/node/fcp/ClientPut.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPut.java   2006-03-04 20:56:02 UTC 
(rev 8162)
+++ trunk/freenet/src/freenet/node/fcp/ClientPut.java   2006-03-04 22:02:57 UTC 
(rev 8163)
@@ -99,6 +99,8 @@
                String mimeType = message.contentType;
                clientToken = message.clientToken;
                block = new InsertBlock(message.bucket, new 
ClientMetadata(mimeType), uri);
+               if(persistenceType != PERSIST_CONNECTION)
+                       client.register(this);
                inserter = new ClientPutter(this, message.bucket, uri, new 
ClientMetadata(mimeType), ctx, client.node.putScheduler, priorityClass, 
getCHKOnly, false, client);
                if(persistenceType != PERSIST_CONNECTION && handler != null)
                        sendPendingMessages(handler.outputHandler, true);

Modified: trunk/freenet/src/freenet/node/fcp/FCPClient.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPClient.java   2006-03-04 20:56:02 UTC 
(rev 8162)
+++ trunk/freenet/src/freenet/node/fcp/FCPClient.java   2006-03-04 22:02:57 UTC 
(rev 8163)
@@ -89,11 +89,13 @@
                        completedUnackedRequests.push(get);

                        if(completedUnackedRequests.size() > 
MAX_UNACKED_REQUESTS) {
+                               
clientRequestsByIdentifier.remove(dropped.getIdentifier());
                                dropped = (ClientRequest) 
completedUnackedRequests.pop();
                        }
                }
-               if(dropped != null)
+               if(dropped != null) {
                        dropped.dropped();
+               }
                if(get.isPersistentForever())
                        server.forceStorePersistentRequests();
        }
@@ -139,9 +141,9 @@
                synchronized(this) {
                        req = (ClientRequest) 
clientRequestsByIdentifier.get(identifier);
                        if(req == null)
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, null, 
identifier);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, "Not in hash", 
identifier);
                        else if(!(runningPersistentRequests.remove(req) | 
completedUnackedRequests.remove(req)))
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, null, 
identifier);
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, "Not found", 
identifier);
                        clientRequestsByIdentifier.remove(identifier);
                }
                server.forceStorePersistentRequests();

Modified: trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java        
2006-03-04 20:56:02 UTC (rev 8162)
+++ trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java        
2006-03-04 22:02:57 UTC (rev 8163)
@@ -116,12 +116,13 @@
                        outputHandler.queue(msg);
                        return;
                } else {
-                       cg.start();
+                       // Register before starting, because it may complete 
immediately, and if it does,
+                       // we may end up with it not being removable because it 
wasn't registered!
                        if(cg.isPersistent()) {
-                               client.register(cg);
                                if(cg.isPersistentForever())
                                        server.forceStorePersistentRequests();
                        }
+                       cg.start();
                }
        }

@@ -143,12 +144,13 @@
                        outputHandler.queue(msg);
                        return;
                } else {
-                       cp.start();
+                       // Register before starting, because it may complete 
immediately, and if it does,
+                       // we may end up with it not being removable because it 
wasn't registered!
                        if(cp.isPersistent()) {
-                               client.register(cp);
                                if(cp.isPersistentForever())
                                        server.forceStorePersistentRequests();
                        }
+                       cp.start();
                }
        }


Modified: 
trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java     
2006-03-04 20:56:02 UTC (rev 8162)
+++ trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java     
2006-03-04 22:02:57 UTC (rev 8163)
@@ -101,6 +101,7 @@
                final PCFBMode pcfb;
                final OutputStream out;
                final int streamNumber;
+               private boolean closed;

                public PaddedEphemerallyEncryptedOutputStream(OutputStream out, 
int streamNumber) {
                        this.out = out;
@@ -110,6 +111,7 @@
                }

                public void write(int b) throws IOException {
+                       if(closed) throw new IOException("Already closed!");
                        if(streamNumber != lastOutputStream)
                                throw new IllegalStateException("Writing to old 
stream in "+getName());
                        if(b < 0 || b > 255)
@@ -122,6 +124,7 @@
                }

                public void write(byte[] buf, int offset, int length) throws 
IOException {
+                       if(closed) throw new IOException("Already closed!");
                        if(streamNumber != lastOutputStream)
                                throw new IllegalStateException("Writing to old 
stream in "+getName());
                        byte[] enc = new byte[length];
@@ -135,12 +138,14 @@

                // Override this or FOS will use write(int)
                public void write(byte[] buf) throws IOException {
+                       if(closed) throw new IOException("Already closed!");
                        if(streamNumber != lastOutputStream)
                                throw new IllegalStateException("Writing to old 
stream in "+getName());
                        write(buf, 0, buf.length);
                }

                public void close() throws IOException {
+                       if(closed) return;
                        try {
                                if(streamNumber != lastOutputStream) {
                                        Logger.normal(this, "Not padding out to 
length because have been superceded: "+getName());
@@ -160,6 +165,7 @@
                                        }
                                }
                        } finally {
+                               closed = true;
                                out.close();
                        }
                }
@@ -255,6 +261,10 @@
                return "Encrypted:"+bucket.getName();
        }

+       public String toString() {
+               return super.toString()+":"+bucket.toString();
+       }
+       
        public long size() {
                return dataLength;
        }

Modified: trunk/freenet/src/freenet/support/io/FileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileBucket.java        2006-03-04 
20:56:02 UTC (rev 8162)
+++ trunk/freenet/src/freenet/support/io/FileBucket.java        2006-03-04 
22:02:57 UTC (rev 8163)
@@ -320,4 +320,8 @@
                                        "Delete failed on bucket " + 
file.getName());
                }
        }
+       
+       public String toString() {
+               return super.toString()+":"+file.getPath();
+       }
 }


Reply via email to