* Implemented a MetaNamingService.
This commit is contained in:
60
core/java/src/net/i2p/client/naming/MetaNamingService.java
Normal file
60
core/java/src/net/i2p/client/naming/MetaNamingService.java
Normal file
@ -0,0 +1,60 @@
|
||||
package net.i2p.client.naming;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Destination;
|
||||
|
||||
public class MetaNamingService extends NamingService {
|
||||
|
||||
private final static String PROP_NAME_SERVICES = "i2p.nameservicelist";
|
||||
private final static String DEFAULT_NAME_SERVICES =
|
||||
"net.i2p.client.naming.PetNameNamingService,net.i2p.client.naming.HostsTxtNamingService";
|
||||
private List _services;
|
||||
|
||||
public MetaNamingService(I2PAppContext context) {
|
||||
super(context);
|
||||
|
||||
String list = _context.getProperty(PROP_NAME_SERVICES, DEFAULT_NAME_SERVICES);
|
||||
StringTokenizer tok = new StringTokenizer(list, ",");
|
||||
_services = new ArrayList(tok.countTokens());
|
||||
while (tok.hasMoreTokens()) {
|
||||
try {
|
||||
Class cls = Class.forName(tok.nextToken());
|
||||
Constructor con = cls.getConstructor(new Class[] { I2PAppContext.class });
|
||||
_services.add(con.newInstance(new Object[] { context }));
|
||||
} catch (Exception ex) {
|
||||
_services.add(new DummyNamingService(context)); // fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Destination lookup(String hostname) {
|
||||
Iterator iter = _services.iterator();
|
||||
while (iter.hasNext()) {
|
||||
NamingService ns = (NamingService)iter.next();
|
||||
Destination dest = ns.lookup(hostname);
|
||||
if (dest != null) {
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
return lookupBase64(hostname);
|
||||
}
|
||||
|
||||
public String reverseLookup(Destination dest) {
|
||||
Iterator iter = _services.iterator();
|
||||
while (iter.hasNext()) {
|
||||
NamingService ns = (NamingService)iter.next();
|
||||
String hostname = ns.reverseLookup(dest);
|
||||
if (hostname != null) {
|
||||
return hostname;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -22,27 +22,27 @@ public class PetNameNamingService extends NamingService {
|
||||
|
||||
//If the petnamedb file doesn't exist, create it, using the
|
||||
//contents of hosts.txt.
|
||||
File nameFile = new File(file);
|
||||
if (!nameFile.exists()) {
|
||||
Properties hosts = new Properties();
|
||||
File hostsFile = new File("hosts.txt");
|
||||
if (hostsFile.exists() && hostsFile.canRead()) {
|
||||
try {
|
||||
DataHelper.loadProps(hosts, hostsFile);
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
Iterator iter = hosts.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
String hostname = (String)iter.next();
|
||||
PetName pn = new PetName(hostname, "i2p", "http", hosts.getProperty(hostname));
|
||||
_petnameDb.set(hostname, pn);
|
||||
}
|
||||
try {
|
||||
_petnameDb.store(file);
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
// File nameFile = new File(file);
|
||||
// if (!nameFile.exists()) {
|
||||
// Properties hosts = new Properties();
|
||||
// File hostsFile = new File("hosts.txt");
|
||||
// if (hostsFile.exists() && hostsFile.canRead()) {
|
||||
// try {
|
||||
// DataHelper.loadProps(hosts, hostsFile);
|
||||
// } catch (IOException ioe) {
|
||||
// }
|
||||
// }
|
||||
// Iterator iter = hosts.keySet().iterator();
|
||||
// while (iter.hasNext()) {
|
||||
// String hostname = (String)iter.next();
|
||||
// PetName pn = new PetName(hostname, "i2p", "http", hosts.getProperty(hostname));
|
||||
// _petnameDb.set(hostname, pn);
|
||||
// }
|
||||
// try {
|
||||
// _petnameDb.store(file);
|
||||
// } catch (IOException ioe) {
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
_petnameDb.load(file);
|
||||
|
10
history.txt
10
history.txt
@ -1,11 +1,17 @@
|
||||
$Id: history.txt,v 1.257 2005/09/17 20:29:59 jrandom Exp $
|
||||
$Id: history.txt,v 1.258 2005/09/18 00:41:46 ragnarok Exp $
|
||||
|
||||
2005-09-17 Ragnarok
|
||||
* Implemented a naming service using Syndie's petname db. It's not enabled
|
||||
by default, but you can try it out by setting
|
||||
i2p.naming.impl=net.i2p.client.naming.PetNameNamingService in
|
||||
router.config.
|
||||
|
||||
* Implemented a meta naming service that will first lookup names in the
|
||||
PetNameNamingService then fallback on the HostTxtNamingService. Which
|
||||
naming services are checked and in which order is specified by
|
||||
i2p.nameservicelist. This will probably become the default naming service
|
||||
so please help test it out by setting
|
||||
i2p.naming.impl=net.i2p.client.naming.MetaNamingService in router.config.
|
||||
|
||||
* 2005-09-17 0.6.0.6 released
|
||||
|
||||
2005-09-17 jrandom
|
||||
|
Reference in New Issue
Block a user