Changeset 074c630a for router


Ignore:
Timestamp:
Dec 24, 2016 1:46:51 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a749226
Parents:
f902a63
Message:

Utils: Add RKG command line tool

Location:
router/java/src/net/i2p
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/data/router/RouterKeyGenerator.java

    rf902a63 r074c630a  
    2323import net.i2p.data.Hash;
    2424import net.i2p.data.RoutingKeyGenerator;
     25import net.i2p.util.ConvertToHash;
    2526import net.i2p.util.HexDump;
    2627import net.i2p.util.Log;
     
    217218    }
    218219
    219 /****
     220    /**
     221     * @since 0.9.29
     222     */
    220223    public static void main(String args[]) {
    221         Hash k1 = new Hash();
    222         byte k1d[] = new byte[Hash.HASH_LENGTH];
    223         RandomSource.getInstance().nextBytes(k1d);
    224         k1.setData(k1d);
    225 
    226         for (int i = 0; i < 10; i++) {
    227             System.out.println("K1:  " + k1);
    228             Hash k1m = RoutingKeyGenerator.getInstance().getRoutingKey(k1);
    229             System.out.println("MOD: " + new String(RoutingKeyGenerator.getInstance().getModData()));
    230             System.out.println("K1M: " + k1m);
    231         }
    232         try {
    233             Thread.sleep(2000);
    234         } catch (Throwable t) { // nop
    235         }
    236     }
    237 ****/
     224        if (args.length <= 0) {
     225            System.err.println("Usage: RouterKeyGenerator [-days] [+days] hash|hostname|destination");
     226            System.exit(1);
     227        }
     228        long now = System.currentTimeMillis();
     229        Hash h;
     230        if (args.length > 1 && (args[0].startsWith("+") || args[0].startsWith("-"))) {
     231            now += Integer.parseInt(args[0]) * 24*60*60*1000L;
     232            h = ConvertToHash.getHash(args[1]);
     233        } else {
     234            h = ConvertToHash.getHash(args[0]);
     235        }
     236        if (h == null) {
     237            System.err.println("Bad hash");
     238            System.exit(1);
     239        }
     240        RouterKeyGenerator rkg = new RouterKeyGenerator(I2PAppContext.getGlobalContext());
     241        Hash rkey = rkg.getRoutingKey(h, now);
     242        System.out.println("Date:         " + rkg._fmt.format(now));
     243        System.out.println("Original key: " + h.toBase64());
     244        System.out.println("Routing key:  " + rkey.toBase64());
     245    }
    238246}
  • router/java/src/net/i2p/router/CommandLine.java

    rf902a63 r074c630a  
    1616    protected static final List<String> RCLASSES = Arrays.asList(new String[] {
    1717        "net.i2p.data.router.RouterInfo",
     18        "net.i2p.data.router.RouterKeyGenerator",
    1819        "net.i2p.router.MultiRouter",
    1920        "net.i2p.router.Router",
Note: See TracChangeset for help on using the changeset viewer.