forked from I2P_Developers/i2p.i2p
Compare commits
4 Commits
i2p-2.6.1
...
i2p.i2p.2.
Author | SHA1 | Date | |
---|---|---|---|
b8091e9b07 | |||
15af2c7d78 | |||
06b3994a67 | |||
e74d32f11f |
@ -409,6 +409,7 @@ public interface I2PSession {
|
|||||||
* @return null on failure
|
* @return null on failure
|
||||||
*/
|
*/
|
||||||
public Destination lookupDest(String name, long maxWait) throws I2PSessionException;
|
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.
|
* Ask the router to lookup a Destination by hostname.
|
||||||
|
@ -1663,6 +1663,10 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
|||||||
return lookupDest(h, 10*1000);
|
return lookupDest(h, 10*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean deleteDest(String h) {
|
||||||
|
return _context.namingService().remove(h);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocking.
|
* Blocking.
|
||||||
* @param maxWait ms
|
* @param maxWait ms
|
||||||
|
@ -96,21 +96,38 @@ public class LookupDest {
|
|||||||
return rv;
|
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 {
|
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)
|
if (dest == null)
|
||||||
System.err.println("Destination not found!");
|
System.err.println("Destination not found!");
|
||||||
else {
|
else {
|
||||||
NamingService ns = I2PAppContext.getGlobalContext().namingService();
|
boolean named = deleteHostname2(ctx, hostname);
|
||||||
if (ns != null)
|
if (named) {
|
||||||
return ns.remove(hostname, dest);
|
return dest;
|
||||||
System.err.print("ns is null");
|
}
|
||||||
}
|
}
|
||||||
} catch (I2PSessionException ise) {
|
} catch (I2PSessionException ise) {
|
||||||
ise.printStackTrace();
|
ise.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,12 +160,14 @@ public class LookupDest {
|
|||||||
* TODO: does not support I2CP options.
|
* TODO: does not support I2CP options.
|
||||||
*/
|
*/
|
||||||
public static void main(String args[]) {
|
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 hostname|b32");
|
||||||
|
System.err.println("Usage: LookupDest -d hostname");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
if (args[0].length() == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
|
System.err.println("looking up hostname: " + args[0]);
|
||||||
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), args[0]);
|
Destination dest = lookupHostname(I2PAppContext.getGlobalContext(), args[0]);
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
System.err.println("Destination not found!");
|
System.err.println("Destination not found!");
|
||||||
@ -157,12 +176,15 @@ public class LookupDest {
|
|||||||
} catch (I2PSessionException ise) {
|
} catch (I2PSessionException ise) {
|
||||||
ise.printStackTrace();
|
ise.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (args[0].length() == 2) {
|
if (args[0].equals("-d")) {
|
||||||
if (args[0] == "-d") {
|
System.err.println("deleting hostname: " + args[1]);
|
||||||
deleteHostname(I2PAppContext.getGlobalContext(), 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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user