Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
redesign of fining of peers by ip: more leightweight method to read the seed databases
Michael Christen20e3084bd48e
diff --git a/htroot/AccessTracker_p.java b/htroot/AccessTracker_p.javaindex 8aea5239a..1ef99630e 100644--- a/htroot/AccessTracker_p.java+++ b/htroot/AccessTracker_p.java@@ -24,16 +24,16 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+import java.text.SimpleDateFormat;import java.util.Collection;import java.util.ConcurrentModificationException;import java.util.Date;import java.util.Iterator;import java.util.Locale;import java.util.Map;-import java.util.TreeSet;import java.util.Map.Entry;+import java.util.TreeSet;import java.util.concurrent.ConcurrentLinkedQueue;-import java.text.SimpleDateFormat;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;@@ -42,11 +42,10 @@ import net.yacy.peers.Seed;import net.yacy.search.Switchboard;import net.yacy.search.query.AccessTracker;import net.yacy.search.query.QueryParams;-+import de.anomic.server.serverAccessTracker.Track;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.server.serverAccessTracker.Track;public class AccessTracker_p {@@ -267,7 +266,7 @@ public class AccessTracker_p {prop.put("page_list_" + m + "_dark", ((dark) ? 1 : 0) ); dark =! dark;prop.putHTML("page_list_" + m + "_host", host);if (page == 5) {- final Seed remotepeer = sb.peers.lookupByIP(Domains.dnsResolve(host), true, true, true);+ final Seed remotepeer = sb.peers.lookupByIP(Domains.dnsResolve(host), -1, true, true, true);prop.putHTML("page_list_" + m + "_peername", (remotepeer == null) ? "UNKNOWN" : remotepeer.getName());}prop.putNum("page_list_" + m + "_count", handles.size());diff --git a/htroot/Connections_p.java b/htroot/Connections_p.javaindex 524db3d89..74efaee55 100644--- a/htroot/Connections_p.java+++ b/htroot/Connections_p.java@@ -39,13 +39,10 @@ import net.yacy.kelondro.workflow.WorkflowThread;import net.yacy.peers.PeerActions;import net.yacy.peers.Seed;import net.yacy.search.Switchboard;--//import de.anomic.http.client.ConnectionInfo;-//import de.anomic.http.client.Client;import de.anomic.server.serverCore;+import de.anomic.server.serverCore.Session;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.server.serverCore.Session;public final class Connections_p {@@ -98,7 +95,7 @@ public final class Connections_p {// determining if the source is a yacy hostSeed seed = null;if (doNameLookup) {- seed = sb.peers.lookupByIP(userAddress,true,false,false);+ seed = sb.peers.lookupByIP(userAddress, -1, true, false, false);if (seed != null && (seed.hash.equals(sb.peers.mySeed().hash)) &&(!seed.get(Seed.PORT,"").equals(Integer.toString(userPort)))) {seed = null;diff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex 580142489..7dd686a1b 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -417,7 +417,7 @@ public final class search {}// prepare search statistics- theQuery.remotepeer = client == null ? null : sb.peers.lookupByIP(Domains.dnsResolve(client), true, false, false);+ theQuery.remotepeer = client == null ? null : sb.peers.lookupByIP(Domains.dnsResolve(client), -1, true, false, false);theQuery.resultcount = (theSearch == null) ? 0 : joincount;theQuery.searchtime = System.currentTimeMillis() - timestamp;theQuery.urlretrievaltime = (theSearch == null) ? 0 : theSearch.result().getURLRetrievalTime();diff --git a/source/net/yacy/peers/PeerActions.java b/source/net/yacy/peers/PeerActions.javaindex 354c4d5f8..e37583ae6 100644--- a/source/net/yacy/peers/PeerActions.java+++ b/source/net/yacy/peers/PeerActions.java@@ -83,7 +83,7 @@ public class PeerActions {return false;}- final Seed doubleSeed = this.seedDB.lookupByIP(seed.getInetAddress(), true, false, false);+ final Seed doubleSeed = this.seedDB.lookupByIP(seed.getInetAddress(), seed.getPort(), true, false, false);if ((doubleSeed != null) && (doubleSeed.getPort() == seed.getPort()) && (!(doubleSeed.hash.equals(seed.hash)))) {// a user frauds with his peer different peer hashesif (Network.log.isFine()) Network.log.logFine("connect: rejecting FRAUD (double hashes " + doubleSeed.hash + "/" + seed.hash + " on same port " + seed.getPort() + ") peer " + seed.getName());diff --git a/source/net/yacy/peers/SeedDB.java b/source/net/yacy/peers/SeedDB.javaindex baaa8f35e..18dd19c52 100644--- a/source/net/yacy/peers/SeedDB.java+++ b/source/net/yacy/peers/SeedDB.java@@ -51,7 +51,6 @@ import net.yacy.cora.protocol.http.HTTPClient;import net.yacy.kelondro.blob.MapDataMining;import net.yacy.kelondro.data.meta.DigestURI;import net.yacy.kelondro.data.word.Word;-import net.yacy.kelondro.index.HandleSet;import net.yacy.kelondro.index.RowSpaceExceededException;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.order.Base64Order;@@ -675,13 +674,13 @@ public final class SeedDB implements AlternativeDomainNames {public Seed lookupByIP(final InetAddress peerIP,+ final int port,final boolean lookupConnected,final boolean lookupDisconnected,final boolean lookupPotential) {if (peerIP == null) return null;- Seed seed = null;// local peer?if (Domains.isThisHostIP(peerIP)) {@@ -691,112 +690,85 @@ public final class SeedDB implements AlternativeDomainNames {// then try to use the cachefinal SoftReference<Seed> ref = this.ipLookupCache.get(peerIP);+ Seed seed = null;if (ref != null) {seed = ref.get();- if (seed != null) return seed;+ if (seed != null) {+ //System.out.println("*** found lookupByIP in cache: " + peerIP.toString() + " -> " + this.mySeed.getName());+ return seed;+ }}- int pos = -1;- String addressStr = null;- InetAddress seedIPAddress = null;- final HandleSet badPeerHashes = new HandleSet(12, Base64Order.enhancedCoder, 0);-+ String ipString = peerIP.getHostAddress();+if (lookupConnected) {- // enumerate the cache and simultaneously insert values- final Iterator<Seed> e = seedsConnected(true, false, null, (float) 0.0);- while (e.hasNext()) {- seed = e.next();- if (seed != null) {- addressStr = seed.getPublicAddress();- if (addressStr == null) {- Log.logWarning("YACY","lookupByIP/Connected: address of seed " + seed.getName() + "/" + seed.hash + " is null.");- try {- badPeerHashes.put(ASCII.getBytes(seed.hash));- } catch (final RowSpaceExceededException e1) {- Log.logException(e1);- break;- }- continue;- }- if ((pos = addressStr.indexOf(':'))!= -1) {- addressStr = addressStr.substring(0,pos);- }- seedIPAddress = Domains.dnsResolve(addressStr);- if (seedIPAddress == null) continue;- if (seed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<Seed>(seed));- if (seedIPAddress.equals(peerIP)) return seed;+ 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;+ String p = entry.getValue().get(Seed.PORT);+ if (p == null) continue;+ if (port > 0 && Integer.parseInt(p) != port) continue;+ seed = this.getConnected(ASCII.String(entry.getKey()));+ if (seed == null) continue;+ this.ipLookupCache.put(peerIP, new SoftReference<Seed>(seed));+ //System.out.println("*** found lookupByIP in connected: " + peerIP.toString() + " -> " + seed.getName());+ return seed;}+ } catch ( IOException e ) {}- // delete bad peers- final Iterator<byte[]> i = badPeerHashes.iterator();- while (i.hasNext()) try {this.seedActiveDB.delete(i.next());} catch (final IOException e1) {Log.logException(e1);}- badPeerHashes.clear();}if (lookupDisconnected) {- // enumerate the cache and simultanous insert values- final Iterator<Seed>e = seedsDisconnected(true, false, null, (float) 0.0);-- while (e.hasNext()) {- seed = e.next();- if (seed != null) {- addressStr = seed.getPublicAddress();- if (addressStr == null) {- Log.logWarning("YACY","lookupByIPDisconnected: address of seed " + seed.getName() + "/" + seed.hash + " is null.");- try {- badPeerHashes.put(UTF8.getBytes(seed.hash));- } catch (final RowSpaceExceededException e1) {- Log.logException(e1);- break;- }- continue;- }- if ((pos = addressStr.indexOf(':'))!= -1) {- addressStr = addressStr.substring(0,pos);- }- seedIPAddress = Domains.dnsResolve(addressStr);- if (seedIPAddress == null) continue;- if (seed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<Seed>(seed));- if (seedIPAddress.equals(peerIP)) return seed;+ 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;+ String p = entry.getValue().get(Seed.PORT);+ if (p == null) continue;+ if (port > 0 && Integer.parseInt(p) != port) continue;+ seed = this.getDisconnected(ASCII.String(entry.getKey()));+ if (seed == null) continue;+ this.ipLookupCache.put(peerIP, new SoftReference<Seed>(seed));+ //System.out.println("*** found lookupByIP in disconnected: " + peerIP.toString() + " -> " + seed.getName());+ return seed;}+ } catch ( IOException e ) {}- // delete bad peers- final Iterator<byte[]> i = badPeerHashes.iterator();- while (i.hasNext()) try {this.seedActiveDB.delete(i.next());} catch (final IOException e1) {Log.logException(e1);}- badPeerHashes.clear();}if (lookupPotential) {- // enumerate the cache and simultanous insert values- final Iterator<Seed> e = seedsPotential(true, false, null, (float) 0.0);-- while (e.hasNext()) {- seed = e.next();- if ((seed != null) && ((addressStr = seed.getPublicAddress()) != null)) {- if ((pos = addressStr.indexOf(':'))!= -1) {- addressStr = addressStr.substring(0,pos);- }- seedIPAddress = Domains.dnsResolve(addressStr);- if (seedIPAddress == null) continue;- if (seed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<Seed>(seed));- if (seedIPAddress.equals(peerIP)) return seed;+ 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;+ String p = entry.getValue().get(Seed.PORT);+ if (p == null) continue;+ if (port > 0 && Integer.parseInt(p) != port) continue;+ seed = this.getPotential(ASCII.String(entry.getKey()));+ if (seed == null) continue;+ this.ipLookupCache.put(peerIP, new SoftReference<Seed>(seed));+ //System.out.println("*** found lookupByIP in potential: " + peerIP.toString() + " -> " + seed.getName());+ return seed;}+ } catch ( IOException e ) {}}// check local seedif (this.mySeed == null) return null;- addressStr = this.mySeed.getPublicAddress();- if (addressStr == null) return null;- if ((pos = addressStr.indexOf(':'))!= -1) {- addressStr = addressStr.substring(0,pos);- }- seedIPAddress = Domains.dnsResolve(addressStr);- if (seedIPAddress == null) return null;- if (this.mySeed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<Seed>(this.mySeed));- if (seedIPAddress.equals(peerIP)) return this.mySeed;- // nothing found- return null;+ String s = this.mySeed.getIP();+ if (s == null || !ipString.equals(s)) return null;+ int p = this.mySeed.getPort();+ if (p != port) return null;+ //System.out.println("*** found lookupByIP as my seed: " + peerIP.toString() + " -> " + this.mySeed.getName());+ return this.mySeed;}private ArrayList<String> storeSeedList(final File seedFile, final boolean addMySeed) throws IOException {