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

Skip to content
Snippets Groups Projects
Commit 56473c6b authored by zzz's avatar zzz
Browse files

add reverse lookup by hash

parent d222c7a9
No related branches found
No related tags found
No related merge requests found
......@@ -16,8 +16,10 @@ import java.util.Set;
import java.util.StringTokenizer;
import net.i2p.I2PAppContext;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.util.Log;
/**
......@@ -135,4 +137,34 @@ public class HostsTxtNamingService extends NamingService {
}
return null;
}
@Override
public String reverseLookup(Hash h) {
List filenames = getFilenames();
for (int i = 0; i < filenames.size(); i++) {
String hostsfile = (String)filenames.get(i);
Properties hosts = new Properties();
try {
File f = new File(hostsfile);
if ( (f.exists()) && (f.canRead()) ) {
DataHelper.loadProps(hosts, f, true);
Set keyset = hosts.keySet();
Iterator iter = keyset.iterator();
while (iter.hasNext()) {
String host = (String)iter.next();
String key = hosts.getProperty(host);
try {
Destination destkey = new Destination();
destkey.fromBase64(key);
if (h.equals(destkey.calculateHash()))
return host;
} catch (DataFormatException dfe) {}
}
}
} catch (Exception ioe) {
_log.error("Error loading hosts file " + hostsfile, ioe);
}
}
return null;
}
}
......@@ -16,6 +16,7 @@ import java.util.Map;
import net.i2p.I2PAppContext;
import net.i2p.data.DataFormatException;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.util.Log;
/**
......@@ -61,6 +62,7 @@ public abstract class NamingService {
* <code>null</code> if no reverse lookup is possible.
*/
public abstract String reverseLookup(Destination dest);
public String reverseLookup(Hash h) { return null; };
/**
* Check if host name is valid Base64 encoded dest and return this
......
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