public class BlockfileNamingService extends DummyNamingService
"%%__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 TBDAll host names are converted to lower case.
BASE32_HASH_LENGTH, CACHE_MAX_SIZE, DEST_SIZE, PROP_B32
_context, _listeners, _log, _updaters, PROP_IMPL
Constructor and Description |
---|
BlockfileNamingService(I2PAppContext context)
Opens the database at hostsdb.blockfile or creates a new
one and imports entries from hosts.txt, userhosts.txt, and privatehosts.txt.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addDestination(String hostname,
Destination d,
Properties options)
Add a Destination to an existing hostname's entry in the addressbook.
|
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.
|
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.
|
Set<String> |
getNames(Properties options) |
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,
Properties lookupOptions,
List<Properties> storedOptions)
Return all of the entries found in the first list found, or in the list
specified in lookupOptions.
|
static void |
main(String[] args)
BlockfileNamingService [force]
force = force writable
|
boolean |
put(String hostname,
Destination d,
Properties options)
Add a hostname and Destination to the addressbook.
|
boolean |
putIfAbsent(String hostname,
Destination d,
Properties options)
Add a hostname and Destination to the addressbook.
|
static Properties |
readProperties(ByteArrayInputStream in)
Same as DataHelper.readProperties, UTF-8, unsorted,
except that values may up to 4K bytes.
|
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.
|
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 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.
|
void |
shutdown()
Parent will call when removed.
|
int |
size(Properties options)
This implementation returns -1.
|
clearCache, getCache, putCache, removeCache
addDestination, addNamingService, addNamingService, createInstance, export, getConfiguration, getEntries, getName, getNames, getNamingServices, getParent, lookup, lookup, lookupAll, lookupBase32, lookupBase64, put, putAll, putIfAbsent, registerListener, registerUpdater, remove, remove, removeNamingService, requestUpdate, reverseLookup, reverseLookupAll, setConfiguration, size, start, toString, unregisterListener, unregisterUpdater, update
public BlockfileNamingService(I2PAppContext context)
RuntimeException
- on fatal errorpublic Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions)
NamingService
lookup
in class DummyNamingService
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-nullpublic boolean put(String hostname, Destination d, Properties options)
NamingService
put
in class NamingService
options
- If non-null and contains the key "list", add to that list
(default "hosts.txt")
Use the key "s" for the sourcepublic boolean putIfAbsent(String hostname, Destination d, Properties options)
NamingService
putIfAbsent
in class NamingService
options
- 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.public boolean remove(String hostname, Properties options)
NamingService
remove
in class NamingService
options
- If non-null and contains the key "list", remove
from that list (default "hosts.txt", NOT all lists)public Map<String,Destination> getEntries(Properties options)
NamingService
getEntries
in class NamingService
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.public Map<String,String> getBase64Entries(Properties options)
NamingService
getBase64Entries
in class NamingService
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.public void export(Writer out, Properties options) throws IOException
export
in class NamingService
options
- 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 iterationIOException
public Set<String> getNames(Properties options)
getNames
in class NamingService
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.public String reverseLookup(Destination d, Properties options)
NamingService
reverseLookup
in class NamingService
options
- ignoredd
- non-nullpublic String reverseLookup(Hash h)
NamingService
reverseLookup
in class NamingService
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 d, Properties options)
NamingService
reverseLookupAll
in class NamingService
options
- ignoredd
- non-nullnull
public List<String> reverseLookupAll(Hash h)
NamingService
reverseLookupAll
in class NamingService
h
- non-nullnull
if none is known. It is safe for subclasses to always return
null
if no reverse lookup is possible.public int size(Properties options)
NamingService
size
in class NamingService
options
- If non-null and contains the key "list", return the
size of that list (default "hosts.txt", NOT all lists)public void shutdown()
NamingService
shutdown
in class NamingService
public List<Destination> lookupAll(String hostname, Properties lookupOptions, List<Properties> storedOptions)
lookupAll
in class NamingService
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, Properties options)
addDestination
in class NamingService
options
- NamingService-specific, may be nullpublic boolean remove(String hostname, Destination d, Properties options)
remove
in class NamingService
options
- NamingService-specific, may be nullpublic static Properties readProperties(ByteArrayInputStream in) throws DataFormatException, IOException
in
- stream to read the mapping fromDataFormatException
- if the format is invalidIOException
- if there is a problem reading the datapublic static void main(String[] args)