/** * Get the generator for this context. * * @return null in I2PAppContext; non-null in RouterContext. */ public static RoutingKeyGenerator getInstance() { return I2PAppContext.getGlobalContext().routingKeyGenerator(); }
/** * @throws IllegalStateException if not in RouterContext */ public boolean validateRoutingKey() { I2PAppContext ctx = I2PAppContext.getGlobalContext(); if (!ctx.isRouterContext()) throw new IllegalStateException("Not in router context"); RoutingKeyGenerator gen = ctx.routingKeyGenerator(); Hash destKey = getHash(); Hash rk = gen.getRoutingKey(destKey); return rk.equals(getRoutingKey()); }
/** * Get the routing key for the structure using the current modifier in the RoutingKeyGenerator. * This only calculates a new one when necessary though (if the generator's key modifier changes) * * @throws IllegalStateException if not in RouterContext */ public Hash getRoutingKey() { I2PAppContext ctx = I2PAppContext.getGlobalContext(); if (!ctx.isRouterContext()) throw new IllegalStateException("Not in router context"); RoutingKeyGenerator gen = ctx.routingKeyGenerator(); long mod = gen.getLastChanged(); if (mod != _routingKeyGenMod) { _currentRoutingKey = gen.getRoutingKey(getHash()); _routingKeyGenMod = mod; } return _currentRoutingKey; }