better lookup for peer names

pull/1/head
Michael Christen 13 years ago
parent 20e3084bd4
commit 85bd4cc8bc

@ -126,6 +126,7 @@ public class IndexControlRWIs_p
final String keystring = post.get("keystring", "").trim(); final String keystring = post.get("keystring", "").trim();
byte[] keyhash = post.get("keyhash", "").trim().getBytes(); byte[] keyhash = post.get("keyhash", "").trim().getBytes();
if (keyhash == null || keyhash.length == 0) keyhash = Word.word2hash(keystring);
prop.putHTML("keystring", keystring); prop.putHTML("keystring", keystring);
prop.putHTML("keyhash", ASCII.String(keyhash)); prop.putHTML("keyhash", ASCII.String(keyhash));
@ -149,7 +150,6 @@ public class IndexControlRWIs_p
final boolean delurlref = post.containsKey("delurlref"); final boolean delurlref = post.containsKey("delurlref");
if ( post.containsKey("keystringsearch") ) { if ( post.containsKey("keystringsearch") ) {
keyhash = Word.word2hash(keystring);
prop.put("keyhash", keyhash); prop.put("keyhash", keyhash);
final RWIProcess ranking = genSearchresult(prop, sb, segment, keyhash, null); final RWIProcess ranking = genSearchresult(prop, sb, segment, keyhash, null);
if ( ranking.filteredCount() == 0 ) { if ( ranking.filteredCount() == 0 ) {

@ -247,7 +247,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed> {
* @return a checked name without "<" and ">" * @return a checked name without "<" and ">"
*/ */
private final static Pattern tp = Pattern.compile("<|>"); private final static Pattern tp = Pattern.compile("<|>");
private static String checkPeerName(String name) { public static String checkPeerName(String name) {
name = tp.matcher(name).replaceAll("_"); name = tp.matcher(name).replaceAll("_");
return name; return name;
} }

@ -438,11 +438,6 @@ public final class SeedDB implements AlternativeDomainNames {
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, this.seedPassiveDB, minVersion); return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, this.seedPassiveDB, minVersion);
} }
private Iterator<Seed> seedsPotential(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, this.seedPotentialDB, minVersion);
}
public Seed anySeedVersion(final float minVersion) { public Seed anySeedVersion(final float minVersion) {
// return just any seed that has a specific minimum version number // return just any seed that has a specific minimum version number
final Iterator<Seed> e = seedsConnected(true, true, Seed.randomHash(), minVersion); final Iterator<Seed> e = seedsConnected(true, true, Seed.randomHash(), minVersion);
@ -643,26 +638,47 @@ public final class SeedDB implements AlternativeDomainNames {
} }
// then try to use the cache // then try to use the cache
peerName = peerName.toLowerCase();
final String seedhash = this.nameLookupCache.get(peerName); final String seedhash = this.nameLookupCache.get(peerName);
Seed seed; Seed seed;
if (seedhash != null) { if (seedhash != null) {
seed = this.get(seedhash); seed = this.get(seedhash);
if (seed != null) return seed; if (seed != null) {
//System.out.println("*** found lookupByName in cache: " + peerName);
return seed;
}
} }
// enumerate the cache and simultanous insert values // enumerate the cache
String name; String name = Seed.checkPeerName(peerName);
for (int table = 0; table < 2; table++) { Map.Entry<byte[], Map<String, String>> entry;
final Iterator<Seed> e = (table == 0) ? seedsConnected(true, false, null, (float) 0.0) : seedsDisconnected(true, false, null, (float) 0.0); try {
while (e.hasNext()) { Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedActiveDB.entries(Seed.NAME, name);
seed = e.next(); while (mmap.hasNext()) {
if (seed != null) { entry = mmap.next();
name = seed.getName().toLowerCase(); if (entry == null) break;
if (seed.isProper(false) == null) this.nameLookupCache.put(name, seed.hash); seed = this.getConnected(ASCII.String(entry.getKey()));
if (name.equals(peerName)) return seed; if (seed == null) continue;
} if (seed.isProper(false) == null) this.nameLookupCache.put(seed.getName().toLowerCase(), seed.hash);
} //System.out.println("*** found lookupByName in seedActiveDB: " + peerName);
return seed;
}
} catch ( IOException e ) {
}
try {
Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPassiveDB.entries(Seed.NAME, name);
while (mmap.hasNext()) {
entry = mmap.next();
if (entry == null) break;
seed = this.getConnected(ASCII.String(entry.getKey()));
if (seed == null) continue;
if (seed.isProper(false) == null) this.nameLookupCache.put(seed.getName().toLowerCase(), seed.hash);
//System.out.println("*** found lookupByName in seedPassiveDB: " + peerName);
return seed;
}
} catch ( IOException e ) {
} }
// check local seed // check local seed
if (this.mySeed == null) initMySeed(); if (this.mySeed == null) initMySeed();
name = this.mySeed.getName().toLowerCase(); name = this.mySeed.getName().toLowerCase();
@ -701,10 +717,10 @@ public final class SeedDB implements AlternativeDomainNames {
String ipString = peerIP.getHostAddress(); String ipString = peerIP.getHostAddress();
Map.Entry<byte[], Map<String, String>> entry;
if (lookupConnected) { if (lookupConnected) {
try { try {
Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedActiveDB.entries(Seed.IP, ipString); Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedActiveDB.entries(Seed.IP, ipString);
Map.Entry<byte[], Map<String, String>> entry;
while (mmap.hasNext()) { while (mmap.hasNext()) {
entry = mmap.next(); entry = mmap.next();
if (entry == null) break; if (entry == null) break;
@ -724,7 +740,6 @@ public final class SeedDB implements AlternativeDomainNames {
if (lookupDisconnected) { if (lookupDisconnected) {
try { try {
Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPassiveDB.entries(Seed.IP, ipString); Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPassiveDB.entries(Seed.IP, ipString);
Map.Entry<byte[], Map<String, String>> entry;
while (mmap.hasNext()) { while (mmap.hasNext()) {
entry = mmap.next(); entry = mmap.next();
if (entry == null) break; if (entry == null) break;
@ -744,7 +759,6 @@ public final class SeedDB implements AlternativeDomainNames {
if (lookupPotential) { if (lookupPotential) {
try { try {
Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPotentialDB.entries(Seed.IP, ipString); Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPotentialDB.entries(Seed.IP, ipString);
Map.Entry<byte[], Map<String, String>> entry;
while (mmap.hasNext()) { while (mmap.hasNext()) {
entry = mmap.next(); entry = mmap.next();
if (entry == null) break; if (entry == null) break;

Loading…
Cancel
Save