Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
network functions for robinson peers: server-side protection
orbiter657585fe0d49
diff --git a/htroot/yacy/crawlOrder.java b/htroot/yacy/crawlOrder.javaindex 35decf377..162e8c8d1 100644--- a/htroot/yacy/crawlOrder.java+++ b/htroot/yacy/crawlOrder.java@@ -99,7 +99,7 @@ public final class crawlOrder {String reason = "false-input";String delay = "5";String lurl = "";- boolean granted = switchboard.getConfig("crawlResponse", "false").equals("true");+ boolean granted = switchboard.getConfigBool("crawlResponse", false);int acceptDepth = Integer.parseInt(switchboard.getConfig("crawlResponseDepth", "0"));int ppm = yacyCore.seedDB.mySeed.getPPM();int acceptDelay = (ppm == 0) ? 10 : (2 + 60 / yacyCore.seedDB.mySeed.getPPM());@@ -108,11 +108,17 @@ public final class crawlOrder {// check if requester is authorizedif ((yacyCore.seedDB.mySeed == null) || (!(yacyCore.seedDB.mySeed.hash.equals(youare)))) {- // this request has a wrong target+ // this request has a wrong targetresponse = "denied";reason = "authentify-problem";delay = "3600"; // may request one hour later again- } else if (orderDepth > 0) {+ } else if ((switchboard.isRobinsonMode()) && (!switchboard.isInMyCluster(iam))) {+ // check network environment, if we are a robinson peer or in a robinson cluster+ // then the request must come from a peer that is in the same cluster as we are+ reason = "not in my cluster";+ response = "denied";+ delay = "9999";+ } else if (orderDepth > 0) {response = "denied";reason = "order depth must be 0";delay = "3600"; // may request one hour later againdiff --git a/htroot/yacy/crawlReceipt.java b/htroot/yacy/crawlReceipt.javaindex 9567e78c0..150d562a1 100644--- a/htroot/yacy/crawlReceipt.java+++ b/htroot/yacy/crawlReceipt.java@@ -124,6 +124,11 @@ public final class crawlReceipt {return prop;}+ if ((switchboard.isRobinsonMode()) && (!switchboard.isInMyCluster(otherPeer))) {+ // we reject urls that are from outside our cluster+ prop.putASIS("delay", "9999");+ }+// generating a new loaded URL entryindexURLEntry entry = switchboard.wordIndex.loadedURL.newEntry(propStr);if (entry == null) {diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex 28a2bc3fc..e40f2d2f9 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -49,6 +49,7 @@import java.util.Date;import de.anomic.http.httpHeader;+import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;@@ -62,6 +63,7 @@ public final class hello {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) throws InterruptedException {if (post == null || ss == null || yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return null; }+ plasmaSwitchboard sb = (plasmaSwitchboard) ss;// return variable that accumulates replacementsfinal serverObjects prop = new serverObjects();if (prop == null) { return null; }@@ -80,6 +82,7 @@ public final class hello {// System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString()));if (remoteSeed == null) { return null; }+// final String properTest = remoteSeed.isProper();// The remote peer might not know its IP yet, so don't abort if the IP check fails// if ((properTest != null) && (! properTest.substring(0,1).equals("IP"))) { return null; }@@ -91,6 +94,11 @@ public final class hello {final String reportedPeerType = remoteSeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR);final float clientversion = remoteSeed.getVersion();+ if ((sb.isRobinsonMode()) && (!sb.isOpenRobinsonCluster())) {+ // if we are a robinson cluster, answer only if this client is known by our network definition+ return null;+ }+int urls = -1;// if the remote client has reported its own IP address and the client supports// the port forwarding feature (if client version >= 0.383) then we try todiff --git a/htroot/yacy/list.java b/htroot/yacy/list.javaindex feaa4fc2c..6ad7858ff 100644--- a/htroot/yacy/list.java+++ b/htroot/yacy/list.java@@ -57,6 +57,7 @@ import de.anomic.data.listManager;import de.anomic.data.wikiCode;import de.anomic.http.httpHeader;import de.anomic.net.URL;+import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;@@ -69,6 +70,7 @@ public final class list {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {if (post == null || ss == null)throw new NullPointerException("post: " + post + ", sb: " + ss);+ plasmaSwitchboard sb = (plasmaSwitchboard) ss;// return variable that accumulates replacementsfinal serverObjects prop = new serverObjects();@@ -83,6 +85,11 @@ public final class list {}if (otherPeerName == null) otherPeerName = (String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP);+ if ((sb.isRobinsonMode()) && (!sb.isInMyCluster(otherPeerName))) {+ // if we are a robinson cluster, answer only if this client is known by our network definition+ return null;+ }+if (col.equals("black")) {final StringBuffer out = new StringBuffer();@@ -109,16 +116,16 @@ public final class list {final int count = Math.min(post.getInt("count", 50), CrawlURLFetchStack_p.maxURLsPerFetch);if (count > 0 && db.size() > 0) {- final StringBuffer sb = new StringBuffer();+ final StringBuffer b = new StringBuffer();URL url;int cnt = 0;for (int i=0; i<count; i++) {if ((url = db.pop()) == null) continue;- sb.append(wikiCode.deReplaceHTMLEntities(url.toNormalform())).append("\n");+ b.append(wikiCode.deReplaceHTMLEntities(url.toNormalform())).append("\n");cnt++;}- prop.put("list", sb);+ prop.put("list", b);CrawlURLFetchStack_p.fetchMap.put(otherPeerName,new Integer(((CrawlURLFetchStack_p.fetchMap.get(otherPeerName) == null)diff --git a/htroot/yacy/message.java b/htroot/yacy/message.javaindex 1a5d733c9..d63562a2d 100644--- a/htroot/yacy/message.java+++ b/htroot/yacy/message.java@@ -79,8 +79,6 @@ public final class message {serverObjects prop = new serverObjects();if (prop == null || sb == null) { return null; }-// System.out.println("yacy/message:post=" + post.toString());-String process = post.get("process", "permission");String key = post.get("key", "");@@ -90,17 +88,22 @@ public final class message {prop.putASIS("messagesize", "0");prop.putASIS("attachmentsize", "0");-// System.out.println("DEBUG yacy/message: message post values = " + post.toString());-String youare = post.get("youare", ""); // seed hash of the target peer, needed for network stability// check if we are the right target and requester has correct information about this peerif ((yacyCore.seedDB.mySeed == null) || (!(yacyCore.seedDB.mySeed.hash.equals(youare)))) {// this request has a wrong target-// System.out.println("DEBUG yacy/message: authenticate failed");prop.putASIS("response", "-1"); // request rejectedreturn prop;}+ if ((sb.isRobinsonMode()) &&+ (!((sb.isOpenRobinsonCluster()) ||+ (sb.isInMyCluster((String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP)))))) {+ // if we are a robinson cluster, answer only if this client is known by our network definition+ prop.putASIS("response", "-1"); // request rejected+ return prop;+ }+prop.putASIS("messagesize", Integer.toString(messagesize));prop.putASIS("attachmentsize", Integer.toString(attachmentsize));diff --git a/htroot/yacy/profile.java b/htroot/yacy/profile.javaindex 0be7511c5..f0d4eccda 100644--- a/htroot/yacy/profile.java+++ b/htroot/yacy/profile.java@@ -56,6 +56,7 @@ import java.util.Map;import java.util.Properties;import de.anomic.http.httpHeader;+import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;@@ -64,8 +65,17 @@ public final class profile {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {// return variable that accumulates replacementsserverObjects prop = new serverObjects();+ plasmaSwitchboard sb = (plasmaSwitchboard) ss;if (prop == null) { return null; }+ if ((sb.isRobinsonMode()) &&+ (!((sb.isOpenRobinsonCluster()) ||+ (sb.isInMyCluster((String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP)))))) {+ // if we are a robinson cluster, answer only if this client is known by our network definition+ prop.put("list", 0);+ return prop;+ }+Properties profile = new Properties();int count=0;String key="";diff --git a/htroot/yacy/query.java b/htroot/yacy/query.javaindex 835416c81..bb92fb7d8 100644--- a/htroot/yacy/query.java+++ b/htroot/yacy/query.java@@ -64,6 +64,14 @@ public final class query {final serverObjects prop = new serverObjects();if (prop == null || sb == null) { return null; }+ if ((sb.isRobinsonMode()) &&+ (!((sb.isOpenRobinsonCluster()) ||+ (sb.isInMyCluster((String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP)))))) {+ // if we are a robinson cluster, answer only if this client is known by our network definition+ prop.putASIS("response", "-1"); // request rejected+ return prop;+ }+// System.out.println("YACYQUERY: RECEIVED POST = " + ((post == null) ? "NULL" : post.toString()));// final String iam = post.get("iam", ""); // complete seed of the requesting peerdiff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex ee1dd58cb..ba5fec59c 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -114,6 +114,18 @@ public final class search {// http://localhost:8080/yacy/search.html?query=4galTpdpDM5Qgh8DKIhGKXws&abstracts=auto (search for linux and book, generate abstract automatically)// http://localhost:8080/yacy/search.html?query=&abstracts=4galTpdpDM5Q (only abstracts for linux)+ serverObjects prop = new serverObjects();++ if ((sb.isRobinsonMode()) &&+ (!((sb.isOpenRobinsonCluster()) ||+ (sb.isInMyCluster((String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP)))))) {+ // if we are a robinson cluster, answer only if this client is known by our network definition+ prop.putASIS("links", "");+ prop.putASIS("linkcount", "0");+ prop.putASIS("references", "");+ return prop;+ }+// tell all threads to do nothing for a specific timesb.intermissionAllThreads(2 * duetime);@@ -130,7 +142,6 @@ public final class search {final TreeSet queryhashes = plasmaSearchQuery.hashes2Set(query);final TreeSet excludehashes = (exclude.length() == 0) ? new TreeSet(kelondroBase64Order.enhancedCoder) : plasmaSearchQuery.hashes2Set(exclude);final long timestamp = System.currentTimeMillis();- serverObjects prop = new serverObjects();// prepare an abstract resultStringBuffer indexabstract = new StringBuffer();diff --git a/htroot/yacy/transfer.java b/htroot/yacy/transfer.javaindex 03166f00e..1d21c8708 100644--- a/htroot/yacy/transfer.java+++ b/htroot/yacy/transfer.java@@ -79,6 +79,11 @@ public final class transfer {prop.putASIS("process_path", "");prop.putASIS("process_maxsize", "0");+ if (sb.isRobinsonMode()) {+ // in a robinson environment, do not answer. We do not do any transfer in a robinson cluster.+ return prop;+ }+if (!sb.rankingOn) { return prop; }yacySeed otherseed = yacyCore.seedDB.get(otherpeer);diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.javaindex 5cb9329fb..6dd0057cb 100644--- a/htroot/yacy/transferRWI.java+++ b/htroot/yacy/transferRWI.java@@ -105,7 +105,7 @@ public final class transferRWI {}*/- if (!granted) {+ if ((!granted) || (sb.isRobinsonMode())) {// we dont want to receive indexessb.getLog().logInfo("Rejecting RWIs from peer " + otherPeerName + ". Not granted.");result = "not_granted";diff --git a/htroot/yacy/transferURL.java b/htroot/yacy/transferURL.javaindex b56a0a46c..be6a966f2 100644--- a/htroot/yacy/transferURL.java+++ b/htroot/yacy/transferURL.java@@ -89,7 +89,10 @@ public final class transferURL {final yacySeed otherPeer = yacyCore.seedDB.get(iam);final String otherPeerName = iam + ":" + ((otherPeer == null) ? "NULL" : (otherPeer.getName() + "/" + otherPeer.getVersion()));- if (granted) {+ if ((!granted) || (sb.isRobinsonMode())) {+ sb.getLog().logInfo("Rejecting URLs from peer " + otherPeerName + ". Not granted.");+ result = "error_not_granted";+ } else {int received = 0;int blocked = 0;final int sizeBefore = sb.wordIndex.loadedURL.size();@@ -154,9 +157,6 @@ public final class transferURL {sb.getLog().logInfo("Received " + received + " URLs from peer " + otherPeerName + " in " + (System.currentTimeMillis() - start) + " ms, Blocked " + blocked + " URLs");if ((received - more) > 0) sb.getLog().logSevere("Received " + doublevalues + " double URLs from peer " + otherPeerName);result = "ok";- } else {- sb.getLog().logInfo("Rejecting URLs from peer " + otherPeerName + ". Not granted.");- result = "error_not_granted";}prop.putASIS("double", doublevalues);diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex 018d1f72b..45d808bbf 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -1331,17 +1331,18 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements serreturn getConfigBool(plasmaSwitchboard.INDEX_DIST_ALLOW, false) && !getConfigBool(plasmaSwitchboard.INDEX_RECEIVE_ALLOW, false);}- public boolean isClosedRobinsonCluster() {+ public boolean isOpenRobinsonCluster() {// robinson peers may be member of robinson clusters, which can be public or private// this does not check the robinson attribute, only the specific subtype of the clusterString clustermode = getConfig("cluster.mode", "publicpeer");- return (clustermode.equals("privatecluster")) || (clustermode.equals("privatepeer"));+ return (clustermode.equals("publiccluster")) || (clustermode.equals("publicepeer"));}public boolean isInMyCluster(String peer) {// check if the given peer is in the own network, if this is a robinson cluster// depending on the robinson cluster type, the peer String may be a peerhash (b64-hash)// or a ip:port String or simply a ip String+ // if this robinson mode does not define a cluster membership, false is returnedif (!isRobinsonMode()) return false;String clustermode = getConfig("cluster.mode", "publicpeer");if (clustermode.equals("privatecluster")) {@@ -1368,6 +1369,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements serpublic boolean isInMyCluster(yacySeed seed) {// check if the given peer is in the own network, if this is a robinson cluster+ // if this robinson mode does not define a cluster membership, false is returnedif (seed == null) return false;if (!isRobinsonMode()) return false;String clustermode = getConfig("cluster.mode", "publicpeer");