forked from I2P_Developers/i2p.i2p
move init, add config
This commit is contained in:
@@ -93,6 +93,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
|||||||
_log.info("Socket manager created. \ndefault options: " + _defaultOptions
|
_log.info("Socket manager created. \ndefault options: " + _defaultOptions
|
||||||
+ "\noriginal properties: " + opts);
|
+ "\noriginal properties: " + opts);
|
||||||
}
|
}
|
||||||
|
debugInit(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public I2PSocketOptions buildOptions() { return buildOptions(null); }
|
public I2PSocketOptions buildOptions() { return buildOptions(null); }
|
||||||
@@ -269,4 +270,25 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
|||||||
public void removeDisconnectListener(I2PSocketManager.DisconnectListener lsnr) {
|
public void removeDisconnectListener(I2PSocketManager.DisconnectListener lsnr) {
|
||||||
_connectionManager.getMessageHandler().removeDisconnectListener(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,9 +29,6 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
|||||||
private volatile int _nackCount;
|
private volatile int _nackCount;
|
||||||
private volatile boolean _retransmitted;
|
private volatile boolean _retransmitted;
|
||||||
private SimpleTimer2.TimedEvent _resendEvent;
|
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) {
|
public PacketLocal(I2PAppContext ctx, Destination to) {
|
||||||
this(ctx, to, null);
|
this(ctx, to, null);
|
||||||
@@ -46,12 +43,6 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
|||||||
_cancelledOn = -1;
|
_cancelledOn = -1;
|
||||||
_nackCount = 0;
|
_nackCount = 0;
|
||||||
_retransmitted = false;
|
_retransmitted = false;
|
||||||
synchronized(initLock) {
|
|
||||||
if (!_initialized) {
|
|
||||||
initPcap();
|
|
||||||
_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Destination getTo() { return _to; }
|
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 writeFailed() { return _cancelledOn > 0; }
|
||||||
public boolean writeSuccessful() { return _ackOn > 0 && _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,
|
/** Generate a pcap/tcpdump-compatible format,
|
||||||
* so we can use standard debugging tools.
|
* so we can use standard debugging tools.
|
||||||
*/
|
*/
|
||||||
public void logTCPDump(boolean isInbound) {
|
public void logTCPDump(boolean isInbound) {
|
||||||
if (!_log.shouldLog(Log.INFO)) return;
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info(toString());
|
_log.info(toString());
|
||||||
if (_pcapWriter != null) {
|
if (I2PSocketManagerFull.pcapWriter != null &&
|
||||||
|
Boolean.valueOf(_context.getProperty(I2PSocketManagerFull.PROP_PCAP)).booleanValue()) {
|
||||||
try {
|
try {
|
||||||
_pcapWriter.write(this, isInbound);
|
I2PSocketManagerFull.pcapWriter.write(this, isInbound);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
_log.warn("pcap write ioe: " + ioe);
|
_log.warn("pcap write ioe: " + ioe);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user