Author: toad
Date: 2005-12-09 21:45:59 +0000 (Fri, 09 Dec 2005)
New Revision: 7700

Removed:
   trunk/freenet/src/freenet/keys/ClientPublishStreamKey.java
   trunk/freenet/src/freenet/keys/PublishStreamKey.java
Modified:
   trunk/freenet/src/freenet/keys/ClientCHKBlock.java
   trunk/freenet/src/freenet/keys/Key.java
   trunk/freenet/src/freenet/keys/NodeCHK.java
   trunk/freenet/src/freenet/node/InsertHandler.java
   trunk/freenet/src/freenet/node/InsertSender.java
   trunk/freenet/src/freenet/node/PeerManager.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/support/Serializer.java
Log:
298: (mandatory)
Up keylength to 32 bytes.
Delete some old pub/sub code.

Modified: trunk/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHKBlock.java  2005-12-08 14:22:51 UTC 
(rev 7699)
+++ trunk/freenet/src/freenet/keys/ClientCHKBlock.java  2005-12-09 21:45:59 UTC 
(rev 7700)
@@ -135,14 +135,6 @@

         // Now do the actual encode

-        MessageDigest md160;
-        try {
-            md160 = MessageDigest.getInstance("SHA-1");
-        } catch (NoSuchAlgorithmException e2) {
-            // FIXME: log properly? Not much we can do... But we could log a
-            // more user-friendly message...
-            throw new Error(e2);
-        }
         MessageDigest md256;
         try {
             md256 = MessageDigest.getInstance("SHA-256");
@@ -193,8 +185,8 @@
         pcfb.blockEncipher(data, 0, data.length);

         // Now calculate the final hash
-        md160.update(header);
-        byte[] finalHash = md160.digest(data);
+        md256.update(header);
+        byte[] finalHash = md256.digest(data);

         // Now convert it into a ClientCHK
         key = new ClientCHK(finalHash, encKey, asMetadata, 
ClientCHK.ALGO_AES_PCFB_256, compressionAlgorithm);

Deleted: trunk/freenet/src/freenet/keys/ClientPublishStreamKey.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientPublishStreamKey.java  2005-12-08 
14:22:51 UTC (rev 7699)
+++ trunk/freenet/src/freenet/keys/ClientPublishStreamKey.java  2005-12-09 
21:45:59 UTC (rev 7700)
@@ -1,180 +0,0 @@
-package freenet.keys;
-
-import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.Random;
-
-import org.spaceroots.mantissa.random.MersenneTwister;
-
-import freenet.crypt.PCFBMode;
-import freenet.crypt.RandomSource;
-import freenet.crypt.UnsupportedCipherException;
-import freenet.crypt.ciphers.Rijndael;
-import freenet.support.Fields;
-import freenet.support.HexUtil;
-import freenet.support.Logger;
-
-/**
- * Key for a publish/subscribe stream. Contains a pubkey,
- * a routing key, and a symmetric crypto key.
- */
-public class ClientPublishStreamKey {
-    /** The maximum number of bytes in a single packet */
-    public final static int SIZE_MAX = 1024;
-    static final int SYMMETRIC_KEYLENGTH = 32;
-    
-    /** The routing key */
-    private final byte[] routingKey;
-    
-    /** The content encryption/decryption key */
-    private final byte[] symCipherKey;
-
-    /** The encryption/decryption algorithm */
-    private final short cryptoAlgorithm;
-    
-    private final int hashCode;
-
-    private static final int ROUTING_KEY_LENGTH = 20;
-    private static final int SYM_CIPHER_KEY_LENGTH = 32;
-    
-    static final short ALGO_AES_PCFB_256 = 1;
-
-    private ClientPublishStreamKey(byte[] routingKey2, byte[] symCipherKey2) {
-        routingKey = routingKey2;
-        symCipherKey = symCipherKey2;
-        hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(symCipherKey);
-        cryptoAlgorithm = ALGO_AES_PCFB_256;
-    }
-
-    /**
-     * @param uri
-     */
-    public ClientPublishStreamKey(FreenetURI uri) throws MalformedURLException 
{
-        if(!uri.getKeyType().equals("PSK"))
-            throw new MalformedURLException("Not PSK");
-        routingKey = uri.getRoutingKey();
-        symCipherKey = uri.getCryptoKey();
-        byte[] extra = uri.getExtra();
-        if(extra == null || extra.length < 2)
-            throw new MalformedURLException();
-        cryptoAlgorithm = (short)(((extra[0] & 0xff) << 8) + (extra[1] & 
0xff));
-        if(cryptoAlgorithm != ALGO_AES_PCFB_256) {
-            throw new MalformedURLException("Unrecognized crypto algorithm: 
"+cryptoAlgorithm);
-        }
-        hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(symCipherKey);
-    }
-
-    /**
-     * @return The URI for this stream key.
-     */
-    public FreenetURI getURI() {
-        return new FreenetURI("PSK", "", routingKey, symCipherKey, new byte[] 
{ (byte)(cryptoAlgorithm>>8), (byte)cryptoAlgorithm });
-    }
-
-    public static ClientPublishStreamKey createRandom(RandomSource random) {
-        byte[] routingKey = new byte[ROUTING_KEY_LENGTH];
-        byte[] symCipherKey = new byte[SYM_CIPHER_KEY_LENGTH];
-        random.nextBytes(routingKey);
-        random.nextBytes(symCipherKey);
-        return new ClientPublishStreamKey(routingKey, symCipherKey);
-    }
-
-    /**
-     * @return The node-level key
-     */
-    public PublishStreamKey getKey() {
-        return new PublishStreamKey(routingKey);
-    }
-    
-    // FIXME: add a DSA key to sign messages
-    // FIXME: maybe encrypt too?
-    
-    public boolean equals(Object o) {
-        if(o == this) return true;
-        if(o instanceof ClientPublishStreamKey) {
-            ClientPublishStreamKey key = (ClientPublishStreamKey)o;
-            return Arrays.equals(key.routingKey, routingKey) &&
-               Arrays.equals(key.symCipherKey, symCipherKey);
-        } else return false;
-    }
-    
-    public int hashCode() {
-        return hashCode;
-    }
-
-    /**
-     * Encrypt a packet to be sent out on the stream.
-     * @param packetNumber
-     * @param origData
-     * @return
-     */
-    public byte[] encrypt(long packetNumber, byte[] data, Random random) {
-        if(data.length > SIZE_MAX) throw new IllegalArgumentException();
-        // Encrypt: IV(32) data(1024) datalength(2)
-        byte[] buf = new byte[SYMMETRIC_KEYLENGTH + SIZE_MAX + 2];
-        byte[] iv = new byte[SYMMETRIC_KEYLENGTH];
-        random.nextBytes(iv);
-        System.arraycopy(iv, 0, buf, 0, iv.length);
-        System.arraycopy(data, 0, buf, SYMMETRIC_KEYLENGTH, data.length);
-        if(data.length != SIZE_MAX) {
-            MersenneTwister mt = new MersenneTwister(random.nextLong());
-            byte[] temp = new byte[SIZE_MAX - data.length];
-            mt.nextBytes(temp);
-            System.arraycopy(temp, 0, buf, SYMMETRIC_KEYLENGTH + data.length, 
SIZE_MAX - data.length);
-        }
-        buf[SYMMETRIC_KEYLENGTH+SIZE_MAX] = (byte)(data.length >> 8);
-        buf[SYMMETRIC_KEYLENGTH+SIZE_MAX+1] = (byte)(data.length);
-        Logger.minor(this, "Length: "+data.length+": 
"+buf[SYMMETRIC_KEYLENGTH+SIZE_MAX]+","+buf[SYMMETRIC_KEYLENGTH+SIZE_MAX+1]);
-        Logger.minor(this, "Plaintext : "+HexUtil.bytesToHex(buf));
-        Rijndael r;
-        try {
-            r = new Rijndael(256,256);
-        } catch (UnsupportedCipherException e) {
-            throw new Error(e);
-        }
-        r.initialize(symCipherKey);
-        PCFBMode pcfb = new PCFBMode(r);
-        pcfb.blockEncipher(buf, 0, buf.length);
-        Logger.minor(this, "Ciphertext: "+HexUtil.bytesToHex(buf));
-        //Logger.minor(this, "Encrypting with 
"+HexUtil.bytesToHex(symCipherKey));
-        return buf;
-    }
-    
-    /**
-     * Decrypt a packet from the stream.
-     * @param packetNumber
-     * @param packetData
-     * @return
-     */
-    public byte[] decrypt(long packetNumber, byte[] packetData) {
-        if(packetData.length != SIZE_MAX + SYMMETRIC_KEYLENGTH + 2) {
-            Logger.error(this, "Stream packet wrong size!", new 
Exception("error"));
-            return null;
-        }
-        Rijndael r;
-        try {
-            r = new Rijndael(256,256);
-        } catch (UnsupportedCipherException e) {
-            throw new Error(e);
-        }
-        r.initialize(symCipherKey);
-        //Logger.minor(this, "Decrypting with 
"+HexUtil.bytesToHex(symCipherKey));
-        PCFBMode pcfb = new PCFBMode(r);
-        Logger.minor(this, "Ciphertext: "+HexUtil.bytesToHex(packetData));
-        pcfb.blockDecipher(packetData, 0, packetData.length);
-        Logger.minor(this, "Plaintext : "+HexUtil.bytesToHex(packetData));
-        // Discard first SYMMETRIC_KEYLENGTH bytes (IV)
-        int len1 = (packetData[SYMMETRIC_KEYLENGTH+SIZE_MAX] & 0xff);
-        int len2 = (packetData[SYMMETRIC_KEYLENGTH+SIZE_MAX+1] & 0xff);
-        int length = (len1 << 8) + len2;
-               
-        if(length > SIZE_MAX) {
-            Logger.error(this, "Could not decrypt packet: length="+length+" 
("+len1+","+len2+")");
-            return null;
-        }
-        
-        byte[] output = new byte[length];
-        System.arraycopy(packetData, SYMMETRIC_KEYLENGTH, output, 0, length);
-        return output;
-    }
-}

Modified: trunk/freenet/src/freenet/keys/Key.java
===================================================================
--- trunk/freenet/src/freenet/keys/Key.java     2005-12-08 14:22:51 UTC (rev 
7699)
+++ trunk/freenet/src/freenet/keys/Key.java     2005-12-09 21:45:59 UTC (rev 
7700)
@@ -13,8 +13,8 @@
  */
 public abstract class Key implements WritableToDataOutputStream {

-    /** 20 bytes for hash, 2 bytes for type */
-    public static final short KEY_SIZE_ON_DISK = 22;
+    /** 32 bytes for hash, 2 bytes for type */
+    public static final short KEY_SIZE_ON_DISK = 34;

     /**
      * Write to disk.
@@ -32,8 +32,6 @@
         short type = raf.readShort();
         if(type == NodeCHK.TYPE) {
             return NodeCHK.read(raf);
-        } else if(type == PublishStreamKey.TYPE) {
-            return PublishStreamKey.read(raf);
         }
         throw new IOException("Unrecognized format: "+type);
     }

Modified: trunk/freenet/src/freenet/keys/NodeCHK.java
===================================================================
--- trunk/freenet/src/freenet/keys/NodeCHK.java 2005-12-08 14:22:51 UTC (rev 
7699)
+++ trunk/freenet/src/freenet/keys/NodeCHK.java 2005-12-09 21:45:59 UTC (rev 
7700)
@@ -29,7 +29,7 @@
         cachedNormalizedDouble = -1;
     }

-    static final int KEY_LENGTH = 20;
+    static final int KEY_LENGTH = 32;

     byte[] routingKey;
     public static final short TYPE = 0x0302;

Deleted: trunk/freenet/src/freenet/keys/PublishStreamKey.java
===================================================================
--- trunk/freenet/src/freenet/keys/PublishStreamKey.java        2005-12-08 
14:22:51 UTC (rev 7699)
+++ trunk/freenet/src/freenet/keys/PublishStreamKey.java        2005-12-09 
21:45:59 UTC (rev 7700)
@@ -1,111 +0,0 @@
-package freenet.keys;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
-import freenet.support.Fields;
-import freenet.support.HexUtil;
-import freenet.support.Logger;
-
-public class PublishStreamKey extends Key {
-
-    public static final short TYPE = 0x0401;
-    static final short ALGO_AES_PCFB_256 = 1;
-    static final int KEY_LENGTH = 20;
-    
-    private final byte[] routingKey;
-    private final int hashCode;
-    private boolean hasSecureLongHashCode;
-    private long secureLongHashCode;
-    double cachedNormalizedDouble;
-    
-    public PublishStreamKey(byte[] routingKey) {
-        this.routingKey = routingKey;
-        hashCode = Fields.hashCode(routingKey);
-    }
-
-    public void write(DataOutput _index) throws IOException {
-        _index.writeShort(TYPE);
-        _index.write(routingKey);
-    }
-
-    public boolean equals(Object o) {
-        if(o == this) return true;
-        if(o instanceof PublishStreamKey) {
-            PublishStreamKey k = (PublishStreamKey) o;
-            return Arrays.equals(k.routingKey, routingKey);
-        } else return false;
-    }
-    
-    public int hashCode() {
-        return hashCode;
-    }
-    
-    public String toString() {
-        return super.toString()+":"+HexUtil.bytesToHex(routingKey);
-    }
-
-    /**
-     * @return A secure (given the length) 64-bit hash of
-     * the key.
-     */
-    public synchronized long secureLongHashCode() {
-        if(hasSecureLongHashCode) return secureLongHashCode;
-        MessageDigest md;
-        try {
-            md = MessageDigest.getInstance("SHA-1");
-        } catch (NoSuchAlgorithmException e) {
-            Logger.error(this, "No such algorithm: SHA-1 !!!!!", e);
-            throw new RuntimeException(e);
-        }
-        md.update((byte)(TYPE >> 8));
-        md.update((byte)TYPE);
-        md.update(routingKey);
-        byte[] digest = md.digest();
-        secureLongHashCode = Fields.bytesToLong(digest);
-        hasSecureLongHashCode = true;
-        return secureLongHashCode;
-    }
-
-    public double toNormalizedDouble() {
-        if(cachedNormalizedDouble > 0) return cachedNormalizedDouble;
-        MessageDigest md;
-        try {
-            md = MessageDigest.getInstance("SHA-256");
-        } catch (NoSuchAlgorithmException e) {
-            throw new Error(e);
-        }
-        md.update(routingKey);
-        md.update((byte)(TYPE >> 8));
-        md.update((byte)TYPE);
-        byte[] digest = md.digest();
-        long asLong = Math.abs(Fields.bytesToLong(digest));
-        // Math.abs can actually return negative...
-        if(asLong == Long.MIN_VALUE)
-            asLong = Long.MAX_VALUE;
-        cachedNormalizedDouble = ((double)asLong)/((double)Long.MAX_VALUE);
-        return cachedNormalizedDouble;
-    }
-
-    public void writeToDataOutputStream(DataOutputStream stream) throws 
IOException {
-        stream.writeShort(TYPE);
-        stream.write(routingKey);
-    }
-    
-    public static Key read(DataInput raf, boolean readType) throws IOException 
{
-        if(readType) {
-            short type = raf.readShort();
-            if(type != TYPE)
-                // FIXME there has to be a better way to deal with format 
errors...
-                throw new IOException("Invalid type");
-        }
-        byte[] buf = new byte[KEY_LENGTH];
-        raf.readFully(buf);
-        return new PublishStreamKey(buf);
-    }
-}

Modified: trunk/freenet/src/freenet/node/InsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/InsertHandler.java   2005-12-08 14:22:51 UTC 
(rev 7699)
+++ trunk/freenet/src/freenet/node/InsertHandler.java   2005-12-09 21:45:59 UTC 
(rev 7700)
@@ -152,7 +152,8 @@
         while(true) {
             synchronized(sender) {
                 try {
-                    sender.wait(5000);
+                       if(sender.getStatus() != InsertSender.NOT_FINISHED)
+                               sender.wait(5000);
                 } catch (InterruptedException e) {
                     // Cool, probably this is because the receive failed...
                 }
@@ -166,6 +167,7 @@
             }

             if((!receivedRejectedOverload) && 
sender.receivedRejectedOverload()) {
+               receivedRejectedOverload = true;
                // Forward it
                Message m = DMT.createFNPRejectedOverload(uid, false);
                source.send(m);

Modified: trunk/freenet/src/freenet/node/InsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/InsertSender.java    2005-12-08 14:22:51 UTC 
(rev 7699)
+++ trunk/freenet/src/freenet/node/InsertSender.java    2005-12-09 21:45:59 UTC 
(rev 7700)
@@ -516,11 +516,9 @@
                        // There weren't any transfers
                        allTransfersCompleted = true;
                }
-        }
-        
-        synchronized(this) {
             notifyAll();
         }
+        
         Logger.minor(this, "Returning from finish()");
     }


Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java     2005-12-08 14:22:51 UTC 
(rev 7699)
+++ trunk/freenet/src/freenet/node/PeerManager.java     2005-12-09 21:45:59 UTC 
(rev 7700)
@@ -324,7 +324,7 @@
             count++;
             any = p;
             double diff = distance(p, loc);
-            Logger.minor(this, "p.loc="+p.getLocation().getValue()+", 
loc="+loc+", d="+distance(p.getLocation().getValue(), loc)+" usedD="+diff);
+            Logger.minor(this, "p.loc="+p.getLocation().getValue()+", 
loc="+loc+", d="+distance(p.getLocation().getValue(), loc)+" usedD="+diff+" for 
"+p.getPeer());
             if((!ignoreSelf) && diff > maxDiff) continue;
             if(diff < bestDiff) {
                 best = p;

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-12-08 14:22:51 UTC (rev 
7699)
+++ trunk/freenet/src/freenet/node/Version.java 2005-12-09 21:45:59 UTC (rev 
7700)
@@ -20,10 +20,10 @@
        public static final String protocolVersion = "1.0";

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

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

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

Modified: trunk/freenet/src/freenet/support/Serializer.java
===================================================================
--- trunk/freenet/src/freenet/support/Serializer.java   2005-12-08 14:22:51 UTC 
(rev 7699)
+++ trunk/freenet/src/freenet/support/Serializer.java   2005-12-09 21:45:59 UTC 
(rev 7700)
@@ -19,14 +19,17 @@

 package freenet.support;

-import freenet.io.*;
-import freenet.io.comm.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import freenet.io.WritableToDataOutputStream;
+import freenet.io.comm.Peer;
 import freenet.keys.Key;
-import freenet.keys.PublishStreamKey;

-import java.io.*;
-import java.util.*;
-
 /**
  * @author ian
  *
@@ -78,8 +81,6 @@
                        return new BitArray(dis);
                } else if (type.equals(Key.class)) {
                    return Key.read(dis);
-               } else if (type.equals(PublishStreamKey.class)) {
-                   return PublishStreamKey.read(dis, true);
                } else {
                        throw new RuntimeException("Unrecognised field type: " 
+ type);
                }


Reply via email to