I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 51e45d12 authored by zzz's avatar zzz
Browse files

* Tunnels: Debug code and other cleanups

parent 57650ef0
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,8 @@ class BatchedPreprocessor extends TrivialPreprocessor { ...@@ -48,6 +48,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
private long _pendingSince; private long _pendingSince;
private final String _name; private final String _name;
private static final boolean DEBUG = false;
public BatchedPreprocessor(RouterContext ctx, String name) { public BatchedPreprocessor(RouterContext ctx, String name) {
super(ctx); super(ctx);
_name = name; _name = name;
...@@ -175,7 +177,8 @@ class BatchedPreprocessor extends TrivialPreprocessor { ...@@ -175,7 +177,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
+ " len=" + cur.getData().length + " alloc=" + allocated); + " len=" + cur.getData().length + " alloc=" + allocated);
if (timingBuf != null) if (timingBuf != null)
timingBuf.append(" sent " + cur); 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.batchFragmentation", cur.getFragmentNumber() + 1);
_context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length); _context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length);
} }
...@@ -184,7 +187,8 @@ class BatchedPreprocessor extends TrivialPreprocessor { ...@@ -184,7 +187,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
PendingGatewayMessage cur = pending.remove(0); PendingGatewayMessage cur = pending.remove(0);
if (timingBuf != null) if (timingBuf != null)
timingBuf.append(" sent perfect fit " + cur).append("."); 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.batchFragmentation", cur.getFragmentNumber() + 1);
_context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length); _context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length);
} }
...@@ -234,7 +238,8 @@ class BatchedPreprocessor extends TrivialPreprocessor { ...@@ -234,7 +238,8 @@ class BatchedPreprocessor extends TrivialPreprocessor {
if (cur.getOffset() < cur.getData().length) if (cur.getOffset() < cur.getData().length)
break; break;
pending.remove(0); 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.batchFragmentation", cur.getFragmentNumber() + 1);
_context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length); _context.statManager().addRateData("tunnel.writeDelay", cur.getLifetime(), cur.getData().length);
} }
...@@ -383,9 +388,12 @@ class BatchedPreprocessor extends TrivialPreprocessor { ...@@ -383,9 +388,12 @@ class BatchedPreprocessor extends TrivialPreprocessor {
} }
long msgId = sender.sendPreprocessed(preprocessed, rec); long msgId = sender.sendPreprocessed(preprocessed, rec);
for (int i = 0; i < pending.size(); i++) { if (DEBUG) {
PendingGatewayMessage cur = pending.get(i); // creates a list in PGM
cur.addMessageId(msgId); for (int i = 0; i < pending.size(); i++) {
PendingGatewayMessage cur = pending.get(i);
cur.addMessageId(msgId);
}
} }
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Sent " + startAt + ":" + sendThrough + " out of " + pending + " in message " + msgId); _log.debug("Sent " + startAt + ":" + sendThrough + " out of " + pending + " in message " + msgId);
......
...@@ -11,8 +11,8 @@ import net.i2p.router.RouterContext; ...@@ -11,8 +11,8 @@ import net.i2p.router.RouterContext;
* *
*/ */
class BatchedRouterPreprocessor extends BatchedPreprocessor { class BatchedRouterPreprocessor extends BatchedPreprocessor {
private TunnelCreatorConfig _config; private final TunnelCreatorConfig _config;
protected HopConfig _hopConfig; protected final HopConfig _hopConfig;
private final long _sendDelay; private final long _sendDelay;
/** /**
...@@ -34,12 +34,14 @@ class BatchedRouterPreprocessor extends BatchedPreprocessor { ...@@ -34,12 +34,14 @@ class BatchedRouterPreprocessor extends BatchedPreprocessor {
public BatchedRouterPreprocessor(RouterContext ctx, TunnelCreatorConfig cfg) { public BatchedRouterPreprocessor(RouterContext ctx, TunnelCreatorConfig cfg) {
super(ctx, getName(cfg)); super(ctx, getName(cfg));
_config = cfg; _config = cfg;
_hopConfig = null;
_sendDelay = initialSendDelay(); _sendDelay = initialSendDelay();
} }
/** for IBGWs */ /** for IBGWs */
public BatchedRouterPreprocessor(RouterContext ctx, HopConfig cfg) { public BatchedRouterPreprocessor(RouterContext ctx, HopConfig cfg) {
super(ctx, getName(cfg)); super(ctx, getName(cfg));
_config = null;
_hopConfig = cfg; _hopConfig = cfg;
_sendDelay = initialSendDelay(); _sendDelay = initialSendDelay();
} }
......
...@@ -10,30 +10,30 @@ import net.i2p.util.Log; ...@@ -10,30 +10,30 @@ import net.i2p.util.Log;
* *
*/ */
class OutboundSender implements TunnelGateway.Sender { class OutboundSender implements TunnelGateway.Sender {
private final I2PAppContext _context; //private final I2PAppContext _context;
private final Log _log; //private final Log _log;
private final TunnelCreatorConfig _config; private final TunnelCreatorConfig _config;
private final OutboundGatewayProcessor _processor; private final OutboundGatewayProcessor _processor;
//static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION; //static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
public OutboundSender(I2PAppContext ctx, TunnelCreatorConfig config) { public OutboundSender(I2PAppContext ctx, TunnelCreatorConfig config) {
_context = ctx; //_context = ctx;
_log = ctx.logManager().getLog(OutboundSender.class); //_log = ctx.logManager().getLog(OutboundSender.class);
_config = config; _config = config;
_processor = new OutboundGatewayProcessor(_context, config); _processor = new OutboundGatewayProcessor(ctx, config);
} }
public long sendPreprocessed(byte[] preprocessed, TunnelGateway.Receiver receiver) { public long sendPreprocessed(byte[] preprocessed, TunnelGateway.Receiver receiver) {
if (_log.shouldLog(Log.DEBUG)) //if (_log.shouldLog(Log.DEBUG))
_log.debug("preprocessed data going out " + _config + ": " + Base64.encode(preprocessed)); // _log.debug("preprocessed data going out " + _config + ": " + Base64.encode(preprocessed));
//if (USE_ENCRYPTION) //if (USE_ENCRYPTION)
_processor.process(preprocessed, 0, preprocessed.length); _processor.process(preprocessed, 0, preprocessed.length);
if (_log.shouldLog(Log.DEBUG)) //if (_log.shouldLog(Log.DEBUG))
_log.debug("after wrapping up the preprocessed data on " + _config); // _log.debug("after wrapping up the preprocessed data on " + _config);
long rv = receiver.receiveEncrypted(preprocessed); long rv = receiver.receiveEncrypted(preprocessed);
if (_log.shouldLog(Log.DEBUG)) //if (_log.shouldLog(Log.DEBUG))
_log.debug("after receiving on " + _config + ": receiver = " + receiver); // _log.debug("after receiving on " + _config + ": receiver = " + receiver);
return rv; return rv;
} }
} }
...@@ -18,7 +18,7 @@ import net.i2p.util.SimpleByteCache; ...@@ -18,7 +18,7 @@ import net.i2p.util.SimpleByteCache;
* *
* See FragmentHandler Javadoc for tunnel message fragment format * 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 RouterContext _context;
protected final Log _log; protected final Log _log;
...@@ -48,7 +48,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor { ...@@ -48,7 +48,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
* NOTE: Unused here, see BatchedPreprocessor override, super is not called. * NOTE: Unused here, see BatchedPreprocessor override, super is not called.
*/ */
public boolean preprocessQueue(List<PendingGatewayMessage> pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) { 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) {} protected void notePreprocessing(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg) {}
...@@ -265,7 +265,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor { ...@@ -265,7 +265,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
* Does NOT include 4 for the message ID if the message will be fragmented; * Does NOT include 4 for the message ID if the message will be fragmented;
* call getInstructionAugmentationSize() for that. * call getInstructionAugmentationSize() for that.
*/ */
protected int getInstructionsSize(PendingGatewayMessage msg) { protected static int getInstructionsSize(PendingGatewayMessage msg) {
if (msg.getFragmentNumber() > 0) if (msg.getFragmentNumber() > 0)
return 7; return 7;
// control byte // control byte
...@@ -283,7 +283,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor { ...@@ -283,7 +283,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
} }
/** @return 0 or 4 */ /** @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(); int payloadLength = msg.getData().length - msg.getOffset();
if (offset + payloadLength + instructionsSize + IV_SIZE + 1 + 4 > PREPROCESSED_SIZE) { if (offset + payloadLength + instructionsSize + IV_SIZE + 1 + 4 > PREPROCESSED_SIZE) {
// requires fragmentation, so include the messageId // requires fragmentation, so include the messageId
......
...@@ -33,7 +33,7 @@ import net.i2p.util.SimpleTimer2; ...@@ -33,7 +33,7 @@ import net.i2p.util.SimpleTimer2;
* *
* Unused directly - see PumpedTunnelGateway, ThrottledPumpedTunnelGateway, and TunnelGatewayZeroHop overrides. * Unused directly - see PumpedTunnelGateway, ThrottledPumpedTunnelGateway, and TunnelGatewayZeroHop overrides.
*/ */
class TunnelGateway { abstract class TunnelGateway {
protected final RouterContext _context; protected final RouterContext _context;
protected final Log _log; protected final Log _log;
protected final List<PendingGatewayMessage> _queue; protected final List<PendingGatewayMessage> _queue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment