java.lang.Object
net.i2p.router.web.helpers.BanlistRenderer

class BanlistRendererextends Object
Renders HTML display of banned routers for the router console. Displays banlist entries including expiration times, reasons, and provides management interface for router bans. Moved from Banlist.java for separation of concerns.
  • Field Details

    • _context

      private final RouterContext _context
      The router context.
    • IP_HOSTNAME_NORMALIZE

      private static final Pattern IP_HOSTNAME_NORMALIZE
      Pattern normalizing an IP or hostname for display.
    • PIPE_SPLIT

      private static final Pattern PIPE_SPLIT
      Pattern splitting a ban record on the pipes.
    • VERSION_LU_SUFFIX

      private static final Pattern VERSION_LU_SUFFIX
      Pattern matching the local update suffix of a version.
    • VERSION_SUFFIX

      private static final Pattern VERSION_SUFFIX
      Pattern matching the trailing junk of a version string.
    • VERSION_PREFIX

      private static final Pattern VERSION_PREFIX
      Pattern matching the leading junk of a version string.
    • VERSION_EXTRACT

      private static final Pattern VERSION_EXTRACT
      Pattern extracting the version numbers from a string.
    • MAX_BEFORE_STREAMING

      private static final int MAX_BEFORE_STREAMING
      Render rows in a single write up to this count; above it, flush every STREAM_BATCH rows so the page paints progressively.
      See Also:
    • STREAM_BATCH

      private static final int STREAM_BATCH
      Rows rendered per flush when streaming a large table.
      See Also:
    • KEY_LEN

      private static final int KEY_LEN
      Length of the truncated base64 hash used as a per-row data-key in fragment mode; 16 chars = 96 bits, collision-free at 10K-20K rows.
      See Also:
  • Constructor Details

    • BanlistRenderer

      public BanlistRenderer(RouterContext context)
      Stores the router context used to reach the banlist and network database.
      Parameters:
      context - the router context
  • Method Details

    • reverseLookup

      private String reverseLookup(String ip)
      Looks up the hostname for a banned IP.
      Parameters:
      ip - the address to look up
      Returns:
      the hostname, null if not found
    • readSessionBans

      private Object[] readSessionBans()
      Read sessionbans.txt once and build all three data structures in a single pass. Replaces the three separate readSessionBans* methods that each opened the file independently.
      Returns:
      array of [Map<String,String> ipMap, Map<String,String> hostnameMap, List<IPBanEntry> ipOnlyBans]
    • extractIP

      private String extractIP(String ipPort)
      Extract IP address from IP:PORT format. Handles both IPv4 (1.2.3.4:port) and IPv6 ([::1]:port) formats.
      Parameters:
      ipPort - the address string to split, may be null or empty
      Returns:
      the IP without the port; the input unchanged when null, empty or portless
    • extractPort

      private String extractPort(String ipPort)
      Extract port from IP:PORT format. Returns null if no port is found.
      Parameters:
      ipPort - the address string to split, may be null or empty
      Returns:
      the port as a string, or null when no port is present
    • parseDuration

      private long parseDuration(String durationStr, long now)
      Parse duration string to expiration timestamp.
      Parameters:
      durationStr - the duration to parse, e.g. "7d", "12h", "30m", "500ms" or "FOREVER"
      now - the current time in ms the expiration is based on
      Returns:
      the expiration time in ms; FOREVER means 180 days out, an unparseable or unit-less value means now
    • renderBanlistCompact

      public void renderBanlistCompact(Writer out) throws IOException
      Render the compact banlist HTML table.
      Parameters:
      out - the writer to render to
      Throws:
      IOException - if writing fails
    • countBannedFloodfills

      public int countBannedFloodfills()
      Count active bans of floodfill-capable peers, matching the banFF classification used by renderBanlist(Writer, boolean): caps from the session log or netdb, or a "floodfill" cause.
      Returns:
      how many active bans are floodfills
    • renderBanlistFragment

      public void renderBanlistFragment(Writer out) throws IOException
      Render only the <tbody id=sessionBanlist> for the contentonly fragment mode, with a data-key per row for the worker-side row diff. The full page keeps the wrapper div, thead, and tfoot.
      Parameters:
      out - the writer to render to
      Throws:
      IOException - if writing fails
    • renderBanlist

      private void renderBanlist(Writer out, boolean fragmentKeys) throws IOException
      Render the compact banlist table; both renderBanlistCompact(Writer) and renderBanlistFragment(Writer) delegate here.
      Parameters:
      out - the writer to render to
      fragmentKeys - when true, emit only the tbody with data-key rows
      Throws:
      IOException - if writing fails
    • _t

      private String _t(String s)
      Translate a string.
      Parameters:
      s - the string to translate
      Returns:
      the translated string
    • _t

      private String _t(String s, Object o)
      Translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.
      Parameters:
      s - string to be translated containing {0} The {0} will be replaced by the parameter. Single quotes must be doubled, i.e. ' -> '' in the string.
      o - parameter, not translated. To translate parameter also, use _t("foo {0} bar", _t("baz")) Do not double the single quotes in the parameter. Use autoboxing to call with ints, longs, floats, etc.
      Returns:
      the translated string with the first {0} replaced by the parameter
    • getRouterVersion

      private String getRouterVersion(Hash hash, String reason)
      Router version for a banned hash, from NetDB or parsed out of the ban reason.
      Parameters:
      hash - the router hash to look up, null yields no version
      reason - the ban reason string, searched for a version pattern
      Returns:
      the version string, or null if neither source carries one
    • getRouterCaps

      private String getRouterCaps(Hash hash)
      Get router capabilities string from NetDB.
      Parameters:
      hash - the router hash to look up, null yields the empty string
      Returns:
      caps string or empty string
    • cleanReason

      private String cleanReason(String reason, String routerVersion)
      Rewrites a ban reason for display.
      Parameters:
      reason - the reason as logged
      routerVersion - the version string extracted from it
      Returns:
      the reason cleaned for display