java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.SidebarHelper
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().
Nested Class Summary
Modifier and TypeClassDescriptionprivate classCompare translated nicknames - put "shared clients" first in the sort Inner class, can't be Serializable.static enumEnumeration of network reachability state values.static classState message to be displayed to the user in the summary bar.Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringAction parameter from the sidebar form.private static longExpiry for the cached active profile count.private static longExpiry for the cached tunnel build success.private static intCached active profile count.private static StringCached concurrency string.private static StringCached share ratio string.private static intCached tunnel build success percentage.private static longExpiry for the cached concurrency string.private StringConsole nonce for form validation.private NewsHelperCached news helper instance.private HttpServletRequestThe HTTP servlet request.private StringCached request URI.private HttpSessionActive HTTP session for nonce-based form validation.private static longExpiry for the cached share ratio string.private StringUpdate nonce for form validation.(package private) I2PAppContextGlobal application context.(package private) static final StringDefault full summary bar sections.(package private) static final StringDefault full summary bar sections for advanced mode.(package private) static final StringDefault full summary bar sections for new users.(package private) static final StringDefault minimal summary bar sections.(package private) static final StringDefault minimal summary bar sections for advanced mode(package private) StringFirst version the router was started with, used to detect new installs.private static final DecimalFormatInteger formatter with thousands separators.private static final DecimalFormatOne-decimal-place formatter.private static final StringProperty name for advanced mode toggle.(package private) static final StringProperty prefix for summary bar section configuration per page.private static final StringProperty name for unified sidebar toggle.private static final charSeparator character for summary bar section configuration.private static final StringSeparator string for summary bar config.(package private) static final StringThin space separator.private static final DecimalFormatTwo-decimal-place formatter.(package private) StringCurrent I2P core version.private static final DecimalFormatZero-decimal-place formatter.private static final DecimalFormatZero-decimal one-digit formatter.private static final DecimalFormatZero-decimal two-digit formatter.Constructor Summary
ConstructorsConstructorDescriptionNo HTTP session is bound yet, so the summary sections fall back to the session-less nonce path untilstoreSession(HttpSession)supplies one.Method Summary
Modifier and TypeMethodDescriptionbooleanWhether manual reseed should be allowed, based on uptime and known router count or the always-allow property.private intcacheBuildSuccess(int value) Cache the tunnel build success result for the current sidebar refresh cycle.private booleanWhether a signed development SU3 update is on offer.private static StringfmtInt(long val) Format a long value with thousands separators.private static StringformatPair(double in, double out) Output is decimal, not binary.Gets the action the sidebar form submitted.intHow many peers we are talking to now.intHow many active identities have we spoken with recently.intHow many routers we know about, minus ourselves.intAverage peer test round-trip time (good + too-slow combined).intAverage successful peer test round-trip time.intHow many peers are banned.Concurrent build count and average build request time.Build the HTML table for configuring which sidebar sections are shown and their display order.Gets the console nonce submitted with the sidebar form.Render JVM CPU Load Bar.intRetrieve CPU Load as a percentage.intRetrieve CPU Load Average as a percentage.Client destinations connected locally.private static StringGets the version of the development SU3 update on offer.intHow many active peers the router ranks as fast.The firewall status and reseed status/buttons.Format the 5-minute average bandwidth rates for display.intHow many active peers the router ranks as having a high capacity.getIdent()Retrieve the shortened 4 character ident for the router located within the current JVM at the given context.Inbound tunnel build queue size.intHow many inbound client tunnels we have.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).intHow many free inbound tunnels we have.How lagged our job queue is over the last minute (pretty printed with the units attached).Format the lifetime average bandwidth rates for display.Maximum number of tunnels we are willing to participate in, either from config or a reasonable default based on system resources.Retrieve amount of used memory.Render the memory usage bar with blended real-time and one-minute average.How long it takes us to pump out a message, averaged over the last minute (pretty printed with the units attached).Gets the news helper stored for this sidebar render.intHow many active outbound client tunnels we have.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).intHow many active outbound tunnels we have.intHow many tunnels we are participating in.Gets the router's network reachability for the summary bar.Return the request URI, or /home as default.The restart status and buttons.Format the current bandwidth rates for display.Participant-to-client tunnel share ratio.intNumber of router infos stored in the Kademlia netDb.getSummaryBarSections(String page) Get the list of active summary bar sections for a given page.intRetrieve System Load Average as a percentage.private Rate[]getTunnelBuildRates(String name) Fetch the 1-minute and 10-minute rates for a named tunnel build stat.intRetrieve Tunnel build success as a percentage.How long it takes us to test our tunnels, averaged over the last 10 minutes (pretty printed with the units attached).private StringLook up the translated display name for a client destination, checking SessionConfig first then TunnelPoolSettings.Localized tunnel status string (e.g.intHow many peers are unreachable.private static StringGets the version of the unsigned update on offer.Gets the update nonce submitted with the sidebar form.The update status and buttons.Retrieve a pretty printed uptime count (ala 4d or 7h or 39m).Retrieve the version number of the router.intHow many active peers the router ranks as well integrated (floodfill).booleanWhether advanced mode is on, which selects the fuller sidebar sections.booleanAre both the webapp and TCG running?Asks the router how reachable it is.voidRender the full summary bar HTML to the output writer.(package private) static voidsaveSummaryBarSections(RouterContext ctx, String page, Map<Integer, String> sections) Save the summary bar section order to router config.voidForm action, HTML-stripped before storing.voidConsole nonce, HTML-stripped before storing.voidServlet request.voidRequest URI, HTML-stripped before storing.voidUpdate nonce, HTML-stripped before storing.booleanShould we warn about a possible firewall problem?private longHow long cached sidebar stats stay valid: one sidebar refresh interval.voidNewsHelper to store for sidebar rendering.voidstoreSession(HttpSession session) For form validation and session-bound nonce generation.booleanWhether the unified sidebar layout is used instead of the classic one.private booleanWhether an unsigned router update is on offer.private static booleanWhether the sidebar should offer a signed release update.Methods inherited from class HelperBase
_t, _t, _t, _x, getChecked, ngettext, setContextId, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected StringgetChecked(String prop) Get the checked attribute for a boolean property.Translate a string with plural forms (ngettext).voidsetContextId(String contextId) Configure this bean to query a particular router context.voidstoreWriter(Writer out) Store the writer for output.
Field Details
_session
Active HTTP session for nonce-based form validation._buildSuccessCachedUntil
private static volatile long _buildSuccessCachedUntilExpiry 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 _concurrencyCachedUntilExpiry for the cached concurrency string._activeProfilesCachedUntil
private static volatile long _activeProfilesCachedUntilExpiry for the cached active profile count._cachedTunnelBuildSuccess
private static volatile int _cachedTunnelBuildSuccessCached tunnel build success percentage._cachedConcurrency
Cached concurrency string._cachedActiveProfiles
private static volatile int _cachedActiveProfilesCached active profile count.THINSP
S
private static final char SSeparator character for summary bar section configuration.- See Also:
INTEGER_FORMAT
Integer formatter with thousands separators.ONE_DECIMAL
One-decimal-place formatter.TWO_DECIMALS
Two-decimal-place formatter.ZERO_DECIMAL
Zero-decimal-place formatter.ZERO_ONE_DECIMAL
Zero-decimal one-digit formatter.ZERO_TWO_DECIMALS
Zero-decimal two-digit formatter.ctx
I2PAppContext ctxGlobal application context.PROP_ADVANCED
Property name for advanced mode toggle.- See Also:
PROP_UNIFIED_SIDEBAR
Property name for unified sidebar toggle.- See Also:
PROP_SUMMARYBAR
Property prefix for summary bar section configuration per page.- See Also:
firstVersion
String firstVersionFirst version the router was started with, used to detect new installs.version
String versionCurrent I2P core version.DEFAULT_FULL_NEWUSER
Default full summary bar sections for new users.- See Also:
DEFAULT_FULL
DEFAULT_FULL_ADVANCED
Default full summary bar sections for advanced mode.- See Also:
DEFAULT_MINIMAL
Default minimal summary bar sections.- See Also:
DEFAULT_MINIMAL_ADVANCED
Default minimal summary bar sections for advanced mode- See Also:
_newshelper
Cached news helper instance.SS
Separator string for summary bar config._action
Action parameter from the sidebar form._consoleNonce
Console nonce for form validation._updateNonce
Update nonce for form validation._requestURI
Cached request URI._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 untilstoreSession(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
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
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:
isAdvancedin classHelperBase- 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
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
Retrieve the version number of the router.- Returns:
RouterVersion.FULL_VERSION
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
Gets the router's network reachability for the summary bar.- Returns:
- the state plus a localized message explaining it
reachability
Asks the router how reachable it is.- Returns:
- the state and the message to show
getMemory
Retrieve amount of used memory.- Returns:
- a display string of
"used / total M", both in MiB
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
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
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
Format the current bandwidth rates for display.- Returns:
- "x.xx / y.yy {K|M}"
getFiveMinuteKBps
Format the 5-minute average bandwidth rates for display.- Returns:
- "x.xx / y.yy {K|M}"
getLifetimeKBps
Format the lifetime average bandwidth rates for display.- Returns:
- "x.xx / y.yy {K|M}"
formatPair
Output is decimal, not binary.- Parameters:
in- the receive rate in bytes per secondout- the send rate in bytes per second- Returns:
- "x.xx / y.yy {K|M}"
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
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
getTunnelName
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 itsKeysAndCert.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
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
getJobLag
How lagged our job queue is over the last minute (pretty printed with the units attached).- Returns:
- the job lag
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
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
Localized tunnel status string (e.g. overload/congested/normal).- Returns:
- tunnel status or empty string if no context
getConcurrency
Concurrent build count and average build request time.- Returns:
- formatted string "concurrent / requestTime"
getInboundBacklog
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
Gets the version of the unsigned update on offer.- Returns:
- the date and time in the local zone, null if none
getDevSU3UpdateVersion
Gets the version of the development SU3 update on offer.- Returns:
- the HTML-escaped version, null if none
getUpdateStatus
getRestartStatus
getFirewallAndReseedStatus
The firewall status and reseed status/buttons.- Returns:
- the firewall and reseed status
storeNewsHelper
NewsHelper to store for sidebar rendering.- Parameters:
n- NewsHelper to store for sidebar rendering
getNewsHelper
Gets the news helper stored for this sidebar render.- Returns:
- the helper passed to storeNewsHelper(), null before that
getSummaryBarSections
saveSummaryBarSections
Save the summary bar section order to router config.- Parameters:
ctx- the context whose router config receives the settingpage- appended toPROP_SUMMARYBARto form the config key, so a wrong value silently stores a second settingsections- ordered map of section index to section id
renderSummaryBar
Render the full summary bar HTML to the output writer.- Throws:
IOException- if the underlying writer fails partway through the markup
setAction
Form action, HTML-stripped before storing.- Parameters:
s- form action, HTML-stripped before storing
getAction
Gets the action the sidebar form submitted.- Returns:
- the HTML-stripped action, null if setAction() was not called
setConsoleNonce
Console nonce, HTML-stripped before storing.- Parameters:
s- console nonce, HTML-stripped before storing
getConsoleNonce
Gets the console nonce submitted with the sidebar form.- Returns:
- the HTML-stripped nonce, null if not submitted
setUpdateNonce
Update nonce, HTML-stripped before storing.- Parameters:
s- update nonce, HTML-stripped before storing
getUpdateNonce
Gets the update nonce submitted with the sidebar form.- Returns:
- the HTML-stripped nonce, null if not submitted
setRequestURI
Request URI, HTML-stripped before storing.- Parameters:
s- the request URI, HTML-stripped before storing
setRequest
getRequestURI
Return the request URI, or /home as default.- Returns:
- non-null; "/home" if (strangely) not set by jsp
getConfigTable
Build the HTML table for configuring which sidebar sections are shown and their display order.- Returns:
- HTML table with move/delete/add controls