Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
better lookup for peer names
Michael Christen85bd4cc8bc28
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.javaindex 8132b40f1..9412d46f2 100644--- a/htroot/IndexControlRWIs_p.java+++ b/htroot/IndexControlRWIs_p.java@@ -126,6 +126,7 @@ public class IndexControlRWIs_pfinal String keystring = post.get("keystring", "").trim();byte[] keyhash = post.get("keyhash", "").trim().getBytes();+ if (keyhash == null || keyhash.length == 0) keyhash = Word.word2hash(keystring);prop.putHTML("keystring", keystring);prop.putHTML("keyhash", ASCII.String(keyhash));@@ -149,7 +150,6 @@ public class IndexControlRWIs_pfinal boolean delurlref = post.containsKey("delurlref");if ( post.containsKey("keystringsearch") ) {- keyhash = Word.word2hash(keystring);prop.put("keyhash", keyhash);final RWIProcess ranking = genSearchresult(prop, sb, segment, keyhash, null);if ( ranking.filteredCount() == 0 ) {diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.javaindex a8c31a62e..356bb2901 100644--- a/source/net/yacy/peers/Seed.java+++ b/source/net/yacy/peers/Seed.java@@ -247,7 +247,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed> {* @return a checked name without "<" and ">"*/private final static Pattern tp = Pattern.compile("<|>");- private static String checkPeerName(String name) {+ public static String checkPeerName(String name) {name = tp.matcher(name).replaceAll("_");return name;}diff --git a/source/net/yacy/peers/SeedDB.java b/source/net/yacy/peers/SeedDB.javaindex 18dd19c52..cb631d1f2 100644--- a/source/net/yacy/peers/SeedDB.java+++ b/source/net/yacy/peers/SeedDB.java@@ -438,11 +438,6 @@ public final class SeedDB implements AlternativeDomainNames {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) {// return just any seed that has a specific minimum version numberfinal 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+ peerName = peerName.toLowerCase();final String seedhash = this.nameLookupCache.get(peerName);Seed seed;if (seedhash != null) {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- String name;- for (int table = 0; table < 2; table++) {- final Iterator<Seed> e = (table == 0) ? seedsConnected(true, false, null, (float) 0.0) : seedsDisconnected(true, false, null, (float) 0.0);- while (e.hasNext()) {- seed = e.next();- if (seed != null) {- name = seed.getName().toLowerCase();- if (seed.isProper(false) == null) this.nameLookupCache.put(name, seed.hash);- if (name.equals(peerName)) return seed;- }- }+ // enumerate the cache+ String name = Seed.checkPeerName(peerName);+ Map.Entry<byte[], Map<String, String>> entry;+ try {+ Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedActiveDB.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 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 seedif (this.mySeed == null) initMySeed();name = this.mySeed.getName().toLowerCase();@@ -700,11 +716,11 @@ public final class SeedDB implements AlternativeDomainNames {}String ipString = peerIP.getHostAddress();-++ Map.Entry<byte[], Map<String, String>> entry;if (lookupConnected) {try {Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedActiveDB.entries(Seed.IP, ipString);- Map.Entry<byte[], Map<String, String>> entry;while (mmap.hasNext()) {entry = mmap.next();if (entry == null) break;@@ -724,7 +740,6 @@ public final class SeedDB implements AlternativeDomainNames {if (lookupDisconnected) {try {Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPassiveDB.entries(Seed.IP, ipString);- Map.Entry<byte[], Map<String, String>> entry;while (mmap.hasNext()) {entry = mmap.next();if (entry == null) break;@@ -744,7 +759,6 @@ public final class SeedDB implements AlternativeDomainNames {if (lookupPotential) {try {Iterator<Map.Entry<byte[], Map<String, String>>> mmap = this.seedPotentialDB.entries(Seed.IP, ipString);- Map.Entry<byte[], Map<String, String>> entry;while (mmap.hasNext()) {entry = mmap.next();if (entry == null) break;