forked from I2P_Developers/i2p.i2p
2009-04-04 sponge
* Hopeful fixups to the infamous orpahned tunnel problem. * BOB now 0.0.5
This commit is contained in:
@ -27,6 +27,7 @@ excludes=
|
||||
file.reference.build-javadoc=../../i2p.i2p/build/javadoc
|
||||
file.reference.i2p.jar=../../core/java/build/i2p.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.router.jar=../../router/java/build/router.jar
|
||||
file.reference.streaming.jar=../streaming/java/build/streaming.jar
|
||||
|
@ -34,6 +34,7 @@ import java.util.Properties;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.streaming.RetransmissionTimer;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* <span style="font-size:8px;font-family:courier;color:#EEEEEE;background-color:#000000">
|
||||
* ################################################################################<br>
|
||||
@ -157,12 +158,12 @@ public class BOB {
|
||||
boolean save = false;
|
||||
// Set up all defaults to be passed forward to other threads.
|
||||
// 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");
|
||||
|
||||
// This is here just to ensure there is no interference with our threadgroups.
|
||||
RetransmissionTimer Y = RetransmissionTimer.getInstance();
|
||||
i = Y.hashCode();
|
||||
|
||||
{
|
||||
try {
|
||||
FileInputStream fi = new FileInputStream(configLocation);
|
||||
|
@ -46,7 +46,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 = "04", BEXT = "";
|
||||
public static final String BMAJ = "00", BMIN = "00", BREV = "05", BEXT = "";
|
||||
public static final String BOBversion = BMAJ + "." + BMIN + "." + BREV + BEXT;
|
||||
private Socket server;
|
||||
private Properties props;
|
||||
|
@ -62,6 +62,26 @@ public class I2Plistener implements Runnable {
|
||||
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
|
||||
*
|
||||
@ -70,32 +90,49 @@ public class I2Plistener implements Runnable {
|
||||
boolean g = false;
|
||||
I2PSocket sessSocket = null;
|
||||
|
||||
die: {
|
||||
|
||||
serverSocket.setSoTimeout(50);
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
if(info.exists("INPORT")) {
|
||||
try {
|
||||
if (info.exists("INPORT")) {
|
||||
tgwatch = 2;
|
||||
}
|
||||
info.releaseReadLock();
|
||||
database.releaseReadLock();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
runlock();
|
||||
} catch (Exception e2) {
|
||||
break die;
|
||||
}
|
||||
break die;
|
||||
}
|
||||
boolean spin = true;
|
||||
while(spin) {
|
||||
while (spin) {
|
||||
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
try {
|
||||
rlock();
|
||||
} catch (Exception e) {
|
||||
break die;
|
||||
}
|
||||
try {
|
||||
spin = info.get("RUNNING").equals(Boolean.TRUE);
|
||||
info.releaseReadLock();
|
||||
database.releaseReadLock();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
runlock();
|
||||
} catch (Exception e2) {
|
||||
break die;
|
||||
}
|
||||
break die;
|
||||
}
|
||||
try {
|
||||
try {
|
||||
sessSocket = serverSocket.accept();
|
||||
g = true;
|
||||
} catch(ConnectException ce) {
|
||||
} catch (ConnectException ce) {
|
||||
g = false;
|
||||
} catch(SocketTimeoutException ste) {
|
||||
} catch (SocketTimeoutException ste) {
|
||||
g = false;
|
||||
}
|
||||
if(g) {
|
||||
if (g) {
|
||||
g = false;
|
||||
// toss the connection to a new thread.
|
||||
I2PtoTCP conn_c = new I2PtoTCP(sessSocket, info, database);
|
||||
@ -103,31 +140,32 @@ public class I2Plistener implements Runnable {
|
||||
t.start();
|
||||
}
|
||||
|
||||
} catch(I2PException e) {
|
||||
} catch (I2PException e) {
|
||||
// System.out.println("Exception " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// System.out.println("I2Plistener: Close");
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch(I2PException e) {
|
||||
} catch (I2PException e) {
|
||||
// nop
|
||||
}
|
||||
// need to kill off the socket manager too.
|
||||
I2PSession session = socketManager.getSession();
|
||||
if(session != null) {
|
||||
if (session != null) {
|
||||
// System.out.println("I2Plistener: destroySession");
|
||||
try {
|
||||
session.destroySession();
|
||||
} catch(I2PSessionException ex) {
|
||||
} catch (I2PSessionException ex) {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
// System.out.println("I2Plistener: Waiting for children");
|
||||
while(Thread.activeCount() > tgwatch) { // wait for all threads in our threadgroup to finish
|
||||
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) {
|
||||
} catch (Exception e) {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ die: {
|
||||
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
|
||||
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!
|
||||
|
@ -100,7 +100,7 @@ public class MUXlisten implements Runnable {
|
||||
// Everything is OK as far as we can tell.
|
||||
this.database.getWriteLock();
|
||||
this.info.getWriteLock();
|
||||
this.info.add("STARTING", Boolean.TRUE);
|
||||
this.info.add("STARTING", new Boolean(true));
|
||||
this.info.releaseWriteLock();
|
||||
this.database.releaseWriteLock();
|
||||
}
|
||||
@ -134,8 +134,8 @@ public class MUXlisten implements Runnable {
|
||||
try {
|
||||
wlock();
|
||||
try {
|
||||
info.add("RUNNING", Boolean.TRUE);
|
||||
info.add("STARTING", Boolean.FALSE);
|
||||
info.add("RUNNING", new Boolean(true));
|
||||
info.add("STARTING", new Boolean(false));
|
||||
} catch(Exception e) {
|
||||
wunlock();
|
||||
return;
|
||||
@ -198,7 +198,7 @@ die: {
|
||||
try {
|
||||
wlock();
|
||||
try {
|
||||
info.add("RUNNING", Boolean.FALSE);
|
||||
info.add("RUNNING", new Boolean(false));
|
||||
} catch(Exception e) {
|
||||
wunlock();
|
||||
break die;
|
||||
@ -255,9 +255,9 @@ die: {
|
||||
try {
|
||||
wlock();
|
||||
try {
|
||||
info.add("STARTING", Boolean.FALSE);
|
||||
info.add("STOPPING", Boolean.FALSE);
|
||||
info.add("RUNNING", Boolean.FALSE);
|
||||
info.add("STARTING", new Boolean(false));
|
||||
info.add("STOPPING", new Boolean(false));
|
||||
info.add("RUNNING", new Boolean(false));
|
||||
} catch(Exception e) {
|
||||
wunlock();
|
||||
return;
|
||||
|
@ -24,7 +24,7 @@
|
||||
package net.i2p.BOB;
|
||||
|
||||
import net.i2p.client.streaming.RetransmissionTimer;
|
||||
|
||||
import net.i2p.util.SimpleScheduler;
|
||||
/**
|
||||
* Start from command line
|
||||
*
|
||||
@ -39,6 +39,9 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
// THINK THINK THINK THINK THINK THINK
|
||||
RetransmissionTimer Y = RetransmissionTimer.getInstance();
|
||||
// needs SimpleScheduler
|
||||
// no way to stop the scheduler?!?
|
||||
SimpleScheduler.getInstance();
|
||||
BOB.main(args);
|
||||
Y.stop();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class TCPio implements Runnable {
|
||||
|
||||
private InputStream Ain;
|
||||
private OutputStream Aout;
|
||||
private NamedDB info, database;
|
||||
// private NamedDB info, database;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -43,13 +43,14 @@ public class TCPio implements Runnable {
|
||||
* @param Ain
|
||||
* @param Aout
|
||||
* @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.Aout = Aout;
|
||||
this.info = info;
|
||||
this.database = database;
|
||||
// this.info = info;
|
||||
// this.database = database;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,11 +87,11 @@ 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();
|
||||
// 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) {
|
||||
|
@ -63,6 +63,26 @@ public class TCPlistener implements Runnable {
|
||||
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
|
||||
*
|
||||
@ -70,31 +90,58 @@ public class TCPlistener implements Runnable {
|
||||
public void run() {
|
||||
boolean g = false;
|
||||
boolean spin = true;
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
if(info.exists("OUTPORT")) {
|
||||
|
||||
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
|
||||
info.releaseReadLock();
|
||||
database.releaseReadLock();
|
||||
while(spin) {
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
while (spin) {
|
||||
try {
|
||||
rlock();
|
||||
} catch (Exception e) {
|
||||
break die;
|
||||
}
|
||||
try {
|
||||
spin = info.get("RUNNING").equals(Boolean.TRUE);
|
||||
info.releaseReadLock();
|
||||
database.releaseReadLock();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
runlock();
|
||||
} catch (Exception e2) {
|
||||
break die;
|
||||
}
|
||||
break die;
|
||||
}
|
||||
try {
|
||||
server = listener.accept();
|
||||
g = true;
|
||||
} catch(SocketTimeoutException ste) {
|
||||
} catch (SocketTimeoutException ste) {
|
||||
g = false;
|
||||
}
|
||||
if(g) {
|
||||
if (g) {
|
||||
// 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");
|
||||
t.start();
|
||||
g = false;
|
||||
@ -102,41 +149,58 @@ public class TCPlistener implements Runnable {
|
||||
}
|
||||
//System.out.println("TCPlistener: destroySession");
|
||||
listener.close();
|
||||
} catch(IOException ioe) {
|
||||
} catch (IOException ioe) {
|
||||
try {
|
||||
listener.close();
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
// Fatal failure, cause a stop event
|
||||
database.getReadLock();
|
||||
info.getReadLock();
|
||||
try {
|
||||
rlock();
|
||||
try {
|
||||
spin = info.get("RUNNING").equals(Boolean.TRUE);
|
||||
info.releaseReadLock();
|
||||
database.releaseReadLock();
|
||||
if(spin) {
|
||||
database.getWriteLock();
|
||||
info.getWriteLock();
|
||||
} catch (Exception e) {
|
||||
runlock();
|
||||
break die;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
break die;
|
||||
}
|
||||
if (spin) {
|
||||
try {
|
||||
wlock();
|
||||
try {
|
||||
info.add("STOPPING", new Boolean(true));
|
||||
info.add("RUNNING", new Boolean(false));
|
||||
info.releaseWriteLock();
|
||||
database.releaseWriteLock();
|
||||
} catch (Exception e) {
|
||||
wunlock();
|
||||
break die;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
break die;
|
||||
}
|
||||
try {
|
||||
wunlock();
|
||||
} catch (Exception e) {
|
||||
break die;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// need to kill off the socket manager too.
|
||||
I2PSession session = socketManager.getSession();
|
||||
if(session != null) {
|
||||
if (session != null) {
|
||||
try {
|
||||
session.destroySession();
|
||||
} catch(I2PSessionException ex) {
|
||||
} catch (I2PSessionException ex) {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
//System.out.println("TCPlistener: Waiting for children");
|
||||
while(Thread.activeCount() > tgwatch) { // wait for all threads in our threadgroup to finish
|
||||
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) {
|
||||
} catch (Exception e) {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ import net.i2p.i2ptunnel.I2PTunnel;
|
||||
public class TCPtoI2P implements Runnable {
|
||||
|
||||
private I2PSocket I2P;
|
||||
private NamedDB info, database;
|
||||
// private NamedDB info, database;
|
||||
private Socket sock;
|
||||
private I2PSocketManager socketManager;
|
||||
|
||||
@ -84,13 +84,13 @@ public class TCPtoI2P implements Runnable {
|
||||
* Constructor
|
||||
* @param i2p
|
||||
* @param socket
|
||||
* @param info
|
||||
* @param database
|
||||
* param info
|
||||
* param database
|
||||
*/
|
||||
TCPtoI2P(I2PSocketManager i2p, Socket socket, NamedDB info, NamedDB database) {
|
||||
TCPtoI2P(I2PSocketManager i2p, Socket socket /*, NamedDB info, NamedDB database */) {
|
||||
this.sock = socket;
|
||||
this.info = info;
|
||||
this.database = database;
|
||||
// this.info = info;
|
||||
// this.database = database;
|
||||
this.socketManager = i2p;
|
||||
}
|
||||
|
||||
@ -110,6 +110,7 @@ public class TCPtoI2P implements Runnable {
|
||||
|
||||
/**
|
||||
* TCP stream to I2P stream thread starter
|
||||
*
|
||||
*/
|
||||
public void run() {
|
||||
String line, input;
|
||||
@ -138,8 +139,8 @@ public class TCPtoI2P implements Runnable {
|
||||
InputStream Iin = I2P.getInputStream();
|
||||
OutputStream 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
|
||||
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!
|
||||
@ -167,7 +168,8 @@ public class TCPtoI2P implements Runnable {
|
||||
} catch(Exception e) {
|
||||
Emsg("ERROR " + e.toString(), out);
|
||||
}
|
||||
} catch(IOException ioe) {
|
||||
} catch(Exception e) {
|
||||
// bail on anything else
|
||||
}
|
||||
try {
|
||||
// System.out.println("TCPtoI2P: Close I2P");
|
||||
@ -181,6 +183,5 @@ public class TCPtoI2P implements Runnable {
|
||||
} catch(Exception e) {
|
||||
}
|
||||
// System.out.println("TCPtoI2P: Done.");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
|
||||
public class RouterVersion {
|
||||
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 long BUILD = 7;
|
||||
public final static long BUILD = 8;
|
||||
public static void main(String args[]) {
|
||||
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
|
||||
System.out.println("Router ID: " + RouterVersion.ID);
|
||||
|
Reference in New Issue
Block a user