Author: toad
Date: 2006-03-28 23:49:10 +0000 (Tue, 28 Mar 2006)
New Revision: 8349

Modified:
   trunk/freenet/src/freenet/client/FetchException.java
   trunk/freenet/src/freenet/client/Metadata.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java
Log:
583:
MaxSize now works.
Added some fields to GetFailed (and FetchException) when we get a GetFailed to 
indicate expected size, MIME type and whether these are finalized.

Modified: trunk/freenet/src/freenet/client/FetchException.java
===================================================================
--- trunk/freenet/src/freenet/client/FetchException.java        2006-03-28 
22:53:49 UTC (rev 8348)
+++ trunk/freenet/src/freenet/client/FetchException.java        2006-03-28 
23:49:10 UTC (rev 8349)
@@ -14,7 +14,21 @@
        public final int mode;

        public final FreenetURI newURI;
+       
+       public final long expectedSize;
+       
+       String expectedMimeType;
+       
+       boolean finalizedSizeAndMimeType;
+       
+       public String getExpectedMimeType() {
+               return expectedMimeType;
+       }

+       public boolean finalizedSize() {
+               return finalizedSizeAndMimeType;
+       }
+       
        /** For collection errors */
        public final FailureCodeTracker errorCodes;

@@ -31,9 +45,23 @@
                mode = m;
                errorCodes = null;
                newURI = null;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+")", 
this);
        }

+       public FetchException(int m, long expectedSize, boolean finalizedSize, 
String expectedMimeType) {
+               super(getMessage(m));
+               extraMessage = null;
+               this.finalizedSizeAndMimeType = finalizedSize;
+               mode = m;
+               errorCodes = null;
+               newURI = null;
+               this.expectedSize = expectedSize;
+               this.expectedMimeType = expectedMimeType;
+               Logger.minor(this, "FetchException("+getMessage(mode)+")", 
this);
+               
+       }
+       
        public FetchException(MetadataParseException e) {
                super(getMessage(INVALID_METADATA)+": "+e.getMessage());
                extraMessage = e.getMessage();
@@ -41,6 +69,7 @@
                errorCodes = null;
                initCause(e);
                newURI = null;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+"): 
"+e,e);
        }

@@ -51,6 +80,7 @@
                errorCodes = null;
                newURI = null;
                initCause(e);
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+"): 
"+e,e);
        }

@@ -61,6 +91,7 @@
                errorCodes = null;
                initCause(e);
                newURI = null;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+"): 
"+e,e);       }

        public FetchException(int mode, Throwable t) {
@@ -70,6 +101,7 @@
                errorCodes = null;
                initCause(t);
                newURI = null;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+"): 
"+t.getMessage(),t);
        }

@@ -79,6 +111,7 @@
                this.mode = mode;
                this.errorCodes = errorCodes;
                newURI = null;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+")");
        }

@@ -88,6 +121,7 @@
                errorCodes = null;
                this.mode = mode;
                newURI = null;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+"): 
"+msg,this);
        }

@@ -97,6 +131,7 @@
                this.mode = mode;
                errorCodes = null;
                this.newURI = newURI;
+               expectedSize = -1;
                Logger.minor(this, "FetchException("+getMessage(mode)+") -> 
"+newURI, this);
        }


Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java      2006-03-28 22:53:49 UTC 
(rev 8348)
+++ trunk/freenet/src/freenet/client/Metadata.java      2006-03-28 23:49:10 UTC 
(rev 8349)
@@ -839,4 +839,8 @@
        public byte[] splitfileParams() {
                return splitfileParams;
        }
+
+       public long uncompressedDataLength() {
+               return this.decompressedLength;
+       }
 }

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-03-28 22:53:49 UTC (rev 8348)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2006-03-28 23:49:10 UTC (rev 8349)
@@ -23,7 +23,6 @@
 import freenet.keys.KeyDecodeException;
 import freenet.keys.USK;
 import freenet.node.LowLevelGetException;
