public class HostsTxtNamingServiceextends MetaNamingService
A naming service based on multiple "hosts.txt" files. Supports .b32.i2p and {b64} lookups. Supports caching. All host names are converted to lower case.
  • Field Details

    • PROP_HOSTS_FILE

      public static final String PROP_HOSTS_FILE
      If this system property is specified, the tunnel will read the given file for hostname=destKey values when resolving names.
      See Also:
    • DEFAULT_HOSTS_FILE

      public static final String DEFAULT_HOSTS_FILE
      Default hosts.txt filenames.
      See Also:
  • Constructor Details

    • HostsTxtNamingService

      public HostsTxtNamingService(I2PAppContext context)
      The naming service should only be constructed and accessed through the application context. This constructor should only be used by the appropriate application context itself.
      Parameters:
      context - the application context
  • Method Details

    • getFilenames

      private List<String> getFilenames()
      The hosts files configured for this service.
      Returns:
      the file names, empty if none are configured
    • lookup

      public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions)
      Description copied from class: DummyNamingService
      Throws, this service knows no destinations.
      Overrides:
      lookup in class MetaNamingService
      Parameters:
      hostname - mixed case as it could be a key
      lookupOptions - input parameter, NamingService-specific, can be null
      storedOptions - output parameter, NamingService-specific, any stored properties will be added if non-null
      Returns:
      dest or null
    • put

      public boolean put(String hostname, Destination d, Properties options)
      Description copied from class: MetaNamingService
      Stores in the last service.
      Overrides:
      put in class MetaNamingService
      Parameters:
      hostname - the host name to map to the destination, overwriting any existing entry
      d - the destination for the hostname
      options - NamingService-specific, can be null
      Returns:
      true if the entry was stored; this base implementation always returns false
    • putIfAbsent

      public boolean putIfAbsent(String hostname, Destination d, Properties options)
      Description copied from class: MetaNamingService
      Stores in the last service.
      Overrides:
      putIfAbsent in class MetaNamingService
      Parameters:
      hostname - the host name to map to the destination, which must not already be present
      d - the destination for the hostname
      options - NamingService-specific, can be null
      Returns:
      true if no entry existed and the new one was stored; this base implementation always returns false
    • remove

      public boolean remove(String hostname, Properties options)
      Description copied from class: MetaNamingService
      Removes from all services.
      Overrides:
      remove in class MetaNamingService
      Parameters:
      hostname - the host name whose entry is to be deleted
      options - NamingService-specific, can be null
      Returns:
      true if removed successfully, false on error or if it did not exist
    • getNames

      public Set<String> getNames(Properties options)
      All services aggregated, unless options contains the property "file", in which case only for that file.
      Overrides:
      getNames in class MetaNamingService
      Parameters:
      options - NamingService-specific, can be null
      Returns:
      the hostnames from the selected file, or from every service if no file is named