net.i2p.data.router

## Class RouterKeyGenerator

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

-     public class RouterKeyGenerator
      extends RoutingKeyGenerator

  Generates routing keys from hashes using date-based modification to prevent Sybil attacks. Transforms input hashes by appending current GMT date (yyyyMMdd format) and computing SHA256. The modification data changes daily at midnight GMT to randomize routing keys consistently. The transformation takes the original hash, appends the bytes of the current mod data, then returns the SHA256 of that concatenation. This makes Sybil attacks much harder as she needs to essentially take over the whole keyspace. Note: generateDateBasedModData() should be called after midnight GMT once per day to generate the correct routing keys.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RouterKeyGenerator(I2PAppContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `generateDateBasedModData()` Update the current modifier data with some bytes derived from the current date (yyyyMMdd in GMT)
    `long` | `getLastChanged()` The version of the current (today's) mod data.
    `byte[]` | `getModData()` The current (today's) mod data.
    `byte[]` | `getNextModData()` Tomorrow's mod data.
    `Hash` | `getNextRoutingKey(Hash origKey)` Get the routing key using tomorrow's modData, not today's
    `Hash` | `getRoutingKey(Hash origKey)` Generate a modified (yet consistent) hash from the origKey by generating the SHA256 of the targetKey with the current modData appended to it This makes Sybil's job a lot harder, as she needs to essentially take over the whole keyspace.
    `Hash` | `getRoutingKey(Hash origKey, long time)` Get the routing key for the specified date, not today's
    `long` | `getTimeTillMidnight()` How long until midnight (ms)
    `static void` | `main(String[] args)`

    - ### Methods inherited from class net.i2p.data.RoutingKeyGenerator

      `getInstance`

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

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

- - ### Constructor Detail

    - #### RouterKeyGenerator

          public RouterKeyGenerator(I2PAppContext context)

  - ### Method Detail

    - #### generateDateBasedModData

          public boolean generateDateBasedModData()

      Update the current modifier data with some bytes derived from the current date (yyyyMMdd in GMT)
      Returns:
        true if changed

    - #### getLastChanged

          public long getLastChanged()

      Description copied from class: `RoutingKeyGenerator`
      The version of the current (today's) mod data. Use to determine if the routing key should be regenerated.
      Specified by:
        `getLastChanged` in class `RoutingKeyGenerator`

    - #### getModData

          public byte[] getModData()

      The current (today's) mod data. Warning - not a copy, do not corrupt.
      Returns:
        non-null, 8 bytes

    - #### getNextModData

          public byte[] getNextModData()

      Tomorrow's mod data. Warning - not a copy, do not corrupt. For debugging use only.
      Returns:
        non-null, 8 bytes

    - #### getNextRoutingKey

          public Hash getNextRoutingKey(Hash origKey)

      Get the routing key using tomorrow's modData, not today's

    - #### getRoutingKey

          public Hash getRoutingKey(Hash origKey)

      Generate a modified (yet consistent) hash from the origKey by generating the SHA256 of the targetKey with the current modData appended to it This makes Sybil's job a lot harder, as she needs to essentially take over the whole keyspace.
      Specified by:
        `getRoutingKey` in class `RoutingKeyGenerator`
      Throws:
        `IllegalArgumentException` - if origKey is null

    - #### getRoutingKey

          public Hash getRoutingKey(Hash origKey,
                                    long time)

      Get the routing key for the specified date, not today's
      Parameters:
        `time` - Java time

    - #### getTimeTillMidnight

          public long getTimeTillMidnight()

      How long until midnight (ms)
      Returns:
        could be slightly negative

    - #### main

          public static void main(String[] args)