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 Summary
FieldsModifier and TypeFieldDescription(package private) static final StringHostnames the operator has blacklisted, maintained by susidns/addressbook.(package private) static final StringWhere the ping interval is configured.(package private) static final longUsed when the config is absent or unparseable.(package private) static final StringKey naming the ping interval inCONFIG_FILE.(package private) static final StringThe unreachable flag as the checker writes it.(package private) static final StringThe reachable flag as the checker writes it.(package private) static final StringDirectory under the router dir holding the addressbook's own state.(package private) static final StringThe probe results, written by the addressbook host checker.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionblacklisted(File routerDir) Hostnames the operator has blacklisted, cached on the same cycle as the probe results.(package private) static voidDrop the cache.static StringhostFromUrl(String url) Extract the host from a link's URL.static booleanisBlacklisted(String host, Set<String> blacklist) Whether a hostname is blacklisted.static booleanWhether a site should be hidden from the listing.static booleanWhether a host is one the addressbook can hold, i.e.static voidparseBlacklistLine(String line, Set<String> out) Record one entry of the blacklist, which is a bare hostname per line.static longparseInterval(String value) Convert a configured ping interval to milliseconds.static voidparseProbeLine(String line, Map<String, Boolean> out) Record one row of the results file.The probe results, cached for the current ping interval.
Field Details
STATUS_DIR
Directory under the router dir holding the addressbook's own state.- See Also:
STATUS_FILE
The probe results, written by the addressbook host checker.- See Also:
BLACKLIST_FILE
Hostnames the operator has blacklisted, maintained by susidns/addressbook.- See Also:
CONFIG_FILE
PROP_PING_INTERVAL
Key naming the ping interval inCONFIG_FILE.- See Also:
DEFAULT_INTERVAL_MS
static final long DEFAULT_INTERVAL_MSUsed when the config is absent or unparseable. Matches the checker's own default.- See Also:
REACHABLE_YES
The reachable flag as the checker writes it.- See Also:
REACHABLE_NO
The unreachable flag as the checker writes it.- See Also:
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
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
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
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 lowercasedinAddressbook- whether the naming service resolves the hostprobed- result ofprobed(File)- Returns:
- true if the link should not be shown
isBlacklisted
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 byhostFromUrl(String)blacklist- result ofblacklisted(File)- Returns:
- true if the host is blacklisted
parseBlacklistLine
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 blacklistout- receives the hostname
hostFromUrl
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
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.i2pname 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 byhostFromUrl(String)- Returns:
- true if the host is an I2P name
parseProbeLine
Record one row of the results file.Comments and blank lines are skipped, as is any row whose reachable flag is neither
ynorn, 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 fileout- receives host to reachable
parseInterval
Convert a configured ping interval to milliseconds.Follows the checker's own convention: a trailing
Mmeans minutes, anything else means hours. The config in use readspingInterval=1, which means one hour rather than one minute.- Parameters:
value- the raw config value- Returns:
- the interval in milliseconds, or
DEFAULT_INTERVAL_MSif unusable
clearCache
static void clearCache()Drop the cache. For tests, and for reacting to a configuration change.