Skip to content

Commit

Permalink
AddressBook: add -d option to lookupdest command line which deletes a…
Browse files Browse the repository at this point in the history
… hostname if it exists in the addressbook
  • Loading branch information
eyedeekay committed Jul 31, 2023
1 parent 3fc704c commit 3952ce6
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions core/java/src/net/i2p/client/naming/LookupDest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ static Destination lookupHostname(I2PAppContext ctx, String hostname) throws I2P
return rv;
}

private static boolean deleteHostname(I2PAppContext ctx, String hostname) {
try {
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), 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");
}
} catch (I2PSessionException ise) {
ise.printStackTrace();
}
return false;
}

/**
* @since 0.9.40 split out from above
*/
Expand Down Expand Up @@ -130,14 +147,22 @@ public static void main(String args[]) {
System.err.println("Usage: LookupDest hostname|b32");
System.exit(1);
}
try {
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), args[0]);
if (dest == null)
System.err.println("Destination not found!");
else
System.out.println(dest.toBase64());
} catch (I2PSessionException ise) {
ise.printStackTrace();
if (args[0].length() == 1) {
try {
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), args[0]);
if (dest == null)
System.err.println("Destination not found!");
else
System.out.println(dest.toBase64());
} catch (I2PSessionException ise) {
ise.printStackTrace();
}
}
if (args[0].length() == 2) {
if (args[0] == "-d") {
deleteHostname(I2PAppContext.getGlobalContext(), args[1]);
}
}

}
}

0 comments on commit 3952ce6

Please sign in to comment.