Update of /cvsroot/freenet/freenet/src/freenet In directory sc8-pr-cvs1:/tmp/cvs-serv25142/src/freenet
Modified Files:
OpenConnectionManager.java Version.java
Log Message:
6167: only open one new conn to a given peer at a given time.
Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -r1.91 -r1.92
--- OpenConnectionManager.java 30 Aug 2003 23:16:50 -0000 1.91
+++ OpenConnectionManager.java 3 Sep 2003 01:38:52 -0000 1.92
@@ -46,6 +46,9 @@
private final ThreadFactory tf;
private final MultiValueTable chs;
+ private final Hashtable connectionJobs = new Hashtable();
+ // One attempt to open a conn at once to each Peer
+
private int openConns;
private final LRUQueue lru = new LRUQueue();
@@ -253,68 +256,104 @@
*/
public ConnectionHandler createConnection(Core c, Peer p, long timeout)
throws CommunicationException {
-
+
ConnectionHandler ret = null;
- ConnectionJob ct = new ConnectionJob(c, p);
- synchronized (ct) {
- if(timeout == -1) {
- ct.run();
- } else {
- tf.getThread(ct);
- //tm.forceRun(ct);
- // Restored pooled threads (oskar 20020204)
- //Thread job = new Thread(ct,
- // "Non-pooled connection
thread: "
- // + p.getAddress().toString());
- //job.start();
-
-
-
- long endtime = System.currentTimeMillis() + timeout;
-
- while (!ct.done) {
- try {
- if (timeout == 0) {
- ct.wait(5*60*1000);
+ ConnectionJob ct = null;
+ boolean updatedRefcount = false;
+
+ try {
+ synchronized(connectionJobs) {
+ 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);
}
- else {
- long wait = endtime -
System.currentTimeMillis();
- if (wait <= 0) break;
- ct.wait(wait);
+ continue;
+ }
+ break;
+ }
+ if(ct != null) {
+ updatedRefcount = true;
+ ct.incRefcount();
+ } else {
+ ct = new ConnectionJob(c, p);
+ connectionJobs.put(p, ct);
+ updatedRefcount = true;
+ ct.incRefcount();
+ }
+ }
+
+ synchronized (ct) {
+ if(timeout == -1) {
+ ct.run();
+ } else {
+ tf.getThread(ct);
+ //tm.forceRun(ct);
+ // Restored pooled threads (oskar 20020204)
+ //Thread job = new Thread(ct,
+ // "Non-pooled
connection thread: "
+ // +
p.getAddress().toString());
+ //job.start();
+
+
+
+ long endtime = System.currentTimeMillis() +
timeout;
+
+ while (!ct.done) {
+ try {
+ if (timeout == 0) {
+ ct.wait(5*60*1000);
+ } else {
+ long wait = endtime -
System.currentTimeMillis();
+ if (wait <= 0) break;
+ ct.wait(wait);
+ }
}
+ catch (InterruptedException e) {}
+ }
+ }
+ if (ct.ch != null) {
+
Core.diagnostics.occurrenceBinomial("connectionRatio",1,1);
+ ret = ct.ch;
+ } else if (ct.e == null) {
+
Core.diagnostics.occurrenceBinomial("connectionRatio",1,0);
+ if (timeout <= 0) {
+ Core.logger.log(this, "Something is
very wrong new " +
+
"connections for "+ct+". Waited 5 minutes"+
+ "
("+timeout+")", Logger.ERROR);
}
- catch (InterruptedException e) {}
+ ConnectFailedException e =
+ new
ConnectFailedException(p.getAddress(),
+
p.getIdentity(),
+
"Timeout reached while waiting",
+
true);
+ Core.logger.log(this, "Failed to connect on
"+ct.ch+" with "+
+ ct, e,
Logger.DEBUG);
+ throw e;
+ } else {
+
Core.diagnostics.occurrenceBinomial("connectionRatio",1,0);
+ throw ct.e;
}
}
- if (ct.ch != null) {
- Core.diagnostics.occurrenceBinomial("connectionRatio",1,1);
- ret = ct.ch;
- } else if (ct.e == null) {
- Core.diagnostics.occurrenceBinomial("connectionRatio",1,0);
- if (timeout <= 0) {
- Core.logger.log(this, "Something is very wrong new " +
- "connections for "+ct+". Waited 5 minutes"+
- "
("+timeout+")", Logger.ERROR);
- }
- ConnectFailedException e =
- new ConnectFailedException(p.getAddress(),
-
p.getIdentity(),
-
"Timeout reached while waiting",
-
true);
- Core.logger.log(this, "Failed to connect on "+ct.ch+"
with "+
- ct, e, Logger.DEBUG);
- throw e;
- } else {
- Core.diagnostics.occurrenceBinomial("connectionRatio",1,0);
- throw ct.e;
- }
- }
-
- if (ret != null) {
- return ret;
- }
-
- throw new RuntimeException("Assertion Failure: ret != null");
+
+ if (ret != null) {
+ return ret;
+ }
+
+ throw new RuntimeException("Assertion Failure: ret != null");
+ } finally {
+ if(ct != null && updatedRefcount) {
+ ct.decRefcount();
+ }
+ if(ct != null && ct.done) {
+ synchronized(connectionJobs) {
+ if(connectionJobs.get(p) == ct)
+ connectionJobs.remove(p);
+ }
+ }
+ }
}
/**
@@ -726,7 +765,25 @@
private final Core core;
private final Peer p;
-
+
+ private int refcount = 0;
+
+ private void incRefcount() {
+ synchronized(connectionJobs) {
+ refcount++;
+ }
+ }
+
+ private void decRefcount() {
+ synchronized(connectionJobs) {
+ refcount--;
+ if(refcount <= 0) {
+ if(connectionJobs.get(p) == this)
+ connectionJobs.remove(p);
+ }
+ }
+ }
+
public ConnectionJob(Core core, Peer p) {
if(Core.logger.shouldLog(Logger.DEBUG))
Core.logger.log(this, "Creating ConnectionJob (core,
"+p+"): "+
Index: Version.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Version.java,v
retrieving revision 1.359
retrieving revision 1.360
diff -u -r1.359 -r1.360
--- Version.java 2 Sep 2003 22:54:53 -0000 1.359
+++ Version.java 3 Sep 2003 01:38:52 -0000 1.360
@@ -18,7 +18,7 @@
public static String protocolVersion = "1.46";
/** The build number of the current revision */
- public static final int buildNumber = 6166;
+ public static final int buildNumber = 6167;
// 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
