Author: toad
Date: 2006-01-25 00:37:18 +0000 (Wed, 25 Jan 2006)
New Revision: 7914
Modified:
trunk/freenet/src/freenet/keys/ClientCHKBlock.java
trunk/freenet/src/freenet/keys/InsertableClientSSK.java
trunk/freenet/src/freenet/keys/Key.java
trunk/freenet/src/freenet/node/Version.java
Log:
378:
compressed SSKs really do work now!
Modified: trunk/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHKBlock.java 2006-01-25 00:17:14 UTC
(rev 7913)
+++ trunk/freenet/src/freenet/keys/ClientCHKBlock.java 2006-01-25 00:37:18 UTC
(rev 7914)
@@ -152,7 +152,7 @@
ClientCHK key;
short compressionAlgorithm = -1;
try {
- Compressed comp = Key.compress(sourceData,
dontCompress, alreadyCompressedCodec, sourceLength,
MAX_LENGTH_BEFORE_COMPRESSION, MAX_COMPRESSED_DATA_LENGTH);
+ Compressed comp = Key.compress(sourceData,
dontCompress, alreadyCompressedCodec, sourceLength,
MAX_LENGTH_BEFORE_COMPRESSION, MAX_COMPRESSED_DATA_LENGTH, false);
finalData = comp.compressedData;
compressionAlgorithm = comp.compressionAlgorithm;
} catch (KeyEncodeException e2) {
Modified: trunk/freenet/src/freenet/keys/InsertableClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/InsertableClientSSK.java 2006-01-25
00:17:14 UTC (rev 7913)
+++ trunk/freenet/src/freenet/keys/InsertableClientSSK.java 2006-01-25
00:37:18 UTC (rev 7914)
@@ -56,7 +56,7 @@
byte[] compressedData;
short compressionAlgo;
try {
- Compressed comp = Key.compress(sourceData,
dontCompress, alreadyCompressedCodec, sourceLength,
ClientSSKBlock.MAX_DECOMPRESSED_DATA_LENGTH, ClientSSKBlock.DATA_LENGTH);
+ Compressed comp = Key.compress(sourceData,
dontCompress, alreadyCompressedCodec, sourceLength,
ClientSSKBlock.MAX_DECOMPRESSED_DATA_LENGTH, ClientSSKBlock.DATA_LENGTH, true);
compressedData = comp.compressedData;
compressionAlgo = comp.compressionAlgorithm;
} catch (KeyEncodeException e) {
Modified: trunk/freenet/src/freenet/keys/Key.java
===================================================================
--- trunk/freenet/src/freenet/keys/Key.java 2006-01-25 00:17:14 UTC (rev
7913)
+++ trunk/freenet/src/freenet/keys/Key.java 2006-01-25 00:37:18 UTC (rev
7914)
@@ -96,7 +96,7 @@
static Bucket decompress(boolean isCompressed, byte[] output,
BucketFactory bf, int maxLength, short compressionAlgorithm, boolean
shortLength) throws CHKDecodeException, IOException {
if(isCompressed) {
- Logger.minor(Key.class, "Decompressing in decode with codec
"+compressionAlgorithm);
+ Logger.minor(Key.class, "Decompressing "+output.length+" bytes
in decode with codec "+compressionAlgorithm);
if(output.length < (shortLength ? 3 : 5)) throw new
CHKDecodeException("No bytes to decompress");
// Decompress
// First get the length
@@ -129,7 +129,7 @@
short compressionAlgorithm;
}
- static Compressed compress(Bucket sourceData, boolean dontCompress, short
alreadyCompressedCodec, long sourceLength, long MAX_LENGTH_BEFORE_COMPRESSION,
long MAX_COMPRESSED_DATA_LENGTH) throws KeyEncodeException, IOException {
+ static Compressed compress(Bucket sourceData, boolean dontCompress, short
alreadyCompressedCodec, long sourceLength, long MAX_LENGTH_BEFORE_COMPRESSION,
long MAX_COMPRESSED_DATA_LENGTH, boolean shortLength) throws
KeyEncodeException, IOException {
byte[] finalData = null;
short compressionAlgorithm = -1;
// Try to compress it - even if it fits into the block,
@@ -179,12 +179,17 @@
if(cbuf != null) {
// Use it
int compressedLength = cbuf.length;
- finalData = new byte[compressedLength+4];
- System.arraycopy(cbuf, 0, finalData, 4, compressedLength);
- finalData[0] = (byte) ((sourceLength >> 24) & 0xff);
- finalData[1] = (byte) ((sourceLength >> 16) & 0xff);
- finalData[2] = (byte) ((sourceLength >> 8) & 0xff);
- finalData[3] = (byte) ((sourceLength) & 0xff);
+ finalData = new byte[compressedLength+(shortLength?2:4)];
+ System.arraycopy(cbuf, 0, finalData, shortLength?2:4,
compressedLength);
+ if(!shortLength) {
+ finalData[0] = (byte) ((sourceLength >> 24) & 0xff);
+ finalData[1] = (byte) ((sourceLength >> 16) & 0xff);
+ finalData[2] = (byte) ((sourceLength >> 8) & 0xff);
+ finalData[3] = (byte) ((sourceLength) & 0xff);
+ } else {
+ finalData[0] = (byte) ((sourceLength >> 8) & 0xff);
+ finalData[1] = (byte) ((sourceLength) & 0xff);
+ }
}
}
if(finalData == null) {
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-01-25 00:17:14 UTC (rev
7913)
+++ trunk/freenet/src/freenet/node/Version.java 2006-01-25 00:37:18 UTC (rev
7914)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 377;
+ public static final int buildNumber = 378;
/** Oldest build of Fred we will talk to */
public static final int lastGoodBuild = 374;