Author: toad
Date: 2008-04-28 22:39:03 +0000 (Mon, 28 Apr 2008)
New Revision: 19603
Modified:
trunk/freenet/src/freenet/node/OpennetManager.java
Log:
Scale so 20 peers at 16K/sec.
Modified: trunk/freenet/src/freenet/node/OpennetManager.java
===================================================================
--- trunk/freenet/src/freenet/node/OpennetManager.java 2008-04-28 22:33:51 UTC
(rev 19602)
+++ trunk/freenet/src/freenet/node/OpennetManager.java 2008-04-28 22:39:03 UTC
(rev 19603)
@@ -94,6 +94,8 @@
/** Enable scaling of peers with bandwidth? */
static final boolean ENABLE_PEERS_PER_KB_OUTPUT = false;
+ /** Target bandwidth usage - above this, we use MAX_PEERS_FOR_SCALING */
+ static final int TARGET_BANDWIDTH_USAGE = 16*1024; // Same as the
default in the first time wizard.
/** Minimum number of peers */
static final int MIN_PEERS_FOR_SCALING = 10;
/** Maximum number of peers */
@@ -484,9 +486,13 @@
protected int getNumberOfConnectedPeersToAim() {
int max = Integer.MAX_VALUE;
if(ENABLE_PEERS_PER_KB_OUTPUT) {
- max = node.getOutputBandwidthLimit() / 1024;
- if(max < MIN_PEERS_FOR_SCALING) max =
MIN_PEERS_FOR_SCALING;
- if(max > MAX_PEERS_FOR_SCALING) max =
MAX_PEERS_FOR_SCALING;
+ int obwLimit = node.getOutputBandwidthLimit();
+ if(obwLimit >= TARGET_BANDWIDTH_USAGE) {
+ max = MAX_PEERS_FOR_SCALING;
+ } else {
+ max = obwLimit * MAX_PEERS_FOR_SCALING /
TARGET_BANDWIDTH_USAGE;
+ if(max < MIN_PEERS_FOR_SCALING) max =
MIN_PEERS_FOR_SCALING;
+ }
}
return Math.min(max, node.getMaxOpennetPeers() -
node.peers.countConnectedDarknetPeers());
}