java.lang.Object
net.i2p.router.web.helpers.ProfileOrganizerRenderer

class ProfileOrganizerRendererextends Object
Helper class to refactor HTML rendering from out of the ProfileOrganizer.
  • Field Details

    • WHOIS_PAREN

      private static final Pattern WHOIS_PAREN
      Matches the parenthesized note in a WHOIS name.
    • MAX_BEFORE_STREAMING

      private static final int MAX_BEFORE_STREAMING
      Render rows in a single write up to this count; above it, flush every STREAM_BATCH rows so the page paints progressively.
      See Also:
    • STREAM_BATCH

      private static final int STREAM_BATCH
      Rows rendered per flush when streaming a large table.
      See Also:
    • KEY_LEN

      private static final int KEY_LEN
      Length 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

      private final RouterContext _context
      The router context.
    • _organizer

      private final ProfileOrganizer _organizer
      The organizer holding the peer profiles.
    • _fragmentKeys

      private final boolean _fragmentKeys
      Emit a data-key (peer hash) per row for worker-side row diffing; fragment renders only, so full pages stay byte-for-byte identical.
    • _fmt

      private static final DecimalFormat _fmt
      Formatter for the numbers in the table.
    • NA

      private static final String NA
      Placeholder for a missing value.
      See Also:
  • Constructor Details

    • ProfileOrganizerRenderer

      public ProfileOrganizerRenderer(ProfileOrganizer organizer, RouterContext context)
      Creates a new ProfileOrganizerRenderer.
      Parameters:
      organizer - the organizer holding the peer profiles and throttling data to render
      context - 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 render
      context - the router context supplying console translations
      fragmentKeys - when true, rows carry a data-key attribute for the contentonly fragment mode
  • Method Details

    • renderStatusHTML

      public void renderStatusHTML(Writer out, int mode) throws IOException
      Render the peer profile status table.
      Parameters:
      out - the writer to render to
      mode - 0 = all; 1 = fast; 2 = high capacity (non-fast); 3 = floodfill
      Throws:
      IOException - if an I/O error occurs
    • renderFragment

      public void renderFragment(Writer out, int mode, String id) throws IOException
      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 to
      mode - 0 = all; 1 = fast; 2 = high capacity (non-fast); 3 = floodfill
      id - the element id
      Throws:
      IOException - if an I/O error occurs
    • loadProfiles

      private ProfileOrganizerRenderer.ProfileSelection loadProfiles(int mode)
      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

      private static boolean isValid(PeerProfile prof, Hash peer, Hash us, boolean requireTunnelHistory)
      Exclude ourself and profiles never heard from. With requireTunnelHistory, 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 profile
      peer - the candidate peer's hash
      us - our own router hash, never valid
      requireTunnelHistory - 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 to
      sel - 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 to
      mode - 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 to
      count - peers in the tier
      known - total profiles known to this selection
      label - ring label, already translated, drawn on the ring itself
      singular - singular tooltip template ({0} placeholder)
      plural - plural tooltip template ({0} placeholder)
    • renderDefinitions

      private void renderDefinitions(Writer out) throws IOException
      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

      private void renderFloodfillRings(Writer out, Set<PeerProfile> order) throws IOException
      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 to
      order - the selected profiles
      Throws:
      IOException - if an I/O error occurs
    • floodfillStats

      private ProfileOrganizerRenderer.FloodfillStats floodfillStats(Set<PeerProfile> order)
      Compute ProfileOrganizerRenderer.FloodfillStats in a single pass over the ordered profiles.
      Parameters:
      order - the selected profiles
      Returns:
      aggregated statistics, never null
    • renderFloodfill

      private void renderFloodfill(Writer out, Set<PeerProfile> order) throws IOException
      Render the floodfill table, sorted by 1h fail rate ascending.
      Parameters:
      out - the writer to render to
      order - the selected profiles
      Throws:
      IOException - if an I/O error occurs
    • failRatePct

      private static int failRatePct(PeerProfile prof, RateAverages ra)
      1h lookup fail rate as an integer percent, the same value the render emits.
      Parameters:
      prof - the floodfill's profile
      ra - 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

      private static final String num(double num)
      Formats a number for the table.
      Parameters:
      num - the number to format
      Returns:
      the formatted text
    • pct

      private static final String pct(double frac)
      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

      private long avgMs(PeerProfile prof, long rate, RateAverages ra)
      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 read
      rate - the rate window in milliseconds, e.g. 60*60*1000 for 1h
      ra - scratch RateAverages object reused to compute the average
      Returns:
      the average response time in ms, or -1 when no data
    • formatInterval

      private String formatInterval(long now, long then)
      Format a time span for display.
      Parameters:
      now - the current time in ms
      then - 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

      private String _t(String s)
      Translate a string.
      Parameters:
      s - the message key to translate
      Returns:
      the translated text for s
    • _t

      private String _t(String s, Object o)
      Translates a string with one parameter.
      Parameters:
      s - the string to translate
      o - the parameter to substitute
      Returns:
      the translated text
    • ngettext

      public String ngettext(String s, String p, int n)
      Translate with plural support.
      Parameters:
      s - singular string, may contain {0} for the count
      p - plural string, may contain {0} for the count
      n - the count, used to choose between s and p
      Returns:
      translated string