From 7151590abc123756076be862b4275b7531e172dc Mon Sep 17 00:00:00 2001 From: sponge Date: Mon, 8 Jun 2009 08:34:54 +0000 Subject: [PATCH] 2009-06-08 sponge * Fixed NPE and some other goofups in BOB. * BOB bump version --- apps/BOB/src/net/i2p/BOB/BOB.java | 1 - apps/BOB/src/net/i2p/BOB/DoCMDS.java | 2 +- apps/BOB/src/net/i2p/BOB/I2PtoTCP.java | 4 +- apps/BOB/src/net/i2p/BOB/MUXlisten.java | 2 +- apps/BOB/src/net/i2p/BOB/TCPlistener.java | 26 +-- apps/BOB/src/net/i2p/BOB/TCPtoI2P.java | 150 ++++++++++-------- history.txt | 4 + .../src/net/i2p/router/RouterVersion.java | 2 +- 8 files changed, 91 insertions(+), 100 deletions(-) diff --git a/apps/BOB/src/net/i2p/BOB/BOB.java b/apps/BOB/src/net/i2p/BOB/BOB.java index 9f87e4f88f..3ca7331585 100644 --- a/apps/BOB/src/net/i2p/BOB/BOB.java +++ b/apps/BOB/src/net/i2p/BOB/BOB.java @@ -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; /** diff --git a/apps/BOB/src/net/i2p/BOB/DoCMDS.java b/apps/BOB/src/net/i2p/BOB/DoCMDS.java index cc92e66cae..9019ef85bc 100644 --- a/apps/BOB/src/net/i2p/BOB/DoCMDS.java +++ b/apps/BOB/src/net/i2p/BOB/DoCMDS.java @@ -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; diff --git a/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java b/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java index 91ac055895..5df1f3e0e1 100644 --- a/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java +++ b/apps/BOB/src/net/i2p/BOB/I2PtoTCP.java @@ -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(); } diff --git a/apps/BOB/src/net/i2p/BOB/MUXlisten.java b/apps/BOB/src/net/i2p/BOB/MUXlisten.java index 2f22abbeb4..78aff0bc03 100644 --- a/apps/BOB/src/net/i2p/BOB/MUXlisten.java +++ b/apps/BOB/src/net/i2p/BOB/MUXlisten.java @@ -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; diff --git a/apps/BOB/src/net/i2p/BOB/TCPlistener.java b/apps/BOB/src/net/i2p/BOB/TCPlistener.java index 8f559c09f1..9155cb82bd 100644 --- a/apps/BOB/src/net/i2p/BOB/TCPlistener.java +++ b/apps/BOB/src/net/i2p/BOB/TCPlistener.java @@ -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; diff --git a/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java b/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java index 117c2b1036..2073e0e691 100644 --- a/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java +++ b/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java @@ -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(); diff --git a/history.txt b/history.txt index 7c66ec3f0a..22c477493d 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,7 @@ +2009-06-08 sponge + * Fixed NPE and some other goofups in BOB. + * BOB bump version + 2009-06-07 zzz * Build file: - Add updaterWithJettyFixesAndGeoIP, use it in pkg for one release diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 5231b53f93..9ee543940e 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 15; + public final static long BUILD = 16; /** for example "-test" */ public final static String EXTRA = "-rc"; public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;