Author: toad
Date: 2007-12-10 18:18:46 +0000 (Mon, 10 Dec 2007)
New Revision: 16448

Modified:
   trunk/freenet/src/freenet/node/FNPPacketMangler.java
Log:
Better this way. Pad anyway if over MTU and nothing we can do about it.

Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java        2007-12-10 
18:15:33 UTC (rev 16447)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java        2007-12-10 
18:18:46 UTC (rev 16448)
@@ -1568,7 +1568,14 @@
                byte[] hash = SHA256.digest(output);
                if(logMINOR) Logger.minor(this, "Data hash: 
"+HexUtil.bytesToHex(hash));
                int prePaddingLength = iv.length + hash.length + 2 /* length */ 
+ output.length;
-               int paddingLength = node.fastWeakRandom.nextInt(Math.min(100, 
sock.getMaxPacketSize() - prePaddingLength));
+               int maxPacketSize = sock.getMaxPacketSize() - 
sock.getHeadersLength();
+               int paddingLength;
+               if(prePaddingLength > maxPacketSize) {
+                       // Pad anyway if over MTU
+                       paddingLength = node.fastWeakRandom.nextInt(100);
+               } else {
+                       paddingLength = 
node.fastWeakRandom.nextInt(Math.min(100, maxPacketSize - prePaddingLength));
+               }
                // Sometimes we have to send oversize packets (especially 
JFK3/4 with anonymous-initiator)
                if(paddingLength < 0) paddingLength = 0;
                byte[] data = new byte[prePaddingLength + paddingLength];


Reply via email to