Console: Show and set burst bandwidth on /config (ticket #2123)

Better error handling
Comment out some unused things, misc. cleanups
This commit is contained in:
zzz
2018-01-06 16:15:15 +00:00
parent b8f17c7ac4
commit f32d3aaef5
4 changed files with 68 additions and 36 deletions

View File

@ -43,11 +43,11 @@ public class ConfigNetHandler extends FormHandler {
private boolean _upnp; private boolean _upnp;
private boolean _laptop; private boolean _laptop;
private String _inboundRate; private String _inboundRate;
private String _inboundBurstRate; //private String _inboundBurstRate;
private String _inboundBurst; //private String _inboundBurst;
private String _outboundRate; private String _outboundRate;
private String _outboundBurstRate; //private String _outboundBurstRate;
private String _outboundBurst; //private String _outboundBurst;
private String _sharePct; private String _sharePct;
private boolean _ratesOnly; private boolean _ratesOnly;
private boolean _udpDisabled; private boolean _udpDisabled;
@ -114,21 +114,29 @@ public class ConfigNetHandler extends FormHandler {
public void setInboundrate(String rate) { public void setInboundrate(String rate) {
_inboundRate = (rate != null ? rate.trim() : null); _inboundRate = (rate != null ? rate.trim() : null);
} }
/*
public void setInboundburstrate(String rate) { public void setInboundburstrate(String rate) {
_inboundBurstRate = (rate != null ? rate.trim() : null); _inboundBurstRate = (rate != null ? rate.trim() : null);
} }
public void setInboundburstfactor(String factor) { public void setInboundburstfactor(String factor) {
_inboundBurst = (factor != null ? factor.trim() : null); _inboundBurst = (factor != null ? factor.trim() : null);
} }
****/
public void setOutboundrate(String rate) { public void setOutboundrate(String rate) {
_outboundRate = (rate != null ? rate.trim() : null); _outboundRate = (rate != null ? rate.trim() : null);
} }
/*
public void setOutboundburstrate(String rate) { public void setOutboundburstrate(String rate) {
_outboundBurstRate = (rate != null ? rate.trim() : null); _outboundBurstRate = (rate != null ? rate.trim() : null);
} }
public void setOutboundburstfactor(String factor) { public void setOutboundburstfactor(String factor) {
_outboundBurst = (factor != null ? factor.trim() : null); _outboundBurst = (factor != null ? factor.trim() : null);
} }
****/
public void setSharePercentage(String pct) { public void setSharePercentage(String pct) {
_sharePct = (pct != null ? pct.trim() : null); _sharePct = (pct != null ? pct.trim() : null);
} }
@ -487,28 +495,38 @@ public class ConfigNetHandler extends FormHandler {
} }
} }
// Since burst is now hidden in the gui, set burst to +10% for 20 seconds // Since burst is now hidden in the gui, set burst to +10% for 20 seconds (prior to 0.9.33)
// As of 0.9.33, we set strict bandwidth limits. Specified rate is the burst rate,
// and we set the standard rate to 50KB or 10% lower (whichever is less).
if ( (_inboundRate != null) && (_inboundRate.length() > 0) && if ( (_inboundRate != null) && (_inboundRate.length() > 0) &&
!_inboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, "" + FIFOBandwidthRefiller.DEFAULT_INBOUND_BANDWIDTH))) { !_inboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH,
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, _inboundRate); Integer.toString(FIFOBandwidthRefiller.DEFAULT_INBOUND_BURST_BANDWIDTH)))) {
try { try {
int rate = Integer.parseInt(_inboundRate) * (100 + DEF_BURST_PCT) / 100; int rate = Integer.parseInt(_inboundRate);
int kb = DEF_BURST_TIME * rate; int kb = DEF_BURST_TIME * rate;
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, "" + rate); changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, Integer.toString(rate));
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, "" + kb); changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, Integer.toString(kb));
} catch (NumberFormatException nfe) {} rate -= Math.min(rate * DEF_BURST_PCT / 100, 50);
bwUpdated = true; changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, Integer.toString(rate));
bwUpdated = true;
} catch (NumberFormatException nfe) {
addFormError(_t("Invalid bandwidth"));
}
} }
if ( (_outboundRate != null) && (_outboundRate.length() > 0) && if ( (_outboundRate != null) && (_outboundRate.length() > 0) &&
!_outboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, "" + FIFOBandwidthRefiller.DEFAULT_OUTBOUND_BANDWIDTH))) { !_outboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH,
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, _outboundRate); Integer.toString(FIFOBandwidthRefiller.DEFAULT_OUTBOUND_BURST_BANDWIDTH)))) {
try { try {
int rate = Integer.parseInt(_outboundRate) * (100 + DEF_BURST_PCT) / 100; int rate = Integer.parseInt(_outboundRate);
int kb = DEF_BURST_TIME * rate; int kb = DEF_BURST_TIME * rate;
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, "" + rate); changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, Integer.toString(rate));
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, "" + kb); changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, Integer.toString(kb));
} catch (NumberFormatException nfe) {} rate -= Math.min(rate * DEF_BURST_PCT / 100, 50);
bwUpdated = true; changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, Integer.toString(rate));
bwUpdated = true;
} catch (NumberFormatException nfe) {
addFormError(_t("Invalid bandwidth"));
}
} }
if (bwUpdated) { if (bwUpdated) {

View File

@ -235,17 +235,21 @@ public class ConfigNetHelper extends HelperBase {
} }
public String getInboundRate() { public String getInboundRate() {
return "" + _context.bandwidthLimiter().getInboundKBytesPerSecond(); return Integer.toString(_context.bandwidthLimiter().getInboundKBytesPerSecond());
} }
public String getOutboundRate() { public String getOutboundRate() {
return "" + _context.bandwidthLimiter().getOutboundKBytesPerSecond(); return Integer.toString(_context.bandwidthLimiter().getOutboundKBytesPerSecond());
} }
public String getInboundRateBits() {
return kbytesToBits(_context.bandwidthLimiter().getInboundKBytesPerSecond()); public String getInboundBurstRateBits() {
return kbytesToBits(_context.bandwidthLimiter().getInboundBurstKBytesPerSecond());
} }
public String getOutboundRateBits() {
return kbytesToBits(_context.bandwidthLimiter().getOutboundKBytesPerSecond()); public String getOutboundBurstRateBits() {
return kbytesToBits(_context.bandwidthLimiter().getOutboundBurstKBytesPerSecond());
} }
public String getShareRateBits() { public String getShareRateBits() {
return kbytesToBits(getShareBandwidth()); return kbytesToBits(getShareBandwidth());
} }
@ -253,12 +257,16 @@ public class ConfigNetHelper extends HelperBase {
return DataHelper.formatSize(kbytes * (8 * 1024L)) + ' ' + _t("bits per second") + return DataHelper.formatSize(kbytes * (8 * 1024L)) + ' ' + _t("bits per second") +
' ' + _t("or {0} bytes per month maximum", DataHelper.formatSize(kbytes * (1024L * 60 * 60 * 24 * 31))); ' ' + _t("or {0} bytes per month maximum", DataHelper.formatSize(kbytes * (1024L * 60 * 60 * 24 * 31)));
} }
public String getInboundBurstRate() { public String getInboundBurstRate() {
return "" + _context.bandwidthLimiter().getInboundBurstKBytesPerSecond(); return Integer.toString(_context.bandwidthLimiter().getInboundBurstKBytesPerSecond());
} }
public String getOutboundBurstRate() { public String getOutboundBurstRate() {
return "" + _context.bandwidthLimiter().getOutboundBurstKBytesPerSecond(); return Integer.toString(_context.bandwidthLimiter().getOutboundBurstKBytesPerSecond());
} }
/*
public String getInboundBurstFactorBox() { public String getInboundBurstFactorBox() {
int numSeconds = 1; int numSeconds = 1;
int rateKBps = _context.bandwidthLimiter().getInboundBurstKBytesPerSecond(); int rateKBps = _context.bandwidthLimiter().getInboundBurstKBytesPerSecond();
@ -301,10 +309,10 @@ public class ConfigNetHelper extends HelperBase {
return buf.toString(); return buf.toString();
} }
/** removed */
public String getEnableLoadTesting() { public String getEnableLoadTesting() {
return ""; return "";
} }
****/
public String getSharePercentageBox() { public String getSharePercentageBox() {
int pct = (int) (100 * _context.router().getSharePercentage()); int pct = (int) (100 * _context.router().getSharePercentage());

View File

@ -30,21 +30,23 @@
<tr><td class="infohelp" colspan="2"> <tr><td class="infohelp" colspan="2">
<b><%=intl._t("I2P will work best if you configure your rates to match the speed of your internet connection.")%></b> <b><%=intl._t("I2P will work best if you configure your rates to match the speed of your internet connection.")%></b>
</td></tr> </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="inboundRate" />" > <%-- display burst, set standard, handler will fix up --%>
<tr><td><input style="text-align: right; width: 5em;" name="inboundrate" type="text" size="5" maxlength="5" value="<jsp:getProperty name="nethelper" property="inboundBurstRate" />" >
<%=intl._t("KBps In")%> <%=intl._t("KBps In")%>
</td><td>(<jsp:getProperty name="nethelper" property="inboundRateBits" />)</td> </td><td>(<jsp:getProperty name="nethelper" property="inboundBurstRateBits" />)</td>
<% /******** <%--
<!-- let's keep this simple... <!-- let's keep this simple...
bursting up to bursting up to
<input name="inboundburstrate" type="text" size="5" value="<jsp:getProperty name="nethelper" property="inboundBurstRate" />" /> KBps for <input name="inboundburstrate" type="text" size="5" value="<jsp:getProperty name="nethelper" property="inboundBurstRate" />" /> KBps for
<jsp:getProperty name="nethelper" property="inboundBurstFactorBox" /><br> <jsp:getProperty name="nethelper" property="inboundBurstFactorBox" /><br>
--> -->
*********/ %> --%>
</tr><tr> </tr><tr>
<td><input style="text-align: right; width: 5em;" name="outboundrate" type="text" size="5" maxlength="5" value="<jsp:getProperty name="nethelper" property="outboundRate" />" > <%-- 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" />" >
<%=intl._t("KBps Out")%> <%=intl._t("KBps Out")%>
</td><td>(<jsp:getProperty name="nethelper" property="outboundRateBits" />)</td> </td><td>(<jsp:getProperty name="nethelper" property="outboundBurstRateBits" />)</td>
<% /******** <%--
<!-- let's keep this simple... <!-- let's keep this simple...
bursting up to bursting up to
<input name="outboundburstrate" type="text" size="2" value="<jsp:getProperty name="nethelper" property="outboundBurstRate" />" /> KBps for <input name="outboundburstrate" type="text" size="2" value="<jsp:getProperty name="nethelper" property="outboundBurstRate" />" /> KBps for
@ -52,7 +54,7 @@
<i>KBps = kilobytes per second = 1024 bytes per second = 8192 bits per second.<br> <i>KBps = kilobytes per second = 1024 bytes per second = 8192 bits per second.<br>
A negative rate sets the default.</i><br> A negative rate sets the default.</i><br>
--> -->
*********/ %> --%>
</tr><tr> </tr><tr>
<td><jsp:getProperty name="nethelper" property="sharePercentageBox" /> <%=intl._t("Share")%></td> <td><jsp:getProperty name="nethelper" property="sharePercentageBox" /> <%=intl._t("Share")%></td>
<td>(<jsp:getProperty name="nethelper" property="shareRateBits" />) <td>(<jsp:getProperty name="nethelper" property="shareRateBits" />)

View File

@ -233,6 +233,8 @@ public class FIFOBandwidthRefiller implements Runnable {
if (_inboundBurstKBytesPerSecond <= 0) if (_inboundBurstKBytesPerSecond <= 0)
_inboundBurstKBytesPerSecond = DEFAULT_INBOUND_BURST_BANDWIDTH; _inboundBurstKBytesPerSecond = DEFAULT_INBOUND_BURST_BANDWIDTH;
if (_inboundBurstKBytesPerSecond < _inboundKBytesPerSecond)
_inboundBurstKBytesPerSecond = _inboundKBytesPerSecond;
_limiter.setInboundBurstKBps(_inboundBurstKBytesPerSecond); _limiter.setInboundBurstKBps(_inboundBurstKBytesPerSecond);
} }
@ -250,6 +252,8 @@ public class FIFOBandwidthRefiller implements Runnable {
if (_outboundBurstKBytesPerSecond <= 0) if (_outboundBurstKBytesPerSecond <= 0)
_outboundBurstKBytesPerSecond = DEFAULT_OUTBOUND_BURST_BANDWIDTH; _outboundBurstKBytesPerSecond = DEFAULT_OUTBOUND_BURST_BANDWIDTH;
if (_outboundBurstKBytesPerSecond < _outboundKBytesPerSecond)
_outboundBurstKBytesPerSecond = _outboundKBytesPerSecond;
_limiter.setOutboundBurstKBps(_outboundBurstKBytesPerSecond); _limiter.setOutboundBurstKBps(_outboundBurstKBytesPerSecond);
} }