net.i2p.data

## Class RoutingKeyGenerator

- java.lang.Object
- - net.i2p.data.RoutingKeyGenerator

- Direct Known Subclasses:
    RouterKeyGenerator

      public abstract class RoutingKeyGenerator
      extends Object

  Interface for transforming hashes into routing keys for I2P network database operations.

  RoutingKeyGenerator provides hash transformation for distributed hash table routing:

  - Hash Transformation: Consistent munging of hashes into routing keys
  - Mod Data: Transformation parameters updated periodically
  - DHT Routing: Enables efficient key-based lookup in network database
  - Load Distribution: Spreads storage and lookup load across key space

  Key Operations:

  - `getRoutingKey(Hash)` - Transform hash to routing key
  - `getLastChanged()` - Get current mod data version
  - `getInstance()` - Get generator for current context

  Transformation Process:

  - Consistent Algorithm: Same transformation applied to all hashes
  - Mod Data Input: Current network parameters affect transformation
  - Deterministic: Same hash always produces same routing key
  - Reversible: Process can be inverted for analysis

  Context Availability:

  - Router Context: Available only in RouterContext, not I2PAppContext
  - Implementation: Concrete implementation in RouterKeyGenerator
  - Client Limitation: Not available for client-only operations

  Evolution:

  - Pre-0.9.16: Full implementation with transformation logic
  - Post-0.9.16: Interface with router-specific implementation
  - Separation: Core interface in data package, implementation in router

  Usage in I2P:

  - NetDb Storage: Keys determine database storage location
  - Floodfill Operations: Routing keys used for network distribution
  - Lookup Efficiency: Fast key-based data retrieval
  - Load Balancing: Distributes network load across key space

  Security Considerations:

  - Key Distribution: Prevents targeted attacks on specific keys
  - Load Balancing: Avoids hotspots in network database
  - Sybil Resistance: Makes targeted attacks more difficult
  - Mod Data Rotation: Periodic changes prevent long-term attacks

  Performance Aspects:

  - Efficient Lookup: O(1) key-based database access
  - Uniform Distribution: Spreads load across all network nodes
  - Cache Optimization: Hot routing keys cached for fast access
  - Minimal Computation: Fast transformation algorithm

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RoutingKeyGenerator()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static RoutingKeyGenerator` | `getInstance()` Get the generator for this context.
    `abstract long` | `getLastChanged()` The version of the current (today's) mod data.
    `abstract Hash` | `getRoutingKey(Hash origKey)` Get the routing key for a key.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RoutingKeyGenerator

          public RoutingKeyGenerator()

  - ### Method Detail

    - #### getInstance

          public static RoutingKeyGenerator getInstance()

      Get the 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.

    - #### getRoutingKey

          public abstract Hash getRoutingKey(Hash origKey)

      Get the routing key for a key.
      Throws:
        `IllegalArgumentException` - if origKey is null