fix for peer-ping in case that remote peer does not respond with valid values

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4091 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent e192f99134
commit 76e4c2d69e

@ -78,8 +78,6 @@ public final class crawlOrder {
String process = post.get("process", ""); // process type String process = post.get("process", ""); // process type
String key = post.get("key", ""); // transmission key String key = post.get("key", ""); // transmission key
int orderDepth = post.getInt("depth", 0); // crawl depth int 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 // response values
/* /*

@ -71,11 +71,11 @@ public final class crawlReceipt {
// return variable that accumulates replacements // return variable that accumulates replacements
plasmaSwitchboard switchboard = (plasmaSwitchboard) env; plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects(); serverObjects prop = new serverObjects();
serverLog log = switchboard.getLog();
if ((post == null) || (env == null)) return prop; if ((post == null) || (env == null)) return prop;
if (!yacyNetwork.authentifyRequest(post, env)) return prop; if (!yacyNetwork.authentifyRequest(post, env)) return prop;
serverLog log = switchboard.getLog();
//int proxyPrefetchDepth = Integer.parseInt(env.getConfig("proxyPrefetchDepth", "0")); //int proxyPrefetchDepth = Integer.parseInt(env.getConfig("proxyPrefetchDepth", "0"));
//int crawlingDepth = Integer.parseInt(env.getConfig("crawlingDepth", "0")); //int crawlingDepth = Integer.parseInt(env.getConfig("crawlingDepth", "0"));

@ -3,4 +3,5 @@ uptime=#[uptime]#
yourip=#[yourip]# yourip=#[yourip]#
yourtype=#[yourtype]# yourtype=#[yourtype]#
mytime=#[mytime]# mytime=#[mytime]#
message=#[message]#
#[seedlist]# #[seedlist]#

@ -65,13 +65,17 @@ import de.anomic.yacy.yacyVersion;
public final class hello { public final class hello {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) throws InterruptedException { 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; plasmaSwitchboard sb = (plasmaSwitchboard) env;
// return variable that accumulates replacements serverObjects prop = new serverObjects();
final serverObjects prop = new serverObjects(); prop.put("message", "none");
if ((post == null) || (env == null)) return prop; if ((post == null) || (env == null)) {
if (!yacyNetwork.authentifyRequest(post, env)) return prop; 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 iam = (String) post.get("iam", ""); // complete seed of the requesting peer
// final String mytime = (String) post.get(MYTIME, ""); // // 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 time // final Date remoteTime = yacyCore.parseUniversalDate((String) post.get(MYTIME)); // read remote time
if (seed.length() > yacySeed.maxsize) { if (seed.length() > yacySeed.maxsize) {
yacyCore.log.logInfo("hello/server: rejected contacting seed; too large (" + 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); final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key, false);
// System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString())); // 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(); // final String properTest = remoteSeed.isProper();
// The remote peer might not know its IP yet, so don't abort if the IP check fails // 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: // we easily know the caller's IP:
final String clientip = (String) header.get("CLIENTIP", "<unknown>"); // read an artificial header addendum final String clientip = (String) header.get("CLIENTIP", "<unknown>"); // read an artificial header addendum
InetAddress ias = serverDomains.dnsResolve(clientip); InetAddress 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 userAgent = (String) header.get(httpHeader.USER_AGENT, "<unknown>");
final String reportedip = remoteSeed.get(yacySeed.IP, ""); final String reportedip = remoteSeed.get(yacySeed.IP, "");
final String reportedPeerType = remoteSeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR); final String reportedPeerType = remoteSeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR);
@ -105,6 +116,7 @@ public final class hello {
if ((sb.isRobinsonMode()) && (!sb.isPublicRobinson())) { if ((sb.isRobinsonMode()) && (!sb.isPublicRobinson())) {
// if we are a robinson cluster, answer only if this client is known by our network definition // if we are a robinson cluster, answer only if this client is known by our network definition
prop.put("message", "I am robinson, I do not answer");
return prop; return prop;
} }
@ -212,6 +224,7 @@ public final class hello {
prop.putASIS("seedlist", seeds.toString()); prop.putASIS("seedlist", seeds.toString());
// return rewrite properties // return rewrite properties
prop.put("message", "ok " + seed.length());
return prop; return prop;
} }

@ -96,13 +96,11 @@ public final class yacyClient {
// this works of course only if we know the other peer's hash. // this works of course only if we know the other peer's hash.
HashMap result = null; HashMap result = null;
String salt; final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), null);
try { try {
// generate request // generate request
final serverObjects obj = new serverObjects(); post.putASIS("count", "20");
salt = yacyNetwork.enrichRequestPost(obj, plasmaSwitchboard.getSwitchboard(), null); post.putASIS("seed", yacyCore.seedDB.mySeed.genSeedStr(post.get("key", "")));
obj.putASIS("count", "20");
obj.putASIS("seed", yacyCore.seedDB.mySeed.genSeedStr(salt));
yacyCore.log.logFine("yacyClient.publishMySeed thread '" + Thread.currentThread().getName() + "' contacting peer at " + address); yacyCore.log.logFine("yacyClient.publishMySeed thread '" + Thread.currentThread().getName() + "' contacting peer at " + address);
// send request // send request
result = nxTools.table( result = nxTools.table(
@ -112,7 +110,7 @@ public final class yacyClient {
null, null,
null, null,
proxyConfig(), proxyConfig(),
obj, post,
null null
), "UTF-8" ), "UTF-8"
); );
@ -140,7 +138,7 @@ public final class yacyClient {
if (seed.length() > yacySeed.maxsize) { if (seed.length() > yacySeed.maxsize) {
yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")"); yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");
} else { } else {
otherPeer = yacySeed.genRemoteSeed(seed, salt, true); otherPeer = yacySeed.genRemoteSeed(seed, post.get("key", ""), true);
if (otherPeer == null || !otherPeer.hash.equals(otherHash)) { if (otherPeer == null || !otherPeer.hash.equals(otherHash)) {
yacyCore.log.logFine("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong"); yacyCore.log.logFine("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");
return -1; // no success return -1; // no success
@ -168,7 +166,7 @@ public final class yacyClient {
*/ */
if (!serverCore.portForwardingEnabled || otherPeerVersion >= yacyVersion.YACY_SUPPORTS_PORT_FORWARDING) { if (!serverCore.portForwardingEnabled || otherPeerVersion >= yacyVersion.YACY_SUPPORTS_PORT_FORWARDING) {
String mytype = (String) result.get(yacySeed.YOURTYPE); String mytype = (String) result.get(yacySeed.YOURTYPE);
if (mytype == null) { mytype = yacySeed.PEERTYPE_JUNIOR; } if (mytype == null) { mytype = ""; }
yacyAccessible accessible = new yacyAccessible(); yacyAccessible accessible = new yacyAccessible();
if (mytype.equals(yacySeed.PEERTYPE_SENIOR)||mytype.equals(yacySeed.PEERTYPE_PRINCIPAL)) { if (mytype.equals(yacySeed.PEERTYPE_SENIOR)||mytype.equals(yacySeed.PEERTYPE_PRINCIPAL)) {
accessible.IWasAccessed = true; 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 { } 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)) if (yacyCore.seedDB.mySeed.orVirgin().equals(yacySeed.PEERTYPE_VIRGIN))
yacyCore.seedDB.mySeed.put(yacySeed.PEERTYPE, mytype); yacyCore.seedDB.mySeed.put(yacySeed.PEERTYPE, mytype);
@ -226,7 +229,7 @@ public final class yacyClient {
if (seedStr.length() > yacySeed.maxsize) { if (seedStr.length() > yacySeed.maxsize) {
yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")"); yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")");
} else { } 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; return count;
@ -234,8 +237,7 @@ public final class yacyClient {
public static yacySeed querySeed(yacySeed target, String seedHash) { public static yacySeed querySeed(yacySeed target, String seedHash) {
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);
String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);
post.putASIS("object", "seed"); post.putASIS("object", "seed");
post.putASIS("env", seedHash); post.putASIS("env", seedHash);
@ -255,7 +257,7 @@ public final class yacyClient {
if (result == null || result.size() == 0) { return null; } if (result == null || result.size() == 0) { return null; }
//final Date remoteTime = yacyCore.parseUniversalDate((String) result.get(yacySeed.MYTIME)); // read remote time //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) { } catch (Exception e) {
yacyCore.log.logSevere("yacyClient.querySeed error:" + e.getMessage()); yacyCore.log.logSevere("yacyClient.querySeed error:" + e.getMessage());
return null; return null;
@ -264,8 +266,7 @@ public final class yacyClient {
public static int queryRWICount(yacySeed target, String wordHash) { public static int queryRWICount(yacySeed target, String wordHash) {
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);
post.putASIS("object", "rwicount"); post.putASIS("object", "rwicount");
post.putASIS("ttl", "0"); post.putASIS("ttl", "0");
post.putASIS("env", wordHash); post.putASIS("env", wordHash);
@ -297,8 +298,7 @@ public final class yacyClient {
if (yacyCore.seedDB.mySeed == null) return -1; if (yacyCore.seedDB.mySeed == null) return -1;
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);
post.putASIS("object", "lurlcount"); post.putASIS("object", "lurlcount");
post.putASIS("ttl", "0"); post.putASIS("ttl", "0");
post.putASIS("env", ""); post.putASIS("env", "");
@ -367,9 +367,8 @@ public final class yacyClient {
// duetime : maximum time that a peer should spent to create a result // duetime : maximum time that a peer should spent to create a result
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);
final String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash); post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(post.get("key", "")));
post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(salt));
post.put("count", Math.max(10, count)); post.put("count", Math.max(10, count));
post.putASIS("resource", ((global) ? "global" : "local")); post.putASIS("resource", ((global) ? "global" : "local"));
post.put("partitions", partitions); post.put("partitions", partitions);
@ -580,8 +579,7 @@ public final class yacyClient {
if (yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return null; } if (yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return null; }
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetHash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetHash);
post.putASIS("process", "permission"); post.putASIS("process", "permission");
// send request // send request
@ -609,10 +607,9 @@ public final class yacyClient {
// this post a message to the remote message board // this post a message to the remote message board
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetHash);
final String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetHash);
post.putASIS("process", "post"); 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); post.putASIS("subject", subject);
try { try {
post.putASIS("message", new String(message, "UTF-8")); 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) { public static HashMap transferPermission(String targetAddress, long filesize, String filename) {
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), null);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), null);
post.putASIS("process", "permission"); post.putASIS("process", "permission");
post.putASIS("purpose", "crcon"); post.putASIS("purpose", "crcon");
post.putASIS("filename", filename); post.putASIS("filename", filename);
@ -690,8 +686,7 @@ public final class yacyClient {
public static HashMap transferStore(String targetAddress, String access, String filename, byte[] file) { public static HashMap transferStore(String targetAddress, String access, String filename, byte[] file) {
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), null);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), null);
post.putASIS("process", "store"); post.putASIS("process", "store");
post.putASIS("purpose", "crcon"); post.putASIS("purpose", "crcon");
post.putASIS("filename", filename); post.putASIS("filename", filename);
@ -757,8 +752,7 @@ public final class yacyClient {
assert (yacyCore.seedDB.mySeed != target); assert (yacyCore.seedDB.mySeed != target);
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);
post.putASIS("process", "crawl"); post.putASIS("process", "crawl");
if (url.length == 1) { if (url.length == 1) {
post.putASIS("url", crypt.simpleEncode(url[0].toNormalform(true, true))); post.putASIS("url", crypt.simpleEncode(url[0].toNormalform(true, true)));
@ -830,14 +824,13 @@ public final class yacyClient {
*/ */
// prepare request // prepare request
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), target.hash);
String salt = yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), target.hash);
post.putASIS("process", process); post.putASIS("process", process);
post.putASIS("urlhash", ((entry == null) ? "" : entry.hash())); post.putASIS("urlhash", ((entry == null) ? "" : entry.hash()));
post.putASIS("result", result); post.putASIS("result", result);
post.putASIS("reason", reason); post.putASIS("reason", reason);
post.putASIS("wordh", wordhashes); 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 address // determining target address
final String address = target.getClusterAddress(); final String address = target.getClusterAddress();
@ -958,8 +951,7 @@ public final class yacyClient {
if (address == null) { return null; } if (address == null) { return null; }
// prepare post values // prepare post values
final serverObjects post = new serverObjects(); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetSeed.hash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetSeed.hash);
// enabling gzip compression for post request body // enabling gzip compression for post request body
if ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) { if ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) {
@ -1025,8 +1017,7 @@ public final class yacyClient {
if (address == null) { return null; } if (address == null) { return null; }
// prepare post values // prepare post values
final serverObjects post = new serverObjects(5+urls.length); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetSeed.hash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetSeed.hash);
// enabling gzip compression for post request body // enabling gzip compression for post request body
if ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) { if ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) {
@ -1077,8 +1068,7 @@ public final class yacyClient {
public static HashMap getProfile(yacySeed targetSeed) { public static HashMap getProfile(yacySeed targetSeed) {
// this post a message to the remote message board // this post a message to the remote message board
final serverObjects post = new serverObjects(2); final serverObjects post = yacyNetwork.basicRequestPost(plasmaSwitchboard.getSwitchboard(), targetSeed.hash);
yacyNetwork.enrichRequestPost(post, plasmaSwitchboard.getSwitchboard(), targetSeed.hash);
String address = targetSeed.getClusterAddress(); String address = targetSeed.getClusterAddress();
if (address == null) { address = "localhost:8080"; } if (address == null) { address = "localhost:8080"; }

@ -67,9 +67,10 @@ public class yacyNetwork {
return false; 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 // put in all the essentials for routing and network authentification
// generate a session key // generate a session key
serverObjects post = new serverObjects();
final String salt = crypt.randomSalt(); final String salt = crypt.randomSalt();
post.put("key", salt); post.put("key", salt);
@ -96,7 +97,7 @@ public class yacyNetwork {
} }
} }
return salt; return post;
} }
} }

@ -86,7 +86,7 @@ import de.anomic.tools.crypt;
public class yacySeed { public class yacySeed {
public static final int maxsize = 2048; public static final int maxsize = 4096;
/** /**
* <b>substance</b> "sI" (send index/words) * <b>substance</b> "sI" (send index/words)
*/ */

Loading…
Cancel
Save