This database contains the following skiplists:
"%%__INFO__%%" is the master database skiplist, containing one entry:
"info": a Properties, serialized with DataHelper functions:
"version": "4"
"created": Java long time (ms)
"upgraded": Java long time (ms) (as of database version 2)
"lists": Comma-separated list of host databases, to be
searched in-order for lookups
"%%__REVERSE__%%" is the reverse lookup skiplist
(as of database version 2):
The skiplist keys are Integers, the first 4 bytes of the hash of the dest.
The skiplist values are Properties.
There may be multiple entries in the properties, each one is a reverse mapping,
as there may be more than one hostname for a given destination,
or there could be collisions with the same first 4 bytes of the hash.
Each property key is a hostname.
Each property value is the empty string.
For each host database, there is a skiplist containing
the hosts for that database.
The keys/values in these skiplists are as follows:
key: a UTF-8 String
value: a DestEntry, which is:
a one-byte count of the Properties/Destination pairs to follow
(as of database version 4, otherwise one)
that many pairs of:
Properties (serialized with DataHelper)
Destination (serialized as usual).
The DestEntry Properties typically contains:
"a": The time added (Java long time in ms)
"s": The original source of the entry (typically a file name or subscription URL)
others TBD
All host names are converted to lower case.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA DestEntry contains Properties and a Destination, and is serialized in that order.private static classUsed for the values in the addressbook skiplists Take care not to throw on any error.private static classFor multiple destinations per hostname.private static classUsed to store entries that need deleting.private static classUsed for the values in the header skiplist Take care not to throw on any error.private classCloses the service when the JVM exits.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockFileThe block file holding the naming data.Serializer in effect for destination entries.private static final Serializer<BlockfileNamingService.DestEntry> Serializer for version 1 destination entries.private static final Serializer<BlockfileNamingService.DestEntry> Serializer for version 4 destination entries.private static final Serializer<Integer> Serializer for hash index keys.private static final Serializer<Properties> Serializer for the info block.private final List<BlockfileNamingService.InvalidEntry> Entries that failed to parse.private booleanTrue once the service is closed.private booleanTrue if the database uses the version 4 format.Names of the lists in the database.private booleanTrue if the database needs a format upgrade.Cached lookups that found nothing.private final RAIFileRandom access view of the block file.private final booleanTrue if the database may not be written.private static final Serializer<String> Serializer for host names.private StringVersion string of the database format.private static final StringPlaceholder value where none is needed.private static final StringFile name of the fallback hosts list.private static final StringFile name of the block file database.private static final StringSkiplist holding the info block.private static final intDestinations allowed for one host.private static final intLongest destination value accepted.private static final intEntries kept in the negative cache.private static final StringEntry added-date key.private static final StringCreation date key in the info properties.private static final StringConfig key allowing writes in the app context.private static final StringInfo block key in the skiplist.private static final StringLists key in the info properties.private static final StringList version key in the info properties.private static final StringEntry source key.private static final StringUpgrade date key in the info properties.private static final StringVersion key in the info properties.private static final StringSkiplist holding the reverse lookups.private static final StringDatabase format version this code writes.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
ConstructorsConstructorDescriptionBlockfileNamingService(I2PAppContext context) Opens the database at hostsdb.blockfile or creates a new one and imports entries from hosts.txt, userhosts.txt, and privatehosts.txt.Method Summary
Modifier and TypeMethodDescriptionbooleanaddDestination(String hostname, Destination d, Properties options) Add a Destination to an existing hostname's entry in the addressbook.private voidCaller must synchronize.private static voidaddEntry(SkipList<String, BlockfileNamingService.DestEntry> sl, String key, List<Destination> dests, List<Properties> propsList) Multiple dests version.private static voidaddEntry(SkipList<String, BlockfileNamingService.DestEntry> sl, String key, Destination dest, Properties props) Single dest version.private voidaddReverseEntry(String key, Destination dest) Caller must synchronize.private static voidaddReverseEntry(BlockFile bf, String key, Destination dest, Log log) Caller must synchronize.private voidclose()Closes the block file and stops the service.private voidRemove and log all invalid entries queued byvalidate(String, DestEntry, String)while scanning inlookup(String, Properties, Properties)or getEntries().voidexport(Writer out, Properties options) Export in a hosts.txt format.getBase64Entries(Properties options) All entries as Base64 strings.getEntries(Properties options) All entries as destination objects.private BlockfileNamingService.DestEntryFor either v1 or v4.getFilenames(String list) Returns the files backing one naming list.getNames(Properties options) Broken prior to 0.9.62, would only return one name.getReverseEntries(Hash hash) Caller must synchronize.private static IntegergetReverseKey(Destination dest) Reverse lookup key for the destination.private static IntegergetReverseKey(Hash hash) Reverse lookup key for the hash.private BlockFileinitExisting(RAIFile raf) Read the info block of an existing database.private BlockFileCreate a new database and initialize it from the local files privatehosts.txt, userhosts.txt, and hosts.txt, creating a skiplist in the database for each.private static voidFor logging errors in the static serializers below.lookup(String hostname, Properties lookupOptions, Properties storedOptions) Lookup a hostname.private Destinationlookup2(String hostname, Properties lookupOptions, Properties storedOptions) Single dest version lookup.lookupAll(String hostname, Properties lookupOptions, List<Properties> storedOptions) Return all of the entries found in the first list found, or in the list specified in lookupOptions.private List<Destination> lookupAll2(String hostname, Properties lookupOptions, List<Properties> storedOptions) Multiple dests version lookup.static voidBlockfileNamingService [force] force = force writable.private booleanWhether the database is in an old format.private booleanput(String hostname, List<Destination> dests, List<Properties> propsList, boolean checkExisting) Multiple dests version.booleanput(String hostname, Destination d, Properties options) Store a destination, replacing any previous entry for the name.private booleanput(String hostname, Destination d, Properties options, boolean checkExisting) Single dest version This does not prevent adding b32.booleanputIfAbsent(String hostname, Destination d, Properties options) Store a destination only if the name is unused.private static StringSame as DataHelper.readString, except that strings up to 4K bytes are allowed.static PropertiesSame as DataHelper.readProperties, UTF-8, unsorted, except that values may be up to 4K bytes.booleanremove(String hostname, Properties options) Remove the named entry.booleanremove(String hostname, Destination d, Properties options) Remove a hostname's entry only if it contains the Destination d.private static <V> VremoveEntry(SkipList<String, V> sl, String key) Caller must synchronize.private voidremoveReverseEntry(String key, Destination dest) Caller must synchronize.reverseLookup(Destination d, Properties options) Look up a hostname from a Destination's hash.Look up a hostname from a hash.reverseLookupAll(Destination d, Properties options) Return all hostnames registered for this Destination's hash.Return all hostnames registered for this hash.private voidsetVersion(String version) Save new version number in blockfile after upgrade.voidshutdown()Shut down the naming service and close the backing store.intsize(Properties options) Number of entries.private booleanupgrade()Blockfile must be writable of course.private booleanvalidate(String key, BlockfileNamingService.DestEntry de, String listname) Continuously validate anything we read in.private static voidwriteLongStringUTF8(ByteArrayOutputStream out, String string) Same as DataHelper.writeStringUTF8, except that strings up to 4K bytes are allowed.private static voidwriteProperties(ByteArrayOutputStream rawStream, Properties p) Same as DataHelper.writeProperties, UTF-8, unsorted, except that values may be up to 4K bytes.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, addNamingService, addNamingService, createInstance, export, getConfiguration, getEntries, getName, getNames, getNamingServices, getParent, isB32Host, isBlindedHost, isI2PHost, lookup, lookup, lookupAll, lookupBase32, lookupBase64, put, putAll, putIfAbsent, registerListener, registerUpdater, remove, remove, removeNamingService, requestUpdate, reverseLookup, reverseLookupAll, setConfiguration, size, start, toString, unregisterListener, unregisterUpdater, updateModifier and TypeMethodDescriptionbooleanaddDestination(String hostname, Destination d) Add a Destination to an existing hostname's entry in the addressbook.booleanOnly for chaining-capable NamingServices.booleanaddNamingService(NamingService ns, boolean head) Only 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.For daisy chaining (MetaNamingService).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.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 a listener for naming service changes.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.booleanOnly for chaining-capable NamingServices.voidrequestUpdate(Properties options) Ask any registered updaters to update now.reverseLookup(Destination dest) Reverse lookup a destination.reverseLookupAll(Destination dest) Reverse lookup a destination This implementation returns reverseLookupAll(dest, null).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 a listener for naming service changes.voidUnregister an updater for the naming service.booleanupdate(String hostname, Destination d, Properties options) Fails if entry did not previously exist.
Field Details
_bf
The block file holding the naming data._raf
Random access view of the block file._lists
_invalid
Entries that failed to parse._negativeCache
_isClosed
private volatile boolean _isClosedTrue once the service is closed._readOnly
private final boolean _readOnlyTrue if the database may not be written._version
Version string of the database format._isVersion4
private volatile boolean _isVersion4True if the database uses the version 4 format._needsUpgrade
private boolean _needsUpgradeTrue if the database needs a format upgrade._infoSerializer
Serializer for the info block._stringSerializer
Serializer for host names._destSerializerV1
Serializer for version 1 destination entries._destSerializerV4
Serializer for version 4 destination entries._destSerializer
Serializer in effect for destination entries._hashIndexSerializer
Serializer for hash index keys.HOSTS_DB
File name of the block file database.- See Also:
FALLBACK_LIST
File name of the fallback hosts list.- See Also:
PROP_FORCE
Config key allowing writes in the app context.- See Also:
INFO_SKIPLIST
Skiplist holding the info block.- See Also:
REVERSE_SKIPLIST
Skiplist holding the reverse lookups.- See Also:
PROP_INFO
PROP_VERSION
Version key in the info properties.- See Also:
PROP_LISTVERSION
List version key in the info properties.- See Also:
PROP_LISTS
Lists key in the info properties.- See Also:
PROP_CREATED
Creation date key in the info properties.- See Also:
PROP_UPGRADED
Upgrade date key in the info properties.- See Also:
VERSION
Database format version this code writes.- See Also:
PROP_ADDED
PROP_SOURCE
DUMMY
Placeholder value where none is needed.- See Also:
NEGATIVE_CACHE_SIZE
private static final int NEGATIVE_CACHE_SIZEEntries kept in the negative cache.- See Also:
MAX_VALUE_LENGTH
private static final int MAX_VALUE_LENGTHLongest destination value accepted.- See Also:
MAX_DESTS_PER_HOST
private static final int MAX_DESTS_PER_HOSTDestinations allowed for one host.- See Also:
Constructor Details
BlockfileNamingService
Opens the database at hostsdb.blockfile or creates a new one and imports entries from hosts.txt, userhosts.txt, and privatehosts.txt.If not in router context, the database will be opened read-only unless the property
i2p.naming.blockfile.writeInAppContextis true. Not designed for multiple instantiations or simultaneous use by multiple JVMs.- Parameters:
context- the application context whose router directory holds hostsdb.blockfile- Throws:
RuntimeException- on fatal error
Method Details
initNew
Create a new database and initialize it from the local files privatehosts.txt, userhosts.txt, and hosts.txt, creating a skiplist in the database for each.- Parameters:
f- open file the new database is written into- Returns:
- the new database, with one skiplist per hosts file found
- Throws:
IOException- if the file cannot be written, or initialization fails and the cause is wrapped into an IOException
initExisting
Read the info block of an existing database.- Parameters:
raf- open file of the existing database- Returns:
- the database, with version, creation date and list names read
- Throws:
IOException- if the header, its info, the list names or the version are missing, or the version is newer than this implementation supports
needsUpgrade
Whether the database is in an old format.- Parameters:
bf- database being considered, only writable files can upgrade- Returns:
- true if the version is old and the file is writable
upgrade
private boolean upgrade()Blockfile must be writable of course.Version 1->2: Add reverse skiplist and populate Version 2->3: Re-populate reverse skiplist as version 2 didn't keep it updated after the upgrade. No change to format. Version 3->4: Change format to support multiple destinations per hostname.
- Returns:
- true if upgraded successfully
setVersion
Save new version number in blockfile after upgrade. Blockfile must be writable, of course. Side effect: sets _version fieldCaller must synchronize.
- Parameters:
version- version string to record, e.g. "2", "3" or "4"- Throws:
IOException- if the header or its info block is missing
getEntry
For either v1 or v4. Caller must synchronize.- Parameters:
listname- skiplist to read, one of the configured hosts file nameskey- lower-case hostname to look up- Returns:
- the stored entry, or null if the list or the name is absent
- Throws:
IOException- if the database read fails, or a runtime error is wrapped into one
addEntry
private void addEntry(BlockFile bf, String listname, String key, Destination dest, String source) throws IOException Caller must synchronize.- Parameters:
bf- database to write into, must be writablelistname- skiplist the entry goes into, created if absentkey- lower-case hostname to adddest- destination stored under the keysource- how the entry was added, may be null- Throws:
IOException- if the index cannot be read or written, or a runtime error is wrapped into one
addEntry
private static void addEntry(SkipList<String, BlockfileNamingService.DestEntry> sl, String key, Destination dest, Properties props) Single dest version. Caller must synchronize.- Parameters:
sl- skiplist to write intokey- lower-case hostname, any previous entry is replaceddest- destination stored under the keyprops- per-entry properties such as add time and source, may be null- Throws:
RuntimeException- if the skiplist write fails
addEntry
private static void addEntry(SkipList<String, BlockfileNamingService.DestEntry> sl, String key, List<Destination> dests, List<Properties> propsList) Multiple dests version. DB MUST be version 4. Caller must synchronize.- Parameters:
sl- skiplist to write intokey- lower-case hostname, any previous entry is replaceddests- destinations for the name, the first is also stored as destpropsList- properties parallel to dests, may be null, or entries may be null- Throws:
RuntimeException- if the skiplist write fails
getFilenames
removeEntry
Caller must synchronize.- Type Parameters:
V- value type held by the skiplist- Parameters:
sl- skiplist to remove the key fromkey- lower-case hostname to remove- Returns:
- removed object or null
- Throws:
RuntimeException- if the skiplist write fails
getReverseEntries
Caller must synchronize. Returns null without exception on error (logs only). Returns without logging if no reverse skiplist (version 1).- Parameters:
hash- destination hash to look the names up by- Returns:
- all hostnames found for the hash, or null if none or on error
addReverseEntry
Caller must synchronize. Fails without exception on error (logs only).- Parameters:
key- lower-case hostname to record against the hashdest- destination whose hash is the reverse index key
addReverseEntry
Caller must synchronize. Fails without exception on error (logs only). Returns without logging if no reverse skiplist (version 1).We store one or more hostnames for a given hash. The skiplist key is a signed Integer, the first 4 bytes of the dest hash. For convenience (since we have a serializer already) we use a Properties as the value, with a null string as the value for each hostname property. We could in the future use the property value for something.
- Parameters:
bf- database to write into, must be writablekey- lower-case hostname to record against the hashdest- destination whose hash is the reverse index keylog- where a failed write is logged, nothing is rethrown
removeReverseEntry
Caller must synchronize. Fails without exception on error (logs only).- Parameters:
key- lower-case hostname to forgetdest- destination whose hash is the reverse index key
getReverseKey
Reverse lookup key for the destination.- Parameters:
dest- destination whose hash is keyed- Returns:
- the first 4 hash bytes as a signed Integer
getReverseKey
lookup
Lookup a hostname. Will strip a "www." prefix and retry if lookup fails.- Overrides:
lookupin classDummyNamingService- Parameters:
hostname- upper/lower case oklookupOptions- If non-null and contains the key "list", lookup in that list only, otherwise all listsstoredOptions- output parameter, may be null. If non-null, the properties stored with the entry ("a" date added, "s" source, and any options given when the name was added) are added to it when the name is found. A non-null value also disables the Base32 cache, since the cache does not retain the stored properties.- Returns:
- the destination, or null if not found
lookup2
Single dest version lookup.- Parameters:
hostname- name to look up, mixed case ok, lower-cased for the keylookupOptions- If non-null and contains the key "list", lookup in that list only, otherwise all listsstoredOptions- If non-null, stored properties will be added- Returns:
- the destination, or null if not found
lookupAll2
private List<Destination> lookupAll2(String hostname, Properties lookupOptions, List<Properties> storedOptions) Multiple dests version lookup. DB MUST be version 4.- Parameters:
hostname- the host to look up, in one of the configured listslookupOptions- If non-null and contains the key "list", lookup in that list only, otherwise all listsstoredOptions- output list for stored properties, may be null- Returns:
- non-null list of destinations, or null if not found
put
Store a destination, replacing any previous entry for the name.- Overrides:
putin classNamingService- Parameters:
hostname- the host name to map to the destination, overwriting any existing entryd- the destination for the hostnameoptions- If non-null and contains the key "list", add to that list (default "hosts.txt") Use the key "s" for the source- Returns:
- true if the entry was stored; this base implementation always returns false
putIfAbsent
Store a destination only if the name is unused.- Overrides:
putIfAbsentin classNamingService- Parameters:
hostname- the host name to map to the destination, which must not already be presentd- the destination for the hostnameoptions- If non-null and contains the key "list", add to that list (default "hosts.txt") Use the key "s" for the source. Key "a" will be added with the current time, unless "a" is present in options.- Returns:
- true if no entry existed and the new one was stored; this base implementation always returns false
put
Single dest version This does not prevent adding b32. Caller must check.- Parameters:
hostname- name to store, mixed case ok, lower-cased for the keyd- destination to storeoptions- If non-null and contains the key "list", add to that list (default "hosts.txt"). Use the key "s" for the sourcecheckExisting- if true, fail if entry already exists- Returns:
- true if the entry was written, false if the database is read-only or closed, the name was taken, or the write failed
put
private boolean put(String hostname, List<Destination> dests, List<Properties> propsList, boolean checkExisting) Multiple dests version. DB MUST be version 4. This does not prevent adding b32. Caller must check.- Parameters:
hostname- name to store, mixed case ok, lower-cased for the keydests- destinations for the name, at least one is requiredpropsList- may be null, or entries may be nullcheckExisting- if true, fail if entry already exists- Returns:
- true if the entry was written, false if the database is read-only or closed, the name was taken, or the write failed
- Throws:
IllegalArgumentException- if dests is empty
remove
Remove the named entry.- Overrides:
removein classNamingService- Parameters:
hostname- the host name whose entry is to be deletedoptions- If non-null and contains the key "list", remove from that list (default "hosts.txt", NOT all lists)- Returns:
- true if removed successfully, false on error or if it did not exist
getEntries
All entries as destination objects.- Overrides:
getEntriesin classNamingService- Parameters:
options- If non-null and contains the key "list", get from that list (default "hosts.txt", NOT all lists) Key "skip": skip that many entries Key "limit": max number to return Key "search": return only those matching substring Key "startsWith": return only those starting with ("[0-9]" allowed) Key "beginWith": start here in the iteration Don't use both startsWith and beginWith. Search, startsWith, and beginWith values must be lower case.- Returns:
- the matching hostnames mapped to their destinations
getBase64Entries
All entries as Base64 strings.- Overrides:
getBase64Entriesin classNamingService- Parameters:
options- If non-null and contains the key "list", get from that list (default "hosts.txt", NOT all lists) Key "skip": skip that many entries Key "limit": max number to return Key "search": return only those matching substring Key "startsWith": return only those starting with ("[0-9]" allowed) Key "beginWith": start here in the iteration Don't use both startsWith and beginWith. Search, startsWith, and beginWith values must be lower case.- Returns:
- the base64 entries
export
Export in a hosts.txt format. Output is sorted. Caller must close writer.- Overrides:
exportin classNamingService- Parameters:
out- the writer to export tooptions- If non-null and contains the key "list", get from that list (default "hosts.txt", NOT all lists) Key "search": return only those matching substring Key "startsWith": return only those starting with ("[0-9]" allowed) Key "beginWith": start here in the iteration- Throws:
IOException- if an I/O error occurs
getNames
Broken prior to 0.9.62, would only return one name.- Overrides:
getNamesin classNamingService- Parameters:
options- If non-null and contains the key "list", get from that list (default "hosts.txt", NOT all lists) Key "skip": skip that many entries Key "limit": max number to return Key "search": return only those matching substring Key "startsWith": return only those starting with ("[0-9]" allowed) Key "beginWith": start here in the iteration Don't use both startsWith and beginWith. Search, startsWith, and beginWith values must be lower case.- Returns:
- the hostnames matching the filters, never null
reverseLookup
Look up a hostname from a Destination's hash. Returns the first name found, or null.- Overrides:
reverseLookupin classNamingService- Parameters:
d- non-null destination to look upoptions- to configure lookup behavior (unused)- Returns:
- hostname or null
reverseLookup
Look up a hostname from a hash. Returns the first name found, or null.- Overrides:
reverseLookupin classNamingService- Parameters:
h- the hash to look up- Returns:
- the first hostname, or null if none
reverseLookupAll
Return all hostnames registered for this Destination's hash.- Overrides:
reverseLookupAllin classNamingService- Parameters:
d- non-nulloptions- to configure lookup behavior (unused)- Returns:
- a non-empty list of hostnames for this Destination, or
null
reverseLookupAll
Return all hostnames registered for this hash.- Overrides:
reverseLookupAllin classNamingService- Parameters:
h- the hash to look up- Returns:
- the list of hostnames, or null if none
size
Number of entries.- Overrides:
sizein classNamingService- Parameters:
options- If non-null and contains the key "list", return the size of that list (default "hosts.txt", NOT all lists)- Returns:
- number of entries (matching the options if non-null) or -1 if unknown
shutdown
public void shutdown()Shut down the naming service and close the backing store.- Overrides:
shutdownin classNamingService
lookupAll
public List<Destination> lookupAll(String hostname, Properties lookupOptions, List<Properties> storedOptions) Return all of the entries found in the first list found, or in the list specified in lookupOptions. Does not aggregate all destinations found in all lists.If storedOptions is non-null, it must be a List that supports null entries. If the returned value (the List of Destinations) is non-null, the same number of Properties objects will be added to storedOptions. If no properties were found for a given Destination, the corresponding entry in the storedOptions list will be null.
- Overrides:
lookupAllin classNamingService- Parameters:
hostname- the host name to resolve, for which every known destination is returnedlookupOptions- input parameter, NamingService-specific, may be nullstoredOptions- output parameter, NamingService-specific, any stored properties will be added if non-null- Returns:
- non-empty List of Destinations, or null if nothing found
addDestination
Add a Destination to an existing hostname's entry in the addressbook.This does not prevent adding b32. Caller must check.
- Overrides:
addDestinationin classNamingService- Parameters:
hostname- the host name whose existing entry is to be extendedd- the destination to addoptions- NamingService-specific, may be null- Returns:
- true if the destination was added to the entry
remove
Remove a hostname's entry only if it contains the Destination d. If the NamingService supports multiple Destinations per hostname, and this is the only Destination, removes the entire entry. If aditional Destinations remain, it only removes the specified Destination from the entry.- Overrides:
removein classNamingService- Parameters:
hostname- the host name whose entry holds the destination to removed- the destination that must be presentoptions- NamingService-specific, may be null- Returns:
- true if entry containing d was successfully removed.
validate
Continuously validate anything we read in. Queue anything invalid to be removed at the end of the operation. Caller must sync!- Parameters:
key- hostname read from the skiplist, null or empty is invalidde- entry read from the skiplist, null is invalidlistname- skiplist the entry came from, recorded for the cleanup- Returns:
- true if the entry is well-formed and has a usable destination
deleteInvalid
private void deleteInvalid()Remove and log all invalid entries queued byvalidate(String, DestEntry, String)while scanning inlookup(String, Properties, Properties)or getEntries(). We delete in the order detected, as an error may be corrupting later entries in the skiplist. Caller must sync!close
private void close()Closes the block file and stops the service.logError
writeProperties
private static void writeProperties(ByteArrayOutputStream rawStream, Properties p) throws DataFormatException, IOException Same as DataHelper.writeProperties, UTF-8, unsorted, except that values may be up to 4K bytes.- Parameters:
rawStream- stream the length-prefixed mapping is written intop- source may be null- Throws:
DataFormatException- if any key string is over 255 bytes long, if any value string is over 4096 bytes long, or if the total length (not including the two length bytes) is greater than 65535 bytes.IOException- if the stream cannot be written
readProperties
public static Properties readProperties(ByteArrayInputStream in) throws DataFormatException, IOException Same as DataHelper.readProperties, UTF-8, unsorted, except that values may be up to 4K bytes.- Parameters:
in- stream to read the mapping from- Returns:
- the properties read, UTF-8 and unsorted
- Throws:
DataFormatException- if the format is invalid, including a duplicate keyIOException- if there is a problem reading the data
writeLongStringUTF8
private static void writeLongStringUTF8(ByteArrayOutputStream out, String string) throws DataFormatException, IOException Same as DataHelper.writeStringUTF8, except that strings up to 4K bytes are allowed. Format is: one-byte length + data, or 0xff + two-byte length + data.- Parameters:
out- stream to write stringstring- to write out: null strings are valid, but strings of excess length will cause a DataFormatException to be thrown- Throws:
DataFormatException- if the string is not validIOException- if there is an IO error writing the string
readLongString
private static String readLongString(ByteArrayInputStream in) throws DataFormatException, IOException Same as DataHelper.readString, except that strings up to 4K bytes are allowed. Format is: one-byte length + data, or 0xff + two-byte length + data.- Parameters:
in- stream to read from- Returns:
- UTF-8 string
- Throws:
DataFormatException- if the stream doesn't contain a validly formatted stringEOFException- if there aren't enough bytes to read the stringIOException- if there is an IO error reading the string
main
BlockfileNamingService [force] force = force writable.- Parameters:
args- when the first element is "force" the database is opened writable