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

Modified Files:
        ConnectionHandler.java OpenConnectionManager.java Version.java 
Log Message:
6181:
* 
* Keep 1 connection open at least for messages, not 2, and fix race conditions in 
OpenConnectionManager. Should (i.e. might) fix recent behaviour of opening many 
unnecessary connections to nodes.
* Fix NullPointerException in FreenetURI.
* Don't call transferSucceeded for transferring inserts. Reasons outlined in comments. 
Just terminateRouting.
* Logging improvements.


Index: ConnectionHandler.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/ConnectionHandler.java,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -r1.149 -r1.150
--- ConnectionHandler.java      8 Sep 2003 17:03:02 -0000       1.149
+++ ConnectionHandler.java      8 Sep 2003 19:59:41 -0000       1.150
@@ -184,6 +184,7 @@
         */     
     private List sendingQueue = Collections.synchronizedList(new LinkedList());
        private List sentMessages = Collections.synchronizedList(new LinkedList());
+       private int sentMessagesCount = 0;
        private byte[] sendBuffer = null;
     private volatile boolean trailingPresent=false;
     MessageSend currentSender = null;
@@ -878,6 +879,7 @@
                                                                ms.jobDone(pos - opos, 
true);
                                                } else break;
                                        }
+                                       sentMessagesCount = 0;
                                        sentMessages.clear();
                                }
                        }
@@ -961,6 +963,7 @@
                                                        ms.jobDone(pos - opos, (pos <= 
size));
                                        }
                                        lastSizeDone = 0;
+                                       sentMessagesCount = 0;
                                        sentMessages.clear();
                                }
                        }
@@ -1050,6 +1053,7 @@
                                                sentMessages.add(currentSender);
                                                curPacketLength += l;
                                        }
+                                       sentMessagesCount = sentMessages.size();
                                }
                                if(sendBuffer == null) {
                                        int x = maxPacketLength;
@@ -2330,6 +2334,7 @@
                                                                                       
         Logger.DEBUG);
                                                        currentSender = ms;
                                                        sentMessages.add(ms);
+                                                       sentMessagesCount = 1;
                                                        ms.start();
                                                } catch (SendFailedException e) {
                                                        Core.logger.log(this, "Got 
IOException trying to "+
@@ -3178,10 +3183,8 @@
     }
        
        public String toString() {
-               return super.toString()+" for "+conn+","+link;
+               return super.toString()+" for "+conn+","+link+", sending 
"+sentMessagesCount;
        }
-       
-       
 }
 
 

Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- OpenConnectionManager.java  7 Sep 2003 18:18:44 -0000       1.97
+++ OpenConnectionManager.java  8 Sep 2003 19:59:41 -0000       1.98
@@ -158,8 +158,8 @@
      * node identified.
      */
     public ConnectionHandler findFreeConnection(Identity id) {
-               boolean logDebug = Core.logger.shouldLog(Logger.DEBUG);
-               if (logDebug)
+               boolean logDebug = Core.logger.shouldLog(Logger.DEBUG);
+               if (logDebug)
                Core.logger.log(this, "findFreeConnection("+id+")",
                                                new Exception("debug"), Logger.DEBUG);
                Enumeration e = chs.getAll(id); //moved this out here --zab
@@ -200,8 +200,11 @@
                 * you starve the trailers and other messages and end up with a 
feedback loop
                 * I'll test it locally with 1 and report the results.
                 * --zab
+                * Probably. Although it'd be nice to have a spare open for a new 
trailer.
+                * Also possible problems with closed connections.
+                * --amphibian
                 */
-               if(candidates.size() < 2) {  
+               if(candidates.size() < 1) {
                        Main.node.scheduleConnectionOpener(id);
                        // open another one
                }
@@ -227,8 +230,10 @@
                                return best;
                        }
                }
+               if(logDebug)
+                       Core.logger.log(this, "Couldn't find open connection for "+
+                                                       id, Logger.DEBUG);
                return null;
