* Tunnels: Debug code and other cleanups

This commit is contained in:
zzz
2014-08-21 11:55:03 +00:00
parent 57650ef058
commit 51e45d128a
5 changed files with 34 additions and 24 deletions

View File

@ -48,6 +48,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
private long _pendingSince;
private final String _name;
private static final boolean DEBUG = false;
public BatchedPreprocessor(RouterContext ctx, String name) {
super(ctx);
_name = name;
@ -175,7 +177,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
+ " len=" + cur.getData().length + " alloc=" + allocated);
if (timingBuf != null)
timingBuf.append(" sent " + cur);
notePreprocessing(cur.getMessageId(), cur.getFragmentNumber(), cur.getData().length, cur.getMessageIds(), "flushed allocated");
if (DEBUG)
notePreprocessing(cur.getMessageId(), cur.getFragmentNumber(), cur.getData().length, cur.getMessageIds(), "flushed allocated");
_context.statManager().addRateData("tunnel.batchFragmentation", cur.getFragmentNumber() + 1);
_context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length);
}
@ -184,7 +187,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
PendingGatewayMessage cur = pending.remove(0);
if (timingBuf != null)
timingBuf.append(" sent perfect fit " + cur).append(".");
notePreprocessing(cur.getMessageId(), cur.getFragmentNumber(), msg.getData().length, msg.getMessageIds(), "flushed tail, remaining: " + pending);
if (DEBUG)
notePreprocessing(cur.getMessageId(), cur.getFragmentNumber(), msg.getData().length, msg.getMessageIds(), "flushed tail, remaining: " + pending);
_context.statManager().addRateData("tunnel.batchFragmentation", cur.getFragmentNumber() + 1);
_context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length);
}
@ -234,7 +238,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
if (cur.getOffset() < cur.getData().length)
break;
pending.remove(0);
notePreprocessing(cur.getMessageId(), cur.getFragmentNumber(), cur.getData().length, cur.getMessageIds(), "flushed remaining");
if (DEBUG)
notePreprocessing(cur.getMessageId(), cur.getFragmentNumber(), cur.getData().length, cur.getMessageIds(), "flushed remaining");
_context.statManager().addRateData("tunnel.batchFragmentation", cur.getFragmentNumber() + 1);
_context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length);
}
@ -383,9 +388,12 @@ class BatchedPreprocessor extends TrivialPreprocessor {
}
long msgId = sender.sendPreprocessed(preprocessed, rec);
for (int i = 0; i < pending.size(); i++) {
PendingGatewayMessage cur = pending.get(i);
cur.addMessageId(msgId);
if (DEBUG) {
// creates a list in PGM
for (int i = 0; i < pending.size(); i++) {
PendingGatewayMessage cur = pending.get(i);
cur.addMessageId(msgId);
}
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("Sent " + startAt + ":" + sendThrough + " out of " + pending + " in message " + msgId);

View File

@ -11,8 +11,8 @@ import net.i2p.router.RouterContext;
*
*/
class BatchedRouterPreprocessor extends BatchedPreprocessor {
private TunnelCreatorConfig _config;
protected HopConfig _hopConfig;
private final TunnelCreatorConfig _config;
protected final HopConfig _hopConfig;
private final long _sendDelay;
/**
@ -34,12 +34,14 @@ class BatchedRouterPreprocessor extends BatchedPreprocessor {
public BatchedRouterPreprocessor(RouterContext ctx, TunnelCreatorConfig cfg) {
super(ctx, getName(cfg));
_config = cfg;
_hopConfig = null;
_sendDelay = initialSendDelay();
}
/** for IBGWs */
public BatchedRouterPreprocessor(RouterContext ctx, HopConfig cfg) {
super(ctx, getName(cfg));
_config = null;
_hopConfig = cfg;
_sendDelay = initialSendDelay();
}

View File

@ -10,30 +10,30 @@ import net.i2p.util.Log;
*
*/
class OutboundSender implements TunnelGateway.Sender {
private final I2PAppContext _context;
private final Log _log;
//private final I2PAppContext _context;
//private final Log _log;
private final TunnelCreatorConfig _config;
private final OutboundGatewayProcessor _processor;
//static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
public OutboundSender(I2PAppContext ctx, TunnelCreatorConfig config) {
_context = ctx;
_log = ctx.logManager().getLog(OutboundSender.class);
//_context = ctx;
//_log = ctx.logManager().getLog(OutboundSender.class);
_config = config;
_processor = new OutboundGatewayProcessor(_context, config);
_processor = new OutboundGatewayProcessor(ctx, config);
}
public long sendPreprocessed(byte[] preprocessed, TunnelGateway.Receiver receiver) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("preprocessed data going out " + _config + ": " + Base64.encode(preprocessed));
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("preprocessed data going out " + _config + ": " + Base64.encode(preprocessed));
//if (USE_ENCRYPTION)
_processor.process(preprocessed, 0, preprocessed.length);
if (_log.shouldLog(Log.DEBUG))
_log.debug("after wrapping up the preprocessed data on " + _config);
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("after wrapping up the preprocessed data on " + _config);
long rv = receiver.receiveEncrypted(preprocessed);
if (_log.shouldLog(Log.DEBUG))
_log.debug("after receiving on " + _config + ": receiver = " + receiver);
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("after receiving on " + _config + ": receiver = " + receiver);
return rv;
}
}

View File

@ -18,7 +18,7 @@ import net.i2p.util.SimpleByteCache;
*
* See FragmentHandler Javadoc for tunnel message fragment format
*/
class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
abstract class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
protected final RouterContext _context;
protected final Log _log;
@ -48,7 +48,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
* NOTE: Unused here, see BatchedPreprocessor override, super is not called.
*/
public boolean preprocessQueue(List<PendingGatewayMessage> pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) {
throw new IllegalArgumentException("unused, right?");
throw new UnsupportedOperationException("unused, right?");
}
protected void notePreprocessing(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg) {}
@ -265,7 +265,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
* Does NOT include 4 for the message ID if the message will be fragmented;
* call getInstructionAugmentationSize() for that.
*/
protected int getInstructionsSize(PendingGatewayMessage msg) {
protected static int getInstructionsSize(PendingGatewayMessage msg) {
if (msg.getFragmentNumber() > 0)
return 7;
// control byte
@ -283,7 +283,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
}
/** @return 0 or 4 */
protected int getInstructionAugmentationSize(PendingGatewayMessage msg, int offset, int instructionsSize) {
protected static int getInstructionAugmentationSize(PendingGatewayMessage msg, int offset, int instructionsSize) {
int payloadLength = msg.getData().length - msg.getOffset();
if (offset + payloadLength + instructionsSize + IV_SIZE + 1 + 4 > PREPROCESSED_SIZE) {
// requires fragmentation, so include the messageId

View File

@ -33,7 +33,7 @@ import net.i2p.util.SimpleTimer2;
*
* Unused directly - see PumpedTunnelGateway, ThrottledPumpedTunnelGateway, and TunnelGatewayZeroHop overrides.
*/
class TunnelGateway {
abstract class TunnelGateway {
protected final RouterContext _context;
protected final Log _log;
protected final List<PendingGatewayMessage> _queue;