propagate from branch 'i2p.i2p' (head 6fddab77462a92759305edee8fe5a944d6865375)
to branch 'i2p.i2p.zzz.test' (head 45a25185236e38606e761060427ee8fa60144a8c)
This commit is contained in:
@ -1,9 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
|
||||
<file>file:/root/NetBeansProjects/i2p.i2p/apps/BOB/src/net/i2p/BOB/BOB.java</file>
|
||||
<file>file:/root/NetBeansProjects/i2p.i2p/apps/BOB/src/net/i2p/BOB/DoCMDS.java</file>
|
||||
<file>file:/root/NetBeansProjects/i2p.i2p/apps/BOB/src/net/i2p/BOB/MUXlisten.java</file>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
@ -41,7 +41,6 @@ import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.streaming.RetransmissionTimer;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleScheduler;
|
||||
import net.i2p.util.SimpleStore;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ public class DoCMDS implements Runnable {
|
||||
|
||||
// FIX ME
|
||||
// I need a better way to do versioning, but this will do for now.
|
||||
public static final String BMAJ = "00", BMIN = "00", BREV = "06", BEXT = "";
|
||||
public static final String BMAJ = "00", BMIN = "00", BREV = "07", BEXT = "";
|
||||
public static final String BOBversion = BMAJ + "." + BMIN + "." + BREV + BEXT;
|
||||
private Socket server;
|
||||
private Properties props;
|
||||
|
@ -52,12 +52,12 @@ public class I2PtoTCP implements Runnable {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
private void rlock() throws Exception {
|
||||
private void rlock() {
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
}
|
||||
|
||||
private void runlock() throws Exception {
|
||||
private void runlock() {
|
||||
database.releaseReadLock();
|
||||
info.releaseReadLock();
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import net.i2p.util.Log;
|
||||
*/
|
||||
public class MUXlisten implements Runnable {
|
||||
|
||||
private NamedDB database, info;
|
||||
private NamedDB database, info;
|
||||
private Log _log;
|
||||
private I2PSocketManager socketManager;
|
||||
private ByteArrayInputStream prikey;
|
||||
@ -269,27 +269,27 @@ public class MUXlisten implements Runnable {
|
||||
// Wait around till all threads are collected.
|
||||
if (tg != null) {
|
||||
String boner = tg.getName();
|
||||
System.out.println("BOB: MUXlisten: Starting thread collection for: " + boner);
|
||||
// System.out.println("BOB: MUXlisten: Starting thread collection for: " + boner);
|
||||
_log.warn("BOB: MUXlisten: Starting thread collection for: " + boner);
|
||||
// tg.interrupt(); // give my stuff a small smack again.
|
||||
if (tg.activeCount() + tg.activeGroupCount() != 0) {
|
||||
visit(tg, 0, boner);
|
||||
// visit(tg, 0, boner);
|
||||
int foo = tg.activeCount() + tg.activeGroupCount();
|
||||
// hopefully no longer needed!
|
||||
int bar = foo;
|
||||
System.out.println("BOB: MUXlisten: Waiting on threads for " + boner);
|
||||
System.out.println("\nBOB: MUXlisten: ThreadGroup dump BEGIN " + boner);
|
||||
visit(tg, 0, boner);
|
||||
System.out.println("BOB: MUXlisten: ThreadGroup dump END " + boner + "\n");
|
||||
// int bar = foo;
|
||||
// System.out.println("BOB: MUXlisten: Waiting on threads for " + boner);
|
||||
// System.out.println("\nBOB: MUXlisten: ThreadGroup dump BEGIN " + boner);
|
||||
// visit(tg, 0, boner);
|
||||
// System.out.println("BOB: MUXlisten: ThreadGroup dump END " + boner + "\n");
|
||||
// Happily spin forever :-(
|
||||
while (foo != 0) {
|
||||
foo = tg.activeCount() + tg.activeGroupCount();
|
||||
if (foo != bar && foo != 0) {
|
||||
System.out.println("\nBOB: MUXlisten: ThreadGroup dump BEGIN " + boner);
|
||||
visit(tg, 0, boner);
|
||||
System.out.println("BOB: MUXlisten: ThreadGroup dump END " + boner + "\n");
|
||||
}
|
||||
bar = foo;
|
||||
// if (foo != bar && foo != 0) {
|
||||
// System.out.println("\nBOB: MUXlisten: ThreadGroup dump BEGIN " + boner);
|
||||
// visit(tg, 0, boner);
|
||||
// System.out.println("BOB: MUXlisten: ThreadGroup dump END " + boner + "\n");
|
||||
// }
|
||||
// bar = foo;
|
||||
try {
|
||||
Thread.sleep(100); //sleep for 100 ms (One tenth second)
|
||||
} catch (InterruptedException ex) {
|
||||
@ -297,7 +297,7 @@ public class MUXlisten implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("BOB: MUXlisten: Threads went away. Success: " + boner);
|
||||
// System.out.println("BOB: MUXlisten: Threads went away. Success: " + boner);
|
||||
_log.warn("BOB: MUXlisten: Threads went away. Success: " + boner);
|
||||
tg.destroy();
|
||||
// Zap reference to the ThreadGroup so the JVM can GC it.
|
||||
@ -357,41 +357,4 @@ public class MUXlisten implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ public class TCPlistener implements Runnable {
|
||||
|
||||
private NamedDB info, database;
|
||||
private Log _log;
|
||||
private int tgwatch;
|
||||
public I2PSocketManager socketManager;
|
||||
public I2PServerSocket serverSocket;
|
||||
private ServerSocket listener;
|
||||
@ -60,7 +59,6 @@ public class TCPlistener implements Runnable {
|
||||
this._log = _log;
|
||||
this.socketManager = S;
|
||||
this.listener = listener;
|
||||
tgwatch = 1;
|
||||
}
|
||||
|
||||
private void rlock() throws Exception {
|
||||
@ -84,28 +82,6 @@ public class TCPlistener implements Runnable {
|
||||
try {
|
||||
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); // We don't block, we cycle and check.
|
||||
@ -134,7 +110,7 @@ public class TCPlistener implements Runnable {
|
||||
if (g) {
|
||||
conn++;
|
||||
// toss the connection to a new thread.
|
||||
TCPtoI2P conn_c = new TCPtoI2P(socketManager, server);
|
||||
TCPtoI2P conn_c = new TCPtoI2P(socketManager, server, info, database);
|
||||
Thread t = new Thread(conn_c, Thread.currentThread().getName() + " TCPtoI2P " + conn);
|
||||
t.start();
|
||||
g = false;
|
||||
|
@ -33,6 +33,7 @@ import java.net.Socket;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.client.streaming.I2PSocketManager;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.i2ptunnel.I2PTunnel;
|
||||
|
||||
@ -49,15 +50,29 @@ public class TCPtoI2P implements Runnable {
|
||||
private Socket sock;
|
||||
private I2PSocketManager socketManager;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param i2p
|
||||
* @param socket
|
||||
* param info
|
||||
* param database
|
||||
*/
|
||||
TCPtoI2P(I2PSocketManager i2p, Socket socket , NamedDB info, NamedDB database) {
|
||||
this.sock = socket;
|
||||
this.info = info;
|
||||
this.database = database;
|
||||
this.socketManager = i2p;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a more forgiving readline,
|
||||
* it works on unbuffered streams
|
||||
*
|
||||
* @param in
|
||||
* @return line of text as a String
|
||||
* @throws Exception
|
||||
* @throws IOException
|
||||
*/
|
||||
private static String lnRead(InputStream in) throws Exception {
|
||||
private static String lnRead(InputStream in) throws IOException {
|
||||
String S;
|
||||
int b;
|
||||
char c;
|
||||
@ -80,20 +95,6 @@ public class TCPtoI2P implements Runnable {
|
||||
return S;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param i2p
|
||||
* @param socket
|
||||
* param info
|
||||
* param database
|
||||
*/
|
||||
TCPtoI2P(I2PSocketManager i2p, Socket socket /*, NamedDB info, NamedDB database */) {
|
||||
this.sock = socket;
|
||||
// this.info = info;
|
||||
// this.database = database;
|
||||
this.socketManager = i2p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an error message to out
|
||||
*
|
||||
@ -103,19 +104,22 @@ public class TCPtoI2P implements Runnable {
|
||||
*/
|
||||
private void Emsg(String e, OutputStream out) throws IOException {
|
||||
// Debugging System.out.println("ERROR TCPtoI2P: " + e);
|
||||
out.write("ERROR".concat(e).getBytes());
|
||||
out.write(13); // cr
|
||||
out.write("ERROR ".concat(e).getBytes());
|
||||
out.write(13);
|
||||
out.write(10);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
private void rlock() throws Exception {
|
||||
// private void rlock() throws Exception {
|
||||
private void rlock() {
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
}
|
||||
|
||||
private void runlock() throws Exception {
|
||||
database.releaseReadLock();
|
||||
// private void runlock() throws Exception {
|
||||
private void runlock() {
|
||||
info.releaseReadLock();
|
||||
database.releaseReadLock();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,56 +139,64 @@ public class TCPtoI2P implements Runnable {
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
t = new Thread(conn_c, Thread.currentThread().getName() + " TCPioA");
|
||||
q = new Thread(conn_a, Thread.currentThread().getName() + " TCPioB");
|
||||
// Fire!
|
||||
t.start();
|
||||
q.start();
|
||||
boolean spin = true;
|
||||
while (t.isAlive() && q.isAlive()) { // AND is used here to kill off the other thread
|
||||
Thread.sleep(10); //sleep for 10 ms
|
||||
rlock();
|
||||
spin = info.get("RUNNING").equals(Boolean.TRUE);
|
||||
runlock();
|
||||
}
|
||||
} 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);
|
||||
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);
|
||||
|
||||
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
|
||||
t = new Thread(conn_c, Thread.currentThread().getName() + " TCPioA");
|
||||
q = new Thread(conn_a, Thread.currentThread().getName() + " TCPioB");
|
||||
// Fire!
|
||||
t.start();
|
||||
q.start();
|
||||
boolean spin = true;
|
||||
while (t.isAlive() && q.isAlive()) { // AND is used here to kill off the other thread
|
||||
Thread.sleep(10); //sleep for 10 ms
|
||||
rlock();
|
||||
spin = info.get("RUNNING").equals(Boolean.TRUE);
|
||||
runlock();
|
||||
}
|
||||
} catch (I2PException e) {
|
||||
Emsg(e.toString(), out);
|
||||
} catch (ConnectException e) {
|
||||
Emsg(e.toString(), out);
|
||||
} catch (NoRouteToHostException e) {
|
||||
Emsg(e.toString(), out);
|
||||
}
|
||||
|
||||
} catch (InterruptedIOException e) {
|
||||
// We're breaking away.
|
||||
} catch (InterruptedException e) {
|
||||
// ditto
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
Emsg(e.toString(), out);
|
||||
} catch (IOException ex) {
|
||||
// ditto
|
||||
}
|
||||
} catch (DataFormatException e) {
|
||||
try {
|
||||
Emsg(e.toString(), out);
|
||||
} catch (IOException ex) {
|
||||
// ditto
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// bail on anything else
|
||||
}
|
||||
|
||||
} finally {
|
||||
try {
|
||||
t.interrupt();
|
||||
|
Reference in New Issue
Block a user