Author: nextgens
Date: 2007-03-23 18:19:06 +0000 (Fri, 23 Mar 2007)
New Revision: 12285
Modified:
trunk/freenet/src/freenet/client/StandardOnionFECCodec.java
trunk/freenet/src/freenet/support/io/BucketTools.java
Log:
Here I:
* Move the padding method of StandardOnionFecCodec to BucketTools.
* add a "final" attribute to a synchronization object
Modified: trunk/freenet/src/freenet/client/StandardOnionFECCodec.java
===================================================================
--- trunk/freenet/src/freenet/client/StandardOnionFECCodec.java 2007-03-23
17:52:54 UTC (rev 12284)
+++ trunk/freenet/src/freenet/client/StandardOnionFECCodec.java 2007-03-23
18:19:06 UTC (rev 12285)
@@ -7,8 +7,6 @@
import java.io.IOException;
import java.io.OutputStream;
-import org.spaceroots.mantissa.random.MersenneTwister;
-
import com.onionnetworks.fec.FECCode;
import com.onionnetworks.fec.Native8Code;
import com.onionnetworks.fec.PureCode;
@@ -168,7 +166,7 @@
logMINOR = Logger.shouldLog(Logger.MINOR, this);
}
- private static Object runningDecodesSync = new Object();
+ private static final Object runningDecodesSync = new Object();
private static int runningDecodes;
public void decode(SplitfileBlock[] dataBlockStatus, SplitfileBlock[]
checkBlockStatus, int blockLength, BucketFactory bf) throws IOException {
@@ -248,8 +246,7 @@
+ dataBlockStatus[i] + ") is " + sz
+ " not " + blockLength);
if (sz < blockLength)
- buckets[i] =
pad(buckets[i], blockLength, bf,
- (int)
sz);
+ buckets[i] =
BucketTools.pad(buckets[i], blockLength, bf,(int) sz);
else
throw new
IllegalArgumentException("Too big: " + sz
+ "
bigger than " + blockLength);
@@ -434,7 +431,7 @@
throw new
IllegalArgumentException(
"All buckets
except the last must be the full size");
if (sz < blockLength)
- buckets[i] = pad(buckets[i],
blockLength, bf, (int) sz);
+ buckets[i] =
BucketTools.pad(buckets[i], blockLength, bf, (int) sz);
else
throw new
IllegalArgumentException("Too big: " + sz
+ " bigger than
" + blockLength);
@@ -525,27 +522,6 @@
}
}
- private Bucket pad(Bucket oldData, int blockLength, BucketFactory bf,
int l) throws IOException {
- // FIXME move somewhere else?
- byte[] hash = BucketTools.hash(oldData);
- Bucket b = bf.makeBucket(blockLength);
- MersenneTwister mt = new MersenneTwister(hash);
- OutputStream os = b.getOutputStream();
- BucketTools.copyTo(oldData, os, l);
- byte[] buf = new byte[4096];
- for(int x=l;x<blockLength;) {
- int remaining = blockLength - x;
- int thisCycle = Math.min(remaining, buf.length);
- mt.nextBytes(buf); // FIXME??
- os.write(buf, 0, thisCycle);
- x += thisCycle;
- }
- os.close();
- if(b.size() != blockLength)
- throw new IllegalStateException();
- return b;
- }
-
public int countCheckBlocks() {
return n-k;
}
Modified: trunk/freenet/src/freenet/support/io/BucketTools.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BucketTools.java 2007-03-23
17:52:54 UTC (rev 12284)
+++ trunk/freenet/src/freenet/support/io/BucketTools.java 2007-03-23
18:19:06 UTC (rev 12285)
@@ -13,6 +13,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.spaceroots.mantissa.random.MersenneTwister;
+
import freenet.crypt.SHA256;
import freenet.support.api.Bucket;
import freenet.support.api.BucketFactory;
@@ -363,4 +365,34 @@
}
return buckets;
}
+
+ /**
+ * Pad a bucket with random data
+ *
+ * @param oldBucket
+ * @param blockLength
+ * @param BucketFactory
+ * @param length
+ *
+ * @return the paded bucket
+ */
+ public static Bucket pad(Bucket oldBucket, int blockLength,
BucketFactory bf, int length) throws IOException {
+ byte[] hash = BucketTools.hash(oldBucket);
+ Bucket b = bf.makeBucket(blockLength);
+ MersenneTwister mt = new MersenneTwister(hash);
+ OutputStream os = b.getOutputStream();
+ BucketTools.copyTo(oldBucket, os, length);
+ byte[] buf = new byte[4096];
+ for(int x=length;x<blockLength;) {
+ int remaining = blockLength - x;
+ int thisCycle = Math.min(remaining, buf.length);
+ mt.nextBytes(buf); // FIXME??
+ os.write(buf, 0, thisCycle);
+ x += thisCycle;
+ }
+ os.close();
+ if(b.size() != blockLength)
+ throw new IllegalStateException();
+ return b;
+ }
}