Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
fix for peer-ping in case that remote peer does not respond with valid values
orbiter76e4c2d69ea5
diff --git a/htroot/yacy/crawlOrder.java b/htroot/yacy/crawlOrder.javaindex c79d210b4..cd73c6c93 100644--- a/htroot/yacy/crawlOrder.java+++ b/htroot/yacy/crawlOrder.java@@ -78,8 +78,6 @@ public final class crawlOrder {String process = post.get("process", ""); // process typeString key = post.get("key", ""); // transmission keyint orderDepth = post.getInt("depth", 0); // crawl depth- String unitName = post.get("network.unit.name", yacySeed.DFLT_NETWORK_UNIT); // the network unit- if (!unitName.equals(env.getConfig("network.unit.name", yacySeed.DFLT_NETWORK_UNIT))) return null;// response values/*diff --git a/htroot/yacy/crawlReceipt.java b/htroot/yacy/crawlReceipt.javaindex 71371fa06..9438a8acb 100644--- a/htroot/yacy/crawlReceipt.java+++ b/htroot/yacy/crawlReceipt.java@@ -71,10 +71,10 @@ public final class crawlReceipt {// return variable that accumulates replacementsplasmaSwitchboard switchboard = (plasmaSwitchboard) env;serverObjects prop = new serverObjects();- serverLog log = switchboard.getLog();-if ((post == null) || (env == null)) return prop;if (!yacyNetwork.authentifyRequest(post, env)) return prop;++ serverLog log = switchboard.getLog();//int proxyPrefetchDepth = Integer.parseInt(env.getConfig("proxyPrefetchDepth", "0"));//int crawlingDepth = Integer.parseInt(env.getConfig("crawlingDepth", "0"));diff --git a/htroot/yacy/hello.html b/htroot/yacy/hello.htmlindex 7e1dfbef0..54389b873 100644--- a/htroot/yacy/hello.html+++ b/htroot/yacy/hello.html@@ -3,4 +3,5 @@ uptime=#[uptime]#yourip=#[yourip]#yourtype=#[yourtype]#mytime=#[mytime]#+message=#[message]##[seedlist]#diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex af85f330b..2ced4a387 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -65,13 +65,17 @@ import de.anomic.yacy.yacyVersion;public final class hello {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) throws InterruptedException {- if (post == null || env == null || yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return null; }-plasmaSwitchboard sb = (plasmaSwitchboard) env;- // return variable that accumulates replacements- final serverObjects prop = new serverObjects();- if ((post == null) || (env == null)) return prop;- if (!yacyNetwork.authentifyRequest(post, env)) return prop;+ serverObjects prop = new serverObjects();+ prop.put("message", "none");+ if ((post == null) || (env == null)) {+ prop.put("message", "no post or no enviroment");+ return prop;+ }+ if (!yacyNetwork.authentifyRequest(post, env)) {+ prop.put("message", "not in my network");+ return prop;+ }// final String iam = (String) post.get("iam", ""); // complete seed of the requesting peer// final String mytime = (String) post.get(MYTIME, ""); //@@ -83,12 +87,16 @@ public final class hello {// final Date remoteTime = yacyCore.parseUniversalDate((String) post.get(MYTIME)); // read remote timeif (seed.length() > yacySeed.maxsize) {yacyCore.log.logInfo("hello/server: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");- return null;+ prop.put("message", "your seed is too long (" + seed.length() + ")");+ return prop;}final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key, false);// System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString()));- if ((remoteSeed == null) || (remoteSeed.hash == null)) { return null; }+ if ((remoteSeed == null) || (remoteSeed.hash == null)) {+ prop.put("message", "cannot parse your seed");+ return prop;+ }// final String properTest = remoteSeed.isProper();// The remote peer might not know its IP yet, so don't abort if the IP check fails@@ -97,7 +105,10 @@ public final class hello {// we easily know the caller's IP:final String clientip = (String) header.get("CLIENTIP", "<unknown>"); // read an artificial header addendumInetAddress ias = serverDomains.dnsResolve(clientip);- if (ias == null) return null;+ if (ias == null) {+ prop.put("message", "cannot resolve your IP from your reported location " + clientip);+ return prop;+ }final String userAgent = (String) header.get(httpHeader.USER_AGENT, "<unknown>");final String reportedip = remoteSeed.get(yacySeed.IP, "");final String reportedPeerType = remoteSeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR);@@ -105,7 +116,8 @@ public final class hello {if ((sb.isRobinsonMode()) && (!sb.isPublicRobinson())) {// if we are a robinson cluster, answer only if this client is known by our network definition- return prop;+ prop.put("message", "I am robinson, I do not answer");+ return prop;}int urls = -1;@@ -212,6 +224,7 @@ public final class hello {prop.putASIS("seedlist", seeds.toString());// return rewrite properties+ prop.put("message", "ok " + seed.length());return prop;}diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex 825128746..9631af38a 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -96,13 +96,11 @@ public final class yacyClient {// this works of course only if we know the other peer's hash.HashMap result = null;- String salt;+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), null);try {// generate request- final serverObjects obj = new serverObjects();- salt = yacyNetwork.enrichRequestPost(obj, plasmaSwitchboard.getSwitchboard(), null);- obj.putASIS("count", "20");- obj.putASIS("seed", yacyCore.seedDB.mySeed.genSeedStr(salt));+ post.putASIS("count", "20");+ post.putASIS("seed", yacyCore.seedDB.mySeed.genSeedStr(post.get("key", "")));yacyCore.log.logFine("yacyClient.publishMySeed thread '" + Thread.currentThread().getName() + "' contacting peer at " + address);// send requestresult = nxTools.table(@@ -112,7 +110,7 @@ public final class yacyClient {null,null,proxyConfig(),- obj,+ post,null), "UTF-8");@@ -140,7 +138,7 @@ public final class yacyClient {if (seed.length() > yacySeed.maxsize) {yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");} else {- otherPeer = yacySeed.genRemoteSeed(seed, salt, true);+ otherPeer = yacySeed.genRemoteSeed(seed, post.get("key", ""), true);if (otherPeer == null || !otherPeer.hash.equals(otherHash)) {yacyCore.log.logFine("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");return -1; // no success@@ -168,7 +166,7 @@ public final class yacyClient {*/if (!serverCore.portForwardingEnabled || otherPeerVersion >= yacyVersion.YACY_SUPPORTS_PORT_FORWARDING) {String mytype = (String) result.get(yacySeed.YOURTYPE);- if (mytype == null) { mytype = yacySeed.PEERTYPE_JUNIOR; }+ if (mytype == null) { mytype = ""; }yacyAccessible accessible = new yacyAccessible();if (mytype.equals(yacySeed.PEERTYPE_SENIOR)||mytype.equals(yacySeed.PEERTYPE_PRINCIPAL)) {accessible.IWasAccessed = true;@@ -200,8 +198,13 @@ public final class yacyClient {}}}+ } else if ((mytype.equalsIgnoreCase(yacySeed.PEERTYPE_SENIOR)) ||+ (mytype.equalsIgnoreCase(yacySeed.PEERTYPE_PRINCIPAL))) {+ yacyCore.log.logFine("yacyClient.publishMySeed: Peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' reported us as " + mytype + ", accepted other peer.");} else {- yacyCore.log.logFine("yacyClient.publishMySeed: Peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' reported us as " + mytype + ".");+ // wrong type report+ yacyCore.log.logFine("yacyClient.publishMySeed: Peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' reported us as " + mytype + ", rejecting other peer.");+ return -1;}if (yacyCore.seedDB.mySeed.orVirgin().equals(yacySeed.PEERTYPE_VIRGIN))yacyCore.seedDB.mySeed.put(yacySeed.PEERTYPE, mytype);@@ -226,7 +229,7 @@ public final class yacyClient {if (seedStr.length() > yacySeed.maxsize) {yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")");} else {- if (yacyCore.peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, salt, true), (i == 1))) count++;+ if (yacyCore.peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, post.get("key", ""), true), (i == 1))) count++;}}return count;@@ -234,8 +237,7 @@ public final class yacyClient {public static yacySeed querySeed(yacySeed target, String seedHash) {// prepare request- final serverObjects post = new serverObjects();- String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);post.putASIS("object", "seed");post.putASIS("env", seedHash);@@ -255,7 +257,7 @@ public final class yacyClient {if (result == null || result.size() == 0) { return null; }//final Date remoteTime = yacyCore.parseUniversalDate((String) result.get(yacySeed.MYTIME)); // read remote time- return yacySeed.genRemoteSeed((String) result.get("response"), salt, true);+ return yacySeed.genRemoteSeed((String) result.get("response"), post.get("key", ""), true);} catch (Exception e) {yacyCore.log.logSevere("yacyClient.querySeed error:" + e.getMessage());return null;@@ -264,8 +266,7 @@ public final class yacyClient {public static int queryRWICount(yacySeed target, String wordHash) {// prepare request- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);post.putASIS("object", "rwicount");post.putASIS("ttl", "0");post.putASIS("env", wordHash);@@ -297,8 +298,7 @@ public final class yacyClient {if (yacyCore.seedDB.mySeed == null) return -1;// prepare request- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);post.putASIS("object", "lurlcount");post.putASIS("ttl", "0");post.putASIS("env", "");@@ -367,9 +367,8 @@ public final class yacyClient {// duetime : maximum time that a peer should spent to create a result// prepare request- final serverObjects post = new serverObjects();- final String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);- post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(salt));+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);+ post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(post.get("key", "")));post.put("count", Math.max(10, count));post.putASIS("resource", ((global) ? "global" : "local"));post.put("partitions", partitions);@@ -580,8 +579,7 @@ public final class yacyClient {if (yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return null; }// prepare request- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetHash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetHash);post.putASIS("process", "permission");// send request@@ -609,10 +607,9 @@ public final class yacyClient {// this post a message to the remote message board// prepare request- final serverObjects post = new serverObjects();- final String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetHash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetHash);post.putASIS("process", "post");- post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(salt));+ post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(post.get("key", "")));post.putASIS("subject", subject);try {post.putASIS("message", new String(message, "UTF-8"));@@ -657,8 +654,7 @@ public final class yacyClient {public static HashMap transferPermission(String targetAddress, long filesize, String filename) {// prepare request- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), null);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), null);post.putASIS("process", "permission");post.putASIS("purpose", "crcon");post.putASIS("filename", filename);@@ -690,8 +686,7 @@ public final class yacyClient {public static HashMap transferStore(String targetAddress, String access, String filename, byte[] file) {// prepare request- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), null);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), null);post.putASIS("process", "store");post.putASIS("purpose", "crcon");post.putASIS("filename", filename);@@ -757,8 +752,7 @@ public final class yacyClient {assert (yacyCore.seedDB.mySeed != target);// prepare request- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);post.putASIS("process", "crawl");if (url.length == 1) {post.putASIS("url", crypt.simpleEncode(url[0].toNormalform(true, true)));@@ -830,14 +824,13 @@ public final class yacyClient {*/// prepare request- final serverObjects post = new serverObjects();- String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);post.putASIS("process", process);post.putASIS("urlhash", ((entry == null) ? "" : entry.hash()));post.putASIS("result", result);post.putASIS("reason", reason);post.putASIS("wordh", wordhashes);- post.putASIS("lurlEntry", ((entry == null) ? "" : crypt.simpleEncode(entry.toString(), salt)));+ post.putASIS("lurlEntry", ((entry == null) ? "" : crypt.simpleEncode(entry.toString(), post.get("key", ""))));// determining target addressfinal String address = target.getClusterAddress();@@ -958,8 +951,7 @@ public final class yacyClient {if (address == null) { return null; }// prepare post values- final serverObjects post = new serverObjects();- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetSeed.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetSeed.hash);// enabling gzip compression for post request bodyif ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) {@@ -1025,8 +1017,7 @@ public final class yacyClient {if (address == null) { return null; }// prepare post values- final serverObjects post = new serverObjects(5+urls.length);- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetSeed.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetSeed.hash);// enabling gzip compression for post request bodyif ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) {@@ -1077,8 +1068,7 @@ public final class yacyClient {public static HashMap getProfile(yacySeed targetSeed) {// this post a message to the remote message board- final serverObjects post = new serverObjects(2);- yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetSeed.hash);+ final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetSeed.hash);String address = targetSeed.getClusterAddress();if (address == null) { address = "localhost:8080"; }diff --git a/source/de/anomic/yacy/yacyNetwork.java b/source/de/anomic/yacy/yacyNetwork.javaindex 703632028..55bc20236 100644--- a/source/de/anomic/yacy/yacyNetwork.java+++ b/source/de/anomic/yacy/yacyNetwork.java@@ -67,9 +67,10 @@ public class yacyNetwork {return false;}- public static final String enrichRequestPost(serverObjects post, serverSwitch env, String targetHash) {+ public static final serverObjects basicRequestPost(serverSwitch env, String targetHash) {// put in all the essentials for routing and network authentification// generate a session key+ serverObjects post = new serverObjects();final String salt = crypt.randomSalt();post.put("key", salt);@@ -96,7 +97,7 @@ public class yacyNetwork {}}- return salt;+ return post;}}diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.javaindex d903041ab..281b76df2 100644--- a/source/de/anomic/yacy/yacySeed.java+++ b/source/de/anomic/yacy/yacySeed.java@@ -86,7 +86,7 @@ import de.anomic.tools.crypt;public class yacySeed {- public static final int maxsize = 2048;+ public static final int maxsize = 4096;/*** <b>substance</b> "sI" (send index/words)*/