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 757d9d2535902c1abc3126d359c78c91934185d5..f397521d7872e4b708184bf5e1123497ddcb3d63 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java @@ -162,6 +162,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { * */ public static final int DEFAULT_MAX_MESSAGE_SIZE = 1730; + public static final int MIN_MESSAGE_SIZE = 512; public ConnectionOptions() { super(); @@ -389,7 +390,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl { * @return Maximum message size (MTU/MRU) */ public int getMaxMessageSize() { return _maxMessageSize; } - public void setMaxMessageSize(int bytes) { _maxMessageSize = bytes; } + public void setMaxMessageSize(int bytes) { _maxMessageSize = Math.max(bytes, MIN_MESSAGE_SIZE); } /** * how long we want to wait before any data is transferred on the diff --git a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java index 28146ce727be9710e1c3949b866ea2724294c721..2d41aad8b41693aac591f46dc63d077a6c1a76e2 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java @@ -67,12 +67,17 @@ public class ConnectionPacketHandler { } if (packet.isFlagSet(Packet.FLAG_MAX_PACKET_SIZE_INCLUDED)) { - if (packet.getOptionalMaxSize() < con.getOptions().getMaxMessageSize()) { + int size = packet.getOptionalMaxSize(); + if (size < ConnectionOptions.MIN_MESSAGE_SIZE) { + // log.error? connection reset? + size = ConnectionOptions.MIN_MESSAGE_SIZE; + } + if (size < con.getOptions().getMaxMessageSize()) { if (_log.shouldLog(Log.INFO)) - _log.info("Reducing our max message size to " + packet.getOptionalMaxSize() + _log.info("Reducing our max message size to " + size + " from " + con.getOptions().getMaxMessageSize()); - con.getOptions().setMaxMessageSize(packet.getOptionalMaxSize()); - con.getOutputStream().setBufferSize(packet.getOptionalMaxSize()); + con.getOptions().setMaxMessageSize(size); + con.getOutputStream().setBufferSize(size); } }