forked from I2P_Developers/i2p.i2p
work on failing JUnit test
This commit is contained in:
@ -12,6 +12,7 @@ import java.util.Map;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.I2PSessionException;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.util.LHMCache;
|
import net.i2p.util.LHMCache;
|
||||||
|
|
||||||
@ -66,11 +67,15 @@ class DummyNamingService extends NamingService {
|
|||||||
|
|
||||||
// Try Base32 decoding
|
// Try Base32 decoding
|
||||||
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p") &&
|
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p") &&
|
||||||
_context.getBooleanPropertyDefaultTrue(PROP_B32)) {
|
_context.getBooleanPropertyDefaultTrue(PROP_B32)) {
|
||||||
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
|
try {
|
||||||
if (d != null) {
|
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
|
||||||
putCache(hostname, d);
|
if (d != null) {
|
||||||
return d;
|
putCache(hostname, d);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
} catch (I2PSessionException i2pse) {
|
||||||
|
_log.warn("couldn't lookup b32",i2pse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class LookupDest {
|
|||||||
protected LookupDest(I2PAppContext context) {}
|
protected LookupDest(I2PAppContext context) {}
|
||||||
|
|
||||||
/** @param key 52 chars (do not include the .b32.i2p suffix) */
|
/** @param key 52 chars (do not include the .b32.i2p suffix) */
|
||||||
static Destination lookupBase32Hash(I2PAppContext ctx, String key) {
|
static Destination lookupBase32Hash(I2PAppContext ctx, String key) throws I2PSessionException {
|
||||||
byte[] h = Base32.decode(key);
|
byte[] h = Base32.decode(key);
|
||||||
if (h == null)
|
if (h == null)
|
||||||
return null;
|
return null;
|
||||||
@ -56,27 +56,30 @@ class LookupDest {
|
|||||||
****/
|
****/
|
||||||
|
|
||||||
/** @param h 32 byte hash */
|
/** @param h 32 byte hash */
|
||||||
static Destination lookupHash(I2PAppContext ctx, byte[] h) {
|
static Destination lookupHash(I2PAppContext ctx, byte[] h) throws I2PSessionException {
|
||||||
Hash key = Hash.create(h);
|
Hash key = Hash.create(h);
|
||||||
Destination rv = null;
|
Destination rv = null;
|
||||||
|
I2PClient client = new I2PSimpleClient();
|
||||||
|
Properties opts = new Properties();
|
||||||
|
String s = ctx.getProperty(I2PClient.PROP_TCP_HOST);
|
||||||
|
if (s != null)
|
||||||
|
opts.put(I2PClient.PROP_TCP_HOST, s);
|
||||||
|
s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
|
||||||
|
if (s != null)
|
||||||
|
opts.put(I2PClient.PROP_TCP_PORT, s);
|
||||||
|
I2PSession session = null;
|
||||||
try {
|
try {
|
||||||
I2PClient client = new I2PSimpleClient();
|
session = client.createSession(null, opts);
|
||||||
Properties opts = new Properties();
|
|
||||||
String s = ctx.getProperty(I2PClient.PROP_TCP_HOST);
|
|
||||||
if (s != null)
|
|
||||||
opts.put(I2PClient.PROP_TCP_HOST, s);
|
|
||||||
s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
|
|
||||||
if (s != null)
|
|
||||||
opts.put(I2PClient.PROP_TCP_PORT, s);
|
|
||||||
I2PSession session = client.createSession(null, opts);
|
|
||||||
session.connect();
|
session.connect();
|
||||||
rv = session.lookupDest(key, DEFAULT_TIMEOUT);
|
rv = session.lookupDest(key, DEFAULT_TIMEOUT);
|
||||||
session.destroySession();
|
} finally {
|
||||||
} catch (I2PSessionException ise) {}
|
if (session != null)
|
||||||
|
session.destroySession();
|
||||||
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) throws I2PSessionException {
|
||||||
Destination dest = lookupBase32Hash(I2PAppContext.getGlobalContext(), args[0]);
|
Destination dest = lookupBase32Hash(I2PAppContext.getGlobalContext(), args[0]);
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
System.out.println("Destination not found!");
|
System.out.println("Destination not found!");
|
||||||
|
@ -1,18 +1,38 @@
|
|||||||
package net.i2p.client.naming;
|
package net.i2p.client.naming;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.client.I2PClient;
|
||||||
|
import net.i2p.client.I2PSession;
|
||||||
|
import net.i2p.client.I2PSimpleClient;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
|
|
||||||
|
|
||||||
public class DummyNamingServiceTest extends TestCase {
|
public class DummyNamingServiceTest extends TestCase {
|
||||||
private I2PAppContext _context;
|
private I2PAppContext _context;
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
_context = new I2PAppContext();
|
_context = new I2PAppContext();
|
||||||
|
verifySession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** makes sure we can create a session */
|
||||||
|
private void verifySession() throws Exception {
|
||||||
|
I2PClient client = new I2PSimpleClient();
|
||||||
|
Properties opts = new Properties();
|
||||||
|
I2PSession session = null;
|
||||||
|
try {
|
||||||
|
session = client.createSession(null, opts);
|
||||||
|
session.connect();
|
||||||
|
} finally {
|
||||||
|
if (session != null)
|
||||||
|
session.destroySession();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testLookup() throws Exception{
|
public void testLookup() throws Exception{
|
||||||
// The good b64 and b32 are the destination of www.i2p2.i2p =)
|
// The good b64 and b32 are the destination of www.i2p2.i2p =)
|
||||||
String goodB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA";
|
String goodB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA";
|
||||||
|
Reference in New Issue
Block a user