From 692790c4ed85ff4eedeb8045e9f210312e2edf09 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Tue, 5 Dec 2017 15:53:05 +0000
Subject: [PATCH] Router: Parameterize bandwidth classes, fix display on
 /tunnels

---
 .../router/web/helpers/TunnelRenderer.java    | 17 +++++++-----
 router/java/src/net/i2p/router/Router.java    | 27 ++++++++++++++-----
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/TunnelRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/TunnelRenderer.java
index 5bf360dd97..25ea1e4755 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/TunnelRenderer.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/TunnelRenderer.java
@@ -150,21 +150,26 @@ class TunnelRenderer {
         out.write("<h3 class=\"tabletitle\">" + _t("Bandwidth Tiers") + "</h3>\n");
         out.write("<table id=\"tunnel_defs\"><tbody>");
         out.write("<tr><td>&nbsp;</td>"
-                  + "<td><span class=\"tunnel_cap\"><b>L</b></span></td><td>" + _t("{0} shared bandwidth", "12 - 32KBps") + "</td>"
-                  + "<td><span class=\"tunnel_cap\"><b>M</b></span></td><td>" + _t("{0} shared bandwidth", "32 - 64KBps") + "</td>"
+                  + "<td><span class=\"tunnel_cap\"><b>L</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_L, Router.MIN_BW_M)) + "</td>"
+                  + "<td><span class=\"tunnel_cap\"><b>M</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_M, Router.MIN_BW_N)) + "</td>"
                   + "<td>&nbsp;</td></tr>");
         out.write("<tr><td>&nbsp;</td>"
-                  + "<td><span class=\"tunnel_cap\"><b>N</b></span></td><td>" + _t("{0} shared bandwidth", "64 - 128KBps") + "</td>"
-                  + "<td><span class=\"tunnel_cap\"><b>O</b></span></td><td>" + _t("{0} shared bandwidth", "128 - 256KBps") + "</td>"
+                  + "<td><span class=\"tunnel_cap\"><b>N</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_N, Router.MIN_BW_O)) + "</td>"
+                  + "<td><span class=\"tunnel_cap\"><b>O</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_O, Router.MIN_BW_P)) + "</td>"
                   + "<td>&nbsp;</td></tr>");
         out.write("<tr><td>&nbsp;</td>"
-                  + "<td><span class=\"tunnel_cap\"><b>P</b></span></td><td>" + _t("{0} shared bandwidth", "256 - 2000KBps") + "</td>"
-                  + "<td><span class=\"tunnel_cap\"><b>X</b></span></td><td>" + _t("Over {0} shared bandwidth", "2000KBps") + "</td>"
+                  + "<td><span class=\"tunnel_cap\"><b>P</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_P, Router.MIN_BW_X)) + "</td>"
+                  + "<td><span class=\"tunnel_cap\"><b>X</b></span></td><td>" + _t("Over {0} shared bandwidth", Router.MIN_BW_X + " KBps") + "</td>"
                   + "<td>&nbsp;</td></tr>");
         out.write("</tbody></table>");
 
     }
 
+    /** @since 0.9.33 */
+    private static String range(int f, int t) {
+        return f + " - " + t + " KBps";
+    }
+
     private static class TunnelComparator implements Comparator<HopConfig>, Serializable {
          public int compare(HopConfig l, HopConfig r) {
              return (r.getProcessedMessagesCount() - l.getProcessedMessagesCount());
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 95038bd868..651c4e1a9b 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -952,6 +952,21 @@ public class Router implements RouterClock.ClockShiftListener {
     @Deprecated
     public static final char CAPABILITY_NEW_TUNNEL = 'T';
     
+    /** @since 0.9.33 */
+    public static final int MIN_BW_K = 0;
+    /** @since 0.9.33 */
+    public static final int MIN_BW_L = 12;
+    /** @since 0.9.33 */
+    public static final int MIN_BW_M = 48;
+    /** @since 0.9.33 */
+    public static final int MIN_BW_N = 64;
+    /** @since 0.9.33 */
+    public static final int MIN_BW_O = 128;
+    /** @since 0.9.33 */
+    public static final int MIN_BW_P = 256;
+    /** @since 0.9.33 */
+    public static final int MIN_BW_X = 2000;
+
     /**
      *  The current bandwidth class.
      *  For building our RI. Not for external use.
@@ -967,17 +982,17 @@ public class Router implements RouterClock.ClockShiftListener {
         String force = _context.getProperty(PROP_FORCE_BWCLASS);
         if (force != null && force.length() > 0) {
             return force.charAt(0);
-        } else if (bwLim < 12) {
+        } else if (bwLim < MIN_BW_L) {
             return CAPABILITY_BW12;
-        } else if (bwLim <= 48) {
+        } else if (bwLim <= MIN_BW_M) {
             return CAPABILITY_BW32;
-        } else if (bwLim <= 64) {
+        } else if (bwLim <= MIN_BW_N) {
             return CAPABILITY_BW64;
-        } else if (bwLim <= 128) {
+        } else if (bwLim <= MIN_BW_O) {
             return CAPABILITY_BW128;
-        } else if (bwLim <= 256) {
+        } else if (bwLim <= MIN_BW_P) {
             return CAPABILITY_BW256;
-        } else if (bwLim <= 2000) {    // TODO adjust threshold
+        } else if (bwLim <= MIN_BW_X) {    // TODO adjust threshold
             // 512 supported as of 0.9.18;
             return CAPABILITY_BW512;
         } else {
-- 
GitLab