From 657585fe0d49fe2e0ba7ded585338a56239b339d Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 24 Apr 2007 15:11:12 +0000 Subject: [PATCH] network functions for robinson peers: server-side protection git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3591 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/yacy/crawlOrder.java | 12 +++++++++--- htroot/yacy/crawlReceipt.java | 5 +++++ htroot/yacy/hello.java | 8 ++++++++ htroot/yacy/list.java | 13 ++++++++++--- htroot/yacy/message.java | 13 ++++++++----- htroot/yacy/profile.java | 10 ++++++++++ htroot/yacy/query.java | 8 ++++++++ htroot/yacy/search.java | 13 ++++++++++++- htroot/yacy/transfer.java | 5 +++++ htroot/yacy/transferRWI.java | 2 +- htroot/yacy/transferURL.java | 8 ++++---- source/de/anomic/plasma/plasmaSwitchboard.java | 6 ++++-- 12 files changed, 84 insertions(+), 19 deletions(-) diff --git a/htroot/yacy/crawlOrder.java b/htroot/yacy/crawlOrder.java index 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 authorized if ((yacyCore.seedDB.mySeed == null) || (!(yacyCore.seedDB.mySeed.hash.equals(youare)))) { - // this request has a wrong target + // this request has a wrong target response = "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 again diff --git a/htroot/yacy/crawlReceipt.java b/htroot/yacy/crawlReceipt.java index 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 entry indexURLEntry entry = switchboard.wordIndex.loadedURL.newEntry(propStr); if (entry == null) { diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.java index 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 replacements final 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 to diff --git a/htroot/yacy/list.java b/htroot/yacy/list.java index 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 replacements final 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 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.java index 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 ser return 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 cluster String 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 returned if (!isRobinsonMode()) return false; String clustermode = getConfig("cluster.mode", "publicpeer"); if (clustermode.equals("privatecluster")) { @@ -1368,6 +1369,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser public 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 returned if (seed == null) return false; if (!isRobinsonMode()) return false; String clustermode = getConfig("cluster.mode", "publicpeer");