* I2CP: Try to hide Pipe closed messages (several tickets)
This commit is contained in:
@ -9,6 +9,7 @@ package net.i2p.client;
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -515,7 +516,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
|
||||
/**
|
||||
* Recieve notifiation of an error reading the I2CP stream
|
||||
*
|
||||
* @param error non-null
|
||||
*/
|
||||
public void readError(I2CPMessageReader reader, Exception error) {
|
||||
propogateError("There was an error reading data", error);
|
||||
@ -574,10 +575,23 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
/**
|
||||
* Pass off the error to the listener
|
||||
* Misspelled, oh well.
|
||||
* @param error non-null
|
||||
*/
|
||||
void propogateError(String msg, Throwable error) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error(getPrefix() + "Error occurred: " + msg, error);
|
||||
// Only log as WARN if the router went away
|
||||
int level;
|
||||
String msgpfx;
|
||||
if ((error instanceof EOFException) ||
|
||||
(error.getMessage() != null && error.getMessage().startsWith("Pipe closed"))) {
|
||||
level = Log.WARN;
|
||||
msgpfx = "Router closed connection: ";
|
||||
} else {
|
||||
level = Log.ERROR;
|
||||
msgpfx = "Error occurred communicating with router: ";
|
||||
}
|
||||
|
||||
if (_log.shouldLog(level))
|
||||
_log.log(level, getPrefix() + msgpfx + msg, error);
|
||||
if (_sessionListener != null) _sessionListener.errorOccurred(this, msg, error);
|
||||
}
|
||||
|
||||
@ -706,7 +720,25 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
}
|
||||
}
|
||||
|
||||
protected String getPrefix() { return "[" + (_sessionId == null ? -1 : _sessionId.getSessionId()) + "]: "; }
|
||||
/**
|
||||
* try hard to make a decent identifier as this will appear in error logs
|
||||
*/
|
||||
protected String getPrefix() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append('[');
|
||||
String s = _options.getProperty("inbound.nickname");
|
||||
if (s != null)
|
||||
buf.append(s);
|
||||
else
|
||||
buf.append(getClass().getSimpleName());
|
||||
buf.append(" #");
|
||||
if (_sessionId != null)
|
||||
buf.append(_sessionId.getSessionId());
|
||||
else
|
||||
buf.append("n/a");
|
||||
buf.append("]: ");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Destination lookupDest(Hash h) throws I2PSessionException {
|
||||
return null;
|
||||
|
@ -8,6 +8,7 @@ package net.i2p.router.client;
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
@ -451,6 +452,7 @@ public class ClientConnectionRunner {
|
||||
void writeMessage(I2CPMessage msg) {
|
||||
long before = _context.clock().now();
|
||||
try {
|
||||
// We don't still need synchronization here? isn't ClientWriterRunner the only writer?
|
||||
synchronized (_out) {
|
||||
msg.writeMessage(_out);
|
||||
_out.flush();
|
||||
@ -459,13 +461,29 @@ public class ClientConnectionRunner {
|
||||
_log.debug("after writeMessage("+ msg.getClass().getName() + "): "
|
||||
+ (_context.clock().now()-before) + "ms");
|
||||
} catch (I2CPMessageException ime) {
|
||||
_log.error("Message exception sending I2CP message: " + ime);
|
||||
_log.error("Error sending I2CP message to client", ime);
|
||||
stopRunning();
|
||||
} catch (EOFException eofe) {
|
||||
// only warn if client went away
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error sending I2CP message - client went away", eofe);
|
||||
stopRunning();
|
||||
} catch (IOException ioe) {
|
||||
_log.error("IO exception sending I2CP message: " + ioe);
|
||||
// only warn if client went away
|
||||
int level;
|
||||
String emsg;
|
||||
if (ioe.getMessage() != null && ioe.getMessage().startsWith("Pipe closed")) {
|
||||
level = Log.WARN;
|
||||
emsg = "Error sending I2CP message - client went away";
|
||||
} else {
|
||||
level = Log.ERROR;
|
||||
emsg = "IO Error sending I2CP message to client";
|
||||
}
|
||||
if (_log.shouldLog(level))
|
||||
_log.log(level, emsg, ioe);
|
||||
stopRunning();
|
||||
} catch (Throwable t) {
|
||||
_log.log(Log.CRIT, "Unhandled exception sending I2CP message", t);
|
||||
_log.log(Log.CRIT, "Unhandled exception sending I2CP message to client", t);
|
||||
stopRunning();
|
||||
} finally {
|
||||
long after = _context.clock().now();
|
||||
|
Reference in New Issue
Block a user