Update of /cvsroot/freenet/freenet/src/freenet
In directory sc8-pr-cvs1:/tmp/cvs-serv26314/src/freenet

Modified Files:
        OpenConnectionManager.java Peer.java Version.java 
Log Message:
6192:
Correct counting of SendFinished's for RNFs - if it's a failure, it's unreachable, if 
it's a timeout, it's "restarted".
Don't start a ConnJob in-thread if it's already been started by another thread.
Bugfixes to profiling counts of ConnectionHandler occurrences.
Pool ConnectionHandler accumulators too to avoid expensive allocations and object 
churn.
Include size of tcpConnection and ConnectionHandler buffer pools in interesting 
objects dump.
Logging.


Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- OpenConnectionManager.java  10 Sep 2003 20:43:43 -0000      1.100
+++ OpenConnectionManager.java  12 Sep 2003 01:52:25 -0000      1.101
@@ -54,6 +54,7 @@
     private final LRUQueue lru = new LRUQueue();
     private int maxConnections = -1;
     
+       private final boolean doHardConnectionLimit = true; // set true to enable 
special debugging for the Curus Bug (simultaneous connect attempts to the same node)!. 
FIXME: set false before release
     private boolean useOldStyle = false; //Keep track of what HTML mode the user last 
requested
     private int viewLevel = 0;
     private int iSortingMode = 0;
@@ -97,19 +98,27 @@
         ConnectionHandler oldest = null;
                while (true) {
                        synchronized (lru) {
-               
+                               
                                if (maxConnections > 0 && lru.size() > maxConnections) 
{
-                   
+                                       
                                        // Dump an idle connection if possible.
                                        for (Enumeration e = lru.elements(); 
e.hasMoreElements();) {
                                                ConnectionHandler candidate = 
                                                        
(ConnectionHandler)e.nextElement();
                                                if (!(candidate.sending() || 
candidate.receiving())) {
-                                                       if(oldest != null && 
(!oldest.isOpen())) {
-                                                               if(candidate.isOpen()) 
continue;
+                                                       if(oldest != null) {
+                                                               // If the oldest is 
open and the candidate is closed...
+                                                               if(oldest.isOpen() && 
(!candidate.isOpen()))
+                                                                       oldest = null;
+                                                               // Or the oldest is an 
only-conn-to-this-RTNode and the 
+                                                               // candidate is not... 
then use the candidate
+                                                               
if(onlyRTNodeConn(oldest) && (!onlyRTNodeConn(candidate)))
+                                                                       oldest = null;
+                                                       }
+                                                       if(oldest == null) {
+                                                               oldest = candidate;
+                                                               if(!oldest.isOpen()) 
break;
                                                        }
-                                                       oldest = candidate;
-                                                       if(!oldest.isOpen()) break;
                                                        // Otherwise wait for the best 
open conn
                                                        //lru.remove(candidate);
                                                }
@@ -120,7 +129,7 @@
                         //System.err.println("!KILLED OPEN CONNECTION!");
                                                oldest = (ConnectionHandler)lru.pop();
                                        }
-                   
+                                       
                                } else break; // break outer loop - we have killed 
enough connections
                        }
                        if (oldest != null) {
@@ -171,12 +180,12 @@
                                if (!res.isOpen()) {
                                        if(logDebug)
                                                Core.logger.log(this, "Skipped closed 
connection "+res,
-                                                                               
Logger.DEBUG);
+                                                                               
Logger.MINOR);
                                        // It will be terminated eventually
                                        // Do not remove it from OCM because it will 
then be orphaned and take up a fd even though it is not available for sending.
                                } else if (!res.sending()) {
                                        if (logDebug)
-                                       Core.logger.log(this, "Found "+res, 
Logger.DEBUG);
+                                       Core.logger.log(this, "Found "+res, 
Logger.MINOR);
                                        // found one
                                        lru.push(res);
                                        // Mark this connection as cached
@@ -190,7 +199,7 @@
                                                candidates.add(res);
                                        } else if (logDebug) {
                                                Core.logger.log(this, "Skipping: 
"+res+": sending",
-                                                                               
Logger.DEBUG);
+                                                                               
Logger.MINOR);
                                        }
                                }
                        }
