public abstract class NamingService extends Object
| Modifier and Type | Field and Description |
|---|---|
protected I2PAppContext | _contextcontext |
protected Set<NamingServiceListener> | _listenerslisteners |
protected Log | _loglogger |
protected Set<NamingServiceUpdater> | _updatersupdaters |
static String | PROP_IMPLwhat classname should be used as the naming service impl? |
| Modifier | Constructor and Description |
|---|---|
protected | NamingService(I2PAppContext context)The naming service should only be constructed and accessed through the
application context. |
| Modifier and Type | Method and Description |
|---|---|
boolean | addDestination(String hostname,
Destination d)Add a Destination to an existing hostname's entry in the addressbook. |
boolean | addDestination(String hostname,
Destination d,
Properties options)Add a Destination to an existing hostname's entry in the addressbook. |
boolean | addNamingService(NamingService ns)Only for chaining-capable NamingServices. |
boolean | addNamingService(NamingService ns,
boolean head)Only for chaining-capable NamingServices. |
static NamingService | createInstance(I2PAppContext context)WARNING - for use by I2PAppContext only - others must use
I2PAppContext.namingService()
Get a naming service instance. |
void | export(Writer out)Export in a hosts.txt format. |
void | export(Writer out,
Properties options)Export in a hosts.txt format. |
Map<String,String> | getBase64Entries(Properties options)This may be more or less efficient than getEntries(),
depending on the implementation. |
Properties | getConfiguration()Warning - unimplemented in any subclass. |
Map<String,Destination> | getEntries()Warning - This obviously brings the whole database into memory,
so use is discouraged. |
Map<String,Destination> | getEntries(Properties options)Warning - This will bring the whole database into memory
if options is null, empty, or unsupported, use with caution. |
String | getName()Get the name of this naming service. |
Set<String> | getNames()Get all known hostnames. |
Set<String> | getNames(Properties options)Get all known hostnames matching the specified options. |
List<NamingService> | getNamingServices()This implementation returns null. |
NamingService | getParent()This implementation returns null. |
static boolean | isB32Host(String hostname)Is this a b32 hostname?
Does NOT validate the base32 part except for length. |
static boolean | isBlindedHost(String hostname)Is this a blinded ("b33") hostname?
Does NOT validate the base32 part except for length. |
static boolean | isI2PHost(String hostname)Is this an i2p hostname?
ref: https://www.rfc-editor.org/rfc/rfc9476.html |
Destination | lookup(Hash hash,
int timeout)Same as lookupBase32() but with the SHA256 Hash precalculated
This implementation returns null. |
Destination | lookup(String hostname)Look up a hostname. |
abstract Destination | lookup(String hostname,
Properties lookupOptions,
Properties storedOptions)Same as lookup(hostname) but with in and out options
Note that whether this (and lookup(hostname)) resolve Base 32 addresses
in the form {52 chars}.b32.i2p is NamingService-specific. |
List<Destination> | lookupAll(String hostname)For NamingServices that support multiple Destinations for a single hostname,
return all of them. |
List<Destination> | lookupAll(String hostname,
Properties lookupOptions,
List<Properties> storedOptions)For NamingServices that support multiple Destinations and Properties for a single hostname,
return all of them. |
Destination | lookupBase32(String hostname,
int timeout)Lookup a Base 32 address. |
protected Destination | lookupBase64(String hostname)If the hostname is a valid Base64 encoded destination, return the
decoded Destination. |
boolean | put(String hostname,
Destination d)Add a hostname and Destination to the addressbook. |
boolean | put(String hostname,
Destination d,
Properties options)Add a hostname and Destination to the addressbook. |
boolean | putAll(Map<String,Destination> entries,
Properties options)Put all the entries, each with the given options. |
boolean | putIfAbsent(String hostname,
Destination d)Add a hostname and Destination to the addressbook. |
boolean | putIfAbsent(String hostname,
Destination d,
Properties options)Add a hostname and Destination to the addressbook. |
void | registerListener(NamingServiceListener nsl)Register a listener for naming service changes. |
void | registerUpdater(NamingServiceUpdater nsu)Register an updater for the naming service. |
boolean | remove(String hostname)Delete the entry. |
boolean | remove(String hostname,
Destination d)Remove a hostname's entry only if it contains the Destination d. |
boolean | remove(String hostname,
Destination d,
Properties options)Remove a hostname's entry only if it contains the Destination d. |
boolean | remove(String hostname,
Properties options)Delete the entry. |
boolean | removeNamingService(NamingService ns)Only for chaining-capable NamingServices. |
void | requestUpdate(Properties options)Ask any registered updaters to update now |
String | reverseLookup(Destination dest)Reverse lookup a destination. |
String | reverseLookup(Destination d,
Properties options)Same as reverseLookup(dest) but with options
This implementation returns null. |
String | reverseLookup(Hash h)Reverse lookup a hash. |
List<String> | reverseLookupAll(Destination dest)Reverse lookup a destination
This implementation returns reverseLookupAll(dest, null). |
List<String> | reverseLookupAll(Destination d,
Properties options)Same as reverseLookupAll(dest) but with options
This implementation returns the result from reverseLookup, or null. |
List<String> | reverseLookupAll(Hash h)Reverse lookup a hash. |
boolean | setConfiguration(Properties p)Warning - unimplemented in any subclass. |
void | shutdown()Parent will call when removed. |
int | size()Get the number of entries in this naming service. |
int | size(Properties options)This implementation returns -1. |
void | start()Parent will call when added. |
String | toString()Returns a string representation of this naming service. |
void | unregisterListener(NamingServiceListener nsl)Unregister a listener for naming service changes. |
void | unregisterUpdater(NamingServiceUpdater nsu)Unregister an updater for the naming service. |
boolean | update(String hostname,
Destination d,
Properties options)Fails if entry did not previously exist. |
protected final I2PAppContext _context
protected final Set<NamingServiceListener> _listeners
protected final Log _log
protected final Set<NamingServiceUpdater> _updaters
public static final String PROP_IMPL
protected NamingService(I2PAppContext context)
context - the application contextpublic boolean addDestination(String hostname, Destination d)
hostname - the hostnamed - the destination to addpublic boolean addDestination(String hostname, Destination d, Properties options)
hostname - the hostnamed - the destination to addoptions - NamingService-specific, may be nullpublic boolean addNamingService(NamingService ns)
ns - the naming service to addpublic boolean addNamingService(NamingService ns, boolean head)
ns - the naming service to addhead - or tailpublic static final NamingService createInstance(I2PAppContext context)
context - the application contextRuntimeException - if the naming service cannot be loadedpublic void export(Writer out) throws IOException
out - the writer to export toIOException - if an I/O error occurspublic void export(Writer out, Properties options) throws IOException
out - the writer to export tooptions - NamingService-specific, can be nullIOException - if an I/O error occurspublic Map<String,String> getBase64Entries(Properties options)
options - NamingService-specific, can be nullpublic Properties getConfiguration()
public Map<String,Destination> getEntries()
public Map<String,Destination> getEntries(Properties options)
options - NamingService-specific, can be nullpublic String getName()
public Set<String> getNames()
public Set<String> getNames(Properties options)
options - NamingService-specific, can be nullpublic List<NamingService> getNamingServices()
public NamingService getParent()
public static boolean isB32Host(String hostname)
hostname - non-nullpublic static boolean isBlindedHost(String hostname)
hostname - non-nullpublic static boolean isI2PHost(String hostname)
hostname - non-nullpublic Destination lookup(Hash hash, int timeout)
hash - the hash to look uptimeout - in seconds; <= 0 means use router defaultpublic Destination lookup(String hostname)
hostname - the hostnamenull if name is unknown.public abstract Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions)
hostname - the hostnamelookupOptions - input parameter, NamingService-specific, can be nullstoredOptions - output parameter, NamingService-specific, any stored properties will be added if non-nullpublic List<Destination> lookupAll(String hostname)
hostname - the hostnamepublic List<Destination> lookupAll(String hostname, Properties lookupOptions, List<Properties> storedOptions)
hostname - the hostnamelookupOptions - input parameter, NamingService-specific, may be nullstoredOptions - output parameter, NamingService-specific, any stored properties will be added if non-nullpublic Destination lookupBase32(String hostname, int timeout)
hostname - must be {52 chars}.b32.i2ptimeout - in seconds; <= 0 means use router defaultprotected Destination lookupBase64(String hostname)
hostname - 516+ character Base 64public boolean put(String hostname, Destination d)
hostname - the hostnamed - the destination for the hostnamepublic boolean put(String hostname, Destination d, Properties options)
hostname - the hostnamed - the destination for the hostnameoptions - NamingService-specific, can be nullpublic boolean putAll(Map<String,Destination> entries, Properties options)
entries - the entriesoptions - NamingService-specific, can be nullpublic boolean putIfAbsent(String hostname, Destination d)
hostname - the hostnamed - the destination for the hostnamepublic boolean putIfAbsent(String hostname, Destination d, Properties options)
hostname - the hostnamed - the destination for the hostnameoptions - NamingService-specific, can be nullpublic void registerListener(NamingServiceListener nsl)
nsl - the listener to registerpublic void registerUpdater(NamingServiceUpdater nsu)
nsu - the updater to registerpublic boolean remove(String hostname)
hostname - the hostnamepublic boolean remove(String hostname, Destination d)
hostname - the hostnamed - the destination that must be presentpublic boolean remove(String hostname, Destination d, Properties options)
hostname - the hostnamed - the destination that must be presentoptions - NamingService-specific, may be nullpublic boolean remove(String hostname, Properties options)
hostname - the hostnameoptions - NamingService-specific, can be nullpublic boolean removeNamingService(NamingService ns)
ns - the naming service to removepublic void requestUpdate(Properties options)
options - NamingService- or updater-specific, may be nullpublic String reverseLookup(Destination dest)
dest - non-null destination to look upnull
if none is known. It is safe for subclasses to always return
null if no reverse lookup is possible.public String reverseLookup(Destination d, Properties options)
d - non-null destination to look upoptions - NamingService-specific, can be nullpublic String reverseLookup(Hash h)
h - non-null hash to look upnull
if none is known. It is safe for subclasses to always return
null if no reverse lookup is possible.public List<String> reverseLookupAll(Destination dest)
dest - non-null destination to look upnull
if none is known. It is safe for subclasses to always return
null if no reverse lookup is possible.public List<String> reverseLookupAll(Destination d, Properties options)
d - non-nulloptions - NamingService-specific, can be nullnullpublic List<String> reverseLookupAll(Hash h)
h - non-nullnull
if none is known. It is safe for subclasses to always return
null if no reverse lookup is possible.public boolean setConfiguration(Properties p)
p - the properties to setpublic void shutdown()
public int size()
public int size(Properties options)
options - NamingService-specific, can be nullpublic void start()
public String toString()
public void unregisterListener(NamingServiceListener nsl)
nsl - the listener to unregisterpublic void unregisterUpdater(NamingServiceUpdater nsu)
nsu - the updater to unregisterpublic boolean update(String hostname, Destination d, Properties options)
hostname - the hostnamed - may be null if only options are changingoptions - NamingService-specific, can be null