-import freenet.node.Node;
 import freenet.support.Bucket;
 import freenet.support.BucketTools;
 import freenet.support.Logger;
@@ -177,7 +176,11 @@
                        }
                        result = new FetchResult(result, data);
                }
-               rcb.onSuccess(result, this);
+               if(result.size() > ctx.maxOutputLength) {
+                       rcb.onFailure(new 
FetchException(FetchException.TOO_BIG, result.size(), (rcb == parent), 
result.getMimeType()), this);
+               } else {
+                       rcb.onSuccess(result, this);
+               }
        }

        private void handleMetadata() throws FetchException, 
MetadataParseException, ArchiveFailureException, ArchiveRestartException {
@@ -321,6 +324,19 @@
                                        addDecompressor(codec);
                                }

+                               long len = metadata.dataLength();
+                               if(metadata.uncompressedDataLength() > len)
+                                       len = metadata.uncompressedDataLength();
+                               
+                               if(len > ctx.maxOutputLength ||
+                                               len > ctx.maxTempLength) {
+                                       
+                                       boolean finished = (rcb == parent);
+                                       
+                                       onFailure(new 
FetchException(FetchException.TOO_BIG, len, finished, 
clientMetadata.getMIMEType()));
+                                       return;
+                               }
+                               
                                SplitFileFetcher sf = new 
SplitFileFetcher(metadata, rcb, (ClientGetter)parent, ctx, 
                                                decompressors, clientMetadata, 
actx, recursionLevel, returnBucket, false);
                                sf.schedule();

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-03-28 22:53:49 UTC (rev 
8348)
+++ trunk/freenet/src/freenet/node/Version.java 2006-03-28 23:49:10 UTC (rev 
8349)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

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

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

Modified: trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java    2006-03-28 
22:53:49 UTC (rev 8348)
+++ trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java    2006-03-28 
23:49:10 UTC (rev 8349)
@@ -4,7 +4,6 @@

 import freenet.client.FailureCodeTracker;
 import freenet.client.FetchException;
-import freenet.client.InserterException;
 import freenet.node.Node;
 import freenet.support.Fields;
 import freenet.support.Logger;
@@ -19,6 +18,9 @@
        final FailureCodeTracker tracker;
        final boolean isFatal;
        final String identifier;
+       final long expectedDataLength;
+       final String expectedMimeType;
+       final boolean finalizedExpected;

        public GetFailedMessage(FetchException e, String identifier) {
                Logger.minor(this, "Creating get failed from "+e+" for 
"+identifier, e);
@@ -29,6 +31,9 @@
                this.shortCodeDescription = 
FetchException.getShortMessage(code);
                this.isFatal = e.isFatal();
                this.identifier = identifier;
+               this.expectedDataLength = e.expectedSize;
+               this.expectedMimeType = e.getExpectedMimeType();
+               this.finalizedExpected = e.finalizedSize();
        }

        /**
@@ -61,6 +66,13 @@
                } else {
                        tracker = null;
                }
+               expectedMimeType = fs.get("ExpectedMimeType");
+               finalizedExpected = 
Fields.stringToBool(fs.get("FinalizedExpected"), false);
+               String s = fs.get("ExpectedDataLength");
+               if(s != null) {
+                       expectedDataLength = Long.parseLong(s);
+               } else
+                       expectedDataLength = -1;
        }

        public SimpleFieldSet getFieldSet() {
@@ -88,6 +100,13 @@
                if(verbose)
                        sfs.put("ShortCodeDescription", shortCodeDescription);
                sfs.put("Identifier", identifier);
+               if(expectedDataLength > -1) {
+                       sfs.put("ExpectedDataLength", 
Long.toString(expectedDataLength));
+               }
+               if(expectedMimeType != null)
+                       sfs.put("ExpectedMetadata.ContentType", 
expectedMimeType);
+               if(finalizedExpected)
+                       sfs.put("FinalizedExpected", "true");
                return sfs;
        }



Reply via email to