Compare commits

...

4 Commits

3 changed files with 41 additions and 14 deletions

View File

@ -409,6 +409,7 @@ public interface I2PSession {
* @return null on failure
*/
public Destination lookupDest(String name, long maxWait) throws I2PSessionException;
public boolean deleteDest(String name);// { return false; }
/**
* Ask the router to lookup a Destination by hostname.

View File

@ -1663,6 +1663,10 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
return lookupDest(h, 10*1000);
}
public boolean deleteDest(String h) {
return _context.namingService().remove(h);
}
/**
* Blocking.
* @param maxWait ms

View File

@ -96,21 +96,38 @@ public class LookupDest {
return rv;
}
private static boolean deleteHostname(I2PAppContext ctx, String hostname) {
static boolean deleteHostname2(I2PAppContext ctx, String hostname) throws I2PSessionException {
I2PClient client = new I2PSimpleClient();
Properties opts = getOpts(ctx);
I2PSession session = null;
try {
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), hostname);
session = client.createSession(null, opts);
session.connect();
return session.deleteDest(hostname);
} catch(I2PSessionException ise) {
ise.printStackTrace();
return false;
} finally {
if (session != null)
session.destroySession();
}
}
private static Destination deleteHostname(I2PAppContext ctx, String hostname) {
try {
Destination dest = lookupHostname(ctx, hostname);
if (dest == null)
System.err.println("Destination not found!");
else {
NamingService ns = I2PAppContext.getGlobalContext().namingService();
if (ns != null)
return ns.remove(hostname, dest);
System.err.print("ns is null");
boolean named = deleteHostname2(ctx, hostname);
if (named) {
return dest;
}
}
} catch (I2PSessionException ise) {
ise.printStackTrace();
}
return false;
return null;
}
/**
@ -143,12 +160,14 @@ public class LookupDest {
* TODO: does not support I2CP options.
*/
public static void main(String args[]) {
if (args.length != 1) {
if (args.length < 1) {
System.err.println("Usage: LookupDest hostname|b32");
System.err.println("Usage: LookupDest -d hostname");
System.exit(1);
}
if (args[0].length() == 1) {
if (args.length == 1) {
try {
System.err.println("looking up hostname: " + args[0]);
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), args[0]);
if (dest == null)
System.err.println("Destination not found!");
@ -157,12 +176,15 @@ public class LookupDest {
} catch (I2PSessionException ise) {
ise.printStackTrace();
}
}
if (args[0].length() == 2) {
if (args[0] == "-d") {
deleteHostname(I2PAppContext.getGlobalContext(), args[1]);
} else {
if (args[0].equals("-d")) {
System.err.println("deleting hostname: " + args[1]);
Destination deletedDest = deleteHostname(I2PAppContext.getGlobalContext(), args[1]);
if (deletedDest != null)
System.out.println("deleted hostname: " + args[1] + " corresponding to: " + deletedDest.toBase64());
else
System.err.println("hostname not found, not deleted.");
}
}
}
}