java.lang.Object
net.i2p.client.naming.NamingService
net.i2p.client.naming.DummyNamingService
net.i2p.client.naming.MetaNamingService
net.i2p.client.naming.HostsTxtNamingService
A naming service based on multiple "hosts.txt" files. Supports .b32.i2p and {b64} lookups. Supports caching. All host names are converted to lower case.
Field Summary
FieldsFields inherited from class MetaNamingService
_servicesModifier and TypeFieldDescriptionprotected final List<NamingService> Chained naming services, in order.Fields inherited from class DummyNamingService
BASE32_HASH_LENGTH, CACHE_MAX_SIZE, DEST_SIZE, PROP_B32Modifier and TypeFieldDescriptionprotected static final intLength of a base32 hash string.protected static final intMaximum cache size.static final intStandard base64 destination length (no certificate).static final StringProperty to enable b32 lookup.Fields inherited from class NamingService
_context, _listeners, _log, _updaters, PROP_IMPLModifier and TypeFieldDescriptionprotected final I2PAppContextThe app context.protected final Set<NamingServiceListener> The listeners.protected final LogThe logger.protected final Set<NamingServiceUpdater> The updaters.static final StringWhat classname should be used as the naming service impl?Constructor Summary
ConstructorsConstructorDescriptionHostsTxtNamingService(I2PAppContext context) The naming service should only be constructed and accessed through the application context.Method Summary
Modifier and TypeMethodDescriptionThe hosts files configured for this service.getNames(Properties options) All services aggregated, unless options contains the property "file", in which case only for that file.lookup(String hostname, Properties lookupOptions, Properties storedOptions) Throws, this service knows no destinations.booleanput(String hostname, Destination d, Properties options) Stores in the last service.booleanputIfAbsent(String hostname, Destination d, Properties options) Stores in the last service.booleanremove(String hostname, Properties options) Removes from all services.Methods inherited from class MetaNamingService
addNamingService, export, getBase64Entries, getEntries, getNamingServices, registerListener, removeNamingService, reverseLookup, shutdown, size, unregisterListenerModifier and TypeMethodDescriptionfinal booleanaddNamingService(NamingService ns, boolean head) Only for chaining-capable NamingServices.voidexport(Writer out, Properties options) All services aggregated.getBase64Entries(Properties options) All services aggregated.getEntries(Properties options) All services aggregated.For daisy chaining (MetaNamingService).voidRegister a listener for naming service changes.booleanOnly for chaining-capable NamingServices.reverseLookup(Destination dest, Properties options) Same as reverseLookup(dest) but with options This implementation returns null.voidshutdown()Parent will call when removed.intsize(Properties options) All services aggregated.voidUnregister a listener for naming service changes.Methods inherited from class DummyNamingService
clearCache, getCache, putCache, removeCacheModifier and TypeMethodDescriptionprotected static voidClear all cached destinations.protected static DestinationLook up a cached destination.protected static voidputCache(String s, Destination d) Provide basic static caching for all services.protected static voidRemove a cached destination.Methods inherited from class NamingService
addDestination, addDestination, addNamingService, createInstance, export, getConfiguration, getEntries, getName, getNames, getParent, isB32Host, isBlindedHost, isI2PHost, lookup, lookup, lookupAll, lookupAll, lookupBase32, lookupBase64, put, putAll, putIfAbsent, registerUpdater, remove, remove, remove, requestUpdate, reverseLookup, reverseLookup, reverseLookupAll, reverseLookupAll, reverseLookupAll, setConfiguration, size, start, toString, unregisterUpdater, updateModifier and TypeMethodDescriptionbooleanaddDestination(String hostname, Destination d) Add a Destination to an existing hostname's entry in the addressbook.booleanaddDestination(String hostname, Destination d, Properties options) Add a Destination to an existing hostname's entry in the addressbook.booleanOnly for chaining-capable NamingServices.static final NamingServicecreateInstance(I2PAppContext context) WARNING - for use byI2PAppContextonly - others must useI2PAppContext.namingService().voidExport in a hosts.txt format.Warning - unimplemented in any subclass.Warning - This obviously brings the whole database into memory, so use is discouraged.getName()The name of this naming service.getNames()All known hostnames.This implementation returns null.static booleanIs this a b32 hostname? Does NOT validate the base32 part except for length.static booleanisBlindedHost(String hostname) Is this a blinded ("b33") hostname? Does NOT validate the base32 part except for length.static booleanIs this an i2p hostname?Look up a hostname.Same asNamingService.lookupBase32(String, int)but with the SHA256 Hash precalculated This implementation returns null.For NamingServices that support multiple Destinations for a single hostname, return all of them.lookupAll(String hostname, Properties lookupOptions, List<Properties> storedOptions) For NamingServices that support multiple Destinations and Properties for a single hostname, return all of them.lookupBase32(String hostname, int timeout) Lookup a Base 32 address.protected DestinationlookupBase64(String hostname) If the hostname is a valid Base64 encoded destination, return the decoded Destination.booleanput(String hostname, Destination d) Add a hostname and Destination to the addressbook.booleanputAll(Map<String, Destination> entries, Properties options) Put all the entries, each with the given options.booleanputIfAbsent(String hostname, Destination d) Add a hostname and Destination to the addressbook.voidRegister an updater for the naming service.booleanDelete the entry.booleanremove(String hostname, Destination d) Remove a hostname's entry only if it contains the Destination d.booleanremove(String hostname, Destination d, Properties options) Remove a hostname's entry only if it contains the Destination d.voidrequestUpdate(Properties options) Ask any registered updaters to update now.reverseLookup(Destination dest) Reverse lookup a destination.Reverse lookup a hash.reverseLookupAll(Destination dest) Reverse lookup a destination This implementation returns reverseLookupAll(dest, null).reverseLookupAll(Destination d, Properties options) Same as reverseLookupAll(dest) but with options This implementation returns the result from reverseLookup, or null.Reverse lookup a hash.booleanWarning - unimplemented in any subclass.intsize()The number of entries in this naming service.voidstart()Parent will call when added.toString()Returns a string representation of this naming service.voidUnregister an updater for the naming service.booleanupdate(String hostname, Destination d, Properties options) Fails if entry did not previously exist.
Field Details
PROP_HOSTS_FILE
If this system property is specified, the tunnel will read the given file for hostname=destKey values when resolving names.- See Also:
DEFAULT_HOSTS_FILE
Default hosts.txt filenames.- See Also:
Constructor Details
HostsTxtNamingService
The naming service should only be constructed and accessed through the application context. This constructor should only be used by the appropriate application context itself.- Parameters:
context- the application context
Method Details
getFilenames
lookup
Description copied from class:DummyNamingServiceThrows, this service knows no destinations.- Overrides:
lookupin classMetaNamingService- Parameters:
hostname- mixed case as it could be a keylookupOptions- input parameter, NamingService-specific, can be nullstoredOptions- output parameter, NamingService-specific, any stored properties will be added if non-null- Returns:
- dest or null
put
Description copied from class:MetaNamingServiceStores in the last service.- Overrides:
putin classMetaNamingService- Parameters:
hostname- the host name to map to the destination, overwriting any existing entryd- the destination for the hostnameoptions- NamingService-specific, can be null- Returns:
- true if the entry was stored; this base implementation always returns false
putIfAbsent
Description copied from class:MetaNamingServiceStores in the last service.- Overrides:
putIfAbsentin classMetaNamingService- Parameters:
hostname- the host name to map to the destination, which must not already be presentd- the destination for the hostnameoptions- NamingService-specific, can be null- Returns:
- true if no entry existed and the new one was stored; this base implementation always returns false
remove
Description copied from class:MetaNamingServiceRemoves from all services.- Overrides:
removein classMetaNamingService- Parameters:
hostname- the host name whose entry is to be deletedoptions- NamingService-specific, can be null- Returns:
- true if removed successfully, false on error or if it did not exist
getNames
All services aggregated, unless options contains the property "file", in which case only for that file.- Overrides:
getNamesin classMetaNamingService- Parameters:
options- NamingService-specific, can be null- Returns:
- the hostnames from the selected file, or from every service if no file is named