public abstract class NamingService extends Object
Modifier and Type | Field and Description |
---|---|
protected I2PAppContext |
_context |
protected Set<NamingServiceListener> |
_listeners |
protected Log |
_log |
protected Set<NamingServiceUpdater> |
_updaters |
static String |
PROP_IMPL
what 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() |
Set<String> |
getNames() |
Set<String> |
getNames(Properties options) |
List<NamingService> |
getNamingServices()
This implementation returns null.
|
NamingService |
getParent()
This implementation returns null.
|
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 host name.
|
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 host name,
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 host name,
return all of them.
|
Destination |
lookupBase32(String hostname,
int timeout)
Lookup a Base 32 address.
|
protected Destination |
lookupBase64(String hostname)
If the host name 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) |
void |
registerUpdater(NamingServiceUpdater nsu) |
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
This implementation returns reverseLookup(dest, null).
|
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() |
int |
size(Properties options)
This implementation returns -1.
|
void |
start()
Parent will call when added.
|
String |
toString() |
void |
unregisterListener(NamingServiceListener nsl) |
void |
unregisterUpdater(NamingServiceUpdater nsu) |
boolean |
update(String hostname,
Destination d,
Properties options)
Fails if entry did not previously exist.
|
protected final Log _log
protected final I2PAppContext _context
protected final Set<NamingServiceListener> _listeners
protected final Set<NamingServiceUpdater> _updaters
public static final String PROP_IMPL
protected NamingService(I2PAppContext context)
public Destination lookup(String hostname)
null
if name is unknown.public String reverseLookup(Destination dest)
dest
- non-nullnull
if none is known. It is safe for subclasses to always return
null
if no reverse lookup is possible.public String reverseLookup(Hash h)
h
- non-nullnull
if none is known. It is safe for subclasses to always return
null
if no reverse lookup is possible.protected Destination lookupBase64(String hostname)
hostname
- 516+ character Base 64public String getName()
public Properties getConfiguration()
public boolean setConfiguration(Properties p)
public List<NamingService> getNamingServices()
public NamingService getParent()
public boolean addNamingService(NamingService ns)
public boolean addNamingService(NamingService ns, boolean head)
head
- or tailpublic boolean removeNamingService(NamingService ns)
public int size()
public int size(Properties options)
options
- NamingService-specific, can be nullpublic Map<String,Destination> getEntries()
public Map<String,Destination> getEntries(Properties options)
options
- NamingService-specific, can be nullpublic Map<String,String> getBase64Entries(Properties options)
options
- NamingService-specific, can be nullpublic void export(Writer out) throws IOException
IOException
public void export(Writer out, Properties options) throws IOException
options
- NamingService-specific, can be nullIOException
public Set<String> getNames()
public Set<String> getNames(Properties options)
options
- NamingService-specific, can be nullpublic boolean put(String hostname, Destination d)
public boolean put(String hostname, Destination d, Properties options)
options
- NamingService-specific, can be nullpublic boolean putIfAbsent(String hostname, Destination d)
public boolean putIfAbsent(String hostname, Destination d, Properties options)
options
- NamingService-specific, can be nullpublic boolean putAll(Map<String,Destination> entries, Properties options)
options
- NamingService-specific, can be nullpublic boolean update(String hostname, Destination d, Properties options)
d
- may be null if only options are changingoptions
- NamingService-specific, can be nullpublic boolean remove(String hostname)
public boolean remove(String hostname, Properties options)
options
- NamingService-specific, can be nullpublic void requestUpdate(Properties options)
options
- NamingService- or updater-specific, may be nullpublic void registerListener(NamingServiceListener nsl)
public void unregisterListener(NamingServiceListener nsl)
public void registerUpdater(NamingServiceUpdater nsu)
public void unregisterUpdater(NamingServiceUpdater nsu)
public abstract Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions)
lookupOptions
- input parameter, NamingService-specific, can be nullstoredOptions
- output parameter, NamingService-specific, any stored properties will be added if non-nullpublic String reverseLookup(Destination d, Properties options)
d
- non-nulloptions
- NamingService-specific, can be nullpublic Destination lookupBase32(String hostname, int timeout)
hostname
- must be {52 chars}.b32.i2ptimeout
- in seconds; <= 0 means use router defaultpublic Destination lookup(Hash hash, int timeout)
timeout
- in seconds; <= 0 means use router defaultpublic void start()
public void shutdown()
public List<Destination> lookupAll(String hostname)
public List<Destination> lookupAll(String hostname, Properties lookupOptions, List<Properties> storedOptions)
lookupOptions
- input parameter, NamingService-specific, may be nullstoredOptions
- output parameter, NamingService-specific, any stored properties will be added if non-nullpublic boolean addDestination(String hostname, Destination d)
public boolean addDestination(String hostname, Destination d, Properties options)
options
- NamingService-specific, may be nullpublic boolean remove(String hostname, Destination d)
public boolean remove(String hostname, Destination d, Properties options)
options
- NamingService-specific, may be nullpublic 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 List<String> reverseLookupAll(Destination dest)
dest
- non-nullnull
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 nullnull
public static final NamingService createInstance(I2PAppContext context)