forked from I2P_Developers/i2p.i2p
Wizard: Hook test results to form
More fixes and cleanups
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, Object> map = new HashMap<String, Object>(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 */
|
||||
|
||||
@@ -160,28 +160,29 @@
|
||||
<tr><td><%=intl._t("Test server location")%></td><td><%=wizhelper.getServerLocation()%></td></tr>
|
||||
<tr><td><%=intl._t("Completion status")%></td><td><%=wizhelper.getCompletionStatus()%></td></tr>
|
||||
<tr><td><%=intl._t("Details")%></td><td><%=wizhelper.getDetailStatus()%></td></tr>
|
||||
<tr><td><%=intl._t("Upstream Bandwidth")%></td><td><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getUpBandwidth())%>Bps</td></tr>
|
||||
<tr><td><%=intl._t("Downstream Bandwidth")%></td><td><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getDownBandwidth())%>Bps</td></tr>
|
||||
<tr><td><%=intl._t("Upstream Bandwidth")%></td><td><%=net.i2p.data.DataHelper.formatSize2Decimal(wizhelper.getUpBandwidth())%>Bps</td></tr>
|
||||
<tr><td><%=intl._t("Share of Bandwidth for I2P")%></td><td><%=Math.round(net.i2p.router.web.helpers.WizardHelper.BW_SCALE * 100)%>%</td></tr>
|
||||
</table>
|
||||
<h3><%=intl._t("Bandwidth Configuration")%></h3>
|
||||
<table id="bandwidthconfig" class="configtable">
|
||||
<tr><td class="infohelp" colspan="2">
|
||||
<%=intl._t("I2P will work best if you configure your rates to match the speed of your internet connection.")%>
|
||||
</td></tr>
|
||||
<tr><td><input style="text-align: right; width: 5em;" name="inboundrate" type="text" size="5" maxlength="5" value="<jsp:getProperty name="nethelper" property="inboundBurstRate" />" >
|
||||
<tr><td><input style="text-align: right; width: 5em;" name="inboundrate" type="text" size="5" maxlength="5" value="<jsp:getProperty name="wizhelper" property="inboundBurstRate" />" >
|
||||
<%=intl._t("KBps In")%>
|
||||
</td><td>(<jsp:getProperty name="nethelper" property="inboundBurstRateBits" />)</td>
|
||||
</td><td>(<jsp:getProperty name="wizhelper" property="inboundBurstRateBits" />)</td>
|
||||
</tr><tr>
|
||||
<%-- display burst, set standard, handler will fix up --%>
|
||||
<td><input style="text-align: right; width: 5em;" name="outboundrate" type="text" size="5" maxlength="5" value="<jsp:getProperty name="nethelper" property="outboundBurstRate" />" >
|
||||
<td><input style="text-align: right; width: 5em;" name="outboundrate" type="text" size="5" maxlength="5" value="<jsp:getProperty name="wizhelper" property="outboundBurstRate" />" >
|
||||
<%=intl._t("KBps Out")%>
|
||||
</td><td>(<jsp:getProperty name="nethelper" property="outboundBurstRateBits" />)</td>
|
||||
</td><td>(<jsp:getProperty name="wizhelper" property="outboundBurstRateBits" />)</td>
|
||||
</tr><tr>
|
||||
<td><jsp:getProperty name="nethelper" property="sharePercentageBox" /> <%=intl._t("Share")%></td>
|
||||
<td>(<jsp:getProperty name="nethelper" property="shareRateBits" />)
|
||||
<td>(<jsp:getProperty name="wizhelper" property="shareRateBits" />)
|
||||
</td></tr>
|
||||
<tr><td class="infohelp" colspan="2">
|
||||
<% int share = Math.round(nethelper.getShareBandwidth() * 1.024f);
|
||||
<% int share = Math.round(wizhelper.getShareBandwidth() * 1.024f);
|
||||
if (share < 12) {
|
||||
out.print("<b>");
|
||||
out.print(intl._t("NOTE"));
|
||||
|
||||
Reference in New Issue
Block a user