logging, formatting

This commit is contained in:
jrandom
2004-04-22 03:09:03 +00:00
committed by zzz
parent 4fe7105e2f
commit afeecdf4af

View File

@ -79,7 +79,8 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
private final static int DEFAULT_MAX_QUEUED_MESSAGES = 20;
static {
StatManager.getInstance().createRateStat("tcp.queueSize", "How many messages were already in the queue when a new message was added?", "TCP Transport", new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l });
StatManager.getInstance().createRateStat("tcp.queueSize", "How many messages were already in the queue when a new message was added?",
"TCP Transport", new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l });
}
public TCPConnection(Socket s, RouterIdentity myIdent, SigningPrivateKey signingKey, boolean locallyInitiated) {
@ -101,7 +102,7 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
_extraBytes = null;
_lastSliceRun = -1;
if (_log.shouldLog(Log.INFO))
_log.info("Connected with peer: " + s.getInetAddress() + ":" + s.getPort());
updateMaxQueuedMessages();
}
@ -124,6 +125,7 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
_maxQueuedMessages = max;
return;
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid max queued messages [" + str + "]");
}
}
@ -175,7 +177,6 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
_out.write(encr);
// we've identified ourselves, now read who they are
int rlen = (int)DataHelper.readLong(_in, 2);
byte pencr[] = new byte[rlen];
int read = DataHelper.read(_in, pencr);
@ -218,7 +219,8 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
throw new DataFormatException("Station to station identification failed! MITM?");
else {
if (_log.shouldLog(Log.INFO))
_log.info("TCP connection " + _id + " established with " + _remoteIdentity.getHash().toBase64());
_log.info("TCP connection " + _id + " established with "
+ _remoteIdentity.getHash().toBase64());
_in = new AESInputStream(new BandwidthLimitedInputStream(_in, _remoteIdentity), _key, _iv);
_out = new AESOutputStream(new BandwidthLimitedOutputStream(_out, _remoteIdentity), _key, _iv);
_socket.setSoTimeout(0);
@ -247,7 +249,7 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
public void runConnection() {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Run connection");
log.debug("Run connection");
_runner = new ConnectionRunner();
Thread t = new I2PThread(_runner);
t.setName("Run Conn [" + _id + "]");
@ -280,7 +282,7 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
if (fail) {
if (_log.shouldLog(Log.ERROR))
_log.error("too many queued messages");
_log.error("too many queued messages to " + _remoteIdentity.getHash().toBase64());
msg.timestamp("TCPConnection.addMessage exceeded max queued");
_transport.afterSend(msg, false);
@ -303,8 +305,12 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
}
if (slicesTooLong()) {
if (_log.shouldLog(Log.ERROR))
_log.error("onAdd: Slices are taking too long (" + (Clock.getInstance().now()-_lastSliceRun) +"ms) - perhaps the remote side is disconnected or hung? remote=" + _remoteIdentity.getHash().toBase64());
if (_log.shouldLog(Log.ERROR)) {
long sliceTime = Clock.getInstance().now()-_lastSliceRun;
_log.error("onAdd: Slices are taking too long (" + sliceTime
+ "ms) - perhaps the remote side is disconnected or hung? remote="
+ _remoteIdentity.getHash().toBase64());
}
closeConnection();
}
}
@ -314,11 +320,14 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
_closed = true;
if (_remoteIdentity != null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Closing the connection to " + _remoteIdentity.getHash().toBase64(), new Exception("Closed by"));
_log.warn("Closing the connection to " + _remoteIdentity.getHash().toBase64(),
new Exception("Closed by"));
} else {
if (_socket != null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Closing the unestablished connection with " + _socket.getInetAddress().toString() + ":" + _socket.getPort(), new Exception("Closed by"));
_log.warn("Closing the unestablished connection with "
+ _socket.getInetAddress().toString() + ":"
+ _socket.getPort(), new Exception("Closed by"));
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Closing the unestablished connection", new Exception("Closed by"));
@ -336,7 +345,8 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
OutNetMessage msg = (OutNetMessage)iter.next();
msg.timestamp("TCPTransport.closeConnection caused fail");
if (_log.shouldLog(Log.WARN))
_log.warn("Connection closed while the message was sitting on the TCP Connection's queue! too slow by: " + (now-msg.getExpiration()) + "ms: " + msg);
_log.warn("Connection closed while the message was sitting on the TCP Connection's queue! too slow by: "
+ (now-msg.getExpiration()) + "ms: " + msg);
_transport.afterSend(msg, false);
}
_toBeSent.clear();
@ -373,8 +383,12 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
}
if (slicesTooLong()) {
if (_log.shouldLog(Log.ERROR))
_log.error("onReceive: Slices are taking too long (" + (Clock.getInstance().now()-_lastSliceRun) +"ms) - perhaps the remote side is disconnected or hung? peer = " + _remoteIdentity.getHash().toBase64());
if (_log.shouldLog(Log.ERROR)) {
long sliceTime = Clock.getInstance().now()-_lastSliceRun;
_log.error("onReceive: Slices are taking too long (" + sliceTime
+ "ms) - perhaps the remote side is disconnected or hung? peer = "
+ _remoteIdentity.getHash().toBase64());
}
closeConnection();
}
}
@ -407,7 +421,6 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
return (diff > MAX_SLICE_DURATION);
}
class ConnectionRunner implements Runnable {
private boolean _running;
public void run() {
@ -421,7 +434,8 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
}
} catch (IOException ioe) {
if (_log.shouldLog(Log.ERROR))
_log.error("Connection runner failed with an IO exception to " + _remoteIdentity.getHash().toBase64(), ioe);
_log.error("Connection runner failed with an IO exception to "
+ _remoteIdentity.getHash().toBase64(), ioe);
closeConnection();
} catch (Throwable t) {
if (_log.shouldLog(Log.ERROR))
@ -460,7 +474,9 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
for (Iterator iter = timedOut.iterator(); iter.hasNext(); ) {
OutNetMessage failed = (OutNetMessage)iter.next();
if (_log.shouldLog(Log.WARN))
_log.warn("Message timed out while sitting on the TCP Connection's queue! was too slow by: " + (start-msg.getExpiration()) + "ms to " + _remoteIdentity.getHash().toBase64() + ": " + msg);
_log.warn("Message timed out while sitting on the TCP Connection's queue! was too slow by: "
+ (start-msg.getExpiration()) + "ms to "
+ _remoteIdentity.getHash().toBase64() + ": " + msg);
msg.timestamp("TCPConnection.runner.processSlice expired");
_transport.afterSend(msg, false);
return;
@ -480,9 +496,11 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
try {
byte data[] = msg.getMessageData();
msg.timestamp("TCPConnection.runner.processSlice before sending " + data.length + " bytes");
msg.timestamp("TCPConnection.runner.processSlice before sending "
+ data.length + " bytes");
if (_log.shouldLog(Log.DEBUG))
_log.debug("Sending " + data.length + " bytes in the slice... to " + _remoteIdentity.getHash().toBase64());
_log.debug("Sending " + data.length + " bytes in the slice... to "
+ _remoteIdentity.getHash().toBase64());
synchronized (_out) {
_out.write(data);
@ -493,26 +511,38 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
long end = Clock.getInstance().now();
long timeLeft = msg.getMessage().getMessageExpiration().getTime() - end;
if (_log.shouldLog(Log.INFO))
_log.info("Message " + msg.getMessage().getClass().getName() + " (expiring in " + timeLeft + "ms) sent to " + _remoteIdentity.getHash().toBase64() + " from " + _myIdentity.getHash().toBase64() +
" over connection " + _id + " with " + data.length + " bytes in " + (end - start) + "ms");
_log.info("Message " + msg.getMessage().getClass().getName()
+ " (expiring in " + timeLeft + "ms) sent to "
+ _remoteIdentity.getHash().toBase64() + " from "
+ _myIdentity.getHash().toBase64()
+ " over connection " + _id + " with " + data.length
+ " bytes in " + (end - start) + "ms");
if (timeLeft < 10*1000) {
if (_log.shouldLog(Log.DEBUG))
_log.warn("Very little time left... time to send [" + (end-start) + "] time left [" + timeLeft + "] to " +
_remoteIdentity.getHash().toBase64() + "\n" + msg.toString(), msg.getCreatedBy());
_log.warn("Very little time left... time to send [" + (end-start)
+ "] time left [" + timeLeft + "] to "
+ _remoteIdentity.getHash().toBase64() + "\n" + msg.toString(),
msg.getCreatedBy());
}
long lifetime = msg.getLifetime();
if (lifetime > 10*1000) {
if (_log.shouldLog(Log.WARN))
_log.warn("The processing of the message took way too long (" + lifetime + "ms) - time to send (" + (end-start) + "), time left (" + timeLeft + ") to " + _remoteIdentity.getHash().toBase64() + "\n" + msg.toString());
_log.warn("The processing of the message took way too long (" + lifetime
+ "ms) - time to send (" + (end-start) + "), time left (" + timeLeft
+ ") to " + _remoteIdentity.getHash().toBase64() + "\n" + msg.toString());
}
_transport.afterSend(msg, true);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Processing slice - message sent completely: " + msg.getMessage().getClass().getName() + " to " + _remoteIdentity.getHash().toBase64());
_log.debug("Processing slice - message sent completely: "
+ msg.getMessage().getClass().getName() + " to "
+ _remoteIdentity.getHash().toBase64());
if (end - afterExpire > 1000) {
if (_log.shouldLog(Log.WARN))
_log.warn("Actual sending took too long ( " + (end-afterExpire) + "ms) sending " + data.length + " bytes to " + _remoteIdentity.getHash().toBase64());
_log.warn("Actual sending took too long ( " + (end-afterExpire)
+ "ms) sending " + data.length + " bytes to "
+ _remoteIdentity.getHash().toBase64());
}
} catch (IOException ioe) {
msg.timestamp("TCPConnection.runner.processSlice failed to send/flushflushed");