java.lang.Object
net.i2p.router.web.helpers.TunnelRenderer
For /tunnels.jsp, used by
TunnelHelper.Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA bounded LRU cache extending LinkedHashMap with computeIfAbsent support.private static classSorts peers by country then name.private static classData for the tunnel peer count page: the counts per peer plus the validated, sorted peer list shared by the full and fragment renders.private static classEncapsulates results of a reverse DNS lookup and related domain information for a router peer IP address.private classSort tunnels by the name of the tunnel.private static classSorts tunnels by hop configuration.private static classOrder participating tunnels by throughput, fastest first.private static classSorts tunnel infos for the display.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router context.private booleanEmit a per-row data-key (peer hash) for worker-side row diffing; fragment renders only, so full pages stay byte-for-byte identical.private static final PatternA bare "&T" run (whois cleanup).private static final Pattern"AT&T" followed by anything (whois cleanup).private intTunnels listed before the display is truncated.private intTunnels rendered so far on this page.private static final ThreadLocal<FieldPosition> Reusable parse position; a new FieldPosition per call would defeat the reusable scratch buffer.private static final ThreadLocal<StringBuffer> Scratch buffer for the formatters; NumberFormat can only format into a StringBuffer.private static final DecimalFormatSymbolsLocale symbols snapshotted once at class load, cloned by every formatter.private static final intLength of the truncated base64 hash used as a per-row data-key in fragment mode.private static final intRender rows in a single write up to this count; above it, flush everySTREAM_BATCHrows so the page paints progressively.private final TunnelRenderer.BoundedCache<Hash, String> Cached peer to IP mappings for the tunnel graph.private final TunnelRenderer.BoundedCache<Hash, TunnelRenderer.ReverseLookupResult> Cached reverse lookups for the tunnel graph.private final TunnelRenderer.BoundedCache<Hash, RouterInfo> Cached router infos for the tunnel graph.private static final intRows rendered per flush when streaming a large table.private static final PatternMatches the parenthesised name in a tunnel nickname.private static final ThreadLocal<DecimalFormat> DecimalFormat is not thread-safe, so tunnel rows get one formatter per thread.private static final ThreadLocal<DecimalFormat> Per-thread formatter for whole numbers.private static final StringThe ".00" that a whole number formats to and the trimmed forms drop.Constructor Summary
ConstructorsConstructorDescriptionHold the router context every render method reads its pools and statistics from.Method Summary
Modifier and TypeMethodDescriptionprivate StringTranslate a string.Translate a string and substitute one parameter into it.private voidappendPeerCells(StringBuilder buf, TunnelInfo info, int length, int maxLength, boolean isAdvanced, String localHopTip, String localLabel, String tunnelIdTip) Append the peer cells for one tunnel: the local hop renders as a "Local" badge with the tunnel id when advanced mode is on, other hops render as netdb links with their tunnel ids.private voidappendPeerFooter(StringBuilder footerSb, int validPeerCount, int tunnelCount, int partCount) Append the closing tfoot and wrapper for the tunnel peer count table.private voidappendPeerFooterRow(StringBuilder footerSb, int validPeerCount, int tunnelCount, int partCount) Append the totals footer row of the tunnel peer count table.private voidappendPeerIdentity(StringBuilder sb, Hash h, String hB64, String truncHash, String version, RouterInfo info, String ip, TunnelRenderer.ReverseLookupResult rl, String versionTip, String banlistedTip, String unknownLabel, boolean isBanned) Append the identity cells shared by the peer tables: country flag, router hash link, version with netdb link, tier caps, IP address, and reverse-lookup domain.private voidappendPeerRow(StringBuilder chunkSb, Hash h, RouterInfo info, int tunnelCount, int partCount, int localTunnelCount, int transitTunnelCount, String versionTip, String unknownLabel, String configurePeerTip, String editLabel) Append one tunnel peer count row: identity cells plus local and transit tunnel bars and the edit link.private voidappendTableHeader(StringBuilder buf, int maxLength) Append the tunnel table header row: In/Out, Status, Expiry, Latency, Data, Gateway, Participants, and Endpoint columns.private intTally the transit tunnels this router participates in, counting the receive-from and send-to peer of each into pc.private intTally the exploratory and client tunnels longer than one hop, counting each of their peers into lc.private voidflushBuf(Writer out, StringBuilder buf) Write the buffered HTML to the output writer and clear the buffer, used to flush large tables in batches so the page paints progressively.private static voidfmt(StringBuilder buf, double val) Append a value with two decimal places.private static voidfmt0(StringBuilder buf, double val) Append a value with no decimal places, rounded half up.private static voidfmtTrim(StringBuilder buf, double val) Append a value with two decimal places, dropping every ".00".private static StringBufferformat(DecimalFormat formatter, double val) Format through the calling thread's reusable scratch buffer.private longgetNextExpiry(TunnelPool pool) Get next tunnel expiry from pool (excludes failed tunnels).private StringgetPoolTip(TunnelPool in) Get the pool's torrent names for the tooltip, when the tunnel is a shared I2PSnark pool destination and the i2psnark.poolMembers session property is set.getReverseLookupInfo(Hash h, RouterInfo info, long uptime) Performs a cached reverse lookup for the given router hash and its RouterInfo, returning canonical hostname, domain, and cleaned WHOIS data if available.private intCopied fromConfigNetHelper.private StringGet display name for the tunnel.private StringBuilds the netdb link for one peer.private StringBuilds the country flag image for one peer.private TunnelRenderer.PeerRowsCount tunnels per peer, resolve RouterInfos and reverse lookups, and build the validated peer list shared by the full and fragment renders.(package private) static Stringrange(int f, int t) Format one tunnel capacity band for display.private voidrenderExpiryBar(StringBuilder buf, long timeLeft) Generate a percentage bar for expiry time, appending straight to the row buffer.voidrenderGuide(Writer out) Renders an HTML table describing the bandwidth tiers used for tunnels, including their ranges and labels, and writes the output to the provided Writer.voidrenderLifetimeBandwidth(Writer out, TunnelPool in, TunnelPool outPool) Render the lifetime bandwidth table: bytes sent and received by each tunnel of the two pools combined, longest-lived tunnel first.voidrenderParticipating(Writer out, boolean bySpeed) Render the table of tunnels this router participates in, ordered either by speed or by how recently they were added.voidrenderParticipatingFragment(Writer out, boolean bySpeed, String id) Render only the named fragment of the participating tunnels table for the contentonly fragment mode of the transit pages: the "transitPeers" tbody or the "statusnotes" tfoot.private voidrenderParticipatingInternal(Writer out, boolean bySpeed, String fragmentId) Render the participating tunnels block, or a single named fragment of it.voidrenderPeerFragment(Writer out, String id) Render a single named element for the contentonly fragment mode of the tunnel peer count page: the "all peers" tbody with data-key rows, or the totals footer row.voidrenderPeers(Writer out) Render the tunnel peer count table, the "all peers" tbody, or the totals footer row.private voidrenderPool(Writer out, TunnelPool in, TunnelPool outPool) Renders one tunnel pool's table.private voidrenderPoolSummary(Writer out, TunnelPool in, TunnelPool outPool, Hash client) Render a summary table for a tunnel pool.voidrenderStatusHTML(Writer out) Render the whole tunnel status page: the exploratory, client and participating pool summaries followed by the pool detail tables.private voidrenderTestStatus(StringBuilder buf, TunnelInfo info) Append the tunnel test status cell, with the status-specific tooltip.voidRender the transit tunnel summary: the counts of transit tunnels this router builds, and the peers they are shared with.voidrenderTransitSummaryFragment(Writer out, String id) Render only the "transitPeers" tbody of the transit-summary table for the contentonly fragment mode of the transitsummary page.private voidrenderTransitSummaryInternal(Writer out, String fragmentId) Render the transit-summary table, or a single named fragment of it.voidrenderTunnelFragment(Writer out, String id) Render the "tunnelsContainer" fragment for the contentonly fragment mode of the local tunnels page: the container div plus the tunnel summaries and the tunnel-guide section it holds on the full page.private intrenderTunnelRow(StringBuilder buf, TunnelInfo info, long timeLeft, int maxLength, String tib, String tob, String localHopTip, String localLabel, String tunnelIdTip) Append one tunnel row: direction badge, test status, expiry bar, latency, data transferred, and the peer cells.
Field Details
TUNNEL_PAREN
Matches the parenthesised name in a tunnel nickname.ATT_PREFIX
"AT&T" followed by anything (whois cleanup).AMP_T_RUN
A bare "&T" run (whois cleanup)._context
The router context.DISPLAY_LIMIT
private int DISPLAY_LIMITTunnels listed before the display is truncated.MAX_BEFORE_STREAMING
private static final int MAX_BEFORE_STREAMINGRender rows in a single write up to this count; above it, flush everySTREAM_BATCHrows so the page paints progressively.- See Also:
STREAM_BATCH
private static final int STREAM_BATCHRows rendered per flush when streaming a large table.- See Also:
_fragmentKeys
private boolean _fragmentKeysEmit a per-row data-key (peer hash) 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:
displayed
private int displayedTunnels rendered so far on this page.FORMAT_SYMBOLS
Locale symbols snapshotted once at class load, cloned by every formatter.TWO_DECIMALS
DecimalFormat is not thread-safe, so tunnel rows get one formatter per thread.ZERO_DECIMALS
Per-thread formatter for whole numbers.FMT_SCRATCH
Scratch buffer for the formatters; NumberFormat can only format into a StringBuffer.FMT_POS
Reusable parse position; a new FieldPosition per call would defeat the reusable scratch buffer.ZEROES
The ".00" that a whole number formats to and the trimmed forms drop.- See Also:
routerInfoCache
Cached router infos for the tunnel graph.reverseLookupResults
private final TunnelRenderer.BoundedCache<Hash, TunnelRenderer.ReverseLookupResult> reverseLookupResultsCached reverse lookups for the tunnel graph.peerToIP
Cached peer to IP mappings for the tunnel graph.
Constructor Details
TunnelRenderer
Hold the router context every render method reads its pools and statistics from.- Parameters:
ctx- the router context to render from
Method Details
fmt
Append a value with two decimal places.- Parameters:
buf- the buffer to append toval- the value to format
fmt0
Append a value with no decimal places, rounded half up.- Parameters:
buf- the buffer to append toval- the value to format
fmtTrim
Append a value with two decimal places, dropping every ".00".- Parameters:
buf- the buffer to append toval- the value to format
format
Format through the calling thread's reusable scratch buffer.- Parameters:
formatter- the per-thread formatterval- the value to format- Returns:
- the reusable buffer holding the formatted text
renderStatusHTML
Render the whole tunnel status page: the exploratory, client and participating pool summaries followed by the pool detail tables.- Parameters:
out- the writer to render to- Throws:
IOException- if writing fails
renderParticipating
Render the table of tunnels this router participates in, ordered either by speed or by how recently they were added.- Parameters:
out- the writer to render tobySpeed- true for the fastest variety, false for most recent- Throws:
IOException- if writing fails
renderParticipatingFragment
Render only the named fragment of the participating tunnels table for the contentonly fragment mode of the transit pages: the "transitPeers" tbody or the "statusnotes" tfoot. Renders nothing for an unknown id, on hidden-mode errors, or when no transit tunnels currently exist, so a document fragment that omits the element falls back to a whole-div full-page refresh on the client.- Parameters:
out- the writer to render tobySpeed- true for the fastest variety, false for most recentid- the element id to render- Throws:
IOException- if writing fails
renderParticipatingInternal
private void renderParticipatingInternal(Writer out, boolean bySpeed, String fragmentId) throws IOException Render the participating tunnels block, or a single named fragment of it. With a null fragmentId the full block is written exactly as the public renderParticipating always did. The per-element mode emits only that element, so the auto-refresh worker can morph just the live tbody or tfoot from a contentonly response.- Parameters:
out- the writer to render tobySpeed- true for the fastest variety, false for most recentfragmentId- the fragment element id, or null for the full block- Throws:
IOException- if writing fails
renderTransitSummary
Render the transit tunnel summary: the counts of transit tunnels this router builds, and the peers they are shared with.- Parameters:
out- the writer to render to- Throws:
IOException- if writing fails
renderTransitSummaryFragment
Render only the "transitPeers" tbody of the transit-summary table for the contentonly fragment mode of the transitsummary page. Renders nothing for an unknown id, in hidden mode, or when fewer than two transit tunnels currently exist, so a fragment that omits the element falls back to a whole-div full-page refresh on the client.- Parameters:
out- the writer to render toid- the element id to render- Throws:
IOException- if writing fails
renderTransitSummaryInternal
Render the transit-summary table, or a single named fragment of it. With a null fragmentId the full table is written exactly as the public renderTransitSummary always did. The fragment mode emits only the named tbody so the auto-refresh worker can morph just the live rows from a contentonly response.- Parameters:
out- the writer to render tofragmentId- the fragment element id, or null for the full table- Throws:
IOException- if writing fails
renderPeers
Render the tunnel peer count table, the "all peers" tbody, or the totals footer row.Full-page mode renders header, rows, and footer as one table. Fragment mode (contentonly) renders just the named element so the page can refresh the tbody rows and footer without re-sending the full table.
- Parameters:
out- the writer to render to- Throws:
IOException- if writing fails
renderPeerFragment
Render a single named element for the contentonly fragment mode of the tunnel peer count page: the "all peers" tbody with data-key rows, or the totals footer row. Renders nothing for unknown ids.- Parameters:
out- the writer to render toid- the element id- Throws:
IOException- if writing fails
preparePeerRows
Count tunnels per peer, resolve RouterInfos and reverse lookups, and build the validated peer list shared by the full and fragment renders.- Returns:
- the prepared counts and peer list
appendPeerRow
private void appendPeerRow(StringBuilder chunkSb, Hash h, RouterInfo info, int tunnelCount, int partCount, int localTunnelCount, int transitTunnelCount, String versionTip, String unknownLabel, String configurePeerTip, String editLabel) Append one tunnel peer count row: identity cells plus local and transit tunnel bars and the edit link.- Parameters:
chunkSb- the buffer the row markup is appended toh- the peer's router hashinfo- the peer's router info, or null if it is not in the NetDbtunnelCount- total local tunnels, the denominator of the local barpartCount- total transit tunnels, the denominator of the transit barlocalTunnelCount- how many local tunnels this peer is intransitTunnelCount- how many transit tunnels this peer is inversionTip- pre-translated tooltip for the version linkunknownLabel- pre-translated label when the version is unknownconfigurePeerTip- pre-translated tooltip for the edit linkeditLabel- pre-translated label of the edit link
getReverseLookupInfo
private TunnelRenderer.ReverseLookupResult getReverseLookupInfo(Hash h, RouterInfo info, long uptime) Performs a cached reverse lookup for the given router hash and its RouterInfo, returning canonical hostname, domain, and cleaned WHOIS data if available.Uses internal cache to avoid repeated DNS lookups and performs string cleanup on WHOIS data for better display. Reverse lookups occur only if enabled and uptime exceeds 30 seconds.
- Parameters:
h- the router's hash identifierinfo- the RouterInfo instance for the router (may be null)uptime- current router uptime in milliseconds- Returns:
- a ReverseLookupResult holding the IP, canonical hostname, domain, and WHOIS info
renderTunnelFragment
Render the "tunnelsContainer" fragment for the contentonly fragment mode of the local tunnels page: the container div plus the tunnel summaries and the tunnel-guide section it holds on the full page. The element is written without the "hidden" attribute that the full page uses for the no-JS fallback, because the JS-enabled page shows and hides the block interactively and the browser hides it while the refresh runs anyway.- Parameters:
out- the writer to render toid- the element id to render- Throws:
IOException- if writing fails
renderGuide
Renders an HTML table describing the bandwidth tiers used for tunnels, including their ranges and labels, and writes the output to the provided Writer.- Parameters:
out- the Writer to which the HTML content is written- Throws:
IOException- if an I/O error occurs during writing
range
Format one tunnel capacity band for display. The bounds are given in binary (1024) kilobytes per second, as the Router.MIN_BW_* constants are, and are rescaled to decimal KB/s. The upper bound is printed one short of its exact value so adjacent bands do not overlap on the page.- Parameters:
f- start of the band in binary KB/s, inclusivet- end of the band in binary KB/s, exclusive- Returns:
- the band as a "first - last KB/s" string
getTunnelName
Get display name for the tunnel.- Parameters:
in- the inbound pool whose settings provide the destination nickname- Returns:
- the escaped nickname, or the base32 destination when unnamed
getPoolTip
Get the pool's torrent names for the tooltip, when the tunnel is a shared I2PSnark pool destination and the i2psnark.poolMembers session property is set. Single-torrent pools have the torrent's name for a nickname, so the check matches all I2PSnark tunnels; dedicated destinations have no poolMembers property.- Parameters:
in- the tunnel pool- Returns:
- the escaped tooltip text, or null for a dedicated destination
renderPool
Renders one tunnel pool's table.- Parameters:
out- where the HTML is writtenin- the inbound pool, may be nulloutPool- the outbound pool, may be null- Throws:
IOException- if the write fails
appendTableHeader
Append the tunnel table header row: In/Out, Status, Expiry, Latency, Data, Gateway, Participants, and Endpoint columns. The Participants column spans the longest tunnel minus the first and last hops.- Parameters:
buf- the buffer the header markup is appended tomaxLength- the longest tunnel length in hops, deciding which participant and endpoint columns are emitted
renderTunnelRow
private int renderTunnelRow(StringBuilder buf, TunnelInfo info, long timeLeft, int maxLength, String tib, String tob, String localHopTip, String localLabel, String tunnelIdTip) Append one tunnel row: direction badge, test status, expiry bar, latency, data transferred, and the peer cells.Terminates the row only - the caller closes
</tbody>once, after the last row.- Parameters:
buf- the buffer the row markup is appended toinfo- the tunnel to rendertimeLeft- ms until the tunnel expires, greater than 0maxLength- the longest tunnel in the table, the peer cells are padded totib- pre-translated "Inbound" label for the direction celltob- pre-translated "Outbound" label for the direction celllocalHopTip- pre-translated tooltip for the local hop badgelocalLabel- pre-translated label for the local hop badgetunnelIdTip- pre-translated tooltip for the hop's tunnel id- Returns:
- the processed message count, for the bandwidth footer
appendPeerCells
private void appendPeerCells(StringBuilder buf, TunnelInfo info, int length, int maxLength, boolean isAdvanced, String localHopTip, String localLabel, String tunnelIdTip) Append the peer cells for one tunnel: the local hop renders as a "Local" badge with the tunnel id when advanced mode is on, other hops render as netdb links with their tunnel ids. Zero-hop and short tunnels are padded with empty cells to align the table columns.- Parameters:
buf- the buffer the peer cells are appended toinfo- the tunnel whose hops are renderedlength- the number of hops in this tunnelmaxLength- the longest tunnel in the table, the number of cells to pad toisAdvanced- true to show each hop's tunnel id, from the advanced-mode propertylocalHopTip- pre-translated tooltip for the local hop badgelocalLabel- pre-translated label for the local hop badgetunnelIdTip- pre-translated tooltip for the hop's tunnel id
flushBuf
Write the buffered HTML to the output writer and clear the buffer, used to flush large tables in batches so the page paints progressively.- Parameters:
out- the writer the buffer is written tobuf- the buffer to write and then clear- Throws:
IOException- if writing fails
renderTestStatus
Append the tunnel test status cell, with the status-specific tooltip.- Parameters:
buf- the buffer the status cell is appended toinfo- the tunnel whose test status is displayed
renderLifetimeBandwidth
public void renderLifetimeBandwidth(Writer out, TunnelPool in, TunnelPool outPool) throws IOException Render the lifetime bandwidth table: bytes sent and received by each tunnel of the two pools combined, longest-lived tunnel first.- Parameters:
out- the writer to render toin- inbound pool to list, or null for noneoutPool- outbound pool to list, or null for none- Throws:
IOException- if writing fails
countTunnelsPerPeer
Tally the exploratory and client tunnels longer than one hop, counting each of their peers into lc.- Parameters:
lc- the counter to fill in, keyed by peer hash- Returns:
- total number of non-fallback expl. + client tunnels
countParticipatingPerPeer
Tally the transit tunnels this router participates in, counting the receive-from and send-to peer of each into pc.- Parameters:
pc- the counter to fill in, keyed by the participating peer hashes- Returns:
- total number of part. tunnels
netDbLink
peerFlag
appendPeerIdentity
private void appendPeerIdentity(StringBuilder sb, Hash h, String hB64, String truncHash, String version, RouterInfo info, String ip, TunnelRenderer.ReverseLookupResult rl, String versionTip, String banlistedTip, String unknownLabel, boolean isBanned) Append the identity cells shared by the peer tables: country flag, router hash link, version with netdb link, tier caps, IP address, and reverse-lookup domain. The callers append the data cells and the row terminator.- Parameters:
sb- the buffer the identity cells are appended toh- the hash of the peer being renderedhB64- base64 of the peer hash for the netdb linktruncHash- short hash labelversion- router version, may be nullinfo- RouterInfo for the caps cell, may be nullip- primary IP address, may be nullrl- reverse lookup result, may be nullversionTip- tooltip for the version linkbanlistedTip- tooltip for the banlisted markerunknownLabel- fallback label for missing domainsisBanned- whether the peer is banlisted
_t
_t
Translate a string and substitute one parameter into it. Single quotes in s must be doubled for MessageFormat; do not double them in o.- Parameters:
s- the string to be translated, containing {0}o- the parameter, not translated itself- Returns:
- the translated string with {0} replaced by o
renderExpiryBar
Generate a percentage bar for expiry time, appending straight to the row buffer.- Parameters:
buf- the buffer the bar markup is appended totimeLeft- ms until the tunnel expires, clamped at 0, bar full at 10 minutes
renderPoolSummary
private void renderPoolSummary(Writer out, TunnelPool in, TunnelPool outPool, Hash client) throws IOException Render a summary table for a tunnel pool.- Parameters:
out- the writer to render toin- the inbound pool, not nulloutPool- the outbound pool, or null for noneclient- the destination the pool serves, unused by the current body- Throws:
IOException- if writing fails
getNextExpiry
Get next tunnel expiry from pool (excludes failed tunnels).- Parameters:
pool- the pool scanned for the earliest live tunnel expiry- Returns:
- ms since the epoch of that expiry, 0 if no tunnel qualifies