From 85bd4cc8bc28600598488197fe2fa1e4eb7d4f9b Mon Sep 17 00:00:00 2001 From: Michael Christen Date: Sun, 25 Dec 2011 10:14:15 +0100 Subject: [PATCH] better lookup for peer names --- htroot/IndexControlRWIs_p.java | 2 +- source/net/yacy/peers/Seed.java | 2 +- source/net/yacy/peers/SeedDB.java | 58 +++++++++++++++++++------------ 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.java index 8132b40f1..9412d46f2 100644 --- a/htroot/IndexControlRWIs_p.java +++ b/htroot/IndexControlRWIs_p.java @@ -126,6 +126,7 @@ public class IndexControlRWIs_p final 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_p final 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.java index 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, Comparator { * @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.java index 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 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 number final Iterator 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 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> entry; + try { + Iterator>> 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>> 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 if (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> entry; if (lookupConnected) { try { Iterator>> mmap = this.seedActiveDB.entries(Seed.IP, ipString); - Map.Entry> 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>> mmap = this.seedPassiveDB.entries(Seed.IP, ipString); - Map.Entry> 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>> mmap = this.seedPotentialDB.entries(Seed.IP, ipString); - Map.Entry> entry; while (mmap.hasNext()) { entry = mmap.next(); if (entry == null) break;