java.lang.Object
net.i2p.addressbook.Daemon
Main class of addressbook. Performs updates, and runs the main loop. As of 0.9.30, package private, run with
DaemonThread.Field Summary
Modifier and TypeFieldDescriptionprivate final LogLogger writing to the addressbook's own log file.private booleanCleared to stop the subscription checks.private static final StringSubscriptions added on a first run.private static HostCheckerChecks the hosts the service will answer for.(package private) static final StringThe single-host subscription that releases before 0.9.12 used to ship as the hardcoded default.private static final StringAny properties we receive from the subscription, we store to the addressbook with this prefix, so it knows it's part of the signature.static final StringVersion string.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic HostCheckerGet the HostChecker instance for use by web applications.private static NamingServicegetNamingService(String srch) Find the configured NamingService, or return the root.private static voidlogInner(Log log, String action, String name, AddressBook addressbook) Log an addressbook change.private static voidlogMismatch(Log log, String action, String name, List<Destination> dests, String olddest, AddressBook addressbook) Log a destination mismatch with the router.private static voidlogMissing(Log log, String action, String name, AddressBook addressbook) Log a subscription missing from the router.static voidLoad the settings, set the proxy, then enter into the main loop.voidStart the addressbook daemon: resolve the home directory, load or create config.txt there, and run the update loop until shutdown.private static NamingServicesearchNamingService(NamingService ns, String srch) Depth-first search of the naming service tree.voidstop()Stop the daemon.static voidtest()Run a self-test: create a context, run one update cycle, and flush logs.static voidRun an update, using the Map settings to provide the parameters.static voidupdate(AddressBook master, AddressBook router, File published, SubscriptionList subscriptions, Log log) Update the router and published address books using remote data from the subscribed address books listed in subscriptions.static voidupdate(NamingService router, File published, SubscriptionList subscriptions, Log log) Update the router and published address books using remote data from the subscribed address books listed in subscriptions.private static voidupdate(NamingService router, Set<String> knownNames, NamingService publishedNS, AddressBook addressbook, Iterator<Map.Entry<String, HostTxtEntry>> iter, Log log) Add, update or remove subscriptions in the router naming service.voidwakeup()Call this to get the addressbook to reread its config and refetch its subscriptions.
Field Details
VERSION
_running
private volatile boolean _runningCleared to stop the subscription checks.hostChecker
Checks the hosts the service will answer for._log
Logger writing to the addressbook's own log file.DEFAULT_SUB
Subscriptions added on a first run. Keep in step with SubscriptionBean.- See Also:
OLD_DEFAULT_SUB
The single-host subscription that releases before 0.9.12 used to ship as the hardcoded default. It is retained only so ConfigParser can recognize and drop the entry when migrating an old config file to the multi-host DEFAULT_SUB list.- See Also:
RCVD_PROP_PREFIX
Any properties we receive from the subscription, we store to the addressbook with this prefix, so it knows it's part of the signature. This is also chosen so that it can't be spoofed.- See Also:
Constructor Details
Daemon
public Daemon()Constructor. The subscription sources are static defaults, so a bare instance is what DaemonThread runs; the loop is driven by start().
Method Details
update
public static void update(AddressBook master, AddressBook router, File published, SubscriptionList subscriptions, Log log) Update the router and published address books using remote data from the subscribed address books listed in subscriptions.- Parameters:
master- The master AddressBook. This address book is never overwritten, so it is safe for the user to write to. It is only merged to the published addressbook. May be null.router- The router AddressBook. This is the address book read by client applications.published- The published AddressBook. This address book is published on the user's eepsite so that others may subscribe to it. May be null. If non-null, overwrite with the new addressbook.subscriptions- A SubscriptionList listing the remote address books to update from.log- The log to write changes and conflicts to. May be null.
update
public static void update(NamingService router, File published, SubscriptionList subscriptions, Log log) Update the router and published address books using remote data from the subscribed address books listed in subscriptions. Merging of the "master" addressbook is NOT supported.- Parameters:
router- The NamingService to update, generally the root NamingService from the context.published- The published AddressBook. This address book is published on the user's eepsite so that others may subscribe to it. May be null. If non-null, overwrite with the new addressbook.subscriptions- A SubscriptionList listing the remote address books to update from.log- The log to write changes and conflicts to. May be null.
update
private static void update(NamingService router, Set<String> knownNames, NamingService publishedNS, AddressBook addressbook, Iterator<Map.Entry<String, HostTxtEntry>> iter, Log log) Add, update or remove subscriptions in the router naming service.- Parameters:
router- the router's naming service to add, change or delete entries inknownNames- only non-null if router book is a text filepublishedNS- only non-null if we have a published address bookaddressbook- the source addressbook, used only to name it in log messagesiter- iterator over the subscription entries to applylog- where to log progress, or null for no logging
logInner
Log an addressbook change.- Parameters:
log- where to append the message, or null to skip loggingaction- the subscription action that was attemptedname- the key whose inner signature check failedaddressbook- the source addressbook, named in the log message
logMissing
Log a subscription missing from the router.- Parameters:
log- where to append the message, or null to skip loggingaction- the subscription action that was attemptedname- the subscription whose required parameters are missingaddressbook- the source addressbook, named in the log message
logMismatch
private static void logMismatch(Log log, String action, String name, List<Destination> dests, String olddest, AddressBook addressbook) Log a destination mismatch with the router.- Parameters:
log- where to append the message, or null to skip loggingaction- the subscription action that was attemptedname- the subscription whose destinations conflictdests- the destinations from the subscription, listed in the messageolddest- the router's current destination base64, truncated for the messageaddressbook- the source addressbook, named in the log message
update
searchNamingService
Depth-first search of the naming service tree.- Parameters:
ns- the naming service node to search, including its childrensrch- the name to find, matched against the full name or the last path segment- Returns:
- the matching naming service, or null if the tree has no such name
getNamingService
Find the configured NamingService, or return the root.- Parameters:
srch- the naming service name to search for in the tree- Returns:
- the configured NamingService, or the root NamingService
main
Load the settings, set the proxy, then enter into the main loop. The main loop performs an immediate update, and then an update every number of hours, as configured in the settings file.- Parameters:
args- Command line arguments. If there are any arguments provided, the first is taken as addressbook's home directory, and the others are ignored.
test
public static void test()Run a self-test: create a context, run one update cycle, and flush logs.run
Start the addressbook daemon: resolve the home directory, load or create config.txt there, and run the update loop until shutdown. Called on its own thread by DaemonThread.- Parameters:
args- the command line arguments; when non-empty, args[0] names the addressbook home directory, resolved against the router directory if not an absolute path. May be null or empty, in which case the current working directory is used.
wakeup
public void wakeup()Call this to get the addressbook to reread its config and refetch its subscriptions.stop
public void stop()Stop the daemon.getHostChecker
Get the HostChecker instance for use by web applications.- Returns:
- HostChecker instance or null if not initialized