From 426ede1c99a205cb31399a883a1b3cc052b32d6f Mon Sep 17 00:00:00 2001 From: jrandom Date: Sat, 20 Nov 2004 15:52:08 +0000 Subject: [PATCH] * handle con b0rkage more gracefully * close the session on socket manager destroy (the old lib does, and SAM wants it to) --- .../java/src/net/i2p/client/streaming/Connection.java | 4 +++- .../java/src/net/i2p/client/streaming/I2PSocketFull.java | 4 +++- .../net/i2p/client/streaming/I2PSocketManagerFull.java | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java index 656b3be16..d9a959d2c 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java @@ -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()); } diff --git a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java index 1818ccec0..b28262607 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java @@ -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"); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java index f8c97b9e4..9d47b7b69 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java @@ -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); + } + } } /**