diff --git a/router/java/src/net/i2p/router/InNetMessagePool.java b/router/java/src/net/i2p/router/InNetMessagePool.java index 790a343553..afdb8a8f67 100644 --- a/router/java/src/net/i2p/router/InNetMessagePool.java +++ b/router/java/src/net/i2p/router/InNetMessagePool.java @@ -44,7 +44,7 @@ public class InNetMessagePool implements Service { private SharedShortCircuitGatewayJob _shortCircuitGatewayJob; private boolean _alive; - private boolean _dispatchThreaded; + private final boolean _dispatchThreaded; /** Make this >= the max I2NP message type number (currently 24) */ private static final int MAX_I2NP_MESSAGE_TYPE = 31; @@ -56,20 +56,40 @@ public class InNetMessagePool implements Service { * if this is set to false, the messages will be queued up in the jobQueue, * using the jobQueue's single thread. * + * There's three possible cases that might work: + * DISPATCH_DIRECT=true (default, unqueued) + * DISPATCH_DIRECT=false with router.dispatchThreaded=false (job queue) + * DISPATCH_DIRECT=false with router.dispatchThreaded=true (INMP queue) + * + * The fourth case, + * DISPATCH_DIRECT=true with router.dispatchThreaded=true + * will never work, is now prevented below. + * + * Both must be configured before starting. + * Changing defaults not recommended, non-default code to be removed. + * Ref: Ticket 2688 */ - public static final String PROP_DISPATCH_THREADED = "router.dispatchThreaded"; - public static final boolean DEFAULT_DISPATCH_THREADED = false; + private static final String PROP_DISPATCH_THREADED = "router.dispatchThreaded"; + private static final boolean DEFAULT_DISPATCH_THREADED = false; /** * If we aren't doing threaded dispatch for tunnel messages, should we * call the actual dispatch() method inline (on the same thread which * called add())? If false, we queue it up in a shared short circuit * job. + * + * false = job queue + * true = INMP queue */ - private static final boolean DISPATCH_DIRECT = true; + private static final String PROP_DISPATCH_DIRECT = "router.dispatchDirect"; + private static final boolean DEFAULT_DISPATCH_DIRECT = true; + private final boolean DISPATCH_DIRECT; public InNetMessagePool(RouterContext context) { _context = context; _handlerJobBuilders = new HandlerJobBuilder[MAX_I2NP_MESSAGE_TYPE + 1]; + _dispatchThreaded = _context.getProperty(PROP_DISPATCH_THREADED, DEFAULT_DISPATCH_THREADED); + // must be false if threaded is true + DISPATCH_DIRECT = !_dispatchThreaded && _context.getProperty(PROP_DISPATCH_DIRECT, DEFAULT_DISPATCH_DIRECT); if (DISPATCH_DIRECT) { // keep the compiler happy since they are final _pendingDataMessages = null; @@ -128,8 +148,8 @@ public class InNetMessagePool implements Service { public int add(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash) { long exp = messageBody.getMessageExpiration(); - if (_log.shouldLog(Log.INFO)) - _log.info("Rcvd" + if (_log.shouldDebug()) + _log.debug("Rcvd" + " ID " + messageBody.getUniqueId() + " exp. " + new Date(exp) + " type " + messageBody.getClass().getSimpleName()); @@ -313,8 +333,8 @@ public class InNetMessagePool implements Service { } private void doShortCircuitTunnelGateway(I2NPMessage messageBody) { - if (_log.shouldLog(Log.DEBUG)) - _log.debug("Shortcut dispatch tunnelGateway message " + messageBody); + //if (_log.shouldLog(Log.DEBUG)) + // _log.debug("Shortcut dispatch tunnelGateway message " + messageBody); _context.tunnelDispatcher().dispatch((TunnelGatewayMessage)messageBody); } @@ -333,8 +353,8 @@ public class InNetMessagePool implements Service { } } private void doShortCircuitTunnelData(I2NPMessage messageBody, Hash from) { - if (_log.shouldLog(Log.DEBUG)) - _log.debug("Shortcut dispatch tunnelData message " + messageBody); + //if (_log.shouldLog(Log.DEBUG)) + // _log.debug("Shortcut dispatch tunnelData message " + messageBody); _context.tunnelDispatcher().dispatch((TunnelDataMessage)messageBody, from); } @@ -362,11 +382,6 @@ public class InNetMessagePool implements Service { /** does nothing since we aren't threaded */ public synchronized void startup() { _alive = true; - _dispatchThreaded = DEFAULT_DISPATCH_THREADED; - String threadedStr = _context.getProperty(PROP_DISPATCH_THREADED); - if (threadedStr != null) { - _dispatchThreaded = Boolean.parseBoolean(threadedStr); - } if (_dispatchThreaded) { _context.statManager().createRateStat("pool.dispatchDataTime", "How long a tunnel dispatch takes", "Tunnels", new long[] { 10*60*1000l, 60*60*1000l, 24*60*60*1000l }); _context.statManager().createRateStat("pool.dispatchGatewayTime", "How long a tunnel gateway dispatch takes", "Tunnels", new long[] { 10*60*1000l, 60*60*1000l, 24*60*60*1000l });