Author: toad
Date: 2005-11-10 17:23:51 +0000 (Thu, 10 Nov 2005)
New Revision: 7518

Modified:
   trunk/freenet/src/freenet/client/BlockFetcher.java
   trunk/freenet/src/freenet/client/BlockInserter.java
   trunk/freenet/src/freenet/client/DefaultMIMETypes.java
   trunk/freenet/src/freenet/client/FileInserter.java
   trunk/freenet/src/freenet/client/HighLevelSimpleClient.java
   trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
   trunk/freenet/src/freenet/client/InsertSegment.java
   trunk/freenet/src/freenet/client/InserterException.java
   trunk/freenet/src/freenet/client/Metadata.java
   trunk/freenet/src/freenet/client/RetryTracker.java
   trunk/freenet/src/freenet/client/SplitInserter.java
   trunk/freenet/src/freenet/client/SplitfileBlock.java
   trunk/freenet/src/freenet/client/StandardOnionFECCodec.java
   trunk/freenet/src/freenet/client/StdSplitfileBlock.java
   trunk/freenet/src/freenet/node/TextModeClientInterface.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/support/BucketTools.java
Log:
155:
Support for getting CHK without inserting, on any size file.
Use this in splitfiles so we can still build the metadata even if we RNF on the 
blocks.

Modified: trunk/freenet/src/freenet/client/BlockFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/BlockFetcher.java  2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/BlockFetcher.java  2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -89,7 +89,6 @@

        private void fatalError(Throwable e, int code) {
                Logger.normal(this, "Giving up on block: "+this+": "+e);
-               completedTries = -1;
                tracker.fatalError(this, code);
        }

@@ -130,4 +129,8 @@
                        throw new IllegalStateException("Already have data");
                }
        }
+
+       public int getRetryCount() {
+               return completedTries;
+       }
 }
\ No newline at end of file

Modified: trunk/freenet/src/freenet/client/BlockInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/BlockInserter.java 2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/BlockInserter.java 2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -14,19 +14,21 @@
        private final InserterContext ctx;
        private final InsertBlock block;
        private FreenetURI uri;
+       private final boolean getCHKOnly;

        /**
         * Create a BlockInserter.
         * @param bucket The data to insert, or null if it will be filled in 
later.
         * @param num The block number in the splitfile.
         */
