diff --git a/router/java/src/net/i2p/router/transport/udp/InboundMessageState.java b/router/java/src/net/i2p/router/transport/udp/InboundMessageState.java index 6c85b9fb7..71ce7d081 100644 --- a/router/java/src/net/i2p/router/transport/udp/InboundMessageState.java +++ b/router/java/src/net/i2p/router/transport/udp/InboundMessageState.java @@ -30,7 +30,7 @@ public class InboundMessageState { /** expire after 10s */ private static final long MAX_RECEIVE_TIME = 10*1000; - private static final int MAX_FRAGMENTS = 64; + public static final int MAX_FRAGMENTS = 64; private static final ByteCache _fragmentCache = ByteCache.getInstance(64, 2048); diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java b/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java index c9e7db02c..052ff2b4f 100644 --- a/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java +++ b/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java @@ -34,8 +34,11 @@ public class OutboundMessageState { private short _maxSends; private int _nextSendFragment; - public static final int MAX_FRAGMENTS = 32; - private static final ByteCache _cache = ByteCache.getInstance(64, MAX_FRAGMENTS*1024); + public static final int MAX_MSG_SIZE = 32 * 1024; + /** is this enough for a high-bandwidth router? */ + private static final int MAX_ENTRIES = 64; + /** would two caches, one for small and one for large messages, be better? */ + private static final ByteCache _cache = ByteCache.getInstance(MAX_ENTRIES, MAX_MSG_SIZE); public OutboundMessageState(I2PAppContext context) { _context = context; @@ -226,7 +229,9 @@ public class OutboundMessageState { int numFragments = totalSize / fragmentSize; if (numFragments * fragmentSize < totalSize) numFragments++; - + // This should never happen, as 534 bytes * 64 fragments > 32KB, and we won't bid on > 32KB + if (numFragments > InboundMessageState.MAX_FRAGMENTS) + throw new IllegalArgumentException("Fragmenting a " + totalSize + " message into " + numFragments + " fragments - too many!"); if (_log.shouldLog(Log.DEBUG)) _log.debug("Fragmenting a " + totalSize + " message into " + numFragments + " fragments"); diff --git a/router/java/src/net/i2p/router/transport/udp/PeerState.java b/router/java/src/net/i2p/router/transport/udp/PeerState.java index ff1f64f11..74608069c 100644 --- a/router/java/src/net/i2p/router/transport/udp/PeerState.java +++ b/router/java/src/net/i2p/router/transport/udp/PeerState.java @@ -287,15 +287,7 @@ public class PeerState { } private int getDefaultMTU() { - String mtu = _context.getProperty(PROP_DEFAULT_MTU); - if (mtu != null) { - try { - return Integer.valueOf(mtu).intValue(); - } catch (NumberFormatException nfe) { - // ignore - } - } - return DEFAULT_MTU; + return _context.getProperty(PROP_DEFAULT_MTU, DEFAULT_MTU); } /** diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index 720eaed46..38a82d7d1 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -929,6 +929,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority } public TransportBid bid(RouterInfo toAddress, long dataSize) { + if (dataSize > OutboundMessageState.MAX_MSG_SIZE) { + // NTCP max is lower, so msg will get dropped + return null; + } Hash to = toAddress.getIdentity().calculateHash(); PeerState peer = getPeerState(to); if (peer != null) { @@ -1753,7 +1757,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority buf.append(" V "); else buf.append(" V "); - buf.append("idle"); + buf.append("dir/introidle"); appendSortLinks(buf, urlBase, sortFlags, "Sort by idle inbound", FLAG_IDLE_IN); buf.append("/"); appendSortLinks(buf, urlBase, sortFlags, "Sort by idle outbound", FLAG_IDLE_OUT); @@ -1809,32 +1813,11 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority buf.append(name); buf.append("\">"); buf.append(name); -/* - buf.append("@"); - byte ip[] = peer.getRemoteIP(); - for (int j = 0; j < ip.length; j++) { - int num = ip[j] & 0xFF; - if (num < 10) - buf.append("00"); - else if (num < 100) - buf.append("0"); - buf.append(num); - if (j + 1 < ip.length) - buf.append('.'); - } - buf.append(':'); - int port = peer.getRemotePort(); - if (port < 10) - buf.append("0000"); - else if (port < 100) - buf.append("000"); - else if (port < 1000) - buf.append("00"); - else if (port < 10000) - buf.append("0"); - buf.append(port); -*/ - buf.append(" "); + buf.append(""); + //byte ip[] = peer.getRemoteIP(); + //if (ip != null) + // buf.append(' ').append(_context.blocklist().toStr(ip)); + buf.append(""); if (peer.isInbound()) buf.append("in "); else @@ -1990,8 +1973,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority numPeers++; } - buf.append("
\n"); - buf.append(" Total"); + buf.append("
\n"); + buf.append(" Total"); buf.append(" "); buf.append(formatKBps(bpsIn)).append("/").append(formatKBps(bpsOut)); buf.append("KBps");