java.lang.Object
net.i2p.client.naming.NamingService
net.i2p.client.naming.DummyNamingService
net.i2p.client.naming.MetaNamingService
- Direct Known Subclasses:
HostsTxtNamingService
A naming service of multiple naming services. Supports .b32.i2p and {b64} lookups. Supports caching.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<NamingService> Chained naming services, in order.private static final StringThe services used when the property is unset.private static final StringProperty naming the naming services to use.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
ConstructorsConstructorDescriptionMetaNamingService(I2PAppContext context) Adds the services from thei2p.nameservicelistproperty, in order, as chained services.MetaNamingService(I2PAppContext context, List<NamingService> services) Create a new meta naming service with the specified services.Method Summary
All MethodsModifier 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.getNames(Properties options) All services aggregated.For daisy chaining (MetaNamingService).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.voidRegister a listener for naming service changes.booleanremove(String hostname, Properties options) Removes from all services.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_NAME_SERVICES
Property naming the naming services to use.- See Also:
DEFAULT_NAME_SERVICES
The services used when the property is unset.- See Also:
_services
Chained naming services, in order.
Constructor Details
MetaNamingService
Adds the services from thei2p.nameservicelistproperty, in order, as chained services.- Parameters:
context- the application context
MetaNamingService
Create a new meta naming service with the specified services.- Parameters:
context- the app context every wrapped naming service reads its configuration fromservices- if non-null, services to be added. If null, this will only handle b32 and b64, untiladdNamingService(NamingService, boolean)is called later.
Method Details
addNamingService
Description copied from class:NamingServiceOnly for chaining-capable NamingServices. This implementation returns false. Subclasses implementing chaining should override.- Overrides:
addNamingServicein classNamingService- Parameters:
ns- the naming service to addhead- true to prepend to the chain, false to append- Returns:
- true if ns was chained in; this base implementation always returns false
getNamingServices
Description copied from class:NamingServiceFor daisy chaining (MetaNamingService). This implementation returns null. Subclasses implementing chaining should override.- Overrides:
getNamingServicesin classNamingService- Returns:
- chained naming services or null
removeNamingService
Description copied from class:NamingServiceOnly for chaining-capable NamingServices. This implementation returns false. Subclasses implementing chaining should override.- Overrides:
removeNamingServicein classNamingService- Parameters:
ns- the naming service to remove- Returns:
- true if ns was chained out; this base implementation always returns false
registerListener
Description copied from class:NamingServiceRegister a listener for naming service changes.- Overrides:
registerListenerin classNamingService- Parameters:
nsl- the listener to register
unregisterListener
Description copied from class:NamingServiceUnregister a listener for naming service changes.- Overrides:
unregisterListenerin classNamingService- Parameters:
nsl- the listener to unregister
lookup
Description copied from class:DummyNamingServiceThrows, this service knows no destinations.- Overrides:
lookupin classDummyNamingService- 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
reverseLookup
Description copied from class:NamingServiceSame as reverseLookup(dest) but with options This implementation returns null. Subclasses implementing reverse lookups should override.- Overrides:
reverseLookupin classNamingService- Parameters:
dest- non-null destination to look upoptions- NamingService-specific, can be null- Returns:
- hostname or null
put
Stores in the last service.- Overrides:
putin classNamingService- 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
Stores in the last service.- Overrides:
putIfAbsentin classNamingService- 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
Removes from all services.- Overrides:
removein classNamingService- 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
getEntries
All services aggregated.- Overrides:
getEntriesin classNamingService- Parameters:
options- NamingService-specific, can be null- Returns:
- the hostname to destination mapping merged from every delegate service
getBase64Entries
All services aggregated.- Overrides:
getBase64Entriesin classNamingService- Parameters:
options- NamingService-specific, can be null- Returns:
- the base64 entries
getNames
All services aggregated.- Overrides:
getNamesin classNamingService- Parameters:
options- NamingService-specific, can be null- Returns:
- the hostnames known to every delegate service, merged into one set
export
All services aggregated. Duplicates not removed (for efficiency).- Overrides:
exportin classNamingService- Parameters:
out- the writer to export tooptions- NamingService-specific, can be null- Throws:
IOException- if an I/O error occurs
size
All services aggregated.- Overrides:
sizein classNamingService- Parameters:
options- NamingService-specific, can be null- Returns:
- number of entries (matching the options if non-null) or -1 if unknown
shutdown
public void shutdown()Description copied from class:NamingServiceParent will call when removed. If this is the root naming service, the core will stop it. Should not be called by others.- Overrides:
shutdownin classNamingService