Author: nextgens
Date: 2008-08-12 13:31:46 +0000 (Tue, 12 Aug 2008)
New Revision: 21758

Removed:
   
trunk/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java
Modified:
   trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
   trunk/freenet/src/freenet/clients/http/QueueToadlet.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
   trunk/freenet/src/freenet/node/NodeClientCore.java
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
   trunk/freenet/src/freenet/support/io/DelayedFreeBucket.java
   trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java
Log:
Add a new config option: node.encryptPersistentTempBuckets

TESTING IS REQUIRED

Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java     
2008-08-12 13:02:23 UTC (rev 21757)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java     
2008-08-12 13:31:46 UTC (rev 21758)
@@ -98,7 +98,7 @@
                curMaxTempLength = Long.MAX_VALUE;
                curMaxMetadataLength = 1024 * 1024;
                this.cacheLocalRequests = cacheLocalRequests;
-               this.persistentBucketFactory = 
node.persistentEncryptedTempBucketFactory;
+               this.persistentBucketFactory = node.persistentTempBucketFactory;
                this.healingQueue = node.getHealingQueue();
                this.blockEncoder = node.backgroundBlockEncoder;
        }

Modified: trunk/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/QueueToadlet.java    2008-08-12 
13:02:23 UTC (rev 21757)
+++ trunk/freenet/src/freenet/clients/http/QueueToadlet.java    2008-08-12 
13:31:46 UTC (rev 21758)
@@ -54,7 +54,6 @@
 import freenet.support.io.BucketTools;
 import freenet.support.io.Closer;
 import freenet.support.io.FileBucket;
-import java.util.StringTokenizer;

 public class QueueToadlet extends Toadlet implements RequestCompletionCallback 
{

@@ -319,7 +318,7 @@
                                else
                                        fnam = null;
                                /* copy bucket data */
-                               Bucket copiedBucket = 
core.persistentEncryptedTempBucketFactory.makeBucket(file.getData().size());
+                               Bucket copiedBucket = 
core.persistentTempBucketFactory.makeBucket(file.getData().size());
                                BucketTools.copy(file.getData(), copiedBucket);
                                try {
                                        ClientPut clientPut = new 
ClientPut(fcp.getGlobalClient(), insertURI, identifier, Integer.MAX_VALUE, 
RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS, ClientRequest.PERSIST_FOREVER, 
null, false, !compress, -1, ClientPutMessage.UPLOAD_FROM_DIRECT, null, 
file.getContentType(), copiedBucket, null, fnam, false);

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-08-12 
13:02:23 UTC (rev 21757)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-08-12 
13:31:46 UTC (rev 21758)
@@ -720,6 +720,8 @@
 NodeClientCore.downloadAllowedDirsLong=Semicolon separated list of directories 
to which downloads are allowed. "downloads" means downloadsDir, empty means no 
downloads to disk allowed, "all" means downloads allowed from anywhere. 
WARNING! If this is set to "all" any user can download any file to anywhere on 
your computer!
 NodeClientCore.downloadDir=Default download directory
 NodeClientCore.downloadDirLong=The directory to save downloaded files into by 
default
+NodeClientCore.encryptPersistentTempBuckets=Encrypt the persistent temporary 
buckets? LEAVE THIS ALONE!
+NodeClientCore.encryptPersistentTempBucketsLong=Encrypt the persistent 
temporary buckets? In some cases (if you use hard-drive and swap encryption) it 
might not make sense to encrypt persistent temporary buckets. LEAVE THIS ALONE 
IF YOU DON'T KNOW WHAT YOU ARE DOING!
 NodeClientCore.encryptTempBuckets=Encrypt the temporary buckets? LEAVE THIS 
ALONE!
 NodeClientCore.encryptTempBucketsLong=Encrypt the temporary buckets? In some 
cases (if you use hard-drive and swap encryption) it might not make sense to 
encrypt temporary buckets. LEAVE THIS ALONE IF YOU DON'T KNOW WHAT YOU ARE 
DOING!
 NodeClientCore.fileForClientStats=File to store client statistics in

Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2008-08-12 13:02:23 UTC 
(rev 21757)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2008-08-12 13:31:46 UTC 
(rev 21758)
@@ -60,7 +60,6 @@
 import freenet.support.io.FilenameGenerator;
 import freenet.support.io.NativeThread;
 import freenet.support.io.PaddedEphemerallyEncryptedBucketFactory;
-import freenet.support.io.PersistentEncryptedTempBucketFactory;
 import freenet.support.io.PersistentTempBucketFactory;
 import freenet.support.io.TempBucketFactory;

@@ -85,7 +84,6 @@
        final FilenameGenerator tempFilenameGenerator;
        public final PaddedEphemerallyEncryptedBucketFactory tempBucketFactory;
        public final PersistentTempBucketFactory persistentTempBucketFactory;
-       public final PersistentEncryptedTempBucketFactory 
persistentEncryptedTempBucketFactory;
        public final Node node;
        final NodeStats nodeStats;
        public final RandomSource random;
@@ -173,6 +171,18 @@
                }

