Better handling of listening sockets.
This commit is contained in:
@ -25,6 +25,8 @@ package net.i2p.BOB;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.ServerSocket;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import net.i2p.I2PException;
|
import net.i2p.I2PException;
|
||||||
import net.i2p.client.streaming.I2PSocketManager;
|
import net.i2p.client.streaming.I2PSocketManager;
|
||||||
@ -45,9 +47,12 @@ public class MUXlisten implements Runnable {
|
|||||||
private ByteArrayInputStream prikey;
|
private ByteArrayInputStream prikey;
|
||||||
private ThreadGroup tg;
|
private ThreadGroup tg;
|
||||||
private String N;
|
private String N;
|
||||||
|
private ServerSocket listener;
|
||||||
|
private int backlog = 50; // should this be more? less?
|
||||||
|
boolean go_out;
|
||||||
|
boolean come_in;
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor Will fail if INPORT is occupied.
|
||||||
*
|
*
|
||||||
* @param info
|
* @param info
|
||||||
* @param database
|
* @param database
|
||||||
@ -56,6 +61,8 @@ public class MUXlisten implements Runnable {
|
|||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
MUXlisten(nickname database, nickname info, Log _log) throws I2PException, IOException {
|
MUXlisten(nickname database, nickname info, Log _log) throws I2PException, IOException {
|
||||||
|
int port = 0;
|
||||||
|
InetAddress host = null;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this._log = _log;
|
this._log = _log;
|
||||||
@ -68,13 +75,28 @@ public class MUXlisten implements Runnable {
|
|||||||
this.database.releaseReadLock();
|
this.database.releaseReadLock();
|
||||||
this.info.releaseReadLock();
|
this.info.releaseReadLock();
|
||||||
|
|
||||||
|
this.database.getReadLock();
|
||||||
|
this.info.getReadLock();
|
||||||
|
this.go_out = info.exists("OUTPORT");
|
||||||
|
this.come_in = info.exists("INPORT");
|
||||||
|
if(this.come_in) {
|
||||||
|
port = Integer.parseInt(info.get("INPORT").toString());
|
||||||
|
host = InetAddress.getByName(info.get("INHOST").toString());
|
||||||
|
}
|
||||||
|
this.database.releaseReadLock();
|
||||||
|
this.info.releaseReadLock();
|
||||||
|
|
||||||
|
socketManager = I2PSocketManagerFactory.createManager(prikey, Q);
|
||||||
|
if(this.come_in) {
|
||||||
|
this.listener = new ServerSocket(port, backlog, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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", Boolean.TRUE);
|
||||||
this.info.releaseWriteLock();
|
this.info.releaseWriteLock();
|
||||||
this.database.releaseWriteLock();
|
this.database.releaseWriteLock();
|
||||||
|
|
||||||
socketManager = I2PSocketManagerFactory.createManager(prikey, Q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,12 +117,6 @@ public class MUXlisten implements Runnable {
|
|||||||
|
|
||||||
// toss the connections to a new threads.
|
// toss the connections to a new threads.
|
||||||
// will wrap with TCP and UDP when UDP works
|
// will wrap with TCP and UDP when UDP works
|
||||||
this.database.getReadLock();
|
|
||||||
this.info.getReadLock();
|
|
||||||
boolean go_out = info.exists("OUTPORT");
|
|
||||||
boolean come_in = info.exists("INPORT");
|
|
||||||
this.database.releaseReadLock();
|
|
||||||
this.info.releaseReadLock();
|
|
||||||
|
|
||||||
if(go_out) {
|
if(go_out) {
|
||||||
// I2P -> TCP
|
// I2P -> TCP
|
||||||
@ -111,7 +127,7 @@ public class MUXlisten implements Runnable {
|
|||||||
|
|
||||||
if(come_in) {
|
if(come_in) {
|
||||||
// TCP -> I2P
|
// TCP -> I2P
|
||||||
TCPlistener conn = new TCPlistener(socketManager, info, database, _log);
|
TCPlistener conn = new TCPlistener(listener, socketManager, info, database, _log);
|
||||||
Thread q = new Thread(tg, conn, "BOBTCPlistener" + N);
|
Thread q = new Thread(tg, conn, "BOBTCPlistener" + N);
|
||||||
q.start();
|
q.start();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
package net.i2p.BOB;
|
package net.i2p.BOB;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
@ -46,7 +45,7 @@ public class TCPlistener implements Runnable {
|
|||||||
private int tgwatch;
|
private int tgwatch;
|
||||||
public I2PSocketManager socketManager;
|
public I2PSocketManager socketManager;
|
||||||
public I2PServerSocket serverSocket;
|
public I2PServerSocket serverSocket;
|
||||||
private int backlog = 50; // should this be more? less?
|
private ServerSocket listener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -55,11 +54,12 @@ public class TCPlistener implements Runnable {
|
|||||||
* @param database
|
* @param database
|
||||||
* @param _log
|
* @param _log
|
||||||
*/
|
*/
|
||||||
TCPlistener(I2PSocketManager S, nickname info, nickname database, Log _log) {
|
TCPlistener(ServerSocket listener, I2PSocketManager S, nickname info, nickname database, Log _log) {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this._log = _log;
|
this._log = _log;
|
||||||
this.socketManager = S;
|
this.socketManager = S;
|
||||||
|
this.listener = listener;
|
||||||
tgwatch = 1;
|
tgwatch = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,6 @@ public class TCPlistener implements Runnable {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// System.out.println("Starting thread count " + Thread.activeCount());
|
// System.out.println("Starting thread count " + Thread.activeCount());
|
||||||
ServerSocket listener = new ServerSocket(Integer.parseInt(info.get("INPORT").toString()), backlog, InetAddress.getByName(info.get("INHOST").toString()));
|
|
||||||
Socket server = new Socket();
|
Socket server = new Socket();
|
||||||
listener.setSoTimeout(1000);
|
listener.setSoTimeout(1000);
|
||||||
info.releaseReadLock();
|
info.releaseReadLock();
|
||||||
|
@ -493,8 +493,6 @@ public class doCMDS implements Runnable {
|
|||||||
wlock();
|
wlock();
|
||||||
database.add(Arg, nickinfo);
|
database.add(Arg, nickinfo);
|
||||||
nickinfo.add(P_NICKNAME, Arg);
|
nickinfo.add(P_NICKNAME, Arg);
|
||||||
// nickinfo.add(P_INSTATE,new Boolean(false));
|
|
||||||
// nickinfo.add(P_OUTSTATE,new Boolean(false));
|
|
||||||
nickinfo.add(P_STARTING, Boolean.FALSE);
|
nickinfo.add(P_STARTING, Boolean.FALSE);
|
||||||
nickinfo.add(P_RUNNING, Boolean.FALSE);
|
nickinfo.add(P_RUNNING, Boolean.FALSE);
|
||||||
nickinfo.add(P_STOPPING, Boolean.FALSE);
|
nickinfo.add(P_STOPPING, Boolean.FALSE);
|
||||||
|
Reference in New Issue
Block a user