forked from I2P_Developers/i2p.i2p
b32 cleanups
This commit is contained in:
@@ -371,6 +371,9 @@ public class BlockfileNamingService extends DummyNamingService {
|
|||||||
d = super.lookup(hostname, null, null);
|
d = super.lookup(hostname, null, null);
|
||||||
if (d != null)
|
if (d != null)
|
||||||
return d;
|
return d;
|
||||||
|
// Base32 failed?
|
||||||
|
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = hostname.toLowerCase();
|
String key = hostname.toLowerCase();
|
||||||
|
@@ -19,7 +19,7 @@ import net.i2p.data.Destination;
|
|||||||
*/
|
*/
|
||||||
class DummyNamingService extends NamingService {
|
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";
|
public final static String PROP_B32 = "i2p.naming.hostsTxt.useB32";
|
||||||
protected static final int CACHE_MAX_SIZE = 32;
|
protected static final int CACHE_MAX_SIZE = 32;
|
||||||
public static final int DEST_SIZE = 516; // Std. Base64 length (no certificate)
|
public static final int DEST_SIZE = 516; // Std. Base64 length (no certificate)
|
||||||
@@ -41,6 +41,13 @@ class DummyNamingService extends NamingService {
|
|||||||
super(context);
|
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
|
@Override
|
||||||
public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
|
public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
|
||||||
Destination d = getCache(hostname);
|
Destination d = getCache(hostname);
|
||||||
@@ -56,7 +63,7 @@ class DummyNamingService extends NamingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try Base32 decoding
|
// 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)) {
|
_context.getBooleanPropertyDefaultTrue(PROP_B32)) {
|
||||||
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
|
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
@@ -70,6 +77,7 @@ class DummyNamingService extends NamingService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide basic static caching for all services
|
* 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) {
|
protected static void putCache(String s, Destination d) {
|
||||||
if (d == null)
|
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) {
|
protected static Destination getCache(String s) {
|
||||||
synchronized (_cache) {
|
synchronized (_cache) {
|
||||||
return _cache.get(s);
|
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) {
|
protected static void removeCache(String s) {
|
||||||
synchronized (_cache) {
|
synchronized (_cache) {
|
||||||
_cache.remove(s);
|
_cache.remove(s);
|
||||||
|
@@ -66,6 +66,9 @@ public class EepGetNamingService extends DummyNamingService {
|
|||||||
return d;
|
return d;
|
||||||
|
|
||||||
hostname = hostname.toLowerCase();
|
hostname = hostname.toLowerCase();
|
||||||
|
// Base32 failed?
|
||||||
|
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.endsWith(".b32.i2p"))
|
||||||
|
return null;
|
||||||
|
|
||||||
List URLs = getURLs();
|
List URLs = getURLs();
|
||||||
if (URLs.isEmpty())
|
if (URLs.isEmpty())
|
||||||
|
@@ -64,6 +64,9 @@ public class ExecNamingService extends DummyNamingService {
|
|||||||
Destination d = super.lookup(hostname, null, null);
|
Destination d = super.lookup(hostname, null, null);
|
||||||
if (d != null)
|
if (d != null)
|
||||||
return d;
|
return d;
|
||||||
|
// Base32 failed?
|
||||||
|
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
|
||||||
|
return null;
|
||||||
|
|
||||||
hostname = hostname.toLowerCase();
|
hostname = hostname.toLowerCase();
|
||||||
|
|
||||||
|
@@ -100,6 +100,9 @@ public class MetaNamingService extends DummyNamingService {
|
|||||||
Destination d = super.lookup(hostname, null, null);
|
Destination d = super.lookup(hostname, null, null);
|
||||||
if (d != null)
|
if (d != null)
|
||||||
return d;
|
return d;
|
||||||
|
// Base32 failed?
|
||||||
|
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
|
||||||
|
return null;
|
||||||
|
|
||||||
for (NamingService ns : _services) {
|
for (NamingService ns : _services) {
|
||||||
d = ns.lookup(hostname, lookupOptions, storedOptions);
|
d = ns.lookup(hostname, lookupOptions, storedOptions);
|
||||||
|
@@ -422,6 +422,8 @@ public abstract class NamingService {
|
|||||||
* will be only one naming service instance (singleton) as well as
|
* will be only one naming service instance (singleton) as well as
|
||||||
* choose the implementation from the "i2p.naming.impl" system
|
* choose the implementation from the "i2p.naming.impl" system
|
||||||
* property.
|
* property.
|
||||||
|
*
|
||||||
|
* FIXME Actually, it doesn't ensure that. Only call this once!!!
|
||||||
*/
|
*/
|
||||||
public static final synchronized NamingService createInstance(I2PAppContext context) {
|
public static final synchronized NamingService createInstance(I2PAppContext context) {
|
||||||
NamingService instance = null;
|
NamingService instance = null;
|
||||||
|
Reference in New Issue
Block a user