diff --git a/core/java/src/net/i2p/client/naming/LookupDest.java b/core/java/src/net/i2p/client/naming/LookupDest.java index dee20b7be..9705d6cf9 100644 --- a/core/java/src/net/i2p/client/naming/LookupDest.java +++ b/core/java/src/net/i2p/client/naming/LookupDest.java @@ -30,8 +30,9 @@ import net.i2p.data.Hash; * Using an existing I2PSession is much more efficient and * flexible than using this class. * + * Public since 0.9.45 only for main(). Not a public API. */ -class LookupDest { +public class LookupDest { private static final long DEFAULT_TIMEOUT = 15*1000; @@ -120,11 +121,34 @@ class LookupDest { return opts; } - public static void main(String args[]) throws I2PSessionException { - Destination dest = lookupBase32Hash(I2PAppContext.getGlobalContext(), args[0]); - if (dest == null) - System.out.println("Destination not found!"); - else - System.out.println(dest.toBase64()); + /** + * TODO: does not support hostnames, extended b32, I2CP options... + */ + public static void main(String args[]) { + if (args.length != 1) { + System.err.println("Usage: LookupDest base32"); + System.exit(1); + } + String arg = args[0]; + if (arg.endsWith(".b32.i2p")) + arg = arg.substring(0, arg.length() - 8); + if (arg.length() != 52) { + System.err.println("Bad Base32 format"); + System.exit(1); + } + byte[] h = Base32.decode(arg); + if (h == null) { + System.err.println("Bad Base32 format"); + System.exit(1); + } + try { + Destination dest = lookupHash(I2PAppContext.getGlobalContext(), h); + if (dest == null) + System.err.println("Destination not found!"); + else + System.out.println(dest.toBase64()); + } catch (I2PSessionException ise) { + ise.printStackTrace(); + } } } diff --git a/core/java/src/net/i2p/util/CommandLine.java b/core/java/src/net/i2p/util/CommandLine.java index 0fcbbaf21..d21b0180d 100644 --- a/core/java/src/net/i2p/util/CommandLine.java +++ b/core/java/src/net/i2p/util/CommandLine.java @@ -21,6 +21,7 @@ public class CommandLine { protected static final List CLASSES = Arrays.asList(new String[] { "freenet.support.CPUInformation.CPUID", "net.i2p.CoreVersion", + "net.i2p.client.naming.LookupDest", "net.i2p.crypto.Blinding", "net.i2p.crypto.CertUtil", "net.i2p.crypto.CryptoCheck",