[freenet-cvs] r16244 - in trunk/freenet/src/freenet: io/xfer node

toad at freenetproject.org toad at freenetproject.org
Mon Dec 3 21:37:18 UTC 2007


Author: toad
Date: 2007-12-03 21:37:18 +0000 (Mon, 03 Dec 2007)
New Revision: 16244

Modified:
   trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
   trunk/freenet/src/freenet/node/NodeStats.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
Reject requests from a peer if:
- The message queue to that peer is already over 4MB.
- The message queue to that peer will take more than 1 hour to transfer.

Modified: trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PacketThrottle.java	2007-12-03 21:26:58 UTC (rev 16243)
+++ trunk/freenet/src/freenet/io/xfer/PacketThrottle.java	2007-12-03 21:37:18 UTC (rev 16244)
@@ -124,4 +124,8 @@
 	public double getWindowSize() {
 		return _simulatedWindowSize;
 	}
+
+	public double getBandwidth() {
+		return ((PACKET_SIZE * 1000.0 / getDelay())) / 1024;
+	}
 }

Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java	2007-12-03 21:26:58 UTC (rev 16243)
+++ trunk/freenet/src/freenet/node/NodeStats.java	2007-12-03 21:37:18 UTC (rev 16244)
@@ -335,6 +335,11 @@
 	 * (If no packets have been sent, the throttledPacketSendAverage should decrease; if it doesn't, it may go high,
 	 * and then no requests will be accepted, and it will stay high forever. */
 	static final int CHECK_THROTTLE_TIME = 60 * 1000;
+	/** Absolute limit of 4MB queued to any given peer. FIXME make this configurable. 
+	 * Note that for many MessageItem's, the actual memory usage will be significantly more than this figure. */
+	private static final long MAX_PEER_QUEUE_BYTES = 4 * 1024 * 1024;
+	/** Don't accept requests if it'll take more than an hour to send the current message queue */
+	private static final double MAX_PEER_QUEUE_TIME = 60 * 60 * 1000.0;
 	
 	private long lastAcceptedRequest = -1;
 	
@@ -508,6 +513,14 @@
 			return "<freeHeapPercentThreshold ("+SizeUtil.formatSize(freeHeapMemory, false)+" of "+SizeUtil.formatSize(maxHeapMemory, false)+" ("+fix3p1pct.format(percentFreeHeapMemoryOfMax)+"))";
 		}
 
+		if(source != null) {
+			long queuedBytes = source.getMessageQueueLengthBytes();
+			if(queuedBytes > MAX_PEER_QUEUE_BYTES)
+				return "Too many message bytes queued for peer";
+			if(queuedBytes / (source.getThrottle().getBandwidth()+1.0) > MAX_PEER_QUEUE_TIME)
+				return "Peer's queue will take too long to transfer";
+		}
+		
 		synchronized(this) {
 			if(logMINOR) Logger.minor(this, "Accepting request?");
 			lastAcceptedRequest = now;

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java	2007-12-03 21:26:58 UTC (rev 16243)
+++ trunk/freenet/src/freenet/node/PeerNode.java	2007-12-03 21:37:18 UTC (rev 16244)
@@ -898,6 +898,18 @@
         // it wakes up every 100ms *anyway*.
 	}
 
+	public long getMessageQueueLengthBytes() {
+		long x = 0;
+		synchronized(messagesToSendNow) {
+			Iterator i = messagesToSendNow.iterator();
+			for(; i.hasNext();) {
+				MessageItem it = (MessageItem) (i.next());
+				x += it.getData(this).length + 2;
+			}
+		}
+		return x;
+	}
+	
 	/**
 	* @return The last time we received a packet.
 	*/




More information about the cvs mailing list