java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.SidebarHelper

public class SidebarHelperextends HelperBase
Simple helper to query the appropriate router for data necessary to render the summary sections on the router console.

For the full summary bar use renderSummaryBar().

  • Field Details

    • _session

      private HttpSession _session
      Active HTTP session for nonce-based form validation.
    • _buildSuccessCachedUntil

      private static volatile long _buildSuccessCachedUntil
      Expiry for the cached tunnel build success. The cache is shared across requests and refreshed once per sidebar cycle, not on every render.
    • _concurrencyCachedUntil

      private static volatile long _concurrencyCachedUntil
      Expiry for the cached concurrency string.
    • _shareRatioCachedUntil

      private static volatile long _shareRatioCachedUntil
      Expiry for the cached share ratio string.
    • _activeProfilesCachedUntil

      private static volatile long _activeProfilesCachedUntil
      Expiry for the cached active profile count.
    • _cachedTunnelBuildSuccess

      private static volatile int _cachedTunnelBuildSuccess
      Cached tunnel build success percentage.
    • _cachedConcurrency

      private static volatile String _cachedConcurrency
      Cached concurrency string.
    • _cachedShareRatio

      private static volatile String _cachedShareRatio
      Cached share ratio string.
    • _cachedActiveProfiles

      private static volatile int _cachedActiveProfiles
      Cached active profile count.
    • THINSP

      static final String THINSP
      Thin space separator.
      See Also:
    • S

      private static final char S
      Separator character for summary bar section configuration.
      See Also:
    • INTEGER_FORMAT

      private static final DecimalFormat INTEGER_FORMAT
      Integer formatter with thousands separators.
    • ONE_DECIMAL

      private static final DecimalFormat ONE_DECIMAL
      One-decimal-place formatter.
    • TWO_DECIMALS

      private static final DecimalFormat TWO_DECIMALS
      Two-decimal-place formatter.
    • ZERO_DECIMAL

      private static final DecimalFormat ZERO_DECIMAL
      Zero-decimal-place formatter.
    • ZERO_ONE_DECIMAL

      private static final DecimalFormat ZERO_ONE_DECIMAL
      Zero-decimal one-digit formatter.
    • ZERO_TWO_DECIMALS

      private static final DecimalFormat ZERO_TWO_DECIMALS
      Zero-decimal two-digit formatter.
    • ctx

      Global application context.
    • PROP_ADVANCED

      private static final String PROP_ADVANCED
      Property name for advanced mode toggle.
      See Also:
    • PROP_UNIFIED_SIDEBAR

      private static final String PROP_UNIFIED_SIDEBAR
      Property name for unified sidebar toggle.
      See Also:
    • PROP_SUMMARYBAR

      static final String PROP_SUMMARYBAR
      Property prefix for summary bar section configuration per page.
      See Also:
    • firstVersion

      String firstVersion
      First version the router was started with, used to detect new installs.
    • version

      String version
      Current I2P core version.
    • DEFAULT_FULL_NEWUSER

      static final String DEFAULT_FULL_NEWUSER
      Default full summary bar sections for new users.
      See Also:
    • DEFAULT_FULL

      static final String DEFAULT_FULL
      Default full summary bar sections.
      See Also:
    • DEFAULT_FULL_ADVANCED

      static final String DEFAULT_FULL_ADVANCED
      Default full summary bar sections for advanced mode.
      See Also:
    • DEFAULT_MINIMAL

      static final String DEFAULT_MINIMAL
      Default minimal summary bar sections.
      See Also:
    • DEFAULT_MINIMAL_ADVANCED

      static final String DEFAULT_MINIMAL_ADVANCED
      Default minimal summary bar sections for advanced mode
      See Also:
    • _newshelper

      private NewsHelper _newshelper
      Cached news helper instance.
    • SS

      private static final String SS
      Separator string for summary bar config.
    • _action

      private String _action
      Action parameter from the sidebar form.
    • _consoleNonce

      private String _consoleNonce
      Console nonce for form validation.
    • _updateNonce

      private String _updateNonce
      Update nonce for form validation.
    • _requestURI

      private String _requestURI
      Cached request URI.
    • _request

      private HttpServletRequest _request
      The HTTP servlet request.
  • Constructor Details

    • SidebarHelper

      public SidebarHelper()
      No HTTP session is bound yet, so the summary sections fall back to the session-less nonce path until storeSession(HttpSession) supplies one.
  • Method Details

    • statsCacheMs

      private long statsCacheMs()
      How long cached sidebar stats stay valid: one sidebar refresh interval. Never shorter than 1 second so concurrent renders share the cache.
      Returns:
      the refresh interval, in milliseconds
    • storeSession

      public void storeSession(HttpSession session)
      For form validation and session-bound nonce generation.
      Parameters:
      session - the request session to bind, read back when minting CSRF nonces and when rendering the config restart status
    • fmtInt

      private static String fmtInt(long val)
      Format a long value with thousands separators.
      Parameters:
      val - the number to format, grouped in thousands
      Returns:
      the formatted digits with grouping separators
    • isAdvanced

      public boolean isAdvanced()
      Whether advanced mode is on, which selects the fuller sidebar sections.
      Overrides:
      isAdvanced in class HelperBase
      Returns:
      true if routerconsole.advanced is set
    • unifiedSidebar

      public boolean unifiedSidebar()
      Whether the unified sidebar layout is used instead of the classic one.
      Returns:
      true if routerconsole.unifiedSidebar is set
    • getIdent

      public String getIdent()
      Retrieve the shortened 4 character ident for the router located within the current JVM at the given context.
      Returns:
      the first 4 base64 characters of the router hash, or the "[no router]" / "[unknown]" placeholder when no local router is running
    • getVersion

      public String getVersion()
      Retrieve the version number of the router.
      Returns:
      RouterVersion.FULL_VERSION
    • getUptime

      public String getUptime()
      Retrieve a pretty printed uptime count (ala 4d or 7h or 39m).
      Returns:
      the formatted duration, or the "[no router]" / "[not up]" placeholder when no router is running
    • allowReseed

      public boolean allowReseed()
      Whether manual reseed should be allowed, based on uptime and known router count or the always-allow property.
      Returns:
      true if the network database is up and either reseed is warranted or it has been force-allowed, else false
    • getAllPeers

      public int getAllPeers()
      How many routers we know about, minus ourselves.
      Returns:
      peer count, minimum 0
    • getReachability

      public SidebarHelper.NetworkStateMessage getReachability()
      Gets the router's network reachability for the summary bar.
      Returns:
      the state plus a localized message explaining it
    • reachability

      private SidebarHelper.NetworkStateMessage reachability()
      Asks the router how reachable it is.
      Returns:
      the state and the message to show
    • getMemory

      public String getMemory()
      Retrieve amount of used memory.
      Returns:
      a display string of "used / total M", both in MiB
    • getMemoryBar

      public String getMemoryBar()
      Render the memory usage bar with blended real-time and one-minute average.
      Returns:
      HTML for the memory bar display
    • getCPULoad

      public int getCPULoad()
      Retrieve CPU Load as a percentage.
      Returns:
      the CPU load
    • getCPULoadAvg

      public int getCPULoadAvg()
      Retrieve CPU Load Average as a percentage.
      Returns:
      the CPU load avg
    • getSystemLoad

      public int getSystemLoad()
      Retrieve System Load Average as a percentage.
      Returns:
      the system load
    • getCPUBar

      public String getCPUBar()
      Render JVM CPU Load Bar.
      Returns:
      the CPU bar
    • getTunnelBuildSuccess

      public int getTunnelBuildSuccess()
      Retrieve Tunnel build success as a percentage. Returns the higher of the 1-minute or 10-minute average.
      Returns:
      the tunnel build success
    • getTunnelBuildRates

      private Rate[] getTunnelBuildRates(String name)
      Fetch the 1-minute and 10-minute rates for a named tunnel build stat.
      Parameters:
      name - the stat name
      Returns:
      two-element array [ONE_MINUTE, TEN_MINUTES], entries null if the stat is missing
    • cacheBuildSuccess

      private int cacheBuildSuccess(int value)
      Cache the tunnel build success result for the current sidebar refresh cycle.
      Parameters:
      value - the computed percentage
      Returns:
      value, as stored in the cache
    • getActivePeers

      public int getActivePeers()
      How many peers we are talking to now.
      Returns:
      the active peers
    • showFirewallWarning

      public boolean showFirewallWarning()
      Should we warn about a possible firewall problem?
      Returns:
      true if the network database is ready, the router has been up over two minutes, and it knows enough routers but has no active peers, which is the signature of inbound traffic being blocked
    • getActiveProfiles

      public int getActiveProfiles()
      How many active identities have we spoken with recently.

      Counted over a one-hour window, and the underlying scan walks every tracked profile while holding the profile organizer's reorganize read lock - the lock tunnel peer selection contends on. Cached for one refresh interval, like the other sidebar peer stats.

      Returns:
      the active profiles
    • getFastPeers

      public int getFastPeers()
      How many active peers the router ranks as fast.
      Returns:
      fast peer count
    • getHighCapacityPeers

      public int getHighCapacityPeers()
      How many active peers the router ranks as having a high capacity.
      Returns:
      high capacity peer count
    • getWellIntegratedPeers

      public int getWellIntegratedPeers()
      How many active peers the router ranks as well integrated (floodfill).
      Returns:
      floodfill peer count
    • getBanlistedPeers

      public int getBanlistedPeers()
      How many peers are banned.
      Returns:
      banned peer count
    • getUnreachablePeers

      public int getUnreachablePeers()
      How many peers are unreachable.
      Returns:
      unreachable peer count
    • getSecondKBps

      public String getSecondKBps()
      Format the current bandwidth rates for display.
      Returns:
      "x.xx / y.yy {K|M}"
    • getFiveMinuteKBps

      public String getFiveMinuteKBps()
      Format the 5-minute average bandwidth rates for display.
      Returns:
      "x.xx / y.yy {K|M}"
    • getLifetimeKBps

      public String getLifetimeKBps()
      Format the lifetime average bandwidth rates for display.
      Returns:
      "x.xx / y.yy {K|M}"
    • formatPair

      private static String formatPair(double in, double out)
      Output is decimal, not binary.
      Parameters:
      in - the receive rate in bytes per second
      out - the send rate in bytes per second
      Returns:
      "x.xx / y.yy {K|M}"
    • getInboundTransferred

      public String getInboundTransferred()
      How much data have we received since the router started (pretty printed string with 2 decimal places and the appropriate units - GB/MB/KB/bytes).
      Returns:
      the inbound transferred
    • getOutboundTransferred

      public String getOutboundTransferred()
      How much data have we sent since the router started (pretty printed string with 2 decimal places and the appropriate units - GB/MB/KB/bytes).
      Returns:
      the outbound transferred
    • isI2PTunnelRunning

      public boolean isI2PTunnelRunning()
      Are both the webapp and TCG running?
      Returns:
      whether i2 p tunnel running
    • getDestinations

      public String getDestinations()
      Client destinations connected locally.
      Returns:
      html section summary
    • getTunnelName

      private String getTunnelName(Destination d)
      Look up the translated display name for a client destination, checking SessionConfig first then TunnelPoolSettings.
      Parameters:
      d - the destination whose name is wanted, looked up by its KeysAndCert.calculateHash() hash
      Returns:
      translated tunnel name or base32 fallback
    • getInboundTunnels

      public int getInboundTunnels()
      How many free inbound tunnels we have.
      Returns:
      the inbound tunnels
    • getOutboundTunnels

      public int getOutboundTunnels()
      How many active outbound tunnels we have.
      Returns:
      the outbound tunnels
    • getInboundClientTunnels

      public int getInboundClientTunnels()
      How many inbound client tunnels we have.
      Returns:
      the inbound client tunnels
    • getOutboundClientTunnels

      public int getOutboundClientTunnels()
      How many active outbound client tunnels we have.
      Returns:
      the outbound client tunnels
    • getParticipatingTunnels

      public int getParticipatingTunnels()
      How many tunnels we are participating in.
      Returns:
      the participating tunnels
    • getMaxParticipatingTunnels

      public String getMaxParticipatingTunnels()
      Maximum number of tunnels we are willing to participate in, either from config or a reasonable default based on system resources.
      Returns:
      max participating tunnel count as string
    • getShareRatio

      public String getShareRatio()
      Participant-to-client tunnel share ratio.
      Returns:
      ratio string formatted to appropriate precision
    • getJobLag

      public String getJobLag()
      How lagged our job queue is over the last minute (pretty printed with the units attached).
      Returns:
      the job lag
    • getMessageDelay

      public String getMessageDelay()
      How long it takes us to pump out a message, averaged over the last minute (pretty printed with the units attached).
      Returns:
      the message delay
    • getTunnelLag

      public String getTunnelLag()
      How long it takes us to test our tunnels, averaged over the last 10 minutes (pretty printed with the units attached).
      Returns:
      the tunnel lag
    • getTunnelStatus

      public String getTunnelStatus()
      Localized tunnel status string (e.g. overload/congested/normal).
      Returns:
      tunnel status or empty string if no context
    • getConcurrency

      public String getConcurrency()
      Concurrent build count and average build request time.
      Returns:
      formatted string "concurrent / requestTime"
    • getInboundBacklog

      public String getInboundBacklog()
      Inbound tunnel build queue size.
      Returns:
      backlog count as string
    • getAvgPeerTestTime

      public int getAvgPeerTestTime()
      Average peer test round-trip time (good + too-slow combined).
      Returns:
      average test time in milliseconds
    • getAvgPeerTestTimeGood

      public int getAvgPeerTestTimeGood()
      Average successful peer test round-trip time.
      Returns:
      average good-test time in milliseconds
    • getStoredRouterInfos

      public int getStoredRouterInfos()
      Number of router infos stored in the Kademlia netDb.
      Returns:
      stored router info count
    • updateAvailable

      private static boolean updateAvailable()
      Whether the sidebar should offer a signed release update.
      Returns:
      true if one is available and has not been downloaded
    • unsignedUpdateAvailable

      private boolean unsignedUpdateAvailable()
      Whether an unsigned router update is on offer.
      Returns:
      true if one is available and router.updateUnsigned is set
    • devSU3UpdateAvailable

      private boolean devSU3UpdateAvailable()
      Whether a signed development SU3 update is on offer.
      Returns:
      true if one is available and router.updateDevSU3 is set
    • getUnsignedUpdateVersion

      private static String getUnsignedUpdateVersion()
      Gets the version of the unsigned update on offer.
      Returns:
      the date and time in the local zone, null if none
    • getDevSU3UpdateVersion

      private static String getDevSU3UpdateVersion()
      Gets the version of the development SU3 update on offer.
      Returns:
      the HTML-escaped version, null if none
    • getUpdateStatus

      public String getUpdateStatus()
      The update status and buttons.
      Returns:
      the update status
    • getRestartStatus

      public String getRestartStatus()
      The restart status and buttons.
      Returns:
      the restart status
    • getFirewallAndReseedStatus

      public String getFirewallAndReseedStatus()
      The firewall status and reseed status/buttons.
      Returns:
      the firewall and reseed status
    • storeNewsHelper

      public void storeNewsHelper(NewsHelper n)
      NewsHelper to store for sidebar rendering.
      Parameters:
      n - NewsHelper to store for sidebar rendering
    • getNewsHelper

      public NewsHelper getNewsHelper()
      Gets the news helper stored for this sidebar render.
      Returns:
      the helper passed to storeNewsHelper(), null before that
    • getSummaryBarSections

      public List<String> getSummaryBarSections(String page)
      Get the list of active summary bar sections for a given page.
      Parameters:
      page - the page name (e.g. "home" or "default")
      Returns:
      list of section identifiers, or empty list if none configured
    • saveSummaryBarSections

      static void saveSummaryBarSections(RouterContext ctx, String page, Map<Integer,String> sections)
      Save the summary bar section order to router config.
      Parameters:
      ctx - the context whose router config receives the setting
      page - appended to PROP_SUMMARYBAR to form the config key, so a wrong value silently stores a second setting
      sections - ordered map of section index to section id
    • renderSummaryBar

      public void renderSummaryBar() throws IOException
      Render the full summary bar HTML to the output writer.
      Throws:
      IOException - if the underlying writer fails partway through the markup
    • setAction

      public void setAction(String s)
      Form action, HTML-stripped before storing.
      Parameters:
      s - form action, HTML-stripped before storing
    • getAction

      public String getAction()
      Gets the action the sidebar form submitted.
      Returns:
      the HTML-stripped action, null if setAction() was not called
    • setConsoleNonce

      public void setConsoleNonce(String s)
      Console nonce, HTML-stripped before storing.
      Parameters:
      s - console nonce, HTML-stripped before storing
    • getConsoleNonce

      public String getConsoleNonce()
      Gets the console nonce submitted with the sidebar form.
      Returns:
      the HTML-stripped nonce, null if not submitted
    • setUpdateNonce

      public void setUpdateNonce(String s)
      Update nonce, HTML-stripped before storing.
      Parameters:
      s - update nonce, HTML-stripped before storing
    • getUpdateNonce

      public String getUpdateNonce()
      Gets the update nonce submitted with the sidebar form.
      Returns:
      the HTML-stripped nonce, null if not submitted
    • setRequestURI

      public void setRequestURI(String s)
      Request URI, HTML-stripped before storing.
      Parameters:
      s - the request URI, HTML-stripped before storing
    • setRequest

      public void setRequest(HttpServletRequest s)
      Servlet request.
      Parameters:
      s - the servlet request
    • getRequestURI

      public String getRequestURI()
      Return the request URI, or /home as default.
      Returns:
      non-null; "/home" if (strangely) not set by jsp
    • getConfigTable

      public String getConfigTable()
      Build the HTML table for configuring which sidebar sections are shown and their display order.
      Returns:
      HTML table with move/delete/add controls