diff --git a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java index 2e7d8e4fc..261cae5af 100644 --- a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java +++ b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java @@ -87,6 +87,8 @@ public class MLabRunner { */ public ToolRun runNDT(final ToolListener listener) { if (!_running.compareAndSet(false, true)) { + listener.reportSummary("Test already running"); + listener.reportDetail("Test already running"); _log.warn("Test already running"); return null; } @@ -107,10 +109,10 @@ public class MLabRunner { public void reportSummary(String str) { str = str.trim(); - log( str ); - if ( listener != null ){ - if ( !str.startsWith( "Click" )){ - listener.reportSummary( str ); + log(str); + if (listener != null){ + if (!str.startsWith("Click")) { + listener.reportSummary(str); } } } @@ -235,7 +237,7 @@ public class MLabRunner { } else { result_str = "Completed: up=" + DataHelper.formatSize2Decimal(up_bps, false) + - ", down=" + DataHelper.formatSize2Decimal(down_bps, false); + "Bps, down=" + DataHelper.formatSize2Decimal(down_bps, false) + "Bps"; } _log.warn(result_str); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHelper.java index c24fcf22a..6cd435303 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHelper.java @@ -375,9 +375,9 @@ public class ConfigNetHelper extends HelperBase { public int getShareBandwidth() { int irateKBps = _context.bandwidthLimiter().getInboundKBytesPerSecond(); int orateKBps = _context.bandwidthLimiter().getOutboundKBytesPerSecond(); - double pct = _context.router().getSharePercentage(); if (irateKBps < 0 || orateKBps < 0) return DEFAULT_SHARE_KBPS; + double pct = _context.router().getSharePercentage(); return (int) (pct * Math.min(irateKBps, orateKBps)); } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java index 59a2338e0..b9ce0b25f 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java @@ -19,6 +19,11 @@ import net.i2p.router.web.HelperBase; public class WizardHelper extends HelperBase { public static final String PROP_COMPLETE = "routerconsole.welcomeWizardComplete"; + // scale bw test results by this for limiter settings + public static final float BW_SCALE = 0.75f; + // KBps + private static final float MIN_DOWN_BW = 32.0f; + private static final float MIN_UP_BW = 12.0f; // session scope, but it's an underlying singleton private MLabRunner _mlab; @@ -129,6 +134,100 @@ public class WizardHelper extends HelperBase { return null; } + /** + * To populate form with. + * Uses the test result if available, else the current setting + * Adapted from ConfigNetHelper. + * @return decimal KBytes/sec + */ + public String getInboundBurstRate() { + float bw; + long result = getDownBandwidth(); + if (result > 0) { + bw = Math.max(MIN_DOWN_BW, BW_SCALE * result / 1000f); + } else { + bw = _context.bandwidthLimiter().getInboundBurstKBytesPerSecond() * 1.024f; + } + return Integer.toString(Math.round(bw)); + } + + /** + * To populate form with. + * Uses the test result if available, else the current setting + * Adapted from ConfigNetHelper. + * @return decimal KBytes/sec + */ + public String getOutboundBurstRate() { + float bw; + long result = getUpBandwidth(); + if (result > 0) { + bw = Math.max(MIN_UP_BW, BW_SCALE * result / 1000f); + } else { + bw = _context.bandwidthLimiter().getOutboundBurstKBytesPerSecond() * 1.024f; + } + return Integer.toString(Math.round(bw)); + } + + /** + * Copied from ConfigNetHelper. + * @return decimal + */ + public String getInboundBurstRateBits() { + return kbytesToBits(_context.bandwidthLimiter().getInboundBurstKBytesPerSecond()); + } + + /** + * Copied from ConfigNetHelper. + * @return decimal + */ + public String getOutboundBurstRateBits() { + return kbytesToBits(_context.bandwidthLimiter().getOutboundBurstKBytesPerSecond()); + } + + /** + * Copied from ConfigNetHelper. + * @return decimal + */ + public String getShareRateBits() { + return kbytesToBits(getShareBandwidth()); + } + + /** + * Copied from ConfigNetHelper. + * @param kbytes binary K + * @return decimal + */ + private String kbytesToBits(float kbytes) { + return DataHelper.formatSize2Decimal((long) (kbytes * (8 * 1024))) + _t("bits per second") + + "; " + + _t("{0}Bytes per month maximum", DataHelper.formatSize2Decimal((long) (kbytes * (1024L * 60 * 60 * 24 * 31)))); + } + + /** + * Adapted from ConfigNetHelper. + * @return in binary KBytes per second + */ + public int getShareBandwidth() { + float irateKBps; + float orateKBps; + long result = getDownBandwidth(); + if (result > 0) { + irateKBps = Math.max(MIN_DOWN_BW, BW_SCALE * result / 1024f); + } else { + irateKBps = _context.bandwidthLimiter().getInboundKBytesPerSecond(); + } + result = getUpBandwidth(); + if (result > 0) { + orateKBps = Math.max(MIN_UP_BW, BW_SCALE * result / 1024f); + } else { + orateKBps = _context.bandwidthLimiter().getOutboundKBytesPerSecond(); + } + if (irateKBps < 0 || orateKBps < 0) + return ConfigNetHelper.DEFAULT_SHARE_KBPS; + double pct = _context.router().getSharePercentage(); + return (int) (pct * Math.min(irateKBps, orateKBps)); + } + /** * Start the test. Called from the Handler. * @return success @@ -137,15 +236,16 @@ public class WizardHelper extends HelperBase { if (_mlab.isRunning() || _listener != null && !_listener.isComplete()) { return false; } - _listener = new TestListener(); - _runner = _mlab.runNDT(_listener); - if (_runner != null) { - return true; - } else { + TestListener lsnr = new TestListener(); + _runner = _mlab.runNDT(lsnr); + boolean rv = _runner != null; + if (!rv) { Map map = new HashMap(2); - _listener.complete(map); - return false; + lsnr.complete(map); } + // replace the old listener + _listener = lsnr; + return rv; } /** @@ -156,13 +256,12 @@ public class WizardHelper extends HelperBase { if (!_mlab.isRunning()) { return false; } - if (_runner != null) { + boolean rv = _runner != null; + if (rv) { _runner.cancel(); _runner = null; - return true; - } else { - return false; } + return rv; } /** test results */ diff --git a/apps/routerconsole/jsp/welcome.jsp b/apps/routerconsole/jsp/welcome.jsp index 15562ab06..c9070d24b 100644 --- a/apps/routerconsole/jsp/welcome.jsp +++ b/apps/routerconsole/jsp/welcome.jsp @@ -160,28 +160,29 @@ <%=intl._t("Test server location")%><%=wizhelper.getServerLocation()%> <%=intl._t("Completion status")%><%=wizhelper.getCompletionStatus()%> <%=intl._t("Details")%><%=wizhelper.getDetailStatus()%> -<%=intl._t("Upstream Bandwidth")%><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getUpBandwidth())%>Bps <%=intl._t("Downstream Bandwidth")%><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getDownBandwidth())%>Bps +<%=intl._t("Upstream Bandwidth")%><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getUpBandwidth())%>Bps +<%=intl._t("Share of Bandwidth for I2P")%><%=Math.round(net.i2p.router.web.helpers.WizardHelper.BW_SCALE * 100)%>%

<%=intl._t("Bandwidth Configuration")%>

- + <%-- display burst, set standard, handler will fix up --%> - + -
<%=intl._t("I2P will work best if you configure your rates to match the speed of your internet connection.")%>
" > +
" > <%=intl._t("KBps In")%> -()()
" > +" > <%=intl._t("KBps Out")%> -()()
<%=intl._t("Share")%>() +()
-<% int share = Math.round(nethelper.getShareBandwidth() * 1.024f); +<% int share = Math.round(wizhelper.getShareBandwidth() * 1.024f); if (share < 12) { out.print(""); out.print(intl._t("NOTE"));