Author: zothar
Date: 2006-06-02 14:36:17 +0000 (Fri, 02 Jun 2006)
New Revision: 8987

Modified:
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
Wasn't consistently using ignoreHostnames in maybeUpdateHandshakeIPs(), which 
could affect node startup time.  Factored out the actual lookup loop, so 
changes don't get inconsistently applied here again.

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2006-06-02 13:15:25 UTC 
(rev 8986)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2006-06-02 14:36:17 UTC 
(rev 8987)
@@ -491,9 +491,28 @@
     }

     /**
+      * Do the maybeUpdateHandshakeIPs DNS requests, but only if 
ignoreHostnames is false
+      * This method should only be called by maybeUpdateHandshakeIPs
+      */
+    private Peer[] updateHandshakeIPs(Peer[] localHandshakeIPs, boolean 
ignoreHostnames) {
+        for(int i=0;i<localHandshakeIPs.length;i++) {
+          if(ignoreHostnames) {
+            // Don't do a DNS request on the first cycle through PeerNodes by 
DNSRequest
+            // upon startup (I suspect the following won't do anything, but 
just in case)
+            Logger.debug(this, "updateHandshakeIPs: calling getAddress(false) 
on Peer '"+localHandshakeIPs[i]+"' for PeerNode '"+getPeer()+"' named 
'"+myName+"' ("+ignoreHostnames+")");
+            localHandshakeIPs[i].getAddress(false);
+          } else {
+            // Actually do the DNS request for the member Peer of 
localHandshakeIPs
+            Logger.debug(this, "updateHandshakeIPs: calling 
getHandshakeAddress() on Peer '"+localHandshakeIPs[i]+"' for PeerNode 
'"+getPeer()+"' named '"+myName+"' ("+ignoreHostnames+")");
+            localHandshakeIPs[i].getHandshakeAddress();
+          }
+        }
+        return localHandshakeIPs;
+    }
+
+    /**
       * Do occasional DNS requests, but ignoreHostnames should be true
-      * for the first cycle through the peers by DNSRequester at node
-      * startup (faster startup time if we know some IPs already)
+      * on PeerNode construction
       */
     public void maybeUpdateHandshakeIPs(boolean ignoreHostnames) {
        long now = System.currentTimeMillis();
@@ -521,16 +540,7 @@
                        return;
                }
                localHandshakeIPs = new Peer[] { detectedPeer };
-               for(int i=0;i<localHandshakeIPs.length;i++) {
-                       if(ignoreHostnames) {
-                               // Don't do a DNS request on the first cycle 
through PeerNodes by DNSRequest
-                               // upon startup (I suspect the following won't 
do anything, but just in case)
-                               localHandshakeIPs[i].getAddress(false);
-                       } else {
-                               // Actually do the DNS request for the member 
Peer of localHandshakeIPs
-                               localHandshakeIPs[i].getHandshakeAddress();
-                       }
-               }
+               localHandshakeIPs = updateHandshakeIPs(localHandshakeIPs, 
ignoreHostnames);
                synchronized(this) {
                        handshakeIPs = localHandshakeIPs;
                }
@@ -565,10 +575,7 @@
                p = newPeers;
        }
        localHandshakeIPs = p;
-        for(int i=0;i<localHandshakeIPs.length;i++) {
-               // Actually do the DNS request for the member Peer of 
localHandshakeIPs
-               localHandshakeIPs[i].getHandshakeAddress();
-        }
+       localHandshakeIPs = updateHandshakeIPs(localHandshakeIPs, 
ignoreHostnames);
        synchronized(this) {
                handshakeIPs = localHandshakeIPs;
        }


Reply via email to