Direct Known Subclasses:
HostsTxtNamingService

public class MetaNamingServiceextends DummyNamingService
A naming service of multiple naming services. Supports .b32.i2p and {b64} lookups. Supports caching.
  • Field Details

    • PROP_NAME_SERVICES

      private static final String PROP_NAME_SERVICES
      Property naming the naming services to use.
      See Also:
    • DEFAULT_NAME_SERVICES

      private static final String DEFAULT_NAME_SERVICES
      The services used when the property is unset.
      See Also:
    • _services

      protected final List<NamingService> _services
      Chained naming services, in order.
  • Constructor Details

    • MetaNamingService

      public MetaNamingService(I2PAppContext context)
      Adds the services from the i2p.nameservicelist property, in order, as chained services.
      Parameters:
      context - the application context
    • MetaNamingService

      public MetaNamingService(I2PAppContext context, List<NamingService> services)
      Create a new meta naming service with the specified services.
      Parameters:
      context - the app context every wrapped naming service reads its configuration from
      services - if non-null, services to be added. If null, this will only handle b32 and b64, until addNamingService(NamingService, boolean) is called later.
  • Method Details

    • addNamingService

      public final boolean addNamingService(NamingService ns, boolean head)
      Description copied from class: NamingService
      Only for chaining-capable NamingServices. This implementation returns false. Subclasses implementing chaining should override.
      Overrides:
      addNamingService in class NamingService
      Parameters:
      ns - the naming service to add
      head - true to prepend to the chain, false to append
      Returns:
      true if ns was chained in; this base implementation always returns false
    • getNamingServices

      public List<NamingService> getNamingServices()
      Description copied from class: NamingService
      For daisy chaining (MetaNamingService). This implementation returns null. Subclasses implementing chaining should override.
      Overrides:
      getNamingServices in class NamingService
      Returns:
      chained naming services or null
    • removeNamingService

      public boolean removeNamingService(NamingService ns)
      Description copied from class: NamingService
      Only for chaining-capable NamingServices. This implementation returns false. Subclasses implementing chaining should override.
      Overrides:
      removeNamingService in class NamingService
      Parameters:
      ns - the naming service to remove
      Returns:
      true if ns was chained out; this base implementation always returns false
    • registerListener

      public void registerListener(NamingServiceListener nsl)
      Description copied from class: NamingService
      Register a listener for naming service changes.
      Overrides:
      registerListener in class NamingService
      Parameters:
      nsl - the listener to register
    • unregisterListener

      public void unregisterListener(NamingServiceListener nsl)
      Description copied from class: NamingService
      Unregister a listener for naming service changes.
      Overrides:
      unregisterListener in class NamingService
      Parameters:
      nsl - the listener to unregister
    • 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 DummyNamingService
      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
    • reverseLookup

      public String reverseLookup(Destination dest, Properties options)
      Description copied from class: NamingService
      Same as reverseLookup(dest) but with options This implementation returns null. Subclasses implementing reverse lookups should override.
      Overrides:
      reverseLookup in class NamingService
      Parameters:
      dest - non-null destination to look up
      options - NamingService-specific, can be null
      Returns:
      hostname or null
    • put

      public boolean put(String hostname, Destination d, Properties options)
      Stores in the last service.
      Overrides:
      put in class NamingService
      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)
      Stores in the last service.
      Overrides:
      putIfAbsent in class NamingService
      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)
      Removes from all services.
      Overrides:
      remove in class NamingService
      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
    • getEntries

      public Map<String, Destination> getEntries(Properties options)
      All services aggregated.
      Overrides:
      getEntries in class NamingService
      Parameters:
      options - NamingService-specific, can be null
      Returns:
      the hostname to destination mapping merged from every delegate service
    • getBase64Entries

      public Map<String,String> getBase64Entries(Properties options)
      All services aggregated.
      Overrides:
      getBase64Entries in class NamingService
      Parameters:
      options - NamingService-specific, can be null
      Returns:
      the base64 entries
    • getNames

      public Set<String> getNames(Properties options)
      All services aggregated.
      Overrides:
      getNames in class NamingService
      Parameters:
      options - NamingService-specific, can be null
      Returns:
      the hostnames known to every delegate service, merged into one set
    • export

      public void export(Writer out, Properties options) throws IOException
      All services aggregated. Duplicates not removed (for efficiency).
      Overrides:
      export in class NamingService
      Parameters:
      out - the writer to export to
      options - NamingService-specific, can be null
      Throws:
      IOException - if an I/O error occurs
    • size

      public int size(Properties options)
      All services aggregated.
      Overrides:
      size in class NamingService
      Parameters:
      options - NamingService-specific, can be null
      Returns:
      number of entries (matching the options if non-null) or -1 if unknown
    • shutdown

      public void shutdown()
      Description copied from class: NamingService
      Parent will call when removed. If this is the root naming service, the core will stop it. Should not be called by others.
      Overrides:
      shutdown in class NamingService