Author: nextgens
Date: 2007-10-23 15:48:01 +0000 (Tue, 23 Oct 2007)
New Revision: 15500

Modified:
   trunk/freenet/src/freenet/node/FNPPacketMangler.java
Log:
JFK: make the JFK-buffer pruning deterministic

Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java        2007-10-23 
15:31:11 UTC (rev 15499)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java        2007-10-23 
15:48:01 UTC (rev 15500)
@@ -2476,6 +2476,7 @@
                node.executor.execute(new Runnable() {
                        public void run() {
                                synchronized (dhContextFIFO) {
+                                       
dhContextFIFO.remove(findOldestContext());
                                        
dhContextFIFO.addLast(_genLightDiffieHellmanContext());
                                }
                        }
@@ -2548,6 +2549,29 @@
                }
                return null;
        }
+       
+       /**
+        * Used to prune the oldest context
+        * That's O^(N)... but we have only a few elements.
+        * 
+        * @return the oldest DiffieHellmanLightContext
+        */
+       private DiffieHellmanLightContext findOldestContext() {
+               DiffieHellmanLightContext result = null, tmp;
+               long oldestSeen = Long.MAX_VALUE;
+               
+               synchronized (dhContextFIFO) {
+                       Iterator it = dhContextFIFO.iterator();
+                       while(it.hasNext()) {
+                               tmp = (DiffieHellmanLightContext) it.next();
+                               if(result.lifetime < oldestSeen) {
+                                       oldestSeen = result.lifetime;
+                                       result = tmp;
+                               }
+                       }
+               }
+               return result;
+       }

        /*
         * Prepare DH parameters of message2 for them to be signed (useful in 
message3 to check the sig)


Reply via email to