Skip to content

Commit

Permalink
Stall.
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Nov 6, 2023
1 parent 15af2c7 commit b8091e9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/java/src/net/i2p/client/I2PSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public long sendMessage(Destination dest, byte[] payload, int offset, int size,
* @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.
Expand Down
4 changes: 4 additions & 0 deletions core/java/src/net/i2p/client/impl/I2PSessionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,10 @@ public Destination lookupDest(Hash h) throws I2PSessionException {
return lookupDest(h, 10*1000);
}

public boolean deleteDest(String h) {
return _context.namingService().remove(h);
}

/**
* Blocking.
* @param maxWait ms
Expand Down
32 changes: 24 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,19 +96,33 @@ static Destination lookupHostname(I2PAppContext ctx, String hostname) throws I2P
return rv;
}

static boolean deleteHostname2(I2PAppContext ctx, String hostname) throws I2PSessionException {
I2PClient client = new I2PSimpleClient();
Properties opts = getOpts(ctx);
I2PSession session = null;
try {
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 = ctx.namingService();
if (ns != null) {
boolean deleted = ns.remove(hostname, dest);
if (deleted)
return dest;
boolean named = deleteHostname2(ctx, hostname);
if (named) {
return dest;
}
System.err.print("ns is null");
}
} catch (I2PSessionException ise) {
ise.printStackTrace();
Expand Down Expand Up @@ -151,8 +165,9 @@ public static void main(String args[]) {
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!");
Expand All @@ -163,11 +178,12 @@ public static void main(String args[]) {
}
} 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!");
System.err.println("hostname not found, not deleted.");
}
}
}
Expand Down

0 comments on commit b8091e9

Please sign in to comment.