-               
     }
        
     /**
@@ -318,11 +323,10 @@
                                while(ct == null || ct.done) {
                                        ct = (ConnectionJob)(connectionJobs.get(p));
                                        if(ct != null && ct.done) {
-                                               synchronized(connectionJobs) {
-                                                       if(connectionJobs.get(p) == ct)
-                                                               
connectionJobs.remove(p);
+                                               if(connectionJobs.get(p) == ct) {
+                                                       connectionJobs.remove(p);
+                                                       continue;
                                                }
-                                               continue;
                                        }
                                        break;
                                }
@@ -336,14 +340,14 @@
                                        ct = new ConnectionJob(c, p);
                                        connectionJobs.put(p, ct);
                                        updatedRefcount = true;
-                                       Core.logger.log(this, "Created new ConnJob: 
"+ct,
-                                                                       Logger.DEBUG);
+                                       Core.logger.log(this, "Created new ConnJob: 
"+ct+
+                                                                       " for "+p, 
Logger.DEBUG);
                                        ct.incRefcount();
                                }
                        }
                        
                        synchronized (ct) {
-                               if(timeout == -1) {
+                               if(timeout == -1 && !ct.done) {
                                        ct.run();
                                } else {
                                        if(weStarted)
@@ -361,7 +365,7 @@
                                        
                                        while (!ct.done) {
                                                try {
-                                                       if (timeout == 0) {
+                                                       if (timeout < 0) {
                                                                ct.wait(5*60*1000);
                                                        } else {
                                                                long wait = endtime - 
System.currentTimeMillis();
@@ -379,7 +383,8 @@
                                        
Core.diagnostics.occurrenceBinomial("connectionRatio",1,0);
                                        if (timeout <= 0) {
                                                Core.logger.log(this, "Something is 
very wrong new " + 
-                                                                               
"connections for "+ct+". Waited 5 minutes"+
+                                                                               
"connections for "+p+" ("+ct+
+                                                                               "). 
Waited 5 minutes"+
                                                                                " 
("+timeout+")", Logger.ERROR);
                                        }
                                        ConnectFailedException e = 
@@ -556,11 +561,11 @@
                                String imageURL = "/servlet/images/aqua/arrow";
                                if(ch.outbound) imageURL += "_outbound";
                                else imageURL += "_inbound";
-                               if(ch.receiving() && ch.sending()) //Can this happen 
yet?
+                               if(ch.receiving() && ch.reallySending()) //Can this 
happen yet?
                                        imageURL += "_both";
                                else
                                        if(ch.receiving()) imageURL += "_receiving";
-                                       else if(ch.sending()) imageURL += 
"_transmitting";
+                                       else if(ch.reallySending()) imageURL += 
"_transmitting";
                                        else imageURL += "_sleeping";
                                imageURL += ".png";
                                buffer.append("<center><img src='"+imageURL+"' height 
= '15' width = '24'></center></td>");
@@ -592,7 +597,7 @@
                        //int x = ch.sendingCount();
                        //if(x > 0) sending++;;
                        //buffer.append(ch.sendingCount() + sep); Remove until there 
can actually be other values than 0 and 1 here 
-                       if(ch.sending())
+                       if(ch.reallySending())
                                sending++;
                        
                        if(ch.receiving())
@@ -606,7 +611,7 @@
                        
                        buffer.append(sepAlignRight+ch.messages());
                        if(useOldStyle || viewLevel >0){
-                               if(ch.sending())
+                               if(ch.reallySending())
                                        
buffer.append(sepAlignRight+(viewLevel>1?String.valueOf(ch.sendQueueSize()):format(ch.sendQueueSize())));
                                else
                                        buffer.append(sepAlignRight+"-");
@@ -617,7 +622,7 @@
                                        buffer.append(sepAlignRight+"-");
                                
buffer.append(sepAlignRight+(viewLevel>1?String.valueOf(ch.totalDataReceived()):format(ch.totalDataReceived())).replaceAll("
 ","&nbsp;"));
                        }else{
-                               if(ch.sending()||ch.receiving())
+                               if(ch.reallySending()||ch.receiving())
                                        
buffer.append(sepAlignRight+format(ch.sendQueueSize()));
                                else
                                        buffer.append(sepAlignRight+"-");
@@ -670,7 +675,6 @@
                        
pw.println("<tr><td>Connections&nbsp;open&nbsp;(Inbound/Outbound/Limit)</td><td width 
=10></td><td>" + 
(inbound+outbound)+"&nbsp;("+inbound+"/"+outbound+"/"+maxConnections+")</td></tr>");
 
                        
pw.println("<tr><td>Connections&nbsp;transferring&nbsp;(Receiving/Transmitting)</td><td
 width =10></td><td>" 
+(receiving+sending)+"&nbsp;("+receiving+"/"+sending+")</td></tr>");
-                       
                        if(viewLevel>0) {
                                pw.println("<tr><td>Data waiting to be 
transmitted/received</td><td width =10></td><td>" + format(sendQueueSize).replaceAll(" 
","&nbsp;")+"/"+format(receiveQueueSize).replaceAll(" ","&nbsp;")+"</td></tr>");
                                pw.println("<tr><td>Amount of data 
transmitted/received over currently open connections</td><td width =10></td><td>" + 
format(totalDataSent).replaceAll(" 
","&nbsp;")+"/"+format(totalDataReceived).replaceAll(" ","&nbsp;")+"</td></tr>");

Index: Version.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Version.java,v
retrieving revision 1.373
retrieving revision 1.374
diff -u -r1.373 -r1.374
--- Version.java        8 Sep 2003 17:14:48 -0000       1.373
+++ Version.java        8 Sep 2003 19:59:41 -0000       1.374
@@ -18,7 +18,7 @@
     public static String protocolVersion = "1.46";
     
     /** The build number of the current revision */
-    public static final int buildNumber = 6180;
+    public static final int buildNumber = 6181;
     // 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