always use the cached host/port rather than grabbing the socket's InetAddress (in case it disconnects and throws NPEs)

use the NativeBigInteger as part of the session key negotiation (oops, forgot this one last time)
logging
This commit is contained in:
jrandom
2004-06-26 21:05:02 +00:00
committed by zzz
parent 83c88ac0c6
commit 9b4899da07
2 changed files with 19 additions and 17 deletions

View File

@ -250,13 +250,6 @@ class RestrictiveTCPConnection extends TCPConnection {
long start = _context.clock().now(); long start = _context.clock().now();
long success = 0; long success = 0;
if (_log.shouldLog(Log.DEBUG)) _log.debug("Establishing connection..."); if (_log.shouldLog(Log.DEBUG)) _log.debug("Establishing connection...");
int port = _socket.getPort();
String host = null;
// sun keeps the socket's InetAddress around after its been closed, but kaffe (and the rest of classpath)
// doesn't, so we've got to check & cache it here if we want to log it later. (kaffe et al are acting per
// spec, btw)
if (_socket.isConnected())
host = _socket.getInetAddress().getHostName();
BigInteger myPub = _builder.getMyPublicValue(); BigInteger myPub = _builder.getMyPublicValue();
try { try {
@ -315,17 +308,17 @@ class RestrictiveTCPConnection extends TCPConnection {
} catch (IOException ioe) { } catch (IOException ioe) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Error establishing connection with " + host + ":" + port, ioe); _log.warn("Error establishing connection with " + _remoteHost + ":" + _remotePort, ioe);
closeConnection(); closeConnection();
return null; return null;
} catch (DataFormatException dfe) { } catch (DataFormatException dfe) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Error establishing connection with " + host + ":" + port, dfe); _log.warn("Error establishing connection with " + _remoteHost + ":" + _remotePort, dfe);
closeConnection(); closeConnection();
return null; return null;
} catch (Throwable t) { } catch (Throwable t) {
if (_log.shouldLog(Log.ERROR)) if (_log.shouldLog(Log.ERROR))
_log.error("jrandom is paranoid so we're catching it all during establishConnection " + host + ":" + port, t); _log.error("jrandom is paranoid so we're catching it all during establishConnection " + _remoteHost + ":" + _remotePort, t);
closeConnection(); closeConnection();
return null; return null;
} finally { } finally {

View File

@ -37,6 +37,7 @@ import net.i2p.router.transport.BandwidthLimitedInputStream;
import net.i2p.router.transport.BandwidthLimitedOutputStream; import net.i2p.router.transport.BandwidthLimitedOutputStream;
import net.i2p.util.I2PThread; import net.i2p.util.I2PThread;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.util.NativeBigInteger;
/** /**
* Wraps a connection - this contains a reader thread (via I2NPMessageReader) and * Wraps a connection - this contains a reader thread (via I2NPMessageReader) and
@ -50,6 +51,8 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
protected int _id; protected int _id;
protected DHSessionKeyBuilder _builder; protected DHSessionKeyBuilder _builder;
protected Socket _socket; protected Socket _socket;
protected String _remoteHost;
protected int _remotePort;
protected I2NPMessageReader _reader; protected I2NPMessageReader _reader;
protected InputStream _in; protected InputStream _in;
protected OutputStream _out; protected OutputStream _out;
@ -91,8 +94,13 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
_extraBytes = null; _extraBytes = null;
_lastSliceRun = -1; _lastSliceRun = -1;
// sun keeps the socket's InetAddress around after its been closed, but kaffe (and the rest of classpath)
// doesn't, so we've got to check & cache it here if we want to log it later. (kaffe et al are acting per
// spec, btw)
_remoteHost = s.getInetAddress() + "";
_remotePort = s.getPort();
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Connected with peer: " + s.getInetAddress() + ":" + s.getPort()); _log.info("Connected with peer: " + _remoteHost + ":" + _remotePort);
updateMaxQueuedMessages(); updateMaxQueuedMessages();
} }
@ -142,7 +150,7 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("rlen: " + rlen + " peerBytes: " + DataHelper.toString(peerPubBytes) + " read: " + read); _log.debug("rlen: " + rlen + " peerBytes: " + DataHelper.toString(peerPubBytes) + " read: " + read);
BigInteger peerPub = new BigInteger(1, peerPubBytes); BigInteger peerPub = new NativeBigInteger(1, peerPubBytes);
_builder.setPeerPublicValue(peerPub); _builder.setPeerPublicValue(peerPub);
_key = _builder.getSessionKey(); _key = _builder.getSessionKey();
@ -330,10 +338,11 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
new Exception("Closed by")); new Exception("Closed by"));
} else { } else {
if (_socket != null) { if (_socket != null) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN)) {
_log.warn("Closing the unestablished connection with " _log.warn("Closing the unestablished connection with "
+ _socket.getInetAddress().toString() + ":" + _remoteHost + ":"
+ _socket.getPort(), new Exception("Closed by")); + _remotePort, new Exception("Closed by"));
}
} else { } else {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Closing the unestablished connection", new Exception("Closed by")); _log.warn("Closing the unestablished connection", new Exception("Closed by"));
@ -403,8 +412,8 @@ class TCPConnection implements I2NPMessageReader.I2NPMessageEventListener {
public void readError(I2NPMessageReader reader, Exception error) { public void readError(I2NPMessageReader reader, Exception error) {
if (_log.shouldLog(Log.ERROR)) if (_log.shouldLog(Log.ERROR))
_log.error("Error reading from stream to " + _remoteIdentity.getHash().toBase64() + ": " + error.getMessage()); _log.error("Error reading from stream to " + _remoteIdentity.getHash().toBase64() + ": " + error.getMessage());
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.WARN))
_log.debug("Error reading from stream to " + _remoteIdentity.getHash().toBase64(), error); _log.warn("Error reading from stream to " + _remoteIdentity.getHash().toBase64(), error);
} }
/** /**