-       public BlockInserter(Bucket bucket, int num, RetryTracker tracker, 
InserterContext ctx) {
+       public BlockInserter(Bucket bucket, int num, RetryTracker tracker, 
InserterContext ctx, boolean getCHKOnly) {
                super(tracker, num);
                this.data = bucket;
                if(bucket == null) throw new NullPointerException();
                succeeded = false;
                this.ctx = ctx;
                block = new InsertBlock(bucket, null, FreenetURI.EMPTY_CHK_URI);
+               this.getCHKOnly = getCHKOnly;
        }

        public synchronized void setData(Bucket data) {
@@ -38,6 +40,10 @@
                // Do nothing, for now.
        }

+       public String toString() {
+               return super.toString()+" succeeded="+succeeded+" 
tries="+completedTries+" uri="+uri;
+       }
+       
        public FreenetURI getURI() {
                return uri;
        }
@@ -55,7 +61,9 @@
        private void realRun() {
                FileInserter inserter = new FileInserter(ctx);
                try {
-                       uri = inserter.run(block, false);
+                       if(uri == null && !getCHKOnly)
+                               uri = inserter.run(block, false, true);
+                       uri = inserter.run(block, false, getCHKOnly);
                        succeeded = true;
                        tracker.success(this);
                } catch (InserterException e) {
@@ -63,6 +71,7 @@
                        case InserterException.REJECTED_OVERLOAD:
                        case InserterException.ROUTE_NOT_FOUND:
                                nonfatalError(e, e.mode);
+                               return;
                        case InserterException.INTERNAL_ERROR:
                        case InserterException.BUCKET_ERROR:
                                fatalError(e, e.mode);
@@ -89,7 +98,6 @@

        private void fatalError(Throwable e, int code) {
                Logger.normal(this, "Giving up on block: "+this+": "+e);
-               completedTries = -1;
                tracker.fatalError(this, code);
        }

@@ -102,4 +110,8 @@
                if(succeeded)
                        throw new IllegalStateException("Already inserted 
block");
        }
+
+       public int getRetryCount() {
+               return completedTries;
+       }
 }

Modified: trunk/freenet/src/freenet/client/DefaultMIMETypes.java
===================================================================
--- trunk/freenet/src/freenet/client/DefaultMIMETypes.java      2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/DefaultMIMETypes.java      2005-11-10 
17:23:51 UTC (rev 7518)
@@ -31,8 +31,12 @@
         * parameters and there is a separate mechanism for them.
         */
        protected static synchronized void addMIMEType(short number, String 
type) {
-               String s = (String) mimeTypesByNumber.get(number);
-               if(s != null) throw new IllegalArgumentException("Already used: 
"+number);
+               if(mimeTypesByNumber.size() > number) {
+                       String s = (String) mimeTypesByNumber.get(number);
+                       if(s != null) throw new 
IllegalArgumentException("Already used: "+number);
+               } else {
+                       mimeTypesByNumber.add(number, null);
+               }
                mimeTypesByNumber.set(number, type);
                mimeTypesByName.put(type, new Short(number));
        }
@@ -48,7 +52,7 @@
         */
        protected static synchronized void addMIMEType(short number, String 
type, String[] extensions) {
                addMIMEType(number, type);
-               Short t = new Short(type);
+               Short t = new Short(number);
                if(extensions != null)
                        for(int i=0;i<extensions.length;i++) {
                                String ext = extensions[i].toLowerCase();

Modified: trunk/freenet/src/freenet/client/FileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/FileInserter.java  2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/FileInserter.java  2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -28,10 +28,11 @@
        /**
         * Do an insert.
         * @param block The data to insert.
+        * @param localOnly 
         * @return The URI of the inserted data.
         * @throws InserterException 
         */
-       public FreenetURI run(InsertBlock block, boolean metadata) throws 
InserterException {
+       public FreenetURI run(InsertBlock block, boolean metadata, boolean 
getCHKOnly) throws InserterException {
                if(!block.desiredURI.toString(false).equals("CHK@"))
                        throw new 
InserterException(InserterException.INVALID_URI);

@@ -101,11 +102,11 @@
                                Logger.error(this, "Unexpected error: "+e, e);
                                throw new 
InserterException(InserterException.INTERNAL_ERROR);
                        }
-                       return simplePutCHK(chk, block.clientMetadata);
+                       return simplePutCHK(chk, block.clientMetadata, 
getCHKOnly);
                }

                // Too big, encode to a splitfile
-               SplitInserter splitInsert = new SplitInserter(data, 
block.clientMetadata, bestCodec, ctx.splitfileAlgorithm, ctx, this, 
NodeCHK.BLOCK_SIZE);
+               SplitInserter splitInsert = new SplitInserter(data, 
block.clientMetadata, bestCodec, ctx.splitfileAlgorithm, ctx, this, 
NodeCHK.BLOCK_SIZE, getCHKOnly);
                return splitInsert.run();
        }

@@ -117,10 +118,11 @@
         * @return The URI of the resulting CHK.
         * @throws InserterException If there was an error inserting the block.
         */
-       private FreenetURI simplePutCHK(ClientCHKBlock chk, ClientMetadata 
clientMetadata) throws InserterException {
+       private FreenetURI simplePutCHK(ClientCHKBlock chk, ClientMetadata 
clientMetadata, boolean getCHKOnly) throws InserterException {
                try {
                        ctx.eventProducer.produceEvent(new 
SimpleBlockPutEvent(chk.getClientKey()));
-                       ctx.client.putCHK(chk);
+                       if(!getCHKOnly)
+                               ctx.client.putCHK(chk);
                } catch (LowLevelPutException e) {
                        translateException(e);
                }
@@ -131,7 +133,7 @@
                else {
                        // Do need a redirect for the metadata
                        Metadata metadata = new 
Metadata(Metadata.SIMPLE_REDIRECT, chk.getClientKey().getURI(), clientMetadata);
-                       return putMetadataCHK(metadata);
+                       return putMetadataCHK(metadata, getCHKOnly);
                }
        }

@@ -152,7 +154,7 @@
        /** Put a metadata CHK 
         * @throws InserterException If the insert fails.
         */
-       private FreenetURI putMetadataCHK(Metadata metadata) throws 
InserterException {
+       private FreenetURI putMetadataCHK(Metadata metadata, boolean 
getCHKOnly) throws InserterException {
                byte[] data = metadata.writeToByteArray();
                Bucket bucket;
                try {
@@ -161,6 +163,6 @@
                        throw new 
InserterException(InserterException.BUCKET_ERROR);
                }
                InsertBlock block = new InsertBlock(bucket, null, 
FreenetURI.EMPTY_CHK_URI);
-               return run(block, true);
+               return run(block, true, getCHKOnly);
        }
 }

Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClient.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClient.java 2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClient.java 2005-11-10 
17:23:51 UTC (rev 7518)
@@ -25,7 +25,7 @@
         * Blocking insert of a URI
         * @throws InserterException If there is an error inserting the data
         */
-       public FreenetURI insert(InsertBlock insert) throws InserterException;
+       public FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws 
InserterException;

        /**
         * Add a ClientEventListener.

Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java     
2005-11-10 16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java     
2005-11-10 17:23:51 UTC (rev 7518)
@@ -79,10 +79,10 @@
                return f.run();
        }

-       public FreenetURI insert(InsertBlock insert) throws InserterException {
+       public FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws 
InserterException {
                InserterContext context = new InserterContext(client, 
bucketFactory, random, SPLITFILE_INSERT_RETRIES, SPLITFILE_INSERT_THREADS, 
globalEventProducer);
                FileInserter i = new FileInserter(context);
-               return i.run(insert, false);
+               return i.run(insert, false, getCHKOnly);
        }

        public void addGlobalHook(ClientEventListener listener) {

Modified: trunk/freenet/src/freenet/client/InsertSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/InsertSegment.java 2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/InsertSegment.java 2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -16,13 +16,15 @@
        final BucketFactory bf;
        /** Check blocks. Will be created by encode(...). */
        final SplitfileBlock[] checkBlocks;
+       final boolean getCHKOnly;

-       public InsertSegment(short splitfileAlgo, SplitfileBlock[] 
origDataBlocks, int blockLength, BucketFactory bf) {
+       public InsertSegment(short splitfileAlgo, SplitfileBlock[] 
origDataBlocks, int blockLength, BucketFactory bf, boolean getCHKOnly) {
                this.origDataBlocks = origDataBlocks;
                codec = FECCodec.getCodec(splitfileAlgo, origDataBlocks.length);
                checkBlocks = new SplitfileBlock[codec.countCheckBlocks()];
                this.blockLength = blockLength;
                this.bf = bf;
+               this.getCHKOnly = getCHKOnly;
        }

        /**
@@ -44,7 +46,7 @@
        public int encode(int offset, RetryTracker tracker, InserterContext 
ctx) throws IOException {
                if(codec == null) return 0; // no FEC
                for(int i=0;i<checkBlocks.length;i++)
-                       checkBlocks[i] = new BlockInserter(null, offset + i, 
tracker, ctx);
+                       checkBlocks[i] = new BlockInserter(null, offset + i, 
tracker, ctx, getCHKOnly);
                codec.encode(origDataBlocks, checkBlocks, blockLength, bf);
                return checkBlocks.length;
        }

Modified: trunk/freenet/src/freenet/client/InserterException.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterException.java     2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/InserterException.java     2005-11-10 
17:23:51 UTC (rev 7518)
@@ -2,6 +2,8 @@

 import java.io.IOException;

+import freenet.support.Logger;
+
 public class InserterException extends Exception {
        private static final long serialVersionUID = -1106716067841151962L;

@@ -22,6 +24,7 @@

        public InserterException(int mode, IOException e) {
                super(getMessage(mode)+": "+e.getMessage());
+               Logger.minor(this, "Creating InserterException: 
"+getMessage(mode)+": "+e, e);
                this.mode = mode;
                errorCodes = null;
                initCause(e);

Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java      2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/Metadata.java      2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -287,7 +287,10 @@
                if(docType == SIMPLE_REDIRECT) {
                        documentType = docType;
                        clientMetadata = cm;
-                       setMIMEType(cm.getMIMEType());
+                       if(cm != null)
+                               setMIMEType(cm.getMIMEType());
+                       else
+                               setMIMEType(DefaultMIMETypes.DEFAULT_MIME_TYPE);
                        simpleRedirectKey = uri;
                } else
                        throw new IllegalArgumentException();
@@ -304,7 +307,10 @@
                splitfileDataKeys = dataURIs;
                splitfileCheckKeys = checkURIs;
                clientMetadata = cm;
-               setMIMEType(cm.getMIMEType());
+               if(cm != null)
+                       setMIMEType(cm.getMIMEType());
+               else
+                       setMIMEType(DefaultMIMETypes.DEFAULT_MIME_TYPE);
        }

        /**

Modified: trunk/freenet/src/freenet/client/RetryTracker.java
===================================================================
--- trunk/freenet/src/freenet/client/RetryTracker.java  2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/RetryTracker.java  2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -5,6 +5,7 @@
 import java.util.Vector;

 import freenet.crypt.RandomSource;
+import freenet.support.Logger;

 /**
  * Keeps a list of SplitfileBlocks for each retry level.
@@ -173,7 +174,7 @@
        public synchronized void nonfatalError(SplitfileBlock block, int 
reasonCode) {
                nonfatalErrors.inc(reasonCode);
                runningBlocks.remove(block);
-               Level l = block.getLevel();
+               Level l = makeLevel(block.getRetryCount());
                if(l == null) throw new IllegalArgumentException();
                if(l.tracker != this) throw new 
IllegalArgumentException("Belongs to wrong tracker");
                int levelNumber = l.level;
@@ -181,6 +182,7 @@
                levelNumber++;
                if(levelNumber > maxLevel) {
                        failedBlocksTooManyRetries.add(block);
+                       Logger.minor(this, "Finished with "+block);
                } else {
                        Level newLevel = makeLevel(levelNumber);
                        newLevel.add(block);
@@ -196,7 +198,7 @@
        public synchronized void fatalError(SplitfileBlock block, int 
reasonCode) {
                fatalErrors.inc(reasonCode);
                runningBlocks.remove(block);
-               Level l = block.getLevel();
+               Level l = makeLevel(block.getRetryCount());
                if(l == null) throw new IllegalArgumentException();
                if(l.tracker != this) throw new 
IllegalArgumentException("Belongs to wrong tracker");
                l.remove(block);
@@ -211,6 +213,8 @@
        public synchronized void maybeStart(boolean cantCallFinished) {
                if((succeededBlocks.size() >= targetSuccesses)
                                || (runningBlocks.isEmpty() && levels.isEmpty() 
&& finishOnEmpty)) {
+                       Logger.minor(this, "Finishing: succeeded: 
"+succeededBlocks.size()+", target: "+targetSuccesses+
+                                       ", running: "+runningBlocks.size()+", 
levels: "+levels.size()+", finishOnEmpty: "+finishOnEmpty);
                        SplitfileBlock[] running = runningBlocks();
                        for(int i=0;i<running.length;i++) {
                                running[i].kill();
@@ -226,6 +230,7 @@
                } else {
                        while(runningBlocks.size() < maxThreads) {
                                SplitfileBlock block = getBlock();
+                               if(block == null) break;
                                block.start();
                                runningBlocks.add(block);
                        }
@@ -244,6 +249,7 @@
         */
        public synchronized SplitfileBlock getBlock() {
                Level l = (Level) levels.get(new Integer(curMinLevel));
+               if(l == null) return null;
                return l.getBlock();
        }


Modified: trunk/freenet/src/freenet/client/SplitInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/SplitInserter.java 2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/client/SplitInserter.java 2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -29,6 +29,7 @@
        InsertSegment[] segments;
        final Vector unstartedSegments = new Vector();
        private boolean allSegmentsFinished = false;
+       private boolean getCHKOnly;
        private int succeeded;
        private int failed;
        private int fatalErrors;
@@ -36,8 +37,9 @@
        private SplitfileBlock[] fatalErrorBlocks;
        private FileInserter inserter;

-       public SplitInserter(Bucket data, ClientMetadata clientMetadata, 
Compressor compressor, short splitfileAlgorithm, InserterContext ctx, 
FileInserter inserter, int blockLength) throws InserterException {
+       public SplitInserter(Bucket data, ClientMetadata clientMetadata, 
Compressor compressor, short splitfileAlgorithm, InserterContext ctx, 
FileInserter inserter, int blockLength, boolean getCHKOnly) throws 
InserterException {
                this.origData = data;
+               this.getCHKOnly = getCHKOnly;
                this.blockSize = blockLength;
                this.clientMetadata = clientMetadata;
                if(compressor == null)
@@ -49,12 +51,12 @@
                this.dataLength = data.size();
                segmentSize = 
FECCodec.getCodecMaxSegmentDataBlocks(splitfileAlgorithm);
                checkSegmentSize = 
FECCodec.getCodecMaxSegmentCheckBlocks(splitfileAlgorithm);
+               tracker = new RetryTracker(ctx.maxInsertBlockRetries, 
Integer.MAX_VALUE, ctx.random, ctx.maxSplitInsertThreads, true, this);
                try {
                        splitIntoBlocks();
                } catch (IOException e) {
-                       throw new 
InserterException(InserterException.BUCKET_ERROR);
+                       throw new 
InserterException(InserterException.BUCKET_ERROR, e);
                }
-               tracker = new RetryTracker(ctx.maxInsertBlockRetries, 0, 
ctx.random, ctx.maxSplitInsertThreads, true, this);
                this.inserter = inserter;
        }

@@ -115,7 +117,7 @@

                InsertBlock mblock = new InsertBlock(mbucket, clientMetadata, 
FreenetURI.EMPTY_CHK_URI);

-               return inserter.run(mblock, true);
+               return inserter.run(mblock, true, getCHKOnly);
        }

        private FreenetURI[] getCheckURIs() {
@@ -162,7 +164,7 @@
                Bucket[] dataBuckets = BucketTools.split(origData, 
NodeCHK.BLOCK_SIZE, ctx.bf);
                origDataBlocks = new SplitfileBlock[dataBuckets.length];
                for(int i=0;i<origDataBlocks.length;i++) {
-                       origDataBlocks[i] = new BlockInserter(dataBuckets[i], 
i, tracker, ctx);
+                       origDataBlocks[i] = new BlockInserter(dataBuckets[i], 
i, tracker, ctx, getCHKOnly);
                }
        }

@@ -177,7 +179,7 @@
                // First split the data up
                if(dataBlocks < segmentSize || segmentSize == -1) {
                        // Single segment
-                       InsertSegment onlySeg = new 
InsertSegment(splitfileAlgorithm, origDataBlocks, blockSize, ctx.bf);
+                       InsertSegment onlySeg = new 
InsertSegment(splitfileAlgorithm, origDataBlocks, blockSize, ctx.bf, 
getCHKOnly);
                        segs.add(onlySeg);
                } else {
                        int j = 0;
@@ -187,7 +189,7 @@
                                System.arraycopy(origDataBlocks, j, seg, 0, 
i-j);
                                unstartedSegments.add(seg);
                                j = i;
-                               segs.add(new InsertSegment(splitfileAlgorithm, 
seg, blockSize, ctx.bf));
+                               segs.add(new InsertSegment(splitfileAlgorithm, 
seg, blockSize, ctx.bf, getCHKOnly));
                                if(i == dataBlocks) break;
                        }
                }

Modified: trunk/freenet/src/freenet/client/SplitfileBlock.java
===================================================================
--- trunk/freenet/src/freenet/client/SplitfileBlock.java        2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/SplitfileBlock.java        2005-11-10 
17:23:51 UTC (rev 7518)
@@ -19,16 +19,6 @@
        /** Set data */
        abstract void setData(Bucket data);

-       private Level level;
-       
-       final Level getLevel() {
-               return level;
-       }
-       
-       final void setLevel(Level l) {
-               level = l;
-       }
-
        /** Start the fetch (or insert). Implementation is required to call 
relevant
         * methods on RetryTracker when done. */
        abstract void start();
@@ -43,4 +33,6 @@
         * For a request, it is fixed in the constructor.
         */
        abstract public FreenetURI getURI();
+
+       abstract public int getRetryCount();
 }

Modified: trunk/freenet/src/freenet/client/StandardOnionFECCodec.java
===================================================================
--- trunk/freenet/src/freenet/client/StandardOnionFECCodec.java 2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/StandardOnionFECCodec.java 2005-11-10 
17:23:51 UTC (rev 7518)
@@ -47,7 +47,7 @@
                }
        }

-       private static LRUHashtable recentlyUsedCodecs;
+       private static LRUHashtable recentlyUsedCodecs = new LRUHashtable();

        public synchronized static FECCodec getInstance(int dataBlocks, int 
checkBlocks) {
                MyKey key = new MyKey(dataBlocks, checkBlocks + dataBlocks);
@@ -64,12 +64,14 @@
                return codec;
        }

-       private FECCode code;
+       private final FECCode code;

-       private int k;
-       private int n;
+       private final int k;
+       private final int n;

        public StandardOnionFECCodec(int k, int n) {
+               this.k = k;
+               this.n = n;
                code = DefaultFECCodeFactory.getDefault().createFECCode(k,n);
        }


Modified: trunk/freenet/src/freenet/client/StdSplitfileBlock.java
===================================================================
--- trunk/freenet/src/freenet/client/StdSplitfileBlock.java     2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/client/StdSplitfileBlock.java     2005-11-10 
17:23:51 UTC (rev 7518)
@@ -12,6 +12,7 @@
        protected Bucket data;

        public StdSplitfileBlock(RetryTracker tracker2, int index2) {
+               if(tracker2 == null) throw new NullPointerException();
                this.tracker = tracker2;
                this.index = index2;
        }

Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-10 
16:10:49 UTC (rev 7517)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-10 
17:23:51 UTC (rev 7518)
@@ -63,14 +63,17 @@
         System.out.println();
         System.out.println("Build "+Version.buildNumber);
         System.out.println("Enter one of the following commands:");
-        System.out.println("GET:<Freenet key> - fetch a key");
-        System.out.println("PUT:\n<text, until a . on a line by itself> - We 
will insert the document and return the key.");
-        System.out.println("PUT:<text> - put a single line of text to a CHK 
and return the key.");
-        System.out.println("PUTFILE:<filename> - put a file from disk.");
-        System.out.println("GETFILE:<filename> - fetch a key and put it in a 
file. If the key includes a filename we will use it but we will not overwrite 
local files.");
-        System.out.println("PUBLISH:<name> - create a publish/subscribe stream 
called <name>");
-        System.out.println("PUSH:<name>:<text> - publish a single line of text 
to the stream named");
-        System.out.println("SUBSCRIBE:<key> - subscribe to a publish/subscribe 
stream by key");
+        System.out.println("GET:<Freenet key> - Fetch a key");
+        System.out.println("PUT:\n<text, until a . on a line by itself> - 
Insert the document and return the key.");
+        System.out.println("PUT:<text> - Put a single line of text to a CHK 
and return the key.");
+        System.out.println("GETCHK:\n<text, until a . on a line by itself> - 
Get the key that would be returned if the document was inserted.");
+        System.out.println("GETCHK:<text> - Get the key that would be returned 
if the line was inserted.");
+        System.out.println("PUTFILE:<filename> - Put a file from disk.");
+        System.out.println("GETFILE:<filename> - Fetch a key and put it in a 
file. If the key includes a filename we will use it but we will not overwrite 
local files.");
+        System.out.println("GETCHKFILE:<filename> - Get the key that would be 
returned if we inserted the file.");
+//        System.out.println("PUBLISH:<name> - create a publish/subscribe 
stream called <name>");
+//        System.out.println("PUSH:<name>:<text> - publish a single line of 
text to the stream named");
+//        System.out.println("SUBSCRIBE:<key> - subscribe to a 
publish/subscribe stream by key");
         System.out.println("CONNECT:<filename> - connect to a node from its 
ref in a file.");
         System.out.println("CONNECT:\n<noderef including an End on a line by 
itself> - enter a noderef directly.");
         System.out.println("NAME:<new node name> - change the node's name.");
@@ -103,6 +106,7 @@
             System.err.println("Bye... ("+e+")");
             return;
         }
+        boolean getCHKOnly = false;
         if(line == null) line = "QUIT";
         String uline = line.toUpperCase();
         Logger.minor(this, "Command: "+line);
@@ -181,7 +185,7 @@
         } else if(uline.startsWith("QUIT")) {
             System.out.println("Goodbye.");
             System.exit(0);
-        } else if(uline.startsWith("PUT:")) {
+        } else if(uline.startsWith("PUT:") || (getCHKOnly = 
uline.startsWith("GETCHK:"))) {
             // Just insert to local store
             line = line.substring("PUT:".length());
             while(line.length() > 0 && line.charAt(0) == ' ')
@@ -203,14 +207,14 @@

             FreenetURI uri;
             try {
-               uri = client.insert(block);
+               uri = client.insert(block, getCHKOnly);
             } catch (InserterException e) {
                System.out.println("Error: "+e.getMessage());
                return;
             }

             System.out.println("URI: "+uri);
-        } else if(uline.startsWith("PUTFILE:")) {
+        } else if(uline.startsWith("PUTFILE:") || (getCHKOnly = 
uline.startsWith("GETCHKFILE:"))) {
             // Just insert to local store
             line = line.substring("PUTFILE:".length());
             while(line.length() > 0 && line.charAt(0) == ' ')
@@ -226,7 +230,7 @@
                FileBucket fb = new FileBucket(f, true, false, false);
                InsertBlock block = new InsertBlock(fb, null, 
FreenetURI.EMPTY_CHK_URI);

-               FreenetURI uri = client.insert(block);
+               FreenetURI uri = client.insert(block, getCHKOnly);

                // FIXME depends on CHK's still being renamable
                 uri = uri.setDocName(f.getName());

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-11-10 16:10:49 UTC (rev 
7517)
+++ trunk/freenet/src/freenet/node/Version.java 2005-11-10 17:23:51 UTC (rev 
7518)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

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

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

Modified: trunk/freenet/src/freenet/support/BucketTools.java
===================================================================
--- trunk/freenet/src/freenet/support/BucketTools.java  2005-11-10 16:10:49 UTC 
(rev 7517)
+++ trunk/freenet/src/freenet/support/BucketTools.java  2005-11-10 17:23:51 UTC 
(rev 7518)
@@ -384,11 +384,11 @@
         */
        public static Bucket[] split(Bucket origData, int splitSize, 
BucketFactory bf) throws IOException {
                long length = origData.size();
-               if(length > Integer.MAX_VALUE * splitSize)
-                       throw new IllegalArgumentException("Way too big!");
+               if(length > ((long)Integer.MAX_VALUE) * splitSize)
+                       throw new IllegalArgumentException("Way too big!: 
"+length+" for "+splitSize);
                int bucketCount = (int) (length / splitSize);
+               if(length % splitSize > 0) bucketCount++;
                Bucket[] buckets = new Bucket[bucketCount];
-               if(length % splitSize > 0) bucketCount++;
                InputStream is = origData.getInputStream();
                DataInputStream dis = new DataInputStream(is);
                long remainingLength = length;
@@ -396,7 +396,9 @@
                for(int i=0;i<bucketCount;i++) {
                        int len = (int) Math.min(splitSize, remainingLength);
                        Bucket bucket = bf.makeBucket(len);
+                       buckets[i] = bucket;
                        dis.readFully(buf, 0, len);
+                       remainingLength -= len;
                        OutputStream os = bucket.getOutputStream();
                        os.write(buf, 0, len);
                        os.close();


Reply via email to