* I2CP: Try to hide Pipe closed messages (several tickets)

This commit is contained in:
zzz
2010-11-30 15:08:51 +00:00
parent 45b8d8b6b5
commit 243bd412e1
2 changed files with 57 additions and 7 deletions

View File

@ -9,6 +9,7 @@ package net.i2p.client;
* *
*/ */
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -515,7 +516,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
/** /**
* Recieve notifiation of an error reading the I2CP stream * Recieve notifiation of an error reading the I2CP stream
* * @param error non-null
*/ */
public void readError(I2CPMessageReader reader, Exception error) { public void readError(I2CPMessageReader reader, Exception error) {
propogateError("There was an error reading data", 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 * Pass off the error to the listener
* Misspelled, oh well. * Misspelled, oh well.
* @param error non-null
*/ */
void propogateError(String msg, Throwable error) { void propogateError(String msg, Throwable error) {
if (_log.shouldLog(Log.ERROR)) // Only log as WARN if the router went away
_log.error(getPrefix() + "Error occurred: " + msg, error); 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); 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 { public Destination lookupDest(Hash h) throws I2PSessionException {
return null; return null;

View File

@ -8,6 +8,7 @@ package net.i2p.router.client;
* *
*/ */
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
@ -451,6 +452,7 @@ public class ClientConnectionRunner {
void writeMessage(I2CPMessage msg) { void writeMessage(I2CPMessage msg) {
long before = _context.clock().now(); long before = _context.clock().now();
try { try {
// We don't still need synchronization here? isn't ClientWriterRunner the only writer?
synchronized (_out) { synchronized (_out) {
msg.writeMessage(_out); msg.writeMessage(_out);
_out.flush(); _out.flush();
@ -459,13 +461,29 @@ public class ClientConnectionRunner {
_log.debug("after writeMessage("+ msg.getClass().getName() + "): " _log.debug("after writeMessage("+ msg.getClass().getName() + "): "
+ (_context.clock().now()-before) + "ms"); + (_context.clock().now()-before) + "ms");
} catch (I2CPMessageException ime) { } 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(); stopRunning();
} catch (IOException ioe) { } 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(); stopRunning();
} catch (Throwable t) { } 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(); stopRunning();
} finally { } finally {
long after = _context.clock().now(); long after = _context.clock().now();