                // Persistent temp files
+               nodeConfig.register("encryptPersistentTempBuckets", true, 
sortOrder++, true, false, "NodeClientCore.encryptPersistentTempBuckets", 
"NodeClientCore.encryptPersistentTempBucketsLong", new BooleanCallback() {
+
+                       public boolean get() {
+                               return (persistentTempBucketFactory == null ? 
true : persistentTempBucketFactory.isEncrypting());
+                       }
+
+                       public void set(boolean val) throws 
InvalidConfigValueException {
+                               if((val == get()) || 
(persistentTempBucketFactory == null)) return;
+                               persistentTempBucketFactory.setEncryption(val);
+                       }
+               });
+               
                nodeConfig.register("persistentTempDir", new File(nodeDir, 
"persistent-temp-" + portNumber).toString(), sortOrder++, true, false, 
"NodeClientCore.persistentTempDir", "NodeClientCore.persistentTempDirLong",
                        new StringCallback() {

@@ -188,8 +198,7 @@
                                }
                        });
                try {
-                       persistentTempBucketFactory = new 
PersistentTempBucketFactory(new 
File(nodeConfig.getString("persistentTempDir")), "freenet-temp-", random, 
node.fastWeakRandom);
-                       persistentEncryptedTempBucketFactory = new 
PersistentEncryptedTempBucketFactory(persistentTempBucketFactory);
+                       persistentTempBucketFactory = new 
PersistentTempBucketFactory(new 
File(nodeConfig.getString("persistentTempDir")), "freenet-temp-", random, 
node.fastWeakRandom, nodeConfig.getBoolean("encryptPersistentTempBuckets"));
                } catch(IOException e2) {
                        String msg = "Could not find or create persistent 
temporary directory";
                        throw new 
NodeInitException(NodeInitException.EXIT_BAD_TEMP_DIR, msg);

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java   2008-08-12 13:02:23 UTC 
(rev 21757)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java   2008-08-12 13:31:46 UTC 
(rev 21758)
@@ -105,7 +105,7 @@
                        tempFile = null;
                        try {
                                if(persistenceType == PERSIST_FOREVER)
-                                       ret = 
client.server.core.persistentTempBucketFactory.makeEncryptedBucket();
+                                       ret = 
client.server.core.persistentTempBucketFactory.makeBucket(-1);
                                else
                                        ret = fctx.bucketFactory.makeBucket(-1);
                        } catch (IOException e) {
@@ -174,7 +174,7 @@
                        tempFile = null;
                        try {
                                if(persistenceType == PERSIST_FOREVER)
-                                       ret = 
client.server.core.persistentTempBucketFactory.makeEncryptedBucket();
+                                       ret = 
client.server.core.persistentTempBucketFactory.makeBucket(-1);
                                else
                                        ret = fctx.bucketFactory.makeBucket(-1);
                        } catch (IOException e) {
@@ -269,7 +269,7 @@
                                try {
                                        // Create a new temp bucket
                                        if(persistenceType == PERSIST_FOREVER)
-                                               ret = 
client.server.core.persistentTempBucketFactory.makeEncryptedBucket();
+                                               ret = 
client.server.core.persistentTempBucketFactory.makeBucket(-1);
                                        else
                                                ret = 
fctx.bucketFactory.makeBucket(-1);
                                } catch (IOException e1) {

Modified: trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java    2008-08-12 
13:02:23 UTC (rev 21757)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java    2008-08-12 
13:31:46 UTC (rev 21758)
@@ -260,7 +260,7 @@

        Bucket createBucket(BucketFactory bf, long length, FCPServer server) 
throws IOException {
                if(persistenceType == ClientRequest.PERSIST_FOREVER) {
-                       return 
server.core.persistentTempBucketFactory.makeEncryptedBucket();
+                       return 
server.core.persistentTempBucketFactory.makeBucket(length);
                } else {
                        return super.createBucket(bf, length, server);
                }

Modified: trunk/freenet/src/freenet/support/io/DelayedFreeBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/DelayedFreeBucket.java 2008-08-12 
13:02:23 UTC (rev 21757)
+++ trunk/freenet/src/freenet/support/io/DelayedFreeBucket.java 2008-08-12 
13:31:46 UTC (rev 21758)
@@ -20,7 +20,7 @@
        Bucket bucket;
        boolean freed;

-       public DelayedFreeBucket(PersistentTempBucketFactory factory, 
PaddedEphemerallyEncryptedBucket bucket) {
+       public DelayedFreeBucket(PersistentTempBucketFactory factory, Bucket 
bucket) {
                this.factory = factory;
                this.bucket = bucket;
        }

Deleted: 
trunk/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java
===================================================================
--- 
trunk/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java  
    2008-08-12 13:02:23 UTC (rev 21757)
+++ 
trunk/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java  
    2008-08-12 13:31:46 UTC (rev 21758)
@@ -1,23 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.support.io;
-
-import java.io.IOException;
-
-import freenet.support.api.Bucket;
-import freenet.support.api.BucketFactory;
-
-
-public class PersistentEncryptedTempBucketFactory implements BucketFactory {
-
-       PersistentTempBucketFactory bf;
-       
-       public PersistentEncryptedTempBucketFactory(PersistentTempBucketFactory 
bf) {
-               this.bf = bf;
-       }
-
-       public Bucket makeBucket(long size) throws IOException {
-               return bf.makeEncryptedBucket();
-       }
-}

Modified: trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java       
2008-08-12 13:02:23 UTC (rev 21757)
+++ trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java       
2008-08-12 13:31:46 UTC (rev 21758)
@@ -42,12 +42,15 @@

        /** Buckets to free */
        private LinkedList bucketsToFree;
+       
+       private volatile boolean encrypt;

-       public PersistentTempBucketFactory(File dir, final String prefix, 
RandomSource strongPRNG, Random weakPRNG) throws IOException {
+       public PersistentTempBucketFactory(File dir, final String prefix, 
RandomSource strongPRNG, Random weakPRNG, boolean encrypt) throws IOException {
                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                this.dir = dir;
                this.strongPRNG = strongPRNG;
                this.weakPRNG = weakPRNG;
+               this.encrypt = encrypt;
                this.fg = new FilenameGenerator(weakPRNG, false, dir, prefix);
                if(!dir.exists()) {
                        dir.mkdir();
@@ -104,19 +107,11 @@
                originalFiles = null;
        }

-       private Bucket makeRawBucket(long size) throws IOException {
-               return new PersistentTempFileBucket(fg.makeRandomFilename(), 
fg);
-       }
-
        public Bucket makeBucket(long size) throws IOException {
-               Bucket b = makeRawBucket(size);
-               return new DelayedFreeBucket(this, new 
PaddedEphemerallyEncryptedBucket(b, 1024, strongPRNG, weakPRNG));
+               PersistentTempFileBucket rawBucket = new 
PersistentTempFileBucket(fg.makeRandomFilename(), fg);
+               Bucket maybeEncryptedBucket = (encrypt ? new 
PaddedEphemerallyEncryptedBucket(rawBucket, 1024, strongPRNG, weakPRNG) : 
rawBucket);
+               return new DelayedFreeBucket(this, maybeEncryptedBucket);
        }
-       
-       public Bucket makeEncryptedBucket() throws IOException {
-               Bucket b = makeRawBucket(-1);
-               return new DelayedFreeBucket(this, new 
PaddedEphemerallyEncryptedBucket(b, 1024, strongPRNG, weakPRNG));
-       }

        /**
         * Free an allocated bucket, but only after the change has been written 
to disk.
@@ -150,5 +145,12 @@
        public long getID(File file) {
                return fg.getID(file);
        }
+       
+       public boolean isEncrypting() {
+               return encrypt;
+       }

+       public void setEncryption(boolean encrypt) {
+               this.encrypt = encrypt;
+       }
 }


Reply via email to