diff --git a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java index b978ff3be933ca190871adb74471cbe7d8098dfa..7efc6cc401e99f56e9fb6fb1ba4b88c814238224 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java @@ -284,6 +284,8 @@ public class ConnectionManager { // exporting non-public type through public API, this is a potential bug. public ConnectionHandler getConnectionHandler() { return _connectionHandler; } public PacketQueue getPacketQueue() { return _outboundQueue; } + /** do we respond to pings that aren't on an existing connection? */ + public boolean answerPings() { return _defaultOptions.getAnswerPings(); } /** * Something b0rked hard, so kill all of our connections without mercy. diff --git a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java index c7084b4e72d29c79eb41410ad6d55b4572cfec39..13e18baffac0afcd4d67cadc01a19df8f7542747 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java @@ -9,6 +9,7 @@ import java.util.Properties; public class ConnectionOptions extends I2PSocketOptionsImpl { private int _connectDelay; private boolean _fullySigned; + private boolean _answerPings; private volatile int _windowSize; private int _receiveWindow; private int _profile; @@ -51,12 +52,15 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { public static final String PROP_MAX_WINDOW_SIZE = "i2p.streaming.maxWindowSize"; public static final String PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR = "i2p.streaming.congestionAvoidanceGrowthRateFactor"; public static final String PROP_SLOW_START_GROWTH_RATE_FACTOR = "i2p.streaming.slowStartGrowthRateFactor"; + public static final String PROP_ANSWER_PINGS = "i2p.streaming.answerPings"; private static final int TREND_COUNT = 3; static final int INITIAL_WINDOW_SIZE = 6; static final int DEFAULT_MAX_SENDS = 8; public static final int DEFAULT_INITIAL_RTT = 8*1000; static final int MIN_WINDOW_SIZE = 1; + private static final boolean DEFAULT_ANSWER_PINGS = true; + // Syncronization fix, but doing it this way causes NPE... // private final int _trend[] = new int[TREND_COUNT]; private int _trend[]; @@ -198,6 +202,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { setSlowStartGrowthRateFactor(opts.getSlowStartGrowthRateFactor()); setWriteTimeout(opts.getWriteTimeout()); setReadTimeout(opts.getReadTimeout()); + setAnswerPings(opts.getAnswerPings()); } } @@ -221,8 +226,8 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { setInboundBufferSize(getMaxMessageSize() * (Connection.MAX_WINDOW_SIZE + 2)); setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 1)); setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 1)); - setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT)); + setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS)); } @Override @@ -260,9 +265,10 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 2)); if (opts.contains(PROP_SLOW_START_GROWTH_RATE_FACTOR)) setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 2)); - if (opts.containsKey(PROP_CONNECT_TIMEOUT)) setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT)); + if (opts.containsKey(PROP_ANSWER_PINGS)) + setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS)); } /** @@ -282,11 +288,22 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { * or can we deal with signatures on the SYN and FIN packets * only? * + * There is no property name defined for this, so it's safe to + * say this is unused and always false. + * * @return if we want signatures on all packets. */ public boolean getRequireFullySigned() { return _fullySigned; } public void setRequireFullySigned(boolean sign) { _fullySigned = sign; } + /** + * Do we respond to a ping? + * + * @return if we do + */ + public boolean getAnswerPings() { return _answerPings; } + public void setAnswerPings(boolean yes) { _answerPings = yes; } + /** * How many messages will we send before waiting for an ACK? * @@ -492,6 +509,13 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { return buf.toString(); } + private static boolean getBool(Properties opts, String name, boolean defaultVal) { + if (opts == null) return defaultVal; + String val = opts.getProperty(name); + if (val == null) return defaultVal; + return Boolean.valueOf(val).booleanValue(); + } + public static void main(String args[]) { Properties p = new Properties(); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java b/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java index bbb5a9536aeb02b8a5dc50532a8d11a4283ccc03..19e62db0c9d74e795c1e48eac2c988c079da1fbb 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java @@ -129,7 +129,10 @@ public class PacketHandler { private void receiveKnownCon(Connection con, Packet packet) { if (packet.isFlagSet(Packet.FLAG_ECHO)) { if (packet.getSendStreamId() > 0) { - receivePing(packet); + if (con.getOptions().getAnswerPings()) + receivePing(packet); + else if (_log.shouldLog(Log.WARN)) + _log.warn("Dropping Echo packet on existing con: " + packet); } else if (packet.getReceiveStreamId() > 0) { receivePong(packet); } else { @@ -230,7 +233,10 @@ public class PacketHandler { private void receiveUnknownCon(Packet packet, long sendId, boolean queueIfNoConn) { if (packet.isFlagSet(Packet.FLAG_ECHO)) { if (packet.getSendStreamId() > 0) { - receivePing(packet); + if (_manager.answerPings()) + receivePing(packet); + else if (_log.shouldLog(Log.WARN)) + _log.warn("Dropping Echo packet on unknown con: " + packet); } else if (packet.getReceiveStreamId() > 0) { receivePong(packet); } else {