* handle con b0rkage more gracefully

* close the session on socket manager destroy (the old lib does, and SAM wants it to)
This commit is contained in:
jrandom
2004-11-20 15:52:08 +00:00
committed by zzz
parent 21506c1d1b
commit 426ede1c99
3 changed files with 14 additions and 2 deletions

View File

@ -178,6 +178,8 @@ public class Connection {
}
void sendPacket(PacketLocal packet) {
if (packet == null) return;
setNextSendTime(-1);
_unackedPacketsReceived = 0;
if (_options.getRequireFullySigned()) {
@ -227,7 +229,7 @@ public class Connection {
// however, if we are running low on sessionTags we want to send
// something that will get a reply so that we can deliver some new tags -
// ACKs don't get ACKed, but pings do.
if (packet.getTagsSent().size() > 0) {
if ( (packet.getTagsSent() != null) && (packet.getTagsSent().size() > 0) ) {
_log.warn("Sending a ping since the ACK we just sent has " + packet.getTagsSent().size() + " tags");
_connectionManager.ping(_remotePeer, _options.getRTT()*2, false, packet.getKeyUsed(), packet.getTagsSent(), new PingNotifier());
}

View File

@ -21,7 +21,9 @@ public class I2PSocketFull implements I2PSocket {
public void close() throws IOException {
if (_connection == null) return;
if (_connection.getIsConnected()) {
_connection.getOutputStream().close();
OutputStream out = _connection.getOutputStream();
if (out != null)
out.close();
_connection.disconnect(true);
} else {
//throw new IOException("Not connected");

View File

@ -198,6 +198,14 @@ public class I2PSocketManagerFull implements I2PSocketManager {
_connectionManager.disconnectAllHard();
_connectionManager.setAllowIncomingConnections(false);
// should we destroy the _session too?
// yes, since the old lib did (and SAM wants it to, and i dont know why not)
if ( (_session != null) && (!_session.isClosed()) ) {
try {
_session.destroySession();
} catch (I2PSessionException ise) {
_log.warn("Unable to destroy the session", ise);
}
}
}
/**