java.lang.Object
net.i2p.data.RoutingKeyGenerator
Direct Known Subclasses:
RouterKeyGenerator

public abstract class RoutingKeyGeneratorextends Object
Interface for transforming a hash into the key under which it is stored in the network database (KBucketSet).

What the interface defines:

  • getRoutingKey(Hash) maps a hash to a routing key. The transformation, and whether it is a function of changing network-wide "mod data", is up to the implementation - this interface says nothing about reversibility, caching, or cost.
  • getLastChanged() reports when that mod data last changed, so a caller holding a previously derived key can tell whether it is stale and needs to be regenerated.
  • getInstance() returns the generator of the global context, which is null unless that context is a router context.

Availability:

  • Not available in a plain I2PAppContext - I2PAppContext.routingKeyGenerator() returns null there, because only a router holds a network database.
  • The implementation is net.i2p.data.router.RouterKeyGenerator, which appends the current GMT date to the hash and hashes the result, rotating daily at midnight GMT.
  • Constructor Details

    • RoutingKeyGenerator

      public RoutingKeyGenerator()
      Constructor for implementations that map a hash to the key it is stored under.
  • Method Details

    • getInstance

      public static RoutingKeyGenerator getInstance()
      Generator for this context.
      Returns:
      null in I2PAppContext; non-null in RouterContext.
    • getLastChanged

      public abstract long getLastChanged()
      The version of the current (today's) mod data. Use to determine if the routing key should be regenerated.
      Returns:
      the last changed
    • getRoutingKey

      public abstract Hash getRoutingKey(Hash origKey)
      Routing key for a key.

      The result depends on the mod data of the implementing generator, so compare getLastChanged() before reusing a previously derived key.

      Parameters:
      origKey - non-null
      Returns:
      the routing key
      Throws:
      IllegalArgumentException - if origKey is null