java.lang.Object
net.i2p.addressbook.Daemon

public class Daemonextends Object
Main class of addressbook. Performs updates, and runs the main loop. As of 0.9.30, package private, run with DaemonThread.
  • Field Details

    • VERSION

      public static final String VERSION
      Version string.
      See Also:
    • _running

      private volatile boolean _running
      Cleared to stop the subscription checks.
    • hostChecker

      private static HostChecker hostChecker
      Checks the hosts the service will answer for.
    • _log

      private final Log _log
      Logger writing to the addressbook's own log file.
    • DEFAULT_SUB

      private static final String DEFAULT_SUB
      Subscriptions added on a first run. Keep in step with SubscriptionBean.
      See Also:
    • OLD_DEFAULT_SUB

      static final String 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

      private static final String 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 in
      knownNames - only non-null if router book is a text file
      publishedNS - only non-null if we have a published address book
      addressbook - the source addressbook, used only to name it in log messages
      iter - iterator over the subscription entries to apply
      log - where to log progress, or null for no logging
    • logInner

      private static void logInner(Log log, String action, String name, AddressBook addressbook)
      Log an addressbook change.
      Parameters:
      log - where to append the message, or null to skip logging
      action - the subscription action that was attempted
      name - the key whose inner signature check failed
      addressbook - the source addressbook, named in the log message
    • logMissing

      private static void logMissing(Log log, String action, String name, AddressBook addressbook)
      Log a subscription missing from the router.
      Parameters:
      log - where to append the message, or null to skip logging
      action - the subscription action that was attempted
      name - the subscription whose required parameters are missing
      addressbook - 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 logging
      action - the subscription action that was attempted
      name - the subscription whose destinations conflict
      dests - the destinations from the subscription, listed in the message
      olddest - the router's current destination base64, truncated for the message
      addressbook - the source addressbook, named in the log message
    • update

      public static void update(Map<String,String> settings, String home)
      Run an update, using the Map settings to provide the parameters.
      Parameters:
      settings - A Map containg the parameters needed by update.
      home - The directory containing addressbook's configuration files.
    • searchNamingService

      private static NamingService searchNamingService(NamingService ns, String srch)
      Depth-first search of the naming service tree.
      Parameters:
      ns - the naming service node to search, including its children
      srch - 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

      private static NamingService getNamingService(String srch)
      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

      public static void main(String[] args)
      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

      public void run(String[] args)
      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

      public static HostChecker getHostChecker()
      Get the HostChecker instance for use by web applications.
      Returns:
      HostChecker instance or null if not initialized