Author: nextgens
Date: 2008-08-11 14:39:46 +0000 (Mon, 11 Aug 2008)
New Revision: 21748
Modified:
trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
trunk/freenet/src/freenet/node/NodeIPDetector.java
trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
Skip the bandwidth limiting step in the wizard if the node has detected a
recent enough, and working UPnP plugin
Modified: trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
2008-08-11 14:33:18 UTC (rev 21747)
+++ trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
2008-08-11 14:39:46 UTC (rev 21748)
@@ -15,6 +15,7 @@
import freenet.l10n.L10n;
import freenet.node.Node;
import freenet.node.NodeClientCore;
+import freenet.pluginmanager.FredPluginBandwidthIndicator;
import freenet.support.Fields;
import freenet.support.HTMLNode;
import freenet.support.Logger;
@@ -101,7 +102,7 @@
nnameForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "submit", "cancel",
L10n.getString("Toadlet.cancel")});
this.writeHTMLReply(ctx, 200, "OK",
pageNode.generate());
return;
- } else if(currentStep == WIZARD_STEP.BANDWIDTH) {
+ } else if(currentStep == WIZARD_STEP.BANDWIDTH) {
HTMLNode pageNode =
ctx.getPageMaker().getPageNode(l10n("step3Title"), false, ctx);
HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
@@ -114,6 +115,7 @@
HTMLNode bandwidthForm =
ctx.addFormChild(bandwidthInfoboxContent, ".", "bwForm");
HTMLNode result = bandwidthForm.addChild("select",
"name", "bw");
+ // don't forget to update handlePost too if you change
that!
result.addChild("option", "value", "8K",
l10n("bwlimitLowerSpeed"));
// Special case for 128kbps to increase performance at
the cost of some link degradation. Above that we use 50% of the limit.
result.addChild("option", "value", "12K", "512+/128
kbps");
@@ -307,17 +309,28 @@
} catch (InvalidConfigValueException e) {
Logger.error(this, "Should not happen, please
report!" + e, e);
}
- super.writeTemporaryRedirect(ctx, "step3",
TOADLET_URL+"?step="+WIZARD_STEP.BANDWIDTH);
+
+ // Attempt to skip one step if possible
+ FredPluginBandwidthIndicator bwIndicator =
core.node.ipDetector.getBandwidthIndicator();
+ int upstreamBWLimit = (bwIndicator != null ?
bwIndicator.getUpstramMaxBitRate() : -1);
+ if((bwIndicator != null) && (upstreamBWLimit > 0)) {
+ Logger.normal(this, "The node has a
bandwidthIndicator: it has reported "+upstreamBWLimit+ "... we will use that
value and skip the bandwidth selection step of the wizard.");
+ if(upstreamBWLimit < 128000)
+ _setUpstreamBandwidthLimit("8K");
+ else if(upstreamBWLimit < 256000)
+ _setUpstreamBandwidthLimit("12K");
+ else if(upstreamBWLimit < 512000)
+ _setUpstreamBandwidthLimit("32K");
+ else if(upstreamBWLimit < 1024000)
+ _setUpstreamBandwidthLimit("64K");
+ else
+ _setUpstreamBandwidthLimit("1000K");
+ super.writeTemporaryRedirect(ctx, "step4",
TOADLET_URL+"?step="+WIZARD_STEP.DATASTORE_SIZE);
+ } else
+ super.writeTemporaryRedirect(ctx, "step3",
TOADLET_URL+"?step="+WIZARD_STEP.BANDWIDTH);
return;
} else if(request.isPartSet("bwF")) {
- String selectedUploadSpeed
=request.getPartAsString("bw", 6);
-
- try {
- config.get("node").set("outputBandwidthLimit",
selectedUploadSpeed);
- Logger.normal(this, "The outputBandwidthLimit
has been set to "+ selectedUploadSpeed);
- } catch (InvalidConfigValueException e) {
- Logger.error(this, "Should not happen, please
report!" + e, e);
- }
+
_setUpstreamBandwidthLimit(request.getPartAsString("bw", 6));
super.writeTemporaryRedirect(ctx, "step4",
TOADLET_URL+"?step="+WIZARD_STEP.DATASTORE_SIZE);
return;
} else if(request.isPartSet("dsF")) {
@@ -353,4 +366,13 @@
public String supportedMethods() {
return "GET, POST";
}
+
+ private void _setUpstreamBandwidthLimit(String selectedUploadSpeed) {
+ try {
+ config.get("node").set("outputBandwidthLimit",
selectedUploadSpeed);
+ Logger.normal(this, "The outputBandwidthLimit has been
set to " + selectedUploadSpeed);
+ } catch(InvalidConfigValueException e) {
+ Logger.error(this, "Should not happen, please report!"
+ e, e);
+ }
+ }
}
Modified: trunk/freenet/src/freenet/node/NodeIPDetector.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeIPDetector.java 2008-08-11 14:33:18 UTC
(rev 21747)
+++ trunk/freenet/src/freenet/node/NodeIPDetector.java 2008-08-11 14:39:46 UTC
(rev 21748)
@@ -18,6 +18,7 @@
import freenet.node.useralerts.SimpleUserAlert;
import freenet.node.useralerts.UserAlert;
import freenet.pluginmanager.DetectedIP;
+import freenet.pluginmanager.FredPluginBandwidthIndicator;
import freenet.pluginmanager.FredPluginIPDetector;
import freenet.pluginmanager.FredPluginPortForward;
import freenet.support.HTMLNode;
@@ -526,6 +527,18 @@
ipDetectorManager.unregisterPortForwardPlugin(forward);
}
+ //TODO: ugly: deal with multiple instances properly
+ public synchronized void
registerBandwidthIndicatorPlugin(FredPluginBandwidthIndicator indicator) {
+ bandwidthIndicator = indicator;
+ }
+ public synchronized void
unregisterBandwidthIndicatorPlugin(FredPluginBandwidthIndicator indicator) {
+ bandwidthIndicator = null;
+ }
+ public synchronized FredPluginBandwidthIndicator
getBandwidthIndicator() {
+ return bandwidthIndicator;
+ }
+ private FredPluginBandwidthIndicator bandwidthIndicator;
+
boolean hasValidAddressOverride() {
synchronized(this) {
return hasValidAddressOverride;
Modified: trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
2008-08-11 14:33:18 UTC (rev 21747)
+++ trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
2008-08-11 14:39:46 UTC (rev 21748)
@@ -11,31 +11,32 @@
// Parameters to make the object OTP
private boolean fedPluginThread = false;
// Public since only PluginHandler will know about it
- private String className;
+ private final String className;
private Thread thread;
- private long start;
- private String threadName;
+ private final long start;
+ private final String threadName;
final FredPlugin plug;
- private boolean isPproxyPlugin;
- private boolean isThreadlessPlugin;
- private boolean isIPDetectorPlugin;
- private boolean isPortForwardPlugin;
- private boolean isMultiplePlugin;
- private boolean isFCPPlugin;
- private boolean isVersionedPlugin;
- private String filename;
- private HashSet toadletLinks=new HashSet();
- private boolean stopping = false;
- private boolean unregistered = false;
+ private final boolean isPproxyPlugin;
+ private final boolean isThreadlessPlugin;
+ private final boolean isIPDetectorPlugin;
+ private final boolean isBandwidthIndicator;
+ private final boolean isPortForwardPlugin;
+ private final boolean isMultiplePlugin;
+ private final boolean isFCPPlugin;
+ private final boolean isVersionedPlugin;
+ private final String filename;
+ private HashSet toadletLinks = new HashSet();
+ private volatile boolean stopping = false;
+ private volatile boolean unregistered = false;
public PluginInfoWrapper(FredPlugin plug, String filename) {
this.plug = plug;
- if (fedPluginThread) return;
className = plug.getClass().toString();
this.filename = filename;
threadName = 'p' + className.replaceAll("^class ", "") + '_' +
hashCode();
start = System.currentTimeMillis();
fedPluginThread = true;
+ isBandwidthIndicator = (plug instanceof
FredPluginBandwidthIndicator);
isPproxyPlugin = (plug instanceof FredPluginHTTP);
isThreadlessPlugin = (plug instanceof FredPluginThreadless);
isIPDetectorPlugin = (plug instanceof FredPluginIPDetector);
@@ -52,6 +53,7 @@
thread.setName(threadName);
}
+ @Override
public String toString() {
return "ID: \"" +threadName + "\", Name: "+ className +",
Started: " + (new Date(start)).toString();
}
@@ -143,6 +145,8 @@
manager.node.ipDetector.unregisterIPDetectorPlugin((FredPluginIPDetector)plug);
if(isPortForwardPlugin)
manager.node.ipDetector.unregisterPortForwardPlugin((FredPluginPortForward)plug);
+ if(isBandwidthIndicator)
+
manager.node.ipDetector.unregisterBandwidthIndicatorPlugin((FredPluginBandwidthIndicator)plug);
}
public boolean isPproxyPlugin() {
@@ -152,6 +156,10 @@
public String getFilename() {
return filename;
}
+
+ public boolean isBandwidthIndicator() {
+ return isBandwidthIndicator;
+ }
public boolean isThreadlessPlugin() {
return isThreadlessPlugin;
Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2008-08-11
14:33:18 UTC (rev 21747)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2008-08-11
14:39:46 UTC (rev 21748)
@@ -271,6 +271,9 @@
if(pi.isPortForwardPlugin()) {
node.ipDetector.registerPortForwardPlugin((FredPluginPortForward) plug);
}
+ if(pi.isBandwidthIndicator()) {
+
node.ipDetector.registerBandwidthIndicatorPlugin((FredPluginBandwidthIndicator)
plug);
+ }
}
/**