java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.PeerHelper
Helper for peer connections page rendering and form processing.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classSorts peers alphabetically.private static final classTotals accumulated while rendering NTCP peer rows.private static classSorts NTCP connections by a chosen field.private static final classTotals accumulated while rendering SSU peer rows.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DecimalFormatFormatter for the SSU stats display.private booleanEmit a data-key (peer hash) per row for worker-side row diffing; fragment renders only, so full pages stay byte-for-byte identical.private static final NumberFormatFormatter for the rate display.private intFlags selecting the peer list sort order.private StringTransport name being displayed.private StringBase URL for the peer list page.private static final intLength of the truncated base64 hash used as a per-row data-key in fragment mode.private static final String[]Column link targets of the peer list.private static final StringSeparator used in the peer list.private static final String[]Column titles of the peer list.Fields inherited from class HelperBase
_context, _log, _out, CHECKED, PROP_ADVANCED, SELECTEDModifier and TypeFieldDescriptionprotected RouterContextThe router context.protected LogThe log instance.protected WriterThe writer for output.static final StringChecked attribute for HTML checkboxes.static final StringProperty key for advanced mode.static final StringSelected attribute for HTML select options.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static final StringformatKBps(int bps) Formats a byte rate for display.private static StringformatRate(float rate) Formats a rate for the peer list.private Comparator<NTCPConnection> getNTCPComparator(int sortFlags) Returns the comparator for the chosen sort.Render the peer summary table into the page being built.private doublegetStatAvg(String name) Get the 1-minute average of a RateStat, or 0 if unavailable.private doublegetStatCount1m(String name) Get the 1-minute event count of a RateStat, preferring the current partial window.private intgetTab()Return the currently selected tab index.private voidgetTransportBandwidth(Transport transport, int[] peerCounts, int[] bandwidths) Sums peer counts and bandwidth for one transport.private static booleanincludeNTCP(NTCPConnection con, int peerCount, long now) Whether an NTCP connection is recent enough to render.private static booleanincludeSSU(PeerState peer, int peerCount, long now) Whether an SSU peer is recent enough to render.private voidrender(NTCPTransport nt, Writer out, int sortFlags) Render the NTCP transport peer listing.private voidrender(UDPTransport ut, Writer out, String urlBase, int sortFlags, boolean debugmode) Render the SSU/UDP transport peer listing.voidrenderFragment(String id) Render a single named element for the contentonly fragment mode.private voidrenderNavBar(Writer out) Render the peer page navigation bar.private voidrenderNTCPCount(StringBuilder buf, int activePeers, int maxConnections) Append the NTCP connections heading fragment containing the count.private voidrenderNTCPFooter(StringBuilder buf, boolean ipv6Enabled, int activePeers, int peerCount, PeerHelper.NTCPTotals totals) Append the NTCP peer table footer with the accumulated totals.private voidrenderNTCPFragment(NTCPTransport nt, Writer out, String id, int sortFlags) Render a named NTCP element in fragment mode: the count heading, the tbody with data-key rows, or the totals tfoot.private voidrenderNTCPHeader(StringBuilder buf, boolean ipv6Enabled, int activePeers, int maxConnections, boolean hasPeers) Append the NTCP peer table header, including the IPv6 column when enabled.private voidrenderNTCPRow(StringBuilder buf, NTCPConnection con, long now, boolean ipv6Enabled, int peerCount, PeerHelper.NTCPTotals totals) Append one NTCP peer row and accumulate its stats into totals.private voidrenderPeerRings(Writer out) Render peer-landscape ring dashboard above the transport summary table.private voidrenderSSUCount(StringBuilder buf, int activePeers, int maxConnections, boolean debugmode) Append the UDP connections heading fragment containing the count.private voidrenderSSUFooter(StringBuilder buf, boolean debugmode, UDPTransport ut, PeerHelper.SSUTotals totals) Append the SSU peer table footer with the accumulated totals.private voidrenderSSUFragment(UDPTransport ut, Writer out, String id, int sortFlags, boolean debugmode) Render a named SSU element in fragment mode: the count heading, the tbody with data-key rows, or the totals tfoot.private voidrenderSSUHeader(StringBuilder buf, String urlBase, int sortFlags, boolean debugmode, int activePeers, int maxConnections, boolean hasPeers) Append the SSU peer table header, including the sort links in debug mode.private voidrenderSSURow(StringBuilder buf, PeerState peer, long now, boolean debugmode, PeerHelper.SSUTotals totals) Append one SSU peer row and accumulate its stats into totals.private voidrenderStatusHTML(Writer out, String urlBase, int sortFlags) Render the whole peer page: nav bar, rings and transport summary, or the single transport table when a transport is selected.private voidrenderSummary(Writer out) Render the peer connectivity summary section.voidParses the decimal sort order, falling back to 0 when absent or invalid.voidRestrict the peer listing to one transport, as chosen by the console's transport selector.voidsetUrlBase(String base) Stores the console URL prefix that rendered peer links are built from.Methods inherited from class HelperBase
_t, _t, _t, _x, getChecked, isAdvanced, 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.booleanCheck if advanced mode is enabled.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
_sortFlags
private int _sortFlagsFlags selecting the peer list sort order._urlBase
Base URL for the peer list page._transport
Transport name being displayed._fragmentKeys
private boolean _fragmentKeysEmit a data-key (peer hash) per row for worker-side row diffing; fragment renders only, so full pages stay byte-for-byte identical.KEY_LEN
private static final int KEY_LENLength of the truncated base64 hash used as a per-row data-key in fragment mode.- See Also:
titles
Column titles of the peer list.links
Column link targets of the peer list.THINSP
_rateFmt
Formatter for the rate display._fmt
Formatter for the SSU stats display.
Constructor Details
PeerHelper
public PeerHelper()Default constructor for the console peer summary helper.
Method Details
setSort
Parses the decimal sort order, falling back to 0 when absent or invalid.- Parameters:
flags- the decimal sort order requested by the console page; null or unparseable text falls back to 0, the default ordering
setUrlBase
Stores the console URL prefix that rendered peer links are built from.- Parameters:
base- the console URL prefix that the rendered links are built from, ending in a path separator
setTransport
Restrict the peer listing to one transport, as chosen by the console's transport selector.- Parameters:
t- the transport name to list peers for, as passed in the query string, or null for all transports
getPeerSummary
Render the peer summary table into the page being built. The peer page is written straight to the response, so there is no value to hand back.- Returns:
- the empty string, as the page is written straight to the response
renderStatusHTML
Render the whole peer page: nav bar, rings and transport summary, or the single transport table when a transport is selected. Blocking, and slow with many peers.- Parameters:
out- where the peer page markup is streamed tourlBase- console URL prefix the transport tab and sort links are built fromsortFlags- sort column, one of the FLAG_ constants inUDPSorters; negative reverses the order- Throws:
IOException- if the response writer fails while the page is written
getTab
private int getTab()Return the currently selected tab index.- Returns:
- the tab index matching the current transport
getStatAvg
Get the 1-minute average of a RateStat, or 0 if unavailable.- Parameters:
name- the rate stat's full dotted name, e.g.router.activePeers- Returns:
- the average value recorded in the last minute, 0 if the stat or its 1-minute rate is not registered
getStatCount1m
Get the 1-minute event count of a RateStat, preferring the current partial window. For count-type stats whose event value carries no information (e.g.peer.testTimeoutalways records 1), this is the meaningful signal - the average would read a constant 1.0.- Parameters:
name- dotted rate stat name whose 1-minute window is read- Returns:
- events in the last minute, 0 if the stat or its 1-minute rate is not registered
renderPeerRings
Render peer-landscape ring dashboard above the transport summary table. Ten rings: Active, Fast, HighCap, Reliable, Floodfill, Known, Profiles, Unreachable, Banned, Test Fail.- Parameters:
out- where the ring dashboard markup is written- Throws:
IOException- if the rendered dashboard cannot be written to the page
renderSummary
Render the peer connectivity summary section.- Parameters:
out- where the transport summary table is written- Throws:
IOException- if the summary table cannot be written to the page
getTransportBandwidth
Sums peer counts and bandwidth for one transport.- Parameters:
transport- the transport to measurepeerCounts- out: peers per bandwidth tierbandwidths- out: bandwidth per tier
renderFragment
Render a single named element for the contentonly fragment mode. Renders nothing for ids the current transport view does not own.- Parameters:
id- the element id- Throws:
IOException- if an I/O error occurs
renderNTCPFragment
private void renderNTCPFragment(NTCPTransport nt, Writer out, String id, int sortFlags) throws IOException Render a named NTCP element in fragment mode: the count heading, the tbody with data-key rows, or the totals tfoot.- Parameters:
nt- the NTCP transport whose peers are re-renderedout- where the fragment markup is writtenid- DOM id of the element to re-render: ntcpcon, peersNTCP or ntcpfootsortFlags- sort column, one of the FLAG_ constants inUDPSorters; negative reverses the order- Throws:
IOException- if the fragment cannot be written to the page
renderSSUFragment
private void renderSSUFragment(UDPTransport ut, Writer out, String id, int sortFlags, boolean debugmode) throws IOException Render a named SSU element in fragment mode: the count heading, the tbody with data-key rows, or the totals tfoot.- Parameters:
ut- the SSU transport whose peers are re-renderedout- where the fragment markup is writtenid- DOM id of the element to re-render: ssucon, peersSSU or ssufootsortFlags- sort column, one of the FLAG_ constants inUDPSorters; negative reverses the orderdebugmode- true renders the advanced view, with the extra columns- Throws:
IOException- if the fragment cannot be written to the page
includeNTCP
Whether an NTCP connection is recent enough to render.- Parameters:
con- the NTCP connection being considered for displaypeerCount- the number of established connections, which selects the idle cutoffnow- the current time- Returns:
- true when the connection is rendered
includeSSU
Whether an SSU peer is recent enough to render.- Parameters:
peer- the SSU peer state whose last receive time is testedpeerCount- the total peer count, which selects the idle cutoffnow- the current time- Returns:
- true when the peer is rendered
render
Render the NTCP transport peer listing.- Parameters:
nt- the NTCP transport whose established connections are listedout- where the peer table markup is writtensortFlags- sort column, one of the FLAG_ constants inUDPSorters; negative reverses the order- Throws:
IOException- if the peer table cannot be written to the page
renderNTCPHeader
private void renderNTCPHeader(StringBuilder buf, boolean ipv6Enabled, int activePeers, int maxConnections, boolean hasPeers) Append the NTCP peer table header, including the IPv6 column when enabled.- Parameters:
buf- the buffer the header markup is appended to; the caller writes it out and resets itipv6Enabled- true to add the IPv6 column, set from the NTCP or UDP ipv6 propertyactivePeers- established connection count shown in the headingmaxConnections- configured NTCP connection limit shown beside ithasPeers- false writes only the heading and the table opener, and skips the column headers
renderNTCPCount
Append the NTCP connections heading fragment containing the count.- Parameters:
buf- the buffer to append toactivePeers- the established connection countmaxConnections- the configured connection limit
renderNTCPRow
private void renderNTCPRow(StringBuilder buf, NTCPConnection con, long now, boolean ipv6Enabled, int peerCount, PeerHelper.NTCPTotals totals) Append one NTCP peer row and accumulate its stats into totals.- Parameters:
buf- the buffer the row markup is appended tocon- an established NTCP connection to render as one rownow- current time in ms since the epoch, the base for the idle timesipv6Enabled- true to emit the IPv6 cell for this peerpeerCount- peers listed, which sets the idle window a rate must fall inside to be counted: 60s above 300 peers, 3min above 100totals- accumulators this row's rates, uptime and clock skew are added to
formatRate
Formats a rate for the peer list.- Parameters:
rate- the rate, in bytes per second- Returns:
- the formatted text
getNTCPComparator
Returns the comparator for the chosen sort.- Parameters:
sortFlags- the sort flags- Returns:
- the comparator to use
render
private void render(UDPTransport ut, Writer out, String urlBase, int sortFlags, boolean debugmode) throws IOException Render the SSU/UDP transport peer listing.- Parameters:
ut- the SSU transport whose peer states are listedout- where the peer table markup is writtenurlBase- console URL prefix the sort links are built fromsortFlags- sort column, one of the FLAG_ constants inUDPSorters; negative reverses the orderdebugmode- true for the advanced view: the extra columns, the per-column sort links and the wider footer- Throws:
IOException- if the peer table cannot be written to the page
renderSSUHeader
private void renderSSUHeader(StringBuilder buf, String urlBase, int sortFlags, boolean debugmode, int activePeers, int maxConnections, boolean hasPeers) Append the SSU peer table header, including the sort links in debug mode.- Parameters:
buf- the buffer the header markup is appended tourlBase- page path the sort links point at, without a query stringsortFlags- column and direction currently in effect, as passed toUDPSorters.getComparator(int); negative means descendingdebugmode- true adds the sort links, the IPv6 column and the advanced-view table class; false adds the link to itactivePeers- active peer count shown in the headingmaxConnections- configured UDP connection limit shown beside ithasPeers- false writes only the heading and the table opener, and skips the column headers
renderSSUCount
private void renderSSUCount(StringBuilder buf, int activePeers, int maxConnections, boolean debugmode) Append the UDP connections heading fragment containing the count.- Parameters:
buf- the buffer to append toactivePeers- the established connection countmaxConnections- the configured connection limitdebugmode- render the advanced view link
renderSSURow
private void renderSSURow(StringBuilder buf, PeerState peer, long now, boolean debugmode, PeerHelper.SSUTotals totals) Append one SSU peer row and accumulate its stats into totals.- Parameters:
buf- the buffer the row markup is appended topeer- the peer state to render as one rownow- current time in ms since the epoch, the base for the idle times and the uptimedebugmode- true adds the IPv6, ban and failed-send notes and the congestion-window, RTT, RTO and MTU cellstotals- accumulators this row's rates, timings and packet counts are added to
formatKBps
Formats a byte rate for display.- Parameters:
bps- the rate, in bytes per second- Returns:
- the formatted text