b32 cleanups

This commit is contained in:
zzz
2011-05-25 13:34:32 +00:00
parent 641e71c141
commit 27b48034c5
6 changed files with 32 additions and 4 deletions

View File

@ -371,6 +371,9 @@ public class BlockfileNamingService extends DummyNamingService {
d = super.lookup(hostname, null, null);
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
return null;
}
String key = hostname.toLowerCase();

View File

@ -19,7 +19,7 @@ import net.i2p.data.Destination;
*/
class DummyNamingService extends NamingService {
private static final int BASE32_HASH_LENGTH = 52; // 1 + Hash.HASH_LENGTH * 8 / 5
protected static final int BASE32_HASH_LENGTH = 52; // 1 + Hash.HASH_LENGTH * 8 / 5
public final static String PROP_B32 = "i2p.naming.hostsTxt.useB32";
protected static final int CACHE_MAX_SIZE = 32;
public static final int DEST_SIZE = 516; // Std. Base64 length (no certificate)
@ -41,6 +41,13 @@ class DummyNamingService extends NamingService {
super(context);
}
/**
* @param hostname mixed case as it could be a key
* @param lookupOptions input parameter, NamingService-specific, can be null
* @param storedOptions output parameter, NamingService-specific, any stored properties will be added if non-null
* @return dest or null
* @since 0.8.7
*/
@Override
public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
Destination d = getCache(hostname);
@ -56,7 +63,7 @@ class DummyNamingService extends NamingService {
}
// Try Base32 decoding
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.endsWith(".b32.i2p") &&
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p") &&
_context.getBooleanPropertyDefaultTrue(PROP_B32)) {
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
if (d != null) {
@ -70,6 +77,7 @@ class DummyNamingService extends NamingService {
/**
* Provide basic static caching for all services
* @param s case-sensitive, could be a hostname or a full b64 string
*/
protected static void putCache(String s, Destination d) {
if (d == null)
@ -79,14 +87,20 @@ class DummyNamingService extends NamingService {
}
}
/** @return cached dest or null */
/**
* @param s case-sensitive, could be a hostname or a full b64 string
* @return cached dest or null
*/
protected static Destination getCache(String s) {
synchronized (_cache) {
return _cache.get(s);
}
}
/** @since 0.8.7 */
/**
* @param s case-sensitive, could be a hostname or a full b64 string
* @since 0.8.7
*/
protected static void removeCache(String s) {
synchronized (_cache) {
_cache.remove(s);

View File

@ -66,6 +66,9 @@ public class EepGetNamingService extends DummyNamingService {
return d;
hostname = hostname.toLowerCase();
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.endsWith(".b32.i2p"))
return null;
List URLs = getURLs();
if (URLs.isEmpty())

View File

@ -64,6 +64,9 @@ public class ExecNamingService extends DummyNamingService {
Destination d = super.lookup(hostname, null, null);
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
return null;
hostname = hostname.toLowerCase();

View File

@ -100,6 +100,9 @@ public class MetaNamingService extends DummyNamingService {
Destination d = super.lookup(hostname, null, null);
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
return null;
for (NamingService ns : _services) {
d = ns.lookup(hostname, lookupOptions, storedOptions);

View File

@ -422,6 +422,8 @@ public abstract class NamingService {
* will be only one naming service instance (singleton) as well as
* choose the implementation from the "i2p.naming.impl" system
* property.
*
* FIXME Actually, it doesn't ensure that. Only call this once!!!
*/
public static final synchronized NamingService createInstance(I2PAppContext context) {
NamingService instance = null;