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

public class HostCheckStatusextends Object
Whether each site in the Sites of Interest listing is still worth showing.

A site can fail in two independent ways, so two sources are consulted.

Addressbook membership. The router resolves names through BlockfileNamingService, backed by hostsdb.blockfile - the live addressbook, which is much larger than the hosts.txt shipped at install and accumulates entries beyond it. A site the naming service cannot resolve cannot be reached by name, so it is not shown. Membership is therefore asked of NamingService rather than read from any file: hosts.txt is only the seed the database was built from and says nothing about what is live.

Probe status. The addressbook checker periodically probes the sites it knows and appends the outcome to addressbook/hosts_check.txt, one CSV row per probe:

 # Format: timestamp,host,reachable,category,responseTime,leaseSetTypes
 1791429608769,exil3.i2p,y,forum,34765,[6,4]

A site in the addressbook whose latest probe failed is hidden and reappears when a later probe succeeds. A site in the addressbook that has not been probed yet is shown: absence of a result is not evidence of failure, so a cold cache must not empty the page.

Only the host column and the reachable flag are read. The trailing field contains commas of its own ([6,4]); that is harmless because the fields of interest come first and the split is positional.

Probe results are cached for one ping interval, since they cannot change any faster than the checker refreshes them.

  • Field Details

  • Constructor Details

    • HostCheckStatus

      public HostCheckStatus()
      Constructor. Every read below resolves the status directory from the router context on the spot, so a bare instance holds no state.
  • Method Details

    • probed

      public static Map<String,Boolean> probed(File routerDir)
      The probe results, cached for the current ping interval.

      Callers rendering a whole list should fetch once and use isDown(String, boolean, Map) per entry, rather than re-reading per entry.

      Parameters:
      routerDir - the router's working directory
      Returns:
      host to reachable flag; empty if the results file could not be read, which judges nothing rather than judging everything
    • blacklisted

      public static Set<String> blacklisted(File routerDir)
      Hostnames the operator has blacklisted, cached on the same cycle as the probe results.

      This is the susidns/addressbook blacklist, one lowercased hostname per line. It is not the router's Banlist, which is a separate peer-hash mechanism with expiry: the two answer different questions, and a hostname can be blacklisted here without the router ever refusing that peer.

      Parameters:
      routerDir - the router's working directory
      Returns:
      the blacklisted hostnames, empty if the file could not be read
    • isDown

      public static boolean isDown(String host, boolean inAddressbook, Map<String,Boolean> probed)
      Whether a site should be hidden from the listing.

      A site is hidden when it is not in the addressbook at all, or when its latest probe failed. A site in the addressbook with no probe result is shown, because untested is not the same as down.

      Parameters:
      host - hostname, already lowercased
      inAddressbook - whether the naming service resolves the host
      probed - result of probed(File)
      Returns:
      true if the link should not be shown
    • isBlacklisted

      public static boolean isBlacklisted(String host, Set<String> blacklist)
      Whether a hostname is blacklisted.

      A blacklisted host is never offered as a link, whatever the probe results say. That is a stronger rule than "down": the operator has said they do not want it reached, so a successful probe does not earn it a place back.

      Parameters:
      host - lowercase host, as returned by hostFromUrl(String)
      blacklist - result of blacklisted(File)
      Returns:
      true if the host is blacklisted
    • parseBlacklistLine

      public static void parseBlacklistLine(String line, Set<String> out)
      Record one entry of the blacklist, which is a bare hostname per line.

      Comments and blank lines are skipped and the name is lowercased, so the file stays usable if it is ever hand-edited. A line carrying anything other than a hostname is ignored rather than stored, since a malformed entry must not silently blank a link.

      Parameters:
      line - one line from the blacklist
      out - receives the hostname
    • hostFromUrl

      public static String hostFromUrl(String url)
      Extract the host from a link's URL.

      Strips the scheme, any path, any port, and lowercases the result. Returns null when there is no host to extract, which is also the signal that the link is not a site the addressbook could ever hold.

      Parameters:
      url - the configured URL
      Returns:
      the lowercase host, or null
    • isI2pHost

      public static boolean isI2pHost(String host)
      Whether a host is one the addressbook can hold, i.e. an I2P name.

      Links to clearnet or to the console's own paths are always shown; only .i2p names can be judged down.

      A .b32.i2p name is deliberately included: it is an I2P name, and the naming service resolves it. It is left in scope even though resolving one can reach the network, because the listing is not expected to contain them.

      Parameters:
      host - lowercase host, as returned by hostFromUrl(String)
      Returns:
      true if the host is an I2P name
    • parseProbeLine

      public static void parseProbeLine(String line, Map<String,Boolean> out)
      Record one row of the results file.

      Comments and blank lines are skipped, as is any row whose reachable flag is neither y nor n, so a half-written row cannot be mistaken for a verdict and hide a working site. Hosts are lowercased so lookups need not worry about case. Later rows win, which is what lets a recovered site come back.

      Parameters:
      line - one line from the results file
      out - receives host to reachable
    • parseInterval

      public static long parseInterval(String value)
      Convert a configured ping interval to milliseconds.

      Follows the checker's own convention: a trailing M means minutes, anything else means hours. The config in use reads pingInterval=1, which means one hour rather than one minute.

      Parameters:
      value - the raw config value
      Returns:
      the interval in milliseconds, or DEFAULT_INTERVAL_MS if unusable
    • clearCache

      static void clearCache()
      Drop the cache. For tests, and for reacting to a configuration change.