diff --git a/apps/BOB/src/net/i2p/BOB/DoCMDS.java b/apps/BOB/src/net/i2p/BOB/DoCMDS.java
index 16da28ce9..1a2d2a19a 100644
--- a/apps/BOB/src/net/i2p/BOB/DoCMDS.java
+++ b/apps/BOB/src/net/i2p/BOB/DoCMDS.java
@@ -1263,11 +1263,11 @@ public class DoCMDS implements Runnable {
tunnel = new MUXlisten(database, nickinfo, _log);
Thread t = new Thread(tunnel);
t.start();
- try {
- Thread.sleep(1000 * 10); // Slow down the startup.
- } catch(InterruptedException ie) {
- // ignore it
- }
+ // try {
+ // Thread.sleep(1000 * 10); // Slow down the startup.
+ // } catch(InterruptedException ie) {
+ // // ignore it
+ // }
out.println("OK tunnel starting");
} catch (I2PException e) {
out.println("ERROR starting tunnel: " + e);
diff --git a/apps/BOB/src/net/i2p/BOB/I2Plistener.java b/apps/BOB/src/net/i2p/BOB/I2Plistener.java
index a8115893d..caaadc76d 100644
--- a/apps/BOB/src/net/i2p/BOB/I2Plistener.java
+++ b/apps/BOB/src/net/i2p/BOB/I2Plistener.java
@@ -25,6 +25,8 @@ package net.i2p.BOB;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import net.i2p.I2PException;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
@@ -78,91 +80,59 @@ public class I2Plistener implements Runnable {
public void run() {
boolean g = false;
I2PSocket sessSocket = null;
+ int conn = 0;
+ try {
+ die:
+ {
-die: {
+ serverSocket.setSoTimeout(50);
+ boolean spin = true;
+ while (spin) {
- serverSocket.setSoTimeout(50);
-// try {
-// if (info.exists("INPORT")) {
-// tgwatch = 2;
-// }
-// } catch (Exception e) {
-// try {
-// runlock();
-// } catch (Exception e2) {
-// break die;
-// }
-// break die;
-// }
- boolean spin = true;
- while (spin) {
-
- try {
- rlock();
- } catch (Exception e) {
- break die;
- }
- try {
- spin = info.get("RUNNING").equals(Boolean.TRUE);
- } catch (Exception e) {
try {
- runlock();
- } catch (Exception e2) {
+ rlock();
+ } catch (Exception e) {
break die;
}
- break die;
- }
- try {
try {
- sessSocket = serverSocket.accept();
- g = true;
- } catch (ConnectException ce) {
- g = false;
- } catch (SocketTimeoutException ste) {
- g = false;
- }
- if (g) {
- g = false;
- // toss the connection to a new thread.
- I2PtoTCP conn_c = new I2PtoTCP(sessSocket, info, database);
- Thread t = new Thread(conn_c, "BOBI2PtoTCP");
- t.start();
+ spin = info.get("RUNNING").equals(Boolean.TRUE);
+ } catch (Exception e) {
+ try {
+ runlock();
+ } catch (Exception e2) {
+ break die;
+ }
+ break die;
}
+ try {
+ try {
+ sessSocket = serverSocket.accept();
+ g = true;
+ } catch (ConnectException ce) {
+ g = false;
+ } catch (SocketTimeoutException ste) {
+ g = false;
+ }
+ if (g) {
+ g = false;
+ conn++;
+ // toss the connection to a new thread.
+ I2PtoTCP conn_c = new I2PtoTCP(sessSocket, info, database);
+ Thread t = new Thread(conn_c, Thread.currentThread().getName() + " I2PtoTCP " + conn);
+ t.start();
+ }
- } catch (I2PException e) {
- // System.out.println("Exception " + e);
+ } catch (Exception e) {
+ // System.out.println("Exception " + e);
+ }
}
}
- }
+ } finally {
+ try {
+ serverSocket.close();
+ } catch (I2PException ex) {
+ }
// System.out.println("I2Plistener: Close");
-
-
- // Previous level does this cleanup now.
- //
- // try {
- // serverSocket.close();
- // } catch (I2PException e) {
- // nop
- //}
- // need to kill off the socket manager too.
- // I2PSession session = socketManager.getSession();
- // if (session != null) {
- // System.out.println("I2Plistener: destroySession");
- // try {
- // session.destroySession();
- // } catch (I2PSessionException ex) {
- // nop
- // }
- //}
- // System.out.println("I2Plistener: Waiting for children");
- // while (Thread.activeCount() > tgwatch) { // wait for all threads in our threadgroup to finish
- // try {
- // Thread.sleep(100); //sleep for 100 ms (One tenth second)
- // } catch (Exception e) {
- // nop
- // }
- //}
-
- // System.out.println("I2Plistener: Done.");
+ }
}
}
diff --git a/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java b/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java
index 0984823b6..73e936c61 100644
--- a/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java
+++ b/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java
@@ -23,7 +23,6 @@
*/
package net.i2p.BOB;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
@@ -71,90 +70,99 @@ public class I2PtoTCP implements Runnable {
String host;
int port;
boolean tell;
-die: {
- try {
+ InputStream in = null;
+ OutputStream out = null;
+ InputStream Iin = null;
+ OutputStream Iout = null;
+ try {
+ die:
+ {
try {
- rlock();
- } catch(Exception e) {
- break die;
- }
- try {
- host = info.get("OUTHOST").toString();
- port = Integer.parseInt(info.get("OUTPORT").toString());
- tell = info.get("QUIET").equals(Boolean.FALSE);
- } catch(Exception e) {
- runlock();
- break die;
- }
- try {
- runlock();
- } catch(Exception e) {
- break die;
- }
- sock = new Socket(host, port);
- // make readers/writers
- InputStream in = sock.getInputStream();
- OutputStream out = sock.getOutputStream();
- InputStream Iin = I2P.getInputStream();
- OutputStream Iout = I2P.getOutputStream();
- I2P.setReadTimeout(0); // temp bugfix, this *SHOULD* be the default
-
- if(tell) {
- // tell who is connecting
- out.write(I2P.getPeerDestination().toBase64().getBytes());
- out.write(10); // nl
- out.flush(); // not really needed, but...
- }
- // setup to cross the streams
- TCPio conn_c = new TCPio(in, Iout /*, info, database */ ); // app -> I2P
- TCPio conn_a = new TCPio(Iin, out /* , info, database */); // I2P -> app
- Thread t = new Thread(conn_c, "TCPioA");
- Thread q = new Thread(conn_a, "TCPioB");
- // Fire!
- t.start();
- q.start();
- while(t.isAlive() && q.isAlive()) { // AND is used here to kill off the other thread
try {
- Thread.sleep(10); //sleep for 10 ms
- } catch(InterruptedException e) {
+ rlock();
+ } catch (Exception e) {
+ break die;
+ }
+ try {
+ host = info.get("OUTHOST").toString();
+ port = Integer.parseInt(info.get("OUTPORT").toString());
+ tell = info.get("QUIET").equals(Boolean.FALSE);
+ } catch (Exception e) {
+ runlock();
+ break die;
+ }
+ try {
+ runlock();
+ } catch (Exception e) {
+ break die;
+ }
+ sock = new Socket(host, port);
+ // make readers/writers
+ in = sock.getInputStream();
+ out = sock.getOutputStream();
+ Iin = I2P.getInputStream();
+ Iout = I2P.getOutputStream();
+ I2P.setReadTimeout(0); // temp bugfix, this *SHOULD* be the default
+
+ if (tell) {
+ // tell who is connecting
+ out.write(I2P.getPeerDestination().toBase64().getBytes());
+ out.write(10); // nl
+ out.flush(); // not really needed, but...
+ }
+ // setup to cross the streams
+ TCPio conn_c = new TCPio(in, Iout /*, info, database */); // app -> I2P
+ TCPio conn_a = new TCPio(Iin, out /* , info, database */); // I2P -> app
+ Thread t = new Thread(conn_c, Thread.currentThread().getName() + " TCPioA");
+ Thread q = new Thread(conn_a, Thread.currentThread().getName() + " TCPioB");
+ // Fire!
+ t.start();
+ q.start();
+ while (t.isAlive() && q.isAlive()) { // AND is used here to kill off the other thread
try {
- in.close();
- } catch(Exception ex) {
- }
- try {
- out.close();
- } catch(Exception ex) {
- }
- try {
- Iin.close();
- } catch(Exception ex) {
- }
- try {
- Iout.close();
- } catch(Exception ex) {
+ Thread.sleep(10); //sleep for 10 ms
+ } catch (InterruptedException e) {
+ break die;
}
}
- }
// System.out.println("I2PtoTCP: Going away...");
- } catch(Exception e) {
- // System.out.println("I2PtoTCP: Owch! damn!");
- break die;
+ } catch (Exception e) {
+ // System.out.println("I2PtoTCP: Owch! damn!");
+ break die;
+ }
+ } // die
+ } finally {
+ try {
+ in.close();
+ } catch (Exception ex) {
+ }
+ try {
+ out.close();
+ } catch (Exception ex) {
+ }
+ try {
+ Iin.close();
+ } catch (Exception ex) {
+ }
+ try {
+ Iout.close();
+ } catch (Exception ex) {
+ }
+ try {
+ // System.out.println("I2PtoTCP: Close I2P");
+ I2P.close();
+ } catch (Exception e) {
+ tell = false;
+ }
+ //System.out.println("I2PtoTCP: Closed I2P");
+ try {
+ // System.out.println("I2PtoTCP: Close sock");
+ sock.close();
+ } catch (Exception e) {
+ tell = false;
}
- } // die
- try {
- // System.out.println("I2PtoTCP: Close I2P");
- I2P.close();
- } catch(Exception e) {
- tell = false;
- }
- //System.out.println("I2PtoTCP: Closed I2P");
- try {
- // System.out.println("I2PtoTCP: Close sock");
- sock.close();
- } catch(Exception e) {
- tell = false;
- }
// System.out.println("I2PtoTCP: Done");
+ }
}
}
diff --git a/apps/BOB/src/net/i2p/BOB/MUXlisten.java b/apps/BOB/src/net/i2p/BOB/MUXlisten.java
index dc30c5445..91028e7cb 100644
--- a/apps/BOB/src/net/i2p/BOB/MUXlisten.java
+++ b/apps/BOB/src/net/i2p/BOB/MUXlisten.java
@@ -29,8 +29,6 @@ import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.Properties;
import net.i2p.I2PException;
-import net.i2p.client.I2PSession;
-import net.i2p.client.I2PSessionException;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocketManager;
import net.i2p.client.streaming.I2PSocketManagerFactory;
@@ -50,7 +48,7 @@ public class MUXlisten implements Runnable {
private ByteArrayInputStream prikey;
private ThreadGroup tg;
private String N;
- private ServerSocket listener;
+ private ServerSocket listener = null;
private int backlog = 50; // should this be more? less?
boolean go_out;
boolean come_in;
@@ -133,171 +131,162 @@ public class MUXlisten implements Runnable {
*/
public void run() {
I2PServerSocket SS = null;
- int ticks = 1200; // Allow 120 seconds, no more.
+ Thread t = null;
+ Thread q = null;
try {
- wlock();
try {
- info.add("RUNNING", new Boolean(true));
+ wlock();
+ try {
+ info.add("RUNNING", new Boolean(true));
+ } catch (Exception e) {
+ wunlock();
+ return;
+ }
+ } catch (Exception e) {
+ return;
+ }
+ try {
+ wunlock();
} catch (Exception e) {
- wunlock();
return;
}
- } catch (Exception e) {
- return;
- }
- try {
- wunlock();
- } catch (Exception e) {
- return;
- }
// socketManager.addDisconnectListener(new DisconnectListener());
-quit:
- {
- try {
- tg = new ThreadGroup(N);
-die:
- {
- // toss the connections to a new threads.
- // will wrap with TCP and UDP when UDP works
+ quit:
+ {
+ try {
+ tg = new ThreadGroup(N);
+ die:
+ {
+ // toss the connections to a new threads.
+ // will wrap with TCP and UDP when UDP works
- if (go_out) {
- // I2P -> TCP
- SS = socketManager.getServerSocket();
- I2Plistener conn = new I2Plistener(SS, socketManager, info, database, _log);
- Thread t = new Thread(tg, conn, "BOBI2Plistener " + N);
- t.start();
- }
-
- if (come_in) {
- // TCP -> I2P
- TCPlistener conn = new TCPlistener(listener, socketManager, info, database, _log);
- Thread q = new Thread(tg, conn, "BOBTCPlistener" + N);
- q.start();
- }
-
- try {
- wlock();
- try {
- info.add("STARTING", new Boolean(false));
- } catch (Exception e) {
- wunlock();
- break die;
+ if (go_out) {
+ // I2P -> TCP
+ SS = socketManager.getServerSocket();
+ I2Plistener conn = new I2Plistener(SS, socketManager, info, database, _log);
+ t = new Thread(tg, conn, "BOBI2Plistener " + N);
+ t.start();
}
- } catch (Exception e) {
- break die;
- }
- try {
- wunlock();
- } catch (Exception e) {
- break die;
- }
- boolean spin = true;
- while (spin) {
- try {
- Thread.sleep(1000); //sleep for 1 second
- } catch (InterruptedException e) {
- break die;
+
+ if (come_in) {
+ // TCP -> I2P
+ TCPlistener conn = new TCPlistener(listener, socketManager, info, database, _log);
+ q = new Thread(tg, conn, "BOBTCPlistener " + N);
+ q.start();
}
+
try {
- rlock();
+ wlock();
try {
- spin = info.get("STOPPING").equals(Boolean.FALSE);
+ info.add("STARTING", new Boolean(false));
} catch (Exception e) {
- runlock();
+ wunlock();
break die;
}
} catch (Exception e) {
break die;
}
try {
- runlock();
- } catch (Exception e) {
- break die;
- }
- }
-
- try {
- wlock();
- try {
- info.add("RUNNING", new Boolean(false));
- } catch (Exception e) {
wunlock();
+ } catch (Exception e) {
break die;
}
- } catch (Exception e) {
- break die;
- }
- try {
- wunlock();
- } catch (Exception e) {
- break die;
- }
- } // die
-
- if (SS != null) {
- try {
- SS.close();
- } catch (I2PException ex) {
- //Logger.getLogger(MUXlisten.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if (this.come_in) {
- try {
- listener.close();
- } catch (IOException e) {
- }
- }
-
- I2PSession session = socketManager.getSession();
- if (session != null) {
- // System.out.println("I2Plistener: destroySession");
- try {
- session.destroySession();
- } catch (I2PSessionException ex) {
- // nop
- }
- }
- try {
- socketManager.destroySocketManager();
- } catch (Exception e) {
- // nop
- }
- // Wait for child threads and thread groups to die
- // System.out.println("MUXlisten: waiting for children");
- if (tg.activeCount() + tg.activeGroupCount() != 0) {
- while ((tg.activeCount() + tg.activeGroupCount() != 0) && ticks != 0) {
- tg.interrupt(); // unwedge any blocking threads.
- ticks--;
- try {
- Thread.sleep(100); //sleep for 100 ms (One tenth second)
- } catch (InterruptedException ex) {
- break quit;
+ boolean spin = true;
+ while (spin) {
+ try {
+ Thread.sleep(1000); //sleep for 1 second
+ } catch (InterruptedException e) {
+ break die;
+ }
+ try {
+ rlock();
+ try {
+ spin = info.get("STOPPING").equals(Boolean.FALSE);
+ } catch (Exception e) {
+ runlock();
+ break die;
+ }
+ } catch (Exception e) {
+ break die;
+ }
+ try {
+ runlock();
+ } catch (Exception e) {
+ break die;
+ }
}
- }
- if (tg.activeCount() + tg.activeGroupCount() != 0) {
- break quit; // Uh-oh.
- }
- }
- tg.destroy();
- // Zap reference to the ThreadGroup so the JVM can GC it.
- tg = null;
- } catch (Exception e) {
- // System.out.println("MUXlisten: Caught an exception" + e);
- break quit;
- }
- } // quit
- // This is here to catch when something fucks up REALLY bad.
- if (tg != null) {
+ try {
+ wlock();
+ try {
+ info.add("RUNNING", new Boolean(false));
+ } catch (Exception e) {
+ wunlock();
+ break die;
+ }
+ } catch (Exception e) {
+ break die;
+ }
+ try {
+ wunlock();
+ } catch (Exception e) {
+ break die;
+ }
+ } // die
+
+ // I2PSession session = socketManager.getSession();
+ // if (session != null) {
+ // System.out.println("I2Plistener: destroySession");
+ // try {
+ // session.destroySession();
+ // } catch (I2PSessionException ex) {
+ // nop
+ // }
+ // }
+ // try {
+ // socketManager.destroySocketManager();
+ //} catch (Exception e) {
+ // nop
+ //}
+ } catch (Exception e) {
+ // System.out.println("MUXlisten: Caught an exception" + e);
+ break quit;
+ }
+ } // quit
+ } finally {
+ // allow threads above this one to catch the stop signal.
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException ex) {
+ }
+ // zero out everything.
+ try {
+ wlock();
+ try {
+ info.add("STARTING", new Boolean(false));
+ info.add("STOPPING", new Boolean(false));
+ info.add("RUNNING", new Boolean(false));
+ } catch (Exception e) {
+ wunlock();
+ return;
+ }
+ wunlock();
+ } catch (Exception e) {
+ }
+
+ //try {
+ // Thread.sleep(1000 * 20); // how long?? is this even needed??
+ //} catch (InterruptedException ex) {
+ //}
+
if (SS != null) {
try {
SS.close();
} catch (I2PException ex) {
- //Logger.getLogger(MUXlisten.class.getName()).log(Level.SEVERE, null, ex);
}
}
- if (this.come_in) {
+ if (listener != null) {
try {
listener.close();
} catch (IOException e) {
@@ -307,60 +296,46 @@ die:
socketManager.destroySocketManager();
} catch (Exception e) {
// nop
- }
- ticks = 600; // 60 seconds
- if (tg.activeCount() + tg.activeGroupCount() != 0) {
- while ((tg.activeCount() + tg.activeGroupCount() != 0) && ticks != 0) {
- tg.interrupt(); // unwedge any blocking threads.
- ticks--;
- try {
- Thread.sleep(100); //sleep for 100 ms (One tenth second)
- } catch (InterruptedException ex) {
- // nop
+ }
+ // This is here to catch when something fucks up REALLY bad, like those annoying stuck threads!
+ if (tg != null) {
+ String boner = tg.getName();
+ // tg.interrupt(); // give my stuff a small smack again.
+ if (tg.activeCount() + tg.activeGroupCount() != 0) {
+ int foo = tg.activeCount() + tg.activeGroupCount();
+ int bar = foo;
+ // hopefully no longer needed!
+ // System.out.println("BOB: MUXlisten: Waiting on threads for " + boner);
+ // System.out.println("\n\nBOB: MUXlisten: ThreadGroup dump BEGIN " + boner);
+ // visit(tg, 0, boner);
+ // System.out.println("BOB: MUXlisten: ThreadGroup dump END " + boner + "\n\n");
+ // Happily spin forever :-(
+ while ((tg.activeCount() + tg.activeGroupCount() != 0)) {
+ foo = tg.activeCount() + tg.activeGroupCount();
+ // if (foo != bar) {
+ // System.out.println("\n\nBOB: MUXlisten: ThreadGroup dump BEGIN " + boner);
+ // visit(tg, 0, boner);
+ // System.out.println("BOB: MUXlisten: ThreadGroup dump END " + boner + "\n\n");
+ // }
+ bar = foo;
+ try {
+ Thread.sleep(100); //sleep for 100 ms (One tenth second)
+ } catch (InterruptedException ex) {
+ // nop
+ }
}
}
- }
- if (tg.activeCount() + tg.activeGroupCount() == 0) {
+ System.out.println("BOB: MUXlisten: Threads went away. Success: " + boner);
tg.destroy();
// Zap reference to the ThreadGroup so the JVM can GC it.
tg = null;
- } else {
- System.out.println("BOB: MUXlisten: Can't kill threads. Please send the following dump to sponge@mail.i2p");
- System.out.println("\n\nBOB: MUXlisten: ThreadGroup dump BEGIN");
- visit(tg, 0);
- System.out.println("BOB: MUXlisten: ThreadGroup dump END\n\n");
}
}
-
- // This is here to catch when something fucks up REALLY bad.
-// if (tg != null) {
-// System.out.println("BOB: MUXlisten: Something fucked up REALLY bad!");
-// System.out.println("BOB: MUXlisten: Please email the following dump to sponge@mail.i2p");
-// WrapperManager.requestThreadDump();
-// System.out.println("BOB: MUXlisten: Something fucked up REALLY bad!");
-// System.out.println("BOB: MUXlisten: Please email the above dump to sponge@mail.i2p");
-// }
- // zero out everything.
- try {
- wlock();
- try {
- info.add("STARTING", new Boolean(false));
- info.add("STOPPING", new Boolean(false));
- info.add("RUNNING", new Boolean(false));
- } catch (Exception e) {
- wunlock();
- return;
- }
- wunlock();
- } catch (Exception e) {
- }
-
}
// Debugging...
-
- /**
+ /**
* Find the root thread group and print them all.
*
*/
@@ -371,7 +346,7 @@ die:
}
// Visit each thread group
- visit(root, 0);
+ visit(root, 0, root.getName());
}
/**
@@ -379,7 +354,7 @@ die:
* @param group ThreadGroup to visit
* @param level Current level
*/
- private static void visit(ThreadGroup group, int level) {
+ private static void visit(ThreadGroup group, int level, String tn) {
// Get threads in `group'
int numThreads = group.activeCount();
Thread[] threads = new Thread[numThreads * 2];
@@ -389,7 +364,7 @@ die:
for (int i = 0; i < numThreads; i++) {
// Get thread
Thread thread = threads[i];
- System.out.println("BOB: MUXlisten: " + indent + thread.toString());
+ System.out.println("BOB: MUXlisten: " + tn + ": " + indent + thread.toString());
}
// Get thread subgroups of `group'
@@ -399,7 +374,43 @@ die:
// Recursively visit each subgroup
for (int i = 0; i < numGroups; i++) {
- visit(groups[i], level + 1);
+ visit(groups[i], level + 1, groups[i].getName());
+ }
+ }
+
+ private static void nuke(ThreadGroup group, int level) {
+ // Get threads in `group'
+ int numThreads = group.activeCount();
+ Thread[] threads = new Thread[numThreads * 2];
+ numThreads = group.enumerate(threads, false);
+ // Enumerate each thread in `group' and stop it.
+ for (int i = 0; i < numThreads; i++) {
+ // Get thread
+ Thread thread = threads[i];
+ try {
+ if (thread.isAlive()) {
+ thread.stop();
+ }
+ } catch (SecurityException se) {
+ //nop
+ }
+ }
+
+ // Get thread subgroups of `group'
+ int numGroups = group.activeGroupCount();
+ ThreadGroup[] groups = new ThreadGroup[numGroups * 2];
+ numGroups = group.enumerate(groups, false);
+
+ // Recursively visit each subgroup
+ for (int i = 0; i < numGroups; i++) {
+ nuke(groups[i], level + 1);
+ }
+ try {
+ group.destroy();
+ } catch (IllegalThreadStateException IE) {
+ //nop
+ } catch (SecurityException se) {
+ //nop
}
}
}
diff --git a/apps/BOB/src/net/i2p/BOB/TCPio.java b/apps/BOB/src/net/i2p/BOB/TCPio.java
index d4b353c54..d92a5cef0 100644
--- a/apps/BOB/src/net/i2p/BOB/TCPio.java
+++ b/apps/BOB/src/net/i2p/BOB/TCPio.java
@@ -87,23 +87,13 @@ public class TCPio implements Runnable {
boolean spin = true;
try {
while(spin) {
- // database.getReadLock();
- // info.getReadLock();
- // spin = info.get("RUNNING").equals(Boolean.TRUE);
- // info.releaseReadLock();
- // database.releaseReadLock();
b = Ain.read(a, 0, 1);
- // System.out.println(info.get("NICKNAME").toString() + " " + b);
if(b > 0) {
Aout.write(a, 0, b);
} else if(b == 0) {
Thread.yield(); // this should act like a mini sleep.
if(Ain.available() == 0) {
-// try {
- // Thread.yield();
Thread.sleep(10);
-// } catch(InterruptedException ex) {
-// }
}
} else {
/* according to the specs:
@@ -119,19 +109,16 @@ public class TCPio implements Runnable {
return;
}
}
- // System.out.println("TCPio: RUNNING = false");
} catch(Exception e) {
// Eject!!! Eject!!!
//System.out.println("TCPio: Caught an exception " + e);
try {
Ain.close();
} catch (IOException ex) {
-// Logger.getLogger(TCPio.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Aout.close();
} catch (IOException ex) {
-// Logger.getLogger(TCPio.class.getName()).log(Level.SEVERE, null, ex);
}
return;
}
diff --git a/apps/BOB/src/net/i2p/BOB/TCPlistener.java b/apps/BOB/src/net/i2p/BOB/TCPlistener.java
index 78155eb78..0ac67d277 100644
--- a/apps/BOB/src/net/i2p/BOB/TCPlistener.java
+++ b/apps/BOB/src/net/i2p/BOB/TCPlistener.java
@@ -29,6 +29,8 @@ import java.net.Socket;
import java.net.SocketTimeoutException;
// import net.i2p.client.I2PSession;
// import net.i2p.client.I2PSessionException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocketManager;
import net.i2p.util.Log;
@@ -73,16 +75,6 @@ public class TCPlistener implements Runnable {
info.releaseReadLock();
}
- private void wlock() throws Exception {
- database.getWriteLock();
- info.getWriteLock();
- }
-
- private void wunlock() throws Exception {
- info.releaseWriteLock();
- database.releaseWriteLock();
- }
-
/**
* Simply listen on TCP port, and thread connections
*
@@ -90,124 +82,80 @@ public class TCPlistener implements Runnable {
public void run() {
boolean g = false;
boolean spin = true;
-
-die: {
- try {
- rlock();
- } catch (Exception e) {
- break die;
- }
- try {
- if (info.exists("OUTPORT")) {
- tgwatch = 2;
- }
- } catch (Exception e) {
- try {
- runlock();
- } catch (Exception e2) {
- break die;
- }
- break die;
- }
- try {
- runlock();
- } catch (Exception e) {
- break die;
- }
- try {
- Socket server = new Socket();
- listener.setSoTimeout(50); // Half of the expected time from MUXlisten
- while (spin) {
- try {
- rlock();
- } catch (Exception e) {
- break die;
- }
- try {
- spin = info.get("RUNNING").equals(Boolean.TRUE);
- } catch (Exception e) {
- try {
- runlock();
- } catch (Exception e2) {
- break die;
- }
- break die;
- }
- try {
- server = listener.accept();
- g = true;
- } catch (SocketTimeoutException ste) {
- g = false;
- }
- if (g) {
- // toss the connection to a new thread.
- TCPtoI2P conn_c = new TCPtoI2P(socketManager, server /* , info, database */);
- Thread t = new Thread(conn_c, "BOBTCPtoI2P");
- t.start();
- g = false;
- }
- }
- //System.out.println("TCPlistener: destroySession");
- listener.close();
- } catch (IOException ioe) {
- try {
- listener.close();
- } catch (IOException e) {
- }
- // Fatal failure, cause a stop event
+ int conn = 0;
+ try {
+ die:
+ {
try {
rlock();
- try {
- spin = info.get("RUNNING").equals(Boolean.TRUE);
- } catch (Exception e) {
- runlock();
- break die;
- }
} catch (Exception e) {
break die;
}
- if (spin) {
+ try {
+ if (info.exists("OUTPORT")) {
+ tgwatch = 2;
+ }
+ } catch (Exception e) {
try {
- wlock();
- try {
- info.add("STOPPING", new Boolean(true));
- info.add("RUNNING", new Boolean(false));
- } catch (Exception e) {
- wunlock();
- break die;
- }
- } catch (Exception e) {
+ runlock();
+ } catch (Exception e2) {
break die;
}
+ break die;
+ }
+ try {
+ runlock();
+ } catch (Exception e) {
+ break die;
+ }
+ try {
+ Socket server = new Socket();
+ listener.setSoTimeout(50); // We don't block, we cycle and check.
+ while (spin) {
+ try {
+ rlock();
+ } catch (Exception e) {
+ break die;
+ }
+ try {
+ spin = info.get("RUNNING").equals(Boolean.TRUE);
+ } catch (Exception e) {
+ try {
+ runlock();
+ } catch (Exception e2) {
+ break die;
+ }
+ break die;
+ }
+ try {
+ server = listener.accept();
+ g = true;
+ } catch (SocketTimeoutException ste) {
+ g = false;
+ }
+ if (g) {
+ conn++;
+ // toss the connection to a new thread.
+ TCPtoI2P conn_c = new TCPtoI2P(socketManager, server);
+ Thread t = new Thread(conn_c, Thread.currentThread().getName() + " TCPtoI2P " + conn);
+ t.start();
+ g = false;
+ }
+ }
+ listener.close();
+ } catch (IOException ioe) {
try {
- wunlock();
- } catch (Exception e) {
- break die;
+ listener.close();
+ } catch (IOException e) {
}
}
}
+ } finally {
+ try {
+ listener.close();
+ } catch (IOException ex) {
+ }
+ //System.out.println("TCPlistener: " + Thread.currentThread().getName() + "Done.");
}
- // Previous level does this cleanup now.
- //
- // need to kill off the socket manager too.
- // I2PSession session = socketManager.getSession();
- // if (session != null) {
- // try {
- // session.destroySession();
- // } catch (I2PSessionException ex) {
- // nop
- // }
- //}
- //System.out.println("TCPlistener: Waiting for children");
- //while (Thread.activeCount() > tgwatch) { // wait for all threads in our threadgroup to finish
- // try {
- // Thread.sleep(100); //sleep for 100 ms (One tenth second)
- // } catch (Exception e) {
- // // nop
- // }
- //}
- //System.out.println("TCPlistener: Done.");
}
}
-
-
diff --git a/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java b/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java
index c376e16fe..f3f2c7445 100644
--- a/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java
+++ b/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java
@@ -64,17 +64,17 @@ public class TCPtoI2P implements Runnable {
S = new String();
- while(true) {
+ while (true) {
b = in.read();
- if(b == 13) {
+ if (b == 13) {
//skip CR
continue;
}
- if(b < 20 || b > 126) {
+ if (b < 20 || b > 126) {
// exit on anything not legal
break;
}
- c = (char)(b & 0x7f); // We only really give a fuck about ASCII
+ c = (char) (b & 0x7f); // We only really give a fuck about ASCII
S = new String(S + c);
}
return S;
@@ -118,90 +118,87 @@ public class TCPtoI2P implements Runnable {
OutputStream Iout = null;
InputStream in = null;
OutputStream out = null;
-
try {
-
- in = sock.getInputStream();
- out = sock.getOutputStream();
try {
- line = lnRead(in);
- input = line.toLowerCase();
- Destination dest = null;
-
- if(input.endsWith(".i2p")) {
- dest = I2PTunnel.destFromName(input);
- line = dest.toBase64();
- }
- dest = new Destination();
- dest.fromBase64(line);
+ in = sock.getInputStream();
+ out = sock.getOutputStream();
try {
- // get a client socket
- I2P = socketManager.connect(dest);
- I2P.setReadTimeout(0); // temp bugfix, this *SHOULD* be the default
- // make readers/writers
- Iin = I2P.getInputStream();
- Iout = I2P.getOutputStream();
- // setup to cross the streams
- TCPio conn_c = new TCPio(in, Iout /*, info, database */); // app -> I2P
- TCPio conn_a = new TCPio(Iin, out /*, info, database */); // I2P -> app
- Thread t = new Thread(conn_c, "TCPioA");
- Thread q = new Thread(conn_a, "TCPioB");
- // Fire!
- t.start();
- q.start();
- while(t.isAlive() && q.isAlive()) { // AND is used here to kill off the other thread
-// try {
- Thread.sleep(10); //sleep for 10 ms
-// } catch(InterruptedException e) {
- // nop
-// }
- }
- // System.out.println("TCPtoI2P: Going away...");
+ line = lnRead(in);
+ input = line.toLowerCase();
+ Destination dest = null;
- } catch(I2PException e) {
- Emsg("ERROR " + e.toString(), out);
- } catch(ConnectException e) {
- Emsg("ERROR " + e.toString(), out);
- } catch(NoRouteToHostException e) {
- Emsg("ERROR " + e.toString(), out);
- } catch(InterruptedIOException e) {
+ if (input.endsWith(".i2p")) {
+ dest = I2PTunnel.destFromName(input);
+ line = dest.toBase64();
+ }
+ dest = new Destination();
+ dest.fromBase64(line);
+
+ try {
+ // get a client socket
+ I2P = socketManager.connect(dest);
+ I2P.setReadTimeout(0); // temp bugfix, this *SHOULD* be the default
+ // make readers/writers
+ Iin = I2P.getInputStream();
+ Iout = I2P.getOutputStream();
+ // setup to cross the streams
+ TCPio conn_c = new TCPio(in, Iout /*, info, database */); // app -> I2P
+ TCPio conn_a = new TCPio(Iin, out /*, info, database */); // I2P -> app
+ Thread t = new Thread(conn_c, Thread.currentThread().getName() + " TCPioA");
+ Thread q = new Thread(conn_a, Thread.currentThread().getName() + " TCPioB");
+ // Fire!
+ t.start();
+ q.start();
+ while (t.isAlive() && q.isAlive()) { // AND is used here to kill off the other thread
+ Thread.sleep(10); //sleep for 10 ms
+ }
+
+ } catch (I2PException e) {
+ Emsg("ERROR " + e.toString(), out);
+ } catch (ConnectException e) {
+ Emsg("ERROR " + e.toString(), out);
+ } catch (NoRouteToHostException e) {
+ Emsg("ERROR " + e.toString(), out);
+ } catch (InterruptedIOException e) {
+ // We're breaking away.
+ }
+
+ } catch (Exception e) {
Emsg("ERROR " + e.toString(), out);
}
-
- } catch(Exception e) {
- Emsg("ERROR " + e.toString(), out);
+ } catch (Exception e) {
+ // bail on anything else
+ }
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {
+ }
+ try {
+ out.close();
+ } catch (Exception e) {
+ }
+ try {
+ Iin.close();
+ } catch (Exception e) {
+ }
+ try {
+ Iout.close();
+ } catch (Exception e) {
+ }
+ try {
+ // System.out.println("TCPtoI2P: Close I2P");
+ I2P.close();
+ } catch (Exception e) {
}
- } catch(Exception e) {
- // bail on anything else
- }
- try {
- in.close();
- } catch(Exception e) {
- }
- try {
- out.close();
- } catch(Exception e) {
- }
- try {
- Iin.close();
- } catch(Exception e) {
- }
- try {
- Iout.close();
- } catch(Exception e) {
- }
- try {
- // System.out.println("TCPtoI2P: Close I2P");
- I2P.close();
- } catch(Exception e) {
- }
- try {
- // System.out.println("TCPtoI2P: Close sock");
- sock.close();
- } catch(Exception e) {
+ try {
+ // System.out.println("TCPtoI2P: Close sock");
+ sock.close();
+ } catch (Exception e) {
+ }
}
- // System.out.println("TCPtoI2P: Done.");
+ // System.out.println("TCPtoI2P: Done.");
}
}
diff --git a/apps/desktopgui/nbproject/build-impl.xml b/apps/desktopgui/nbproject/build-impl.xml
index f8fea458d..039f8788f 100644
--- a/apps/desktopgui/nbproject/build-impl.xml
+++ b/apps/desktopgui/nbproject/build-impl.xml
@@ -152,7 +152,7 @@ is divided into following sections:
-
+
@@ -218,13 +218,13 @@ is divided into following sections:
-
+
-
+
@@ -255,6 +255,12 @@ is divided into following sections:
+
+
+
+
+
+
@@ -264,7 +270,7 @@ is divided into following sections:
-
+
@@ -311,6 +317,13 @@ is divided into following sections:
===================
-->
+
+
+
+
+
+
+
@@ -331,7 +344,7 @@ is divided into following sections:
-
+
@@ -345,7 +358,7 @@ is divided into following sections:
-
+