@@ -286,6 +295,24 @@
                return count;
     }
     
+       /**
+        * @return true if this connection is the only one currently in the OCM to
+        * a given node in the routing table
+        */
+       protected final boolean onlyRTNodeConn(ConnectionHandler ch) {
+               return onlyRTNodeConn(ch.peerIdentity());
+       }
+       
+       protected final boolean onlyRTNodeConn(Identity id) {
+               if(!Main.node.rt.references(id))
+                       return false;
+               Enumeration e = chs.getAll(id);
+               if(!e.hasMoreElements()) return true; // it has zero
+               e.nextElement();
+               if(!e.hasMoreElements()) return true; // it has one
+               else return false; // it has more than one
+       }
+       
     public synchronized int countOutboundConnections(Identity id) {
                Enumeration e = chs.getAll(id);
                int count = 0;
@@ -347,14 +374,14 @@
                        }
                        
                        synchronized (ct) {
-                               if(timeout == -1 && !ct.done) {
+                               if(timeout == -1 && (!ct.done) && weStarted) {
                                        Core.logger.log(this, "Starting "+ct+
-                                                                       " on thread", 
Logger.DEBUG);
+                                                                       " on this 
thread", Logger.DEBUG);
                                        ct.run();
                                } else {
                                        if(weStarted) {
                                                Core.logger.log(this, "Starting "+ct+
-                                                                               " on 
thread", Logger.DEBUG);
+                                                                               " on 
another thread", Logger.DEBUG);
                                                tf.getThread(ct);
                                        }
                                        //tm.forceRun(ct);
@@ -765,13 +792,16 @@
     //
     private Hashtable blockedConnections = new Hashtable();
     private int blockedConnectionCount = 0;
-
+       
     private final int MAXBLOCKEDCONNECTIONS = 1;
 
     private final void incHardConnectionLimit(Address addr)
         throws ConnectFailedException {
-               boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
         int val = 0;
+               boolean logDebug = Core.logger.shouldLog(Logger.DEBUG);
+               if(logDebug)
+                       Core.logger.log(this, "Increasing blocked connection count for 
"+addr.toString(),
+                                                       Logger.DEBUG);
         synchronized(blockedConnections) {
             blockedConnectionCount++;
             Integer count = (Integer)blockedConnections.get(addr.toString());
@@ -779,12 +809,13 @@
                 val = count.intValue();
                 if (val >= MAXBLOCKEDCONNECTIONS) {
                     
-                                       if(logDEBUG)
+                                       if(logDebug)
                                                
Core.logger.log(OpenConnectionManager.this,
                                                                                " Too 
many blocked connection, aborting: " 
                                                                                + 
addr.toString() +
                                                                                " " + 
val,
-                                                                               
Logger.DEBUGGING);
+                                                                               
Logger.ERROR);
+                                       // This means the createConnection hashtable 
isn't working!
                    
                     // So that the arithmetic works when
                     // dec is called in finally block.
@@ -798,7 +829,7 @@
             blockedConnections.put(addr.toString(), new Integer(val + 1));
         
         }
-               if(logDEBUG) Core.logger.log(OpenConnectionManager.this,
+               if(logDebug) Core.logger.log(OpenConnectionManager.this,
                                                                         " blocked: " 
+ addr.toString() +
                                                                         " " + (val),
                                                                         
Logger.DEBUGGING);
@@ -806,6 +837,10 @@
     }
 
     private final void decHardConnectionLimit(Address addr) {
+               boolean logDebug = Core.logger.shouldLog(Logger.DEBUG);
+               if(logDebug)
+                       Core.logger.log(this, "Decreasing blocked connection count for 
"+addr.toString(),
+                                                       Logger.DEBUG);
         synchronized(blockedConnections) {
             blockedConnectionCount--;
             Integer count = (Integer)blockedConnections.get(addr.toString());
@@ -887,14 +922,16 @@
                         // Fail immediately if there are too 
                         // many blocked connections for 
                         // the requested address.
-                        incHardConnectionLimit(p.getAddress());
+                                               if(doHardConnectionLimit)
+                                                       
incHardConnectionLimit(p.getAddress());
                         c = p.getAddress().connect(false);
                                                // Will be limited but only after 
enableThrottle() called by CH
                        
                                                // We do not throttle at this stage - 
                                                // it will be wrapped after negotiation
                                        } finally {
-                        decHardConnectionLimit(p.getAddress());
+                                               if(doHardConnectionLimit)
+                                                       
decHardConnectionLimit(p.getAddress());
                         if (Core.outboundContacts != null) {
                             String countAddr = null;
                             if (c != null) {
@@ -1101,6 +1138,7 @@
                                                sock = 
((freenet.transport.tcpConnection)c).getSocket();
                                                if(sock == null) throw new 
IOException("Null socket");
                                        } catch (IOException e) {
+                                               ch = null;
                                                this.e = new 
ConnectFailedException(p.getAddress(),
                                                                                       
                                 p.getIdentity(),
                                                                                       
                                 e.getMessage(),
@@ -1135,6 +1173,7 @@
                                                        done = true;
                                                        this.notifyAll();
                                                }
+                                               ch = null;
                                                return;
                                        }
                                        NIOInputStream niois = (NIOInputStream) 
@@ -1180,7 +1219,7 @@
                                                done = true;
                                                this.notifyAll();
                                        }
-                   
+                                       ch = null;
                                        return;
                 } catch (RuntimeException e) {
                                        // FIXME: is there a need for notification 
here?
@@ -1197,6 +1236,7 @@
                                                done = true;
                                                this.notifyAll();
                                        }
+                                       ch = null;
                     throw e;
                 } catch (Error e) {
                                        // FIXME: is there a need for notification 
here?
@@ -1212,6 +1252,7 @@
                                                done = true;
                                                this.notifyAll();
                                        }
+                                       ch = null;
                     throw e;
                 }
             } else if (ch != null) {
@@ -1219,6 +1260,7 @@
                                        Core.logger.log(this, "Failed connection 
("+this+
                                                                        "), 
terminating "+ch, Logger.DEBUG);
                 ch.terminate();
+                               ch = null;
                                if(e == null) {
                     this.e = new ConnectFailedException(p.getAddress(),
                                                         p.getIdentity(),

Index: Peer.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Peer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Peer.java   13 Jan 2002 12:31:37 -0000      1.2
+++ Peer.java   12 Sep 2003 01:52:25 -0000      1.3
@@ -50,7 +50,17 @@
     public boolean equalsIdent(Identity id) {
         return id != null && this.id.equals(id);
     }
-
+    
+    public boolean equals(Object o) {
+       if(o instanceof Peer)
+           return ((Peer)o).equalsIdent(this);
+       else return false;
+    }
+    
+    public int hashCode() {
+       return id.hashCode() ^ addr.hashCode();
+    }
+    
     public String toString() {
         StringBuffer sb = new StringBuffer();
         sb.append("Peer [");

Index: Version.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Version.java,v
retrieving revision 1.384
retrieving revision 1.385
diff -u -r1.384 -r1.385
--- Version.java        11 Sep 2003 22:38:44 -0000      1.384
+++ Version.java        12 Sep 2003 01:52:25 -0000      1.385
@@ -18,7 +18,7 @@
     public static String protocolVersion = "1.46";
     
     /** The build number of the current revision */
-    public static final int buildNumber = 6191;
+    public static final int buildNumber = 6192;
     // 6028: may 3; ARK retrieval fix
 
     public static final int ignoreBuildsAfter = 6500;

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to