Author: toad
Date: 2007-05-24 00:01:15 +0000 (Thu, 24 May 2007)
New Revision: 13352

Modified:
   trunk/freenet/src/freenet/client/ArchiveManager.java
   trunk/freenet/src/freenet/client/ArchiveStoreContext.java
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/keys/NodeCHK.java
Log:
Fixed to length field and always return all the blocks even when fetching from 
an archive manifest.

Modified: trunk/freenet/src/freenet/client/ArchiveManager.java
===================================================================
--- trunk/freenet/src/freenet/client/ArchiveManager.java        2007-05-23 
23:24:06 UTC (rev 13351)
+++ trunk/freenet/src/freenet/client/ArchiveManager.java        2007-05-24 
00:01:15 UTC (rev 13352)
@@ -117,11 +117,12 @@
         * @param archiveType The archive type, defined in Metadata.
         * @return An archive handler. 
         */
-       public synchronized ArchiveHandler makeHandler(FreenetURI key, short 
archiveType, boolean returnNullIfNotFound) {
-               ArchiveHandler handler = getCached(key);
+       public synchronized ArchiveHandler makeHandler(FreenetURI key, short 
archiveType, boolean returnNullIfNotFound, boolean forceRefetchArchive) {
+               ArchiveHandler handler = null;
+               if(!forceRefetchArchive) handler = getCached(key);
                if(handler != null) return handler;
                if(returnNullIfNotFound) return null;
-               handler = new ArchiveStoreContext(this, key, archiveType);
+               handler = new ArchiveStoreContext(this, key, archiveType, 
forceRefetchArchive);
                putCached(key, handler);
                return handler;
        }
@@ -174,7 +175,7 @@
                logMINOR = Logger.shouldLog(Logger.MINOR, this);

                if(logMINOR) Logger.minor(this, "Extracting "+key);
-               
+               ctx.onExtract();
                ctx.removeAllCachedItems(); // flush cache anyway
                long expectedSize = ctx.getLastSize();
                long archiveSize = data.size();

Modified: trunk/freenet/src/freenet/client/ArchiveStoreContext.java
===================================================================
--- trunk/freenet/src/freenet/client/ArchiveStoreContext.java   2007-05-23 
23:24:06 UTC (rev 13351)
+++ trunk/freenet/src/freenet/client/ArchiveStoreContext.java   2007-05-24 
00:01:15 UTC (rev 13352)
@@ -25,12 +25,14 @@
        private ArchiveManager manager;
        private FreenetURI key;
        private short archiveType;
+       private boolean forceRefetchArchive;

-       public ArchiveStoreContext(ArchiveManager manager, FreenetURI key, 
short archiveType) {
+       public ArchiveStoreContext(ArchiveManager manager, FreenetURI key, 
short archiveType, boolean forceRefetchArchive) {
                this.manager = manager;
                this.key = key;
                this.archiveType = archiveType;
                myItems = new DoublyLinkedListImpl();
+               this.forceRefetchArchive = forceRefetchArchive;
        }

        /**
@@ -51,6 +53,8 @@
                // Do loop detection on the archive that we are about to fetch.
                archiveContext.doLoopDetection(key);

+               if(forceRefetchArchive) return null;
+               
                Bucket data;

                // Fetch from cache
@@ -138,4 +142,8 @@
        public void extractToCache(Bucket bucket, ArchiveContext actx) throws 
ArchiveFailureException, ArchiveRestartException {
                manager.extractToCache(key, archiveType, bucket, actx, this);
        }
+
+       public void onExtract() {
+               forceRefetchArchive = false;
+       }
 }

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2007-05-23 
23:24:06 UTC (rev 13351)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2007-05-24 
00:01:15 UTC (rev 13352)
@@ -266,7 +266,7 @@
                        byte[] data = block.getRawData();
                        byte[] pubkey = block.getPubkeyBytes();
                        try {
-                               writeBlobHeader(BLOB_BLOCK, BLOB_BLOCK_VERSION, 
7+keyData.length+headers.length+data.length);
+                               writeBlobHeader(BLOB_BLOCK, BLOB_BLOCK_VERSION, 
9+keyData.length+headers.length+data.length+(pubkey==null?0:pubkey.length));
                                
binaryBlobStream.writeShort(block.getKey().getType());
                                binaryBlobStream.writeByte(keyData.length);
                                binaryBlobStream.writeShort(headers.length);

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2007-05-23 23:24:06 UTC (rev 13351)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2007-05-24 00:01:15 UTC (rev 13352)
@@ -256,9 +256,12 @@
                                        continue;
                                }
                                // First we need the archive metadata.
-                               // Then parse it.
-                               // Then we may need to fetch something from 
inside the archive.
-                               ah = (ArchiveStoreContext) 
ctx.archiveManager.makeHandler(thisKey, metadata.getArchiveType(), false);
+                               // Then parse it. Then we may need to fetch 
something from inside the archive.
+                               // It's more efficient to keep the existing ah 
if we can, and it is vital in
+                               // the case of binary blobs.
+                               if(ah == null || !ah.getKey().equals(thisKey))
+                                       ah = (ArchiveStoreContext) 
ctx.archiveManager.makeHandler(thisKey, metadata.getArchiveType(), false, 
+                                                       (parent instanceof 
ClientGetter ? ((ClientGetter)parent).collectingBinaryBlob() : false));
                                archiveMetadata = metadata;
                                // ah is set. This means we are currently 
handling an archive.
                                Bucket metadataBucket;

Modified: trunk/freenet/src/freenet/keys/NodeCHK.java
===================================================================
--- trunk/freenet/src/freenet/keys/NodeCHK.java 2007-05-23 23:24:06 UTC (rev 
13351)
+++ trunk/freenet/src/freenet/keys/NodeCHK.java 2007-05-24 00:01:15 UTC (rev 
13352)
@@ -7,6 +7,7 @@
 import java.io.DataOutput;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.Arrays;

 import freenet.support.Base64;

@@ -59,7 +60,7 @@
     public boolean equals(Object key) {
         if(key instanceof NodeCHK) {
             NodeCHK chk = (NodeCHK) key;
-            return java.util.Arrays.equals(chk.routingKey, routingKey);
+            return java.util.Arrays.equals(chk.routingKey, routingKey) && 
(cryptoAlgorithm == chk.cryptoAlgorithm);
         }
         return false;
     }
@@ -67,7 +68,7 @@
     public int hashCode(){
        return super.hashCode();
     }
-
+    
        public short getType() {
                return (short) (0x100 + (cryptoAlgorithm & 0xFF));
        }


Reply via email to