java.lang.Object
net.i2p.router.web.helpers.ProfileOrganizerRenderer
Helper class to refactor HTML rendering from out of the ProfileOrganizer.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA peer profile bundled with its 1h lookup fail rate, computed once so the sort key and the rendered value cannot diverge.private static classSorts floodfill rows by 1h fail rate ascending (best first) so the initial render needs no client-side re-sort.private static classAggregates over the floodfill-capable peer set; every field is meant to describe the observed floodfill peers, fed to the health rings above the table.private static classUsed for floodfill-only page As of 0.9.29, sorts in true binary order, not base64 string.private static classSorts profiles by tier (fast > high-cap > standard) using pre-computed tier sets, then by binary hash order within each tier.private static classThe sorted peer set, hidden-stale count, hide window, and pre-computed tier snapshots fromloadProfiles(int).Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router context.private static final DecimalFormatFormatter for the numbers in the table.private final 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 final ProfileOrganizerThe organizer holding the peer profiles.private static final intLength 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.private static final intRender rows in a single write up to this count; above it, flush everySTREAM_BATCHrows so the page paints progressively.private static final StringPlaceholder for a missing value.private static final intRows rendered per flush when streaming a large table.private static final PatternMatches the parenthesized note in a WHOIS name.Constructor Summary
ConstructorsConstructorDescriptionProfileOrganizerRenderer(ProfileOrganizer organizer, RouterContext context) Creates a new ProfileOrganizerRenderer.ProfileOrganizerRenderer(ProfileOrganizer organizer, RouterContext context, boolean fragmentKeys) Creates a new ProfileOrganizerRenderer.Method Summary
Modifier and TypeMethodDescriptionprivate StringTranslate a string.private StringTranslates a string with one parameter.private longavgMs(PeerProfile prof, long rate, RateAverages ra) Average DB response time for the rate in ms, or -1 when no data.private static intfailRatePct(PeerProfile prof, RateAverages ra) 1h lookup fail rate as an integer percent, the same value the render emits.floodfillStats(Set<PeerProfile> order) ComputeProfileOrganizerRenderer.FloodfillStatsin a single pass over the ordered profiles.private StringformatInterval(long now, long then) Format a time span for display.private static booleanisValid(PeerProfile prof, Hash peer, Hash us, boolean requireTunnelHistory) Exclude ourself and profiles never heard from.loadProfiles(int mode) Load, filter, and sort the profiles for the given mode.Translate with plural support.private static final Stringnum(double num) Formats a number for the table.private static final Stringpct(double frac) Format a 0.0-1.0 fraction as an integer percent, e.g.private voidrenderDefinitions(Writer out) Render the definitions block shown on the full "all" page when the advanced setting is off.private voidrenderFloodfill(Writer out, Set<PeerProfile> order) Render the floodfill table, sorted by 1h fail rate ascending.private voidrenderFloodfillRings(Writer out, Set<PeerProfile> order) Render the floodfill health rings above the floodfill table: peer count, reachability, banned floodfills, mean 1h failure, mean response time, recent activity, lookup reliability and store health.voidrenderFragment(Writer out, int mode, String id) Render a single named element for the contentonly fragment mode.private voidRender the profile table body.private voidrenderProfileRings(Writer out, int mode, ProfileOrganizerRenderer.ProfileSelection sel) Render the profile summary rings above the profile table: eight rings per page.voidrenderStatusHTML(Writer out, int mode) Render the peer profile status table.private voidrenderTierCountRing(StringBuilder buf, int count, int known, String label, String singular, String plural) Render a tier count ring: share of known profiles in the tier and the peer count in the center.
Field Details
WHOIS_PAREN
Matches the parenthesized note in a WHOIS name.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:
KEY_LEN
private static final int KEY_LENLength 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:
_context
The router context._organizer
The organizer holding the peer profiles._fragmentKeys
private final 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._fmt
Formatter for the numbers in the table.NA
Constructor Details
ProfileOrganizerRenderer
Creates a new ProfileOrganizerRenderer.- Parameters:
organizer- the organizer holding the peer profiles and throttling data to rendercontext- the router context supplying console translations
ProfileOrganizerRenderer
public ProfileOrganizerRenderer(ProfileOrganizer organizer, RouterContext context, boolean fragmentKeys) Creates a new ProfileOrganizerRenderer.- Parameters:
organizer- the organizer holding the peer profiles and throttling data to rendercontext- the router context supplying console translationsfragmentKeys- when true, rows carry a data-key attribute for the contentonly fragment mode
Method Details
renderStatusHTML
Render the peer profile status table.- Parameters:
out- the writer to render tomode- 0 = all; 1 = fast; 2 = high capacity (non-fast); 3 = floodfill- Throws:
IOException- if an I/O error occurs
renderFragment
Render a single named element for the contentonly fragment mode. Renders nothing for ids the given mode does not own.- Parameters:
out- the writer to render tomode- 0 = all; 1 = fast; 2 = high capacity (non-fast); 3 = floodfillid- the element id- Throws:
IOException- if an I/O error occurs
loadProfiles
Load, filter, and sort the profiles for the given mode. Modes 1 and 2 drop peers that do not match the tier. Mode 3 keeps all peers in binary hash order. Modes 0-2 hide inactive peers not heard from within a cutoff that scales with the candidate count (4h above 500, 2h above 1000, 1h above 2000, 30m above 3000, 15m above 4000, 10m above 5000) to keep the displayed table manageable; mode 3 has no cutoff.- Parameters:
mode- 0 = all; 1 = fast; 2 = high capacity (non-fast); 3 = floodfill- Returns:
- the sorted set, the hidden-stale profile count, and the hide window (zero for mode 3)
isValid
Exclude ourself and profiles never heard from. WithrequireTunnelHistory, also exclude profiles that have never participated in a tunnel build (neither agreed to nor rejected a build request).- Parameters:
prof- the candidate peer's profilepeer- the candidate peer's hashus- our own router hash, never validrequireTunnelHistory- true for modes 0-2, false for mode 3- Returns:
- true if the peer is not us and has been heard from, and when requireTunnelHistory is set also has tunnel build history
renderPbody
private void renderPbody(Writer out, ProfileOrganizerRenderer.ProfileSelection sel) throws IOException Render the profile table body. In fragment mode only the bare<tbody id=pbody>is emitted, with a data-key per row for the worker-side row diff; the full page emits the wrapper table and thead and stays byte-for-byte identical to previous versions.- Parameters:
out- the writer to render tosel- the selected profiles- Throws:
IOException- if an I/O error occurs
renderProfileRings
private void renderProfileRings(Writer out, int mode, ProfileOrganizerRenderer.ProfileSelection sel) throws IOException Render the profile summary rings above the profile table: eight rings per page. The all-profiles page shows total count, share displayed, cutoff window, tier counts, activity and DB health; the tier pages show the tier count, latency boundary and mean tier RTT, loss, hourly freshness, activity and DB health.- Parameters:
out- the writer to render tomode- the page mode (0=all profiles, 1=fast tier, 2=high capacity tier)sel- the selected profiles- Throws:
IOException- if an I/O error occurs
renderTierCountRing
private void renderTierCountRing(StringBuilder buf, int count, int known, String label, String singular, String plural) Render a tier count ring: share of known profiles in the tier and the peer count in the center.- Parameters:
buf- the buffer to append tocount- peers in the tierknown- total profiles known to this selectionlabel- ring label, already translated, drawn on the ring itselfsingular- singular tooltip template ({0} placeholder)plural- plural tooltip template ({0} placeholder)
renderDefinitions
Render the definitions block shown on the full "all" page when the advanced setting is off. Never part of a fragment response.- Parameters:
out- the writer to render to- Throws:
IOException- if an I/O error occurs
renderFloodfillRings
Render the floodfill health rings above the floodfill table: peer count, reachability, banned floodfills, mean 1h failure, mean response time, recent activity, lookup reliability and store health. All aggregated over the observed floodfill peers.- Parameters:
out- the writer to render toorder- the selected profiles- Throws:
IOException- if an I/O error occurs
floodfillStats
ComputeProfileOrganizerRenderer.FloodfillStatsin a single pass over the ordered profiles.- Parameters:
order- the selected profiles- Returns:
- aggregated statistics, never null
renderFloodfill
Render the floodfill table, sorted by 1h fail rate ascending.- Parameters:
out- the writer to render toorder- the selected profiles- Throws:
IOException- if an I/O error occurs
failRatePct
1h lookup fail rate as an integer percent, the same value the render emits.- Parameters:
prof- the floodfill's profilera- scratch RateAverages object reused to compute the rate- Returns:
- the 1h failed-lookup average as an integer percent, 0 when there is no data
num
Formats a number for the table.- Parameters:
num- the number to format- Returns:
- the formatted text
pct
Format a 0.0-1.0 fraction as an integer percent, e.g. "62%".- Parameters:
frac- the fraction to format, 0.0-1.0- Returns:
- the truncated percent with a "%" suffix
avgMs
Average DB response time for the rate in ms, or -1 when no data. Used for the raw sort key of the 1h Resp. Time column; display uses formatDuration2() so the two never share varying units.- Parameters:
prof- the peer whose DB response time stat is readrate- the rate window in milliseconds, e.g. 60*60*1000 for 1hra- scratch RateAverages object reused to compute the average- Returns:
- the average response time in ms, or -1 when no data
formatInterval
Format a time span for display.- Parameters:
now- the current time in msthen- the earlier event time in ms, 0 or less renders the placeholder- Returns:
- the span from then to now formatted for display, at least 1 ms
_t
_t
ngettext