2009-04-04 sponge

* Hopeful fixups to the infamous orpahned tunnel problem.
    * BOB now 0.0.5
This commit is contained in:
sponge
2009-04-04 19:47:36 +00:00
parent a4b5c63702
commit bd489cf439
11 changed files with 236 additions and 127 deletions

View File

@ -27,6 +27,7 @@ excludes=
file.reference.build-javadoc=../../i2p.i2p/build/javadoc file.reference.build-javadoc=../../i2p.i2p/build/javadoc
file.reference.i2p.jar=../../core/java/build/i2p.jar file.reference.i2p.jar=../../core/java/build/i2p.jar
file.reference.i2ptunnel.jar=../i2ptunnel/java/build/i2ptunnel.jar file.reference.i2ptunnel.jar=../i2ptunnel/java/build/i2ptunnel.jar
file.reference.jbigi.jar=../../installer/lib/jbigi/jbigi.jar
file.reference.mstreaming.jar=../ministreaming/java/build/mstreaming.jar file.reference.mstreaming.jar=../ministreaming/java/build/mstreaming.jar
file.reference.router.jar=../../router/java/build/router.jar file.reference.router.jar=../../router/java/build/router.jar
file.reference.streaming.jar=../streaming/java/build/streaming.jar file.reference.streaming.jar=../streaming/java/build/streaming.jar

View File

@ -34,6 +34,7 @@ import java.util.Properties;
import net.i2p.client.I2PClient; import net.i2p.client.I2PClient;
import net.i2p.client.streaming.RetransmissionTimer; import net.i2p.client.streaming.RetransmissionTimer;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
* <span style="font-size:8px;font-family:courier;color:#EEEEEE;background-color:#000000"> * <span style="font-size:8px;font-family:courier;color:#EEEEEE;background-color:#000000">
* ################################################################################<br> * ################################################################################<br>
@ -157,12 +158,12 @@ public class BOB {
boolean save = false; boolean save = false;
// Set up all defaults to be passed forward to other threads. // Set up all defaults to be passed forward to other threads.
// Re-reading the config file in each thread is pretty damn stupid. // Re-reading the config file in each thread is pretty damn stupid.
// I2PClient client = I2PClientFactory.createClient();
String configLocation = System.getProperty(PROP_CONFIG_LOCATION, "bob.config"); String configLocation = System.getProperty(PROP_CONFIG_LOCATION, "bob.config");
// This is here just to ensure there is no interference with our threadgroups. // This is here just to ensure there is no interference with our threadgroups.
RetransmissionTimer Y = RetransmissionTimer.getInstance(); RetransmissionTimer Y = RetransmissionTimer.getInstance();
i = Y.hashCode(); i = Y.hashCode();
{ {
try { try {
FileInputStream fi = new FileInputStream(configLocation); FileInputStream fi = new FileInputStream(configLocation);

View File

@ -46,7 +46,7 @@ public class DoCMDS implements Runnable {
// FIX ME // FIX ME
// I need a better way to do versioning, but this will do for now. // I need a better way to do versioning, but this will do for now.
public static final String BMAJ = "00", BMIN = "00", BREV = "04", BEXT = ""; public static final String BMAJ = "00", BMIN = "00", BREV = "05", BEXT = "";
public static final String BOBversion = BMAJ + "." + BMIN + "." + BREV + BEXT; public static final String BOBversion = BMAJ + "." + BMIN + "." + BREV + BEXT;
private Socket server; private Socket server;
private Properties props; private Properties props;

View File

@ -62,6 +62,26 @@ public class I2Plistener implements Runnable {
tgwatch = 1; tgwatch = 1;
} }
private void rlock() throws Exception {
database.getReadLock();
info.getReadLock();
}
private void runlock() throws Exception {
database.releaseReadLock();
info.releaseReadLock();
}
private void wlock() throws Exception {
database.getWriteLock();
info.getWriteLock();
}
private void wunlock() throws Exception {
info.releaseWriteLock();
database.releaseWriteLock();
}
/** /**
* Simply listen on I2P port, and thread connections * Simply listen on I2P port, and thread connections
* *
@ -70,22 +90,39 @@ public class I2Plistener implements Runnable {
boolean g = false; boolean g = false;
I2PSocket sessSocket = null; I2PSocket sessSocket = null;
die: {
serverSocket.setSoTimeout(50); serverSocket.setSoTimeout(50);
database.getReadLock(); try {
info.getReadLock();
if (info.exists("INPORT")) { if (info.exists("INPORT")) {
tgwatch = 2; tgwatch = 2;
} }
info.releaseReadLock(); } catch (Exception e) {
database.releaseReadLock(); try {
runlock();
} catch (Exception e2) {
break die;
}
break die;
}
boolean spin = true; boolean spin = true;
while (spin) { while (spin) {
database.getReadLock(); try {
info.getReadLock(); rlock();
} catch (Exception e) {
break die;
}
try {
spin = info.get("RUNNING").equals(Boolean.TRUE); spin = info.get("RUNNING").equals(Boolean.TRUE);
info.releaseReadLock(); } catch (Exception e) {
database.releaseReadLock(); try {
runlock();
} catch (Exception e2) {
break die;
}
break die;
}
try { try {
try { try {
sessSocket = serverSocket.accept(); sessSocket = serverSocket.accept();
@ -107,6 +144,7 @@ public class I2Plistener implements Runnable {
// System.out.println("Exception " + e); // System.out.println("Exception " + e);
} }
} }
}
// System.out.println("I2Plistener: Close"); // System.out.println("I2Plistener: Close");
try { try {
serverSocket.close(); serverSocket.close();

View File

@ -105,8 +105,8 @@ die: {
out.flush(); // not really needed, but... out.flush(); // not really needed, but...
} }
// setup to cross the streams // setup to cross the streams
TCPio conn_c = new TCPio(in, Iout, info, database); // app -> I2P TCPio conn_c = new TCPio(in, Iout /*, info, database */ ); // app -> I2P
TCPio conn_a = new TCPio(Iin, out, info, database); // I2P -> app TCPio conn_a = new TCPio(Iin, out /* , info, database */); // I2P -> app
Thread t = new Thread(conn_c, "TCPioA"); Thread t = new Thread(conn_c, "TCPioA");
Thread q = new Thread(conn_a, "TCPioB"); Thread q = new Thread(conn_a, "TCPioB");
// Fire! // Fire!

View File

@ -100,7 +100,7 @@ public class MUXlisten implements Runnable {
// Everything is OK as far as we can tell. // Everything is OK as far as we can tell.
this.database.getWriteLock(); this.database.getWriteLock();
this.info.getWriteLock(); this.info.getWriteLock();
this.info.add("STARTING", Boolean.TRUE); this.info.add("STARTING", new Boolean(true));
this.info.releaseWriteLock(); this.info.releaseWriteLock();
this.database.releaseWriteLock(); this.database.releaseWriteLock();
} }
@ -134,8 +134,8 @@ public class MUXlisten implements Runnable {
try { try {
wlock(); wlock();
try { try {
info.add("RUNNING", Boolean.TRUE); info.add("RUNNING", new Boolean(true));
info.add("STARTING", Boolean.FALSE); info.add("STARTING", new Boolean(false));
} catch(Exception e) { } catch(Exception e) {
wunlock(); wunlock();
return; return;
@ -198,7 +198,7 @@ die: {
try { try {
wlock(); wlock();
try { try {
info.add("RUNNING", Boolean.FALSE); info.add("RUNNING", new Boolean(false));
} catch(Exception e) { } catch(Exception e) {
wunlock(); wunlock();
break die; break die;
@ -255,9 +255,9 @@ die: {
try { try {
wlock(); wlock();
try { try {
info.add("STARTING", Boolean.FALSE); info.add("STARTING", new Boolean(false));
info.add("STOPPING", Boolean.FALSE); info.add("STOPPING", new Boolean(false));
info.add("RUNNING", Boolean.FALSE); info.add("RUNNING", new Boolean(false));
} catch(Exception e) { } catch(Exception e) {
wunlock(); wunlock();
return; return;

View File

@ -24,7 +24,7 @@
package net.i2p.BOB; package net.i2p.BOB;
import net.i2p.client.streaming.RetransmissionTimer; import net.i2p.client.streaming.RetransmissionTimer;
import net.i2p.util.SimpleScheduler;
/** /**
* Start from command line * Start from command line
* *
@ -39,6 +39,9 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// THINK THINK THINK THINK THINK THINK // THINK THINK THINK THINK THINK THINK
RetransmissionTimer Y = RetransmissionTimer.getInstance(); RetransmissionTimer Y = RetransmissionTimer.getInstance();
// needs SimpleScheduler
// no way to stop the scheduler?!?
SimpleScheduler.getInstance();
BOB.main(args); BOB.main(args);
Y.stop(); Y.stop();
} }

View File

@ -35,7 +35,7 @@ public class TCPio implements Runnable {
private InputStream Ain; private InputStream Ain;
private OutputStream Aout; private OutputStream Aout;
private NamedDB info, database; // private NamedDB info, database;
/** /**
* Constructor * Constructor
@ -43,13 +43,14 @@ public class TCPio implements Runnable {
* @param Ain * @param Ain
* @param Aout * @param Aout
* @param info * @param info
* @param database *
* param database
*/ */
TCPio(InputStream Ain, OutputStream Aout, NamedDB info, NamedDB database) { TCPio(InputStream Ain, OutputStream Aout /*, NamedDB info , NamedDB database */) {
this.Ain = Ain; this.Ain = Ain;
this.Aout = Aout; this.Aout = Aout;
this.info = info; // this.info = info;
this.database = database; // this.database = database;
} }
/** /**
@ -86,11 +87,11 @@ public class TCPio implements Runnable {
boolean spin = true; boolean spin = true;
try { try {
while(spin) { while(spin) {
database.getReadLock(); // database.getReadLock();
info.getReadLock(); // info.getReadLock();
spin = info.get("RUNNING").equals(Boolean.TRUE); // spin = info.get("RUNNING").equals(Boolean.TRUE);
info.releaseReadLock(); // info.releaseReadLock();
database.releaseReadLock(); // database.releaseReadLock();
b = Ain.read(a, 0, 1); b = Ain.read(a, 0, 1);
// System.out.println(info.get("NICKNAME").toString() + " " + b); // System.out.println(info.get("NICKNAME").toString() + " " + b);
if(b > 0) { if(b > 0) {

View File

@ -63,6 +63,26 @@ public class TCPlistener implements Runnable {
tgwatch = 1; tgwatch = 1;
} }
private void rlock() throws Exception {
database.getReadLock();
info.getReadLock();
}
private void runlock() throws Exception {
database.releaseReadLock();
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 * Simply listen on TCP port, and thread connections
* *
@ -70,22 +90,49 @@ public class TCPlistener implements Runnable {
public void run() { public void run() {
boolean g = false; boolean g = false;
boolean spin = true; boolean spin = true;
database.getReadLock();
info.getReadLock(); die: {
try {
rlock();
} catch (Exception e) {
break die;
}
try {
if (info.exists("OUTPORT")) { if (info.exists("OUTPORT")) {
tgwatch = 2; tgwatch = 2;
} }
} catch (Exception e) {
try {
runlock();
} catch (Exception e2) {
break die;
}
break die;
}
try {
runlock();
} catch (Exception e) {
break die;
}
try { try {
Socket server = new Socket(); Socket server = new Socket();
listener.setSoTimeout(50); // Half of the expected time from MUXlisten listener.setSoTimeout(50); // Half of the expected time from MUXlisten
info.releaseReadLock();
database.releaseReadLock();
while (spin) { while (spin) {
database.getReadLock(); try {
info.getReadLock(); rlock();
} catch (Exception e) {
break die;
}
try {
spin = info.get("RUNNING").equals(Boolean.TRUE); spin = info.get("RUNNING").equals(Boolean.TRUE);
info.releaseReadLock(); } catch (Exception e) {
database.releaseReadLock(); try {
runlock();
} catch (Exception e2) {
break die;
}
break die;
}
try { try {
server = listener.accept(); server = listener.accept();
g = true; g = true;
@ -94,7 +141,7 @@ public class TCPlistener implements Runnable {
} }
if (g) { if (g) {
// toss the connection to a new thread. // toss the connection to a new thread.
TCPtoI2P conn_c = new TCPtoI2P(socketManager, server, info, database); TCPtoI2P conn_c = new TCPtoI2P(socketManager, server /* , info, database */);
Thread t = new Thread(conn_c, "BOBTCPtoI2P"); Thread t = new Thread(conn_c, "BOBTCPtoI2P");
t.start(); t.start();
g = false; g = false;
@ -108,21 +155,38 @@ public class TCPlistener implements Runnable {
} catch (IOException e) { } catch (IOException e) {
} }
// Fatal failure, cause a stop event // Fatal failure, cause a stop event
database.getReadLock(); try {
info.getReadLock(); rlock();
try {
spin = info.get("RUNNING").equals(Boolean.TRUE); spin = info.get("RUNNING").equals(Boolean.TRUE);
info.releaseReadLock(); } catch (Exception e) {
database.releaseReadLock(); runlock();
break die;
}
} catch (Exception e) {
break die;
}
if (spin) { if (spin) {
database.getWriteLock(); try {
info.getWriteLock(); wlock();
try {
info.add("STOPPING", new Boolean(true)); info.add("STOPPING", new Boolean(true));
info.add("RUNNING", new Boolean(false)); info.add("RUNNING", new Boolean(false));
info.releaseWriteLock(); } catch (Exception e) {
database.releaseWriteLock(); wunlock();
break die;
}
} catch (Exception e) {
break die;
}
try {
wunlock();
} catch (Exception e) {
break die;
}
}
} }
} }
// need to kill off the socket manager too. // need to kill off the socket manager too.
I2PSession session = socketManager.getSession(); I2PSession session = socketManager.getSession();
if (session != null) { if (session != null) {

View File

@ -45,7 +45,7 @@ import net.i2p.i2ptunnel.I2PTunnel;
public class TCPtoI2P implements Runnable { public class TCPtoI2P implements Runnable {
private I2PSocket I2P; private I2PSocket I2P;
private NamedDB info, database; // private NamedDB info, database;
private Socket sock; private Socket sock;
private I2PSocketManager socketManager; private I2PSocketManager socketManager;
@ -84,13 +84,13 @@ public class TCPtoI2P implements Runnable {
* Constructor * Constructor
* @param i2p * @param i2p
* @param socket * @param socket
* @param info * param info
* @param database * param database
*/ */
TCPtoI2P(I2PSocketManager i2p, Socket socket, NamedDB info, NamedDB database) { TCPtoI2P(I2PSocketManager i2p, Socket socket /*, NamedDB info, NamedDB database */) {
this.sock = socket; this.sock = socket;
this.info = info; // this.info = info;
this.database = database; // this.database = database;
this.socketManager = i2p; this.socketManager = i2p;
} }
@ -110,6 +110,7 @@ public class TCPtoI2P implements Runnable {
/** /**
* TCP stream to I2P stream thread starter * TCP stream to I2P stream thread starter
*
*/ */
public void run() { public void run() {
String line, input; String line, input;
@ -138,8 +139,8 @@ public class TCPtoI2P implements Runnable {
InputStream Iin = I2P.getInputStream(); InputStream Iin = I2P.getInputStream();
OutputStream Iout = I2P.getOutputStream(); OutputStream Iout = I2P.getOutputStream();
// setup to cross the streams // setup to cross the streams
TCPio conn_c = new TCPio(in, Iout, info, database); // app -> I2P TCPio conn_c = new TCPio(in, Iout /*, info, database */); // app -> I2P
TCPio conn_a = new TCPio(Iin, out, info, database); // I2P -> app TCPio conn_a = new TCPio(Iin, out /*, info, database */); // I2P -> app
Thread t = new Thread(conn_c, "TCPioA"); Thread t = new Thread(conn_c, "TCPioA");
Thread q = new Thread(conn_a, "TCPioB"); Thread q = new Thread(conn_a, "TCPioB");
// Fire! // Fire!
@ -167,7 +168,8 @@ public class TCPtoI2P implements Runnable {
} catch(Exception e) { } catch(Exception e) {
Emsg("ERROR " + e.toString(), out); Emsg("ERROR " + e.toString(), out);
} }
} catch(IOException ioe) { } catch(Exception e) {
// bail on anything else
} }
try { try {
// System.out.println("TCPtoI2P: Close I2P"); // System.out.println("TCPtoI2P: Close I2P");
@ -181,6 +183,5 @@ public class TCPtoI2P implements Runnable {
} catch(Exception e) { } catch(Exception e) {
} }
// System.out.println("TCPtoI2P: Done."); // System.out.println("TCPtoI2P: Done.");
} }
} }

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion { public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $"; public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 7; public final static long BUILD = 8;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID); System.out.println("Router ID: " + RouterVersion.ID);