Author: toad
Date: 2006-07-26 21:12:13 +0000 (Wed, 26 Jul 2006)
New Revision: 9785

Modified:
   trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
   trunk/freenet/src/freenet/node/Version.java
Log:
910: More major bugfixes for resumable inserts.

Modified: trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java        
2006-07-26 20:49:32 UTC (rev 9784)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java        
2006-07-26 21:12:13 UTC (rev 9785)
@@ -16,6 +16,7 @@
 import freenet.support.SimpleFieldSet;
 import freenet.support.io.Bucket;
 import freenet.support.io.CannotCreateFromFieldSetException;
+import freenet.support.io.NullBucket;
 import freenet.support.io.SerializableToFieldSetBucket;
 import freenet.support.io.SerializableToFieldSetBucketUtil;

@@ -304,24 +305,26 @@
                }
                //parent.parent.notifyClients();
                started = true;
-               if(!encoded)
+               if(!encoded) {
                        Logger.minor(this, "Segment "+segNo+" of "+parent+" 
("+parent.dataLength+") is not encoded");
-               if(splitfileAlgo != null && !encoded) {
-                       Logger.minor(this, "Encoding segment "+segNo+" of 
"+parent+" ("+parent.dataLength+")");
-                       // Encode blocks
-                       Thread t = new Thread(new EncodeBlocksRunnable(), 
"Blocks encoder");
-                       t.setDaemon(true);
-                       t.start();
-                       fin = false;
-               } else if(encoded) {
+                       if(splitfileAlgo != null) {
+                               Logger.minor(this, "Encoding segment "+segNo+" 
of "+parent+" ("+parent.dataLength+")");
+                               // Encode blocks
+                               Thread t = new Thread(new 
EncodeBlocksRunnable(), "Blocks encoder");
+                               t.setDaemon(true);
+                               t.start();
+                               fin = false;
+                       }
+               } else {
                        for(int i=0;i<checkBlockInserters.length;i++) {
-                               if(checkBlocks[i] == null)
+                               if(checkBlocks[i] != null) {
+                                       checkBlockInserters[i] = 
+                                               new 
SingleBlockInserter(parent.parent, checkBlocks[i], (short)-1, 
FreenetURI.EMPTY_CHK_URI, blockInsertContext, this, false, 
CHKBlock.DATA_LENGTH, i + dataBlocks.length, getCHKOnly, false, false, 
parent.token);
+                                       checkBlockInserters[i].schedule();
+                                       fin = false;
+                               } else
                                        parent.parent.completedBlock(true);
-                               else
-                                       fin = false;
                        }
-               }
-               if(encoded) {
                        onEncodedSegment();
                        parent.encodedSegment(this);
                }
@@ -343,20 +346,19 @@

        void encode() {
                try {
+                       synchronized(this) {
+                               if(encoded) return;
+                               encoded = true;
+                       }
                        splitfileAlgo.encode(dataBlocks, checkBlocks, 
CHKBlock.DATA_LENGTH, blockInsertContext.persistentBucketFactory);
                        // Start the inserts
                        for(int i=0;i<checkBlockInserters.length;i++) {
-                               if(checkBlocks[i] != null) { // else already 
finished on creation
-                                       checkBlockInserters[i] = 
-                                               new 
SingleBlockInserter(parent.parent, checkBlocks[i], (short)-1, 
FreenetURI.EMPTY_CHK_URI, blockInsertContext, this, false, 
CHKBlock.DATA_LENGTH, i + dataBlocks.length, getCHKOnly, false, false, 
parent.token);
-                                       checkBlockInserters[i].schedule();
-                               } else {
-                                       parent.parent.completedBlock(true);
-                               }
+                               checkBlockInserters[i] = 
+                                       new SingleBlockInserter(parent.parent, 
checkBlocks[i], (short)-1, FreenetURI.EMPTY_CHK_URI, blockInsertContext, this, 
false, CHKBlock.DATA_LENGTH, i + dataBlocks.length, getCHKOnly, false, false, 
parent.token);
+                               checkBlockInserters[i].schedule();
                        }
                        // Tell parent only after have started the inserts.
                        // Because of the counting.
-                       encoded = true;
                        parent.encodedSegment(this);
                        onEncodedSegment();
                } catch (IOException e) {

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-07-26 20:49:32 UTC (rev 
9784)
+++ trunk/freenet/src/freenet/node/Version.java 2006-07-26 21:12:13 UTC (rev 
9785)
@@ -18,7 +18,7 @@
        public static final String protocolVersion = "1.0";

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

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


Reply via email to