I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 2499aad5 authored by zzz's avatar zzz
Browse files

I2PSocketEepGet: Do hostname lookups in-session for efficiency

parent addb142e
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,12 @@ import java.util.Properties; ...@@ -11,8 +11,12 @@ import java.util.Properties;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.I2PException; import net.i2p.I2PException;
import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException;
import net.i2p.data.Base32;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.util.EepGet; import net.i2p.util.EepGet;
import net.i2p.util.SocketTimeout; import net.i2p.util.SocketTimeout;
...@@ -129,9 +133,31 @@ public class I2PSocketEepGet extends EepGet { ...@@ -129,9 +133,31 @@ public class I2PSocketEepGet extends EepGet {
} }
} }
Destination dest = _context.namingService().lookup(host); // Use existing I2PSession for lookups.
// This is much more efficient than using the naming service
Destination dest;
I2PSession sess = _socketManager.getSession();
if (sess != null && !sess.isClosed()) {
try {
if (host.length() == 60 && host.endsWith(".b32.i2p")) {
byte[] b = Base32.decode(host.substring(0, 52));
if (b != null) {
Hash h = Hash.create(b);
dest = sess.lookupDest(h, 20*1000);
} else {
dest = null;
}
} else {
dest = sess.lookupDest(host, 20*1000);
}
} catch (I2PSessionException ise) {
dest = null;
}
} else {
dest = _context.namingService().lookup(host);
}
if (dest == null) if (dest == null)
throw new UnknownHostException("Unknown or non-i2p host"); throw new UnknownHostException("Unknown or non-i2p host: " + host);
// Set the timeouts, using the other existing options in the socket manager // Set the timeouts, using the other existing options in the socket manager
// This currently duplicates what SocketTimeout is doing in EepGet, // This currently duplicates what SocketTimeout is doing in EepGet,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment