Author: toad
Date: 2007-04-20 20:21:23 +0000 (Fri, 20 Apr 2007)
New Revision: 12826
Modified:
trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
trunk/freenet/src/freenet/node/FNPPacketMangler.java
trunk/freenet/src/freenet/node/NodeStats.java
Log:
Take UDP headers into account in packet size / bytes usage calculations
Modified: trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/UdpSocketManager.java 2007-04-20
20:18:05 UTC (rev 12825)
+++ trunk/freenet/src/freenet/io/comm/UdpSocketManager.java 2007-04-20
20:21:23 UTC (rev 12826)
@@ -692,10 +692,10 @@
// unofficially, PPPoE is often 1472 (seen in the wild). Also PPPoATM
is sometimes 1472.
static final int MAX_ALLOWED_MTU = 1400;
// FIXME this is different for IPv6 (check all uses of constant when
fixing)
- static final int UDP_HEADERS_LENGTH = 28;
+ public static final int UDP_HEADERS_LENGTH = 28;
/**
- * @return The maximum packet size supported by this SocketManager.
+ * @return The maximum packet size supported by this SocketManager, not
including transport (UDP/IP) headers.
*/
public int getMaxPacketSize() { //FIXME: what about passing a peerNode
though and doing it on a per-peer basis?
final int minAdvertisedMTU = node.ipDetector.getMinimumDetectedMTU();
Modified: trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java 2007-04-20
20:18:05 UTC (rev 12825)
+++ trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java 2007-04-20
20:21:23 UTC (rev 12826)
@@ -68,7 +68,7 @@
_ctr = ctr;
_masterThrottle = masterThrottle;
PACKET_SIZE = DMT.packetTransmitSize(_prb._packetSize,
_prb._packets)
- + FNPPacketMangler.HEADERS_LENGTH_ONE_MESSAGE;
+ + FNPPacketMangler.FULL_HEADERS_LENGTH_ONE_MESSAGE;
try {
_sentPackets = new BitArray(_prb.getNumPackets());
} catch (AbortedException e) {
Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java 2007-04-20
20:18:05 UTC (rev 12825)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java 2007-04-20
20:21:23 UTC (rev 12826)
@@ -63,6 +63,11 @@
/** Headers overhead if there is one message and no acks. */
static public final int HEADERS_LENGTH_ONE_MESSAGE =
HEADERS_LENGTH_MINIMUM + 2; // 2 bytes = length of message.
rest is the same.
+
+ static public final int FULL_HEADERS_LENGTH_MINIMUM =
+ HEADERS_LENGTH_MINIMUM + UdpSocketManager.UDP_HEADERS_LENGTH;
+ static public final int FULL_HEADERS_LENGTH_ONE_MESSAGE =
+ HEADERS_LENGTH_ONE_MESSAGE +
UdpSocketManager.UDP_HEADERS_LENGTH;
public FNPPacketMangler(Node node) {
this.node = node;
@@ -1027,7 +1032,7 @@
}
int packetNumber =
kt.allocateOutgoingPacketNumberNeverBlock();
this.processOutgoingPreformatted(buf, 0, buf.length,
pn.getCurrentKeyTracker(), packetNumber, mi.cb, mi.alreadyReportedBytes);
- mi.onSent(buf.length + HEADERS_LENGTH_ONE_MESSAGE);
+ mi.onSent(buf.length + FULL_HEADERS_LENGTH_ONE_MESSAGE);
} catch (NotConnectedException e) {
Logger.normal(this, "Caught "+e+" while sending messages
("+mi_name+") to "+pn.getPeer()+requeueLogString);
// Requeue
@@ -1106,7 +1111,7 @@
for(int i=0;i<messageData.length;i++) {
MessageItem mi = newMsgs[i];
mi_name = (mi.msg == null ? "(not a
Message)" : mi.msg.getSpec().getName());
- mi.onSent(messageData[i].length + 2 +
(HEADERS_LENGTH_MINIMUM / messageData.length));
+ mi.onSent(messageData[i].length + 2 +
(FULL_HEADERS_LENGTH_MINIMUM / messageData.length));
}
} catch (NotConnectedException e) {
Logger.normal(this, "Caught "+e+" while sending messages
("+mi_name+") to "+pn.getPeer()+requeueLogString);
@@ -1153,7 +1158,7 @@
for(int j=lastIndex;j<i;j++) {
MessageItem mi = newMsgs[j];
mi_name =
(mi.msg == null ? "(not a Message)" : mi.msg.getSpec().getName());
-
mi.onSent(messageData[j].length + 2 + (HEADERS_LENGTH_MINIMUM / (i-lastIndex)));
+
mi.onSent(messageData[j].length + 2 + (FULL_HEADERS_LENGTH_MINIMUM /
(i-lastIndex)));
}
} catch (NotConnectedException e) {
Logger.normal(this, "Caught "+e+" while sending
messages ("+mi_name+") to "+pn.getPeer()+requeueLogString);
Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java 2007-04-20 20:18:05 UTC
(rev 12825)
+++ trunk/freenet/src/freenet/node/NodeStats.java 2007-04-20 20:21:23 UTC
(rev 12826)
@@ -314,7 +314,7 @@
static final int ESTIMATED_SIZE_OF_ONE_THROTTLED_PACKET =
1024 + DMT.packetTransmitSize(1024, 32)
- + FNPPacketMangler.HEADERS_LENGTH_ONE_MESSAGE;
+ + FNPPacketMangler.FULL_HEADERS_LENGTH_ONE_MESSAGE;
/* return reject reason as string if should reject, otherwise return
null */
public String shouldRejectRequest(boolean canAcceptAnyway, boolean
isInsert, boolean isSSK) {