java.lang.Object
net.i2p.router.transport.PeerHTMLRenderer

public class PeerHTMLRendererextends Object
HTML rendering of peers (flag, capability bar, identity block) for the NetDb, PeerHelper, and tunnel pages.

Extracted from CommSystemFacadeImpl (2026-09-06) so the peer-render cluster, its RouterInfo/capacity caches, and its i18n state live apart from the facade core. The facade retains thin commSystem() delegators so the public API is unchanged; collaborators (country lookup, reverse-DNS) are injected rather than fetched through commSystem() round-trips.

Pure memory-independent decisions (bandwidth classification, visible-cap cleanup) are package-visible statics so they can be tested without a running router; see PeerHTMLRendererDecisionTest.

  • Field Details

    • BUNDLE_NAME

      private static final String BUNDLE_NAME
      Bundle of the common translated strings.
      See Also:
    • COUNTRY_BUNDLE_NAME

      private static final String COUNTRY_BUNDLE_NAME
      Bundle of the translated country names.
      See Also:
    • _context

      private final RouterContext _context
      Removes the leading D/E/G bandwidth marker from a visible capacity string.
    • _countryLookup

      private final CountryLookup _countryLookup
      The lookup of the peer countries.
    • _rdns

      private final ReverseDnsLookup _rdns
      The reverse dns lookup of peer addresses.
    • routerInfoCache

      private final Map<Hash, RouterInfo> routerInfoCache
      The cached router infos, by peer, to speed repeated lookups.
    • capacityCache

      private final Map<Hash,String> capacityCache
      The cached capacity strings, by peer.
  • Constructor Details

  • Method Details

    • renderPeerHTML

      public String renderPeerHTML(Hash peer, boolean extended)
      Renders HTML for a peer with optional extended info. Uses cached RouterInfo, country info, and reverse lookup cache.
      Parameters:
      peer - the hash of the peer to render
      extended - Whether to show extended capabilities
      Returns:
      HTML snippet representing peer
    • renderPeerFlag

      public String renderPeerFlag(Hash peer)
      Render the HTML flag image for the given peer.
      Parameters:
      peer - the hash of the peer whose country and flag image are rendered
      Returns:
      an HTML span holding the flag image, titled with the country name and resolved host when those are known, else a placeholder
    • renderPeerCaps

      public String renderPeerCaps(Hash peer, boolean inline)
      Renders the peer's capability HTML block. Caches data and removes unnecessary repeated computation.
      Parameters:
      peer - the hash of the peer whose capabilities are being rendered
      inline - If true, render inline without table wrapper
      Returns:
      HTML snippet of peer capabilities
    • getRouterInfoCached

      private RouterInfo getRouterInfoCached(Hash peer)
      Gets the router info from the cache.
      Parameters:
      peer - the hash of the peer
      Returns:
      the router info, null if absent
    • getCapacityCached

      private String getCapacityCached(Hash peer)
      Gets the capacity text from the cache.
      Parameters:
      peer - the hash of the peer
      Returns:
      the capacity text
    • localizedCountryName

      private String localizedCountryName(String code)
      Localized country display name for a two-letter code. Names needing no translation (single words, already localized) are returned verbatim.

      Shared by renderPeerHTML(Hash, boolean) and renderPeerFlag(Hash); extracting it removes the duplicated lookup-and-translate branch from both.

      Parameters:
      code - two-letter country code (never null at call sites)
      Returns:
      country name, translated when multi-word
    • resolveHostForDisplay

      private String resolveHostForDisplay(String ip)
      Reverse-DNS label: resolves ip to its canonical host name when reverse lookups are enabled and the resolver offers a distinct, known name. Otherwise returns the raw IP. Non-blocking-the lookup is served from the rDNS cache and a background lookup is queued on a miss.

      Deduplicates the resolver branch formerly duplicated across renderPeerHTML(Hash, boolean) and renderPeerFlag(Hash); the flag renderer adds the raw-IP suffix itself when the name differs.

      Parameters:
      ip - literal IP string (never null)
      Returns:
      canonical host name or the raw IP
    • classifyCapacity

      static String classifyCapacity(String caps)
      Highest-priority bandwidth capability char present in the caps string, or "?" when none is advertised.

      Priority follows RouterInfo.BW_CAPABILITY_CHARS order, so a peer advertising both a high and a low class is classified at its high end. This is the decision the former getCapacityCached inline loop made; it is exposed so the offline PeerHTMLRendererDecisionTest can pin both the string and the null/empty handling without a router.

      Parameters:
      caps - capabilities string (never null in practice; null treated as none)
      Returns:
      single bandwidth-class char or "?"
    • _t

      private final String _t(String s)
      Looks up the console translation of a string in this renderer's bundle.
      Parameters:
      s - the string to look up
      Returns:
      the localized string, or s itself when no translation exists