Author: toad
Date: 2008-03-04 14:05:18 +0000 (Tue, 04 Mar 2008)
New Revision: 18333
Added:
trunk/freenet/src/freenet/io/xfer/ThrottleDeprecatedException.java
Modified:
trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
trunk/freenet/src/freenet/node/PeerNode.java
Log:
Prevent infinite recursion on a node constantly changing its address.
Modified: trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PacketThrottle.java 2008-03-04
14:00:22 UTC (rev 18332)
+++ trunk/freenet/src/freenet/io/xfer/PacketThrottle.java 2008-03-04
14:05:18 UTC (rev 18333)
@@ -159,7 +159,7 @@
return ((PACKET_SIZE * 1000.0 / getDelay()));
}
- public void sendThrottledMessage(Message msg, PeerContext peer,
DoubleTokenBucket overallThrottle, int packetSize, ByteCounter ctr) throws
NotConnectedException {
+ public void sendThrottledMessage(Message msg, PeerContext peer,
DoubleTokenBucket overallThrottle, int packetSize, ByteCounter ctr) throws
NotConnectedException, ThrottleDeprecatedException {
long start = System.currentTimeMillis();
long bootID = peer.getBootID();
PacketThrottle deprecatedFor = null;
@@ -185,16 +185,10 @@
if(!peer.isConnected()) throw new
NotConnectedException();
if(bootID != peer.getBootID()) throw new
NotConnectedException();
if(_deprecatedFor != null) {
- deprecatedFor = _deprecatedFor;
- break;
+ throw new
ThrottleDeprecatedException(_deprecatedFor);
}
}
}
- if(deprecatedFor != null) {
- // FIXME infinite recursion may be possible here??
- deprecatedFor.sendThrottledMessage(msg, peer,
overallThrottle, packetSize, ctr);
- return;
- }
long waitTime = System.currentTimeMillis() - start;
if(waitTime > 60*1000)
Logger.error(this, "Congestion control wait time:
"+waitTime+" for "+this);
Added: trunk/freenet/src/freenet/io/xfer/ThrottleDeprecatedException.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/ThrottleDeprecatedException.java
(rev 0)
+++ trunk/freenet/src/freenet/io/xfer/ThrottleDeprecatedException.java
2008-03-04 14:05:18 UTC (rev 18333)
@@ -0,0 +1,15 @@
+package freenet.io.xfer;
+
+/**
+ * Thrown when a throttle is deprecated.
+ * @author toad
+ */
+public class ThrottleDeprecatedException extends Exception {
+
+ ThrottleDeprecatedException(PacketThrottle target) {
+ this.target = target;
+ }
+
+ public final PacketThrottle target;
+
+}
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2008-03-04 14:00:22 UTC
(rev 18332)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2008-03-04 14:05:18 UTC
(rev 18333)
@@ -52,6 +52,7 @@
import freenet.io.comm.ReferenceSignatureVerificationException;
import freenet.io.comm.SocketHandler;
import freenet.io.xfer.PacketThrottle;
+import freenet.io.xfer.ThrottleDeprecatedException;
import freenet.keys.ClientSSK;
import freenet.keys.FreenetURI;
import freenet.keys.Key;
@@ -3641,6 +3642,14 @@
}
public void sendThrottledMessage(Message msg, int packetSize,
ByteCounter ctr) throws NotConnectedException {
+ while(true) {
+ try {
getThrottle().sendThrottledMessage(msg, this,
node.outputThrottle, packetSize, ctr);
+ return;
+ } catch (ThrottleDeprecatedException e) {
+ // Try with the new throttle. We don't need it, we'll
get it from getThrottle().
+ continue;
+ }
+ }
}
}