Author: toad
Date: 2005-11-10 14:59:04 +0000 (Thu, 10 Nov 2005)
New Revision: 7516

Added:
   trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java
Modified:
   trunk/freenet/src/freenet/client/FileInserter.java
   trunk/freenet/src/freenet/keys/ClientCHKBlock.java
   trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java
   trunk/freenet/src/freenet/node/TextModeClientInterface.java
   trunk/freenet/src/freenet/node/Version.java
Log:
Insert and retrieve of 35000 bytes of zeros works.

Modified: trunk/freenet/src/freenet/client/FileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/FileInserter.java  2005-11-10 14:48:26 UTC 
(rev 7515)
+++ trunk/freenet/src/freenet/client/FileInserter.java  2005-11-10 14:59:04 UTC 
(rev 7516)
@@ -45,7 +45,8 @@

                Compressor bestCodec = null;
                Bucket bestCompressedData = null;
-               
+
+               long origSize = data.size();
                if(data.size() > NodeCHK.BLOCK_SIZE && (!ctx.dontCompress)) {
                        // Try to compress the data.
                        // Try each algorithm, starting with the fastest and 
weakest.
@@ -86,9 +87,11 @@
                        }
                        try {
                                if(bestCodec == null) {
-                                       chk = ClientCHKBlock.encode(array, 
metadata, true, (short)-1);
+                                       chk = ClientCHKBlock.encode(array, 
metadata, true, (short)-1, 0);
                                } else {
-                                       chk = ClientCHKBlock.encode(array, 
metadata, false, bestCodec.codecNumberForMetadata());
+                                       if(origSize > 
ClientCHKBlock.MAX_LENGTH_BEFORE_COMPRESSION)
+                                               throw new 
IllegalArgumentException("Data too big to compress into single block, but it 
does");
+                                       chk = ClientCHKBlock.encode(array, 
metadata, false, bestCodec.codecNumberForMetadata(), (int)origSize);
                                }
                        } catch (CHKEncodeException e) {
                                Logger.error(this, "Unexpected error: "+e, e);

Added: trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java    
2005-11-10 14:48:26 UTC (rev 7515)
+++ trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java    
2005-11-10 14:59:04 UTC (rev 7516)
@@ -0,0 +1,24 @@
+package freenet.client.events;
+
+import freenet.keys.ClientKey;
+import freenet.keys.Key;
+
+public class SimpleBlockPutEvent implements ClientEvent {
+
+       public final static int code = 0x04;
+       
+       private final ClientKey key;
+       
+       public SimpleBlockPutEvent(ClientKey key) {
+               this.key = key;
+       }
+
+       public String getDescription() {
+               return "Inserting simple CHK: "+key.getURI();
+       }
+
+       public int getCode() {
+               return code;
+       }
+
+}

Modified: trunk/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHKBlock.java  2005-11-10 14:48:26 UTC 
(rev 7515)
+++ trunk/freenet/src/freenet/keys/ClientCHKBlock.java  2005-11-10 14:59:04 UTC 
(rev 7516)
@@ -60,7 +60,7 @@
      * data is already compressed, and this is the algorithm.
      */

-    static public ClientCHKBlock encode(byte[] sourceData, boolean asMetadata, 
boolean dontCompress, short alreadyCompressedCodec) throws CHKEncodeException {
+    static public ClientCHKBlock encode(byte[] sourceData, boolean asMetadata, 
boolean dontCompress, short alreadyCompressedCodec, int sourceLength) throws 
CHKEncodeException {
         byte[] data;
         byte[] header;
         ClientCHK key;
@@ -93,6 +93,7 @@
                                                if (compressedData.size() <= 
MAX_COMPRESSED_DATA_LENGTH) {
                                                        compressionAlgorithm = 
comp
                                                                        
.codecNumberForMetadata();
+                                                       sourceLength = 
sourceData.length;
                                                        try {
                                                                cbuf = 
BucketTools.toByteArray(compressedData);
                                                                // FIXME 
provide a method in ArrayBucket
@@ -107,7 +108,6 @@
                }
                if(cbuf != null) {
                        // Use it
-                int sourceLength = sourceData.length;
                        int compressedLength = cbuf.length;
                 sourceData = new byte[compressedLength+3];
                 System.arraycopy(cbuf, 0, sourceData, 3, compressedLength);

Modified: trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java
===================================================================
--- trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java       
2005-11-10 14:48:26 UTC (rev 7515)
+++ trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java       
2005-11-10 14:59:04 UTC (rev 7516)
@@ -168,7 +168,7 @@
                 Logger.error(RealNodeRequestInsertTest.class,"Inserting: 
\""+dataString+"\" to "+node1);
                 byte[] data = dataString.getBytes();
                 ClientCHKBlock block;
-                block = ClientCHKBlock.encode(data, false, false, (short)-1);
+                block = ClientCHKBlock.encode(data, false, false, (short)-1, 
0);
                 ClientCHK chk = block.getClientKey();
                 byte[] encData = block.getData();
                 byte[] encHeaders = block.getHeader();

Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-10 
14:48:26 UTC (rev 7515)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-10 
14:59:04 UTC (rev 7516)
@@ -220,7 +220,7 @@
             File f = new File(line);
             System.out.println("Attempting to read file "+line);
             try {
-               if(!f.exists() && f.canRead()) {
+               if(!(f.exists() && f.canRead())) {
                        throw new FileNotFoundException();
                }
                FileBucket fb = new FileBucket(f, true, false, false);

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-11-10 14:48:26 UTC (rev 
7515)
+++ trunk/freenet/src/freenet/node/Version.java 2005-11-10 14:59:04 UTC (rev 
7516)
@@ -20,10 +20,10 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       public static final int buildNumber = 151;
+       public static final int buildNumber = 152;

        /** Oldest build of Fred we will talk to */
-       public static final int lastGoodBuild = 151;
+       public static final int lastGoodBuild = 152;

        /** The highest reported build of fred */
        public static int highestSeenBuild = buildNumber;


Reply via email to