2009-06-08 sponge

* Fixed NPE and some other goofups in BOB.
    * BOB bump version
This commit is contained in:
sponge
2009-06-08 08:34:54 +00:00
parent 51faed2c4d
commit 7151590abc
8 changed files with 91 additions and 100 deletions

View File

@ -38,7 +38,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;
/**

View File

@ -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;

View File

@ -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();
}

View File

@ -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;

View File

@ -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;

View File

@ -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();