Class 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!
    0.9.16 moved from
    • Constructor Detail

      • RouterKeyGenerator

        public RouterKeyGenerator​(I2PAppContext context)
    • Method Detail

      • getModData

        public byte[] getModData()
        The current (today's) mod data. Warning - not a copy, do not corrupt.
        non-null, 8 bytes
      • getNextModData

        public byte[] getNextModData()
        Tomorrow's mod data. Warning - not a copy, do not corrupt. For debugging use only.
        non-null, 8 bytes
      • 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)
        could be slightly negative
        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)
        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
        IllegalArgumentException - if origKey is null
      • getNextRoutingKey

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

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

        public static void main​(String[] args)