Util: Improve LookupDest CLI, add to CommandLine

This commit is contained in:
zzz
2020-02-18 17:07:41 +00:00
parent c0db50ed0f
commit 5ee903765e
2 changed files with 32 additions and 7 deletions

View File

@ -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();
}
}
}

View File

@ -21,6 +21,7 @@ public class CommandLine {
protected static final List<String> 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",