Class RouterKeyGenerator

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

public class RouterKeyGenerator extends RoutingKeyGenerator
Component to manage the munging of hashes into routing keys - given a hash, perform some consistent transformation against it and return the result. This transformation is fed by the current "mod data". Right now the mod data is the current date (GMT) as a string: "yyyyMMdd", and the transformation takes the original hash, appends the bytes of that mod data, then returns the SHA256 of that concatenation. Do we want this to simply do the XOR of the SHA256 of the current mod data and the key? does that provide the randomization we need? It'd save an SHA256 op. Bah, too much effort to think about for so little gain. Other algorithms may come into play layer on about making periodic updates to the routing key for data elements to mess with Sybil. This may be good enough though. Also - the method generateDateBasedModData() should be called after midnight GMT once per day to generate the correct routing keys!
Since:
0.9.16 moved from net.i2p.data.RoutingKeyGenerator..
  • Constructor Details

    • RouterKeyGenerator

      public RouterKeyGenerator(I2PAppContext context)
  • Method Details

    • 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
      Since:
      0.9.10
    • 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
    • getTimeTillMidnight

      public long getTimeTillMidnight()
      How long until midnight (ms)
      Returns:
      could be slightly negative
      Since:
      0.9.10 moved from UpdateRoutingKeyModifierJob
    • generateDateBasedModData

      public boolean generateDateBasedModData()
      Update the current modifier data with some bytes derived from the current date (yyyyMMdd in GMT)
      Returns:
      true if changed
    • 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
    • getNextRoutingKey

      public Hash getNextRoutingKey(Hash origKey)
      Get the routing key using tomorrow's modData, not today's
      Since:
      0.9.10
    • getRoutingKey

      public Hash getRoutingKey(Hash origKey, long time)
      Get the routing key for the specified date, not today's
      Parameters:
      time - Java time
      Since:
      0.9.28
    • main

      public static void main(String[] args)
      Since:
      0.9.29