* I2CP:
- New option i2cp.disableInterface to turn off external I2CP port (7654) and allow internal clients only - Disallow internal connect when shut down
This commit is contained in:
@ -43,12 +43,16 @@ import net.i2p.util.Log;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class ClientManager {
|
class ClientManager {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private ClientListenerRunner _listener;
|
private ClientListenerRunner _listener;
|
||||||
private final HashMap<Destination, ClientConnectionRunner> _runners; // Destination --> ClientConnectionRunner
|
private final HashMap<Destination, ClientConnectionRunner> _runners; // Destination --> ClientConnectionRunner
|
||||||
private final Set<ClientConnectionRunner> _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
|
private final Set<ClientConnectionRunner> _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
|
||||||
private RouterContext _ctx;
|
private final RouterContext _ctx;
|
||||||
|
private boolean _isStarted;
|
||||||
|
|
||||||
|
/** Disable external interface, allow internal clients only @since 0.8.3 */
|
||||||
|
private static final String PROP_DISABLE_EXTERNAL = "i2cp.disableInterface";
|
||||||
|
|
||||||
/** ms to wait before rechecking for inbound messages to deliver to clients */
|
/** ms to wait before rechecking for inbound messages to deliver to clients */
|
||||||
private final static int INBOUND_POLL_INTERVAL = 300;
|
private final static int INBOUND_POLL_INTERVAL = 300;
|
||||||
@ -67,11 +71,12 @@ public class ClientManager {
|
|||||||
|
|
||||||
/** Todo: Start a 3rd listener for IPV6? */
|
/** Todo: Start a 3rd listener for IPV6? */
|
||||||
private void startListeners(int port) {
|
private void startListeners(int port) {
|
||||||
_listener = new ClientListenerRunner(_ctx, this, port);
|
if (!_ctx.getBooleanProperty(PROP_DISABLE_EXTERNAL)) {
|
||||||
Thread t = new I2PThread(_listener);
|
_listener = new ClientListenerRunner(_ctx, this, port);
|
||||||
t.setName("ClientListener:" + port);
|
Thread t = new I2PThread(_listener, "ClientListener:" + port, true);
|
||||||
t.setDaemon(true);
|
t.start();
|
||||||
t.start();
|
}
|
||||||
|
_isStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restart() {
|
public void restart() {
|
||||||
@ -93,8 +98,10 @@ public class ClientManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
_isStarted = false;
|
||||||
_log.info("Shutting down the ClientManager");
|
_log.info("Shutting down the ClientManager");
|
||||||
_listener.stopListening();
|
if (_listener != null)
|
||||||
|
_listener.stopListening();
|
||||||
Set<ClientConnectionRunner> runners = new HashSet();
|
Set<ClientConnectionRunner> runners = new HashSet();
|
||||||
synchronized (_runners) {
|
synchronized (_runners) {
|
||||||
for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext();) {
|
for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext();) {
|
||||||
@ -117,10 +124,12 @@ public class ClientManager {
|
|||||||
/**
|
/**
|
||||||
* The InternalClientManager interface.
|
* The InternalClientManager interface.
|
||||||
* Connects to the router, receiving a message queue to talk to the router with.
|
* Connects to the router, receiving a message queue to talk to the router with.
|
||||||
* Might throw I2PSessionException if the router isn't ready, someday.
|
* @throws I2PSessionException if the router isn't ready
|
||||||
* @since 0.8.3
|
* @since 0.8.3
|
||||||
*/
|
*/
|
||||||
public I2CPMessageQueue internalConnect() {
|
public I2CPMessageQueue internalConnect() throws I2PSessionException {
|
||||||
|
if (!_isStarted)
|
||||||
|
throw new I2PSessionException("Router client manager is shut down");
|
||||||
// for now we make these unlimited size
|
// for now we make these unlimited size
|
||||||
LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue();
|
LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue();
|
||||||
LinkedBlockingQueue<I2CPMessage> out = new LinkedBlockingQueue();
|
LinkedBlockingQueue<I2CPMessage> out = new LinkedBlockingQueue();
|
||||||
@ -131,7 +140,9 @@ public class ClientManager {
|
|||||||
return hisQueue;
|
return hisQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlive() { return _listener.isListening(); }
|
public boolean isAlive() {
|
||||||
|
return _isStarted && (_listener == null || _listener.isListening());
|
||||||
|
}
|
||||||
|
|
||||||
public void registerConnection(ClientConnectionRunner runner) {
|
public void registerConnection(ClientConnectionRunner runner) {
|
||||||
synchronized (_pendingRunners) {
|
synchronized (_pendingRunners) {
|
||||||
|
Reference in New Issue
Block a user