From d078ed396f63c2fd3e82c32f97a71774296108ad Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 6 Nov 2009 19:16:23 +0000 Subject: [PATCH] move init, add config --- .../streaming/I2PSocketManagerFull.java | 22 +++++++++++++++ .../net/i2p/client/streaming/PacketLocal.java | 27 ++++--------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java index b904243b10..fc177ba238 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java @@ -93,6 +93,7 @@ public class I2PSocketManagerFull implements I2PSocketManager { _log.info("Socket manager created. \ndefault options: " + _defaultOptions + "\noriginal properties: " + opts); } + debugInit(context); } public I2PSocketOptions buildOptions() { return buildOptions(null); } @@ -269,4 +270,25 @@ public class I2PSocketManagerFull implements I2PSocketManager { public void removeDisconnectListener(I2PSocketManager.DisconnectListener lsnr) { _connectionManager.getMessageHandler().removeDisconnectListener(lsnr); } + + private static final Object _pcapInitLock = new Object(); + private static boolean _pcapInitialized; + static PcapWriter pcapWriter; + static final String PROP_PCAP = "i2p.streaming.pcap"; + private static final String PCAP_FILE = "streaming.pcap"; + + private static void debugInit(I2PAppContext ctx) { + if (!Boolean.valueOf(ctx.getProperty(PROP_PCAP)).booleanValue()) + return; + synchronized(_pcapInitLock) { + if (!_pcapInitialized) { + try { + pcapWriter = new PcapWriter(ctx, PCAP_FILE); + } catch (java.io.IOException ioe) { + System.err.println("pcap init ioe: " + ioe); + } + _pcapInitialized = true; + } + } + } } diff --git a/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java b/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java index 127f53131d..db4eb7293d 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java @@ -29,9 +29,6 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat private volatile int _nackCount; private volatile boolean _retransmitted; private SimpleTimer2.TimedEvent _resendEvent; - private static final Object initLock = new Object(); - private static boolean _initialized; - private static PcapWriter _pcapWriter; public PacketLocal(I2PAppContext ctx, Destination to) { this(ctx, to, null); @@ -46,12 +43,6 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat _cancelledOn = -1; _nackCount = 0; _retransmitted = false; - synchronized(initLock) { - if (!_initialized) { - initPcap(); - _initialized = true; - } - } } public Destination getTo() { return _to; } @@ -255,24 +246,16 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat public boolean writeFailed() { return _cancelledOn > 0; } public boolean writeSuccessful() { return _ackOn > 0 && _cancelledOn <= 0; } - static final String PCAP = "foo.pcap"; - private void initPcap() { - try { - _pcapWriter = new PcapWriter(_context, PCAP); - } catch (IOException ioe) { - System.err.println("pcap init ioe: " + ioe); - } - } - /** Generate a pcap/tcpdump-compatible format, * so we can use standard debugging tools. */ public void logTCPDump(boolean isInbound) { - if (!_log.shouldLog(Log.INFO)) return; - _log.info(toString()); - if (_pcapWriter != null) { + if (_log.shouldLog(Log.INFO)) + _log.info(toString()); + if (I2PSocketManagerFull.pcapWriter != null && + Boolean.valueOf(_context.getProperty(I2PSocketManagerFull.PROP_PCAP)).booleanValue()) { try { - _pcapWriter.write(this, isInbound); + I2PSocketManagerFull.pcapWriter.write(this, isInbound); } catch (IOException ioe) { _log.warn("pcap write ioe: " + ioe); } -- GitLab