From 25a8e55bc9632be7c39c2928e9a2a5081ca582dc Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 26 Oct 2010 15:00:22 +0000 Subject: [PATCH] more logging about bad seeds git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7275 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/yacy/hello.java | 10 +++++++++- htroot/yacy/message.java | 8 +++++++- htroot/yacy/search.java | 9 ++++++++- source/de/anomic/search/Switchboard.java | 18 +++++++++++------- source/de/anomic/yacy/yacyClient.java | 23 +++++++++++++++++------ source/de/anomic/yacy/yacySeed.java | 17 ++++++++--------- 6 files changed, 60 insertions(+), 25 deletions(-) diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.java index 8b7d8eb90..572e4dc4d 100644 --- a/htroot/yacy/hello.java +++ b/htroot/yacy/hello.java @@ -27,6 +27,7 @@ // javac -classpath .:../../classes hello.java // if the shell's current path is HTROOT +import java.io.IOException; import java.net.InetAddress; import java.util.ConcurrentModificationException; import java.util.Iterator; @@ -86,7 +87,14 @@ public final class hello { prop.put("message", "your seed is too long (" + seed.length() + ")"); return prop; } - final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key, true); + yacySeed remoteSeed; + try { + remoteSeed = yacySeed.genRemoteSeed(seed, key, true); + } catch (IOException e) { + yacyCore.log.logInfo("hello/server: bad seed: " + e.getMessage()); + prop.put("message", "bad seed: " + e.getMessage()); + return prop; + } // System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString())); if (remoteSeed == null || remoteSeed.hash == null) { diff --git a/htroot/yacy/message.java b/htroot/yacy/message.java index bd03f5073..81f26c677 100644 --- a/htroot/yacy/message.java +++ b/htroot/yacy/message.java @@ -108,7 +108,13 @@ public final class message { return prop; } //Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time - final yacySeed otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false); + yacySeed otherSeed; + try { + otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false); + } catch (IOException e) { + prop.put("response", "-1"); // don't accept messages for bad seeds + return prop; + } String subject = crypt.simpleDecode(post.get("subject", ""), key); // message's subject String message = crypt.simpleDecode(post.get("message", ""), key); // message body diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java index 55ac52929..64b206263 100644 --- a/htroot/yacy/search.java +++ b/htroot/yacy/search.java @@ -28,6 +28,7 @@ // javac -classpath .:../../Classes search.java // if the shell's current path is htroot/yacy +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; @@ -173,7 +174,13 @@ public final class search { final HandleSet abstractSet = (abstracts.length() == 0 || abstracts.equals("auto")) ? null : QueryParams.hashes2Set(abstracts); // store accessing peer - final yacySeed remoteSeed = yacySeed.genRemoteSeed(oseed, key, false); + yacySeed remoteSeed; + try { + remoteSeed = yacySeed.genRemoteSeed(oseed, key, false); + } catch (IOException e) { + yacyCore.log.logInfo("yacy.search: access with bad seed: " + e.getMessage()); + remoteSeed = null; + } if (sb.peers == null) { yacyCore.log.logSevere("yacy.search: seed cache not initialized"); } else { diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java index 4f0ae564f..1445b5417 100644 --- a/source/de/anomic/search/Switchboard.java +++ b/source/de/anomic/search/Switchboard.java @@ -2463,13 +2463,17 @@ public final class Switchboard extends serverSwitch { enu = FileUtils.strings(content); lc = 0; while (enu.hasNext()) { - ys = yacySeed.genRemoteSeed(enu.next(), null, false); - if ((ys != null) && - ((!peers.mySeedIsDefined()) || !peers.mySeed().hash.equals(ys.hash))) { - if (peers.peerActions.connectPeer(ys, false)) lc++; - //seedDB.writeMap(ys.hash, ys.getMap(), "init"); - //System.out.println("BOOTSTRAP: received peer " + ys.get(yacySeed.NAME, "anonymous") + "/" + ys.getAddress()); - //lc++; + try { + ys = yacySeed.genRemoteSeed(enu.next(), null, false); + if ((ys != null) && + ((!peers.mySeedIsDefined()) || !peers.mySeed().hash.equals(ys.hash))) { + if (peers.peerActions.connectPeer(ys, false)) lc++; + //seedDB.writeMap(ys.hash, ys.getMap(), "init"); + //System.out.println("BOOTSTRAP: received peer " + ys.get(yacySeed.NAME, "anonymous") + "/" + ys.getAddress()); + //lc++; + } + } catch (IOException e) { + yacyCore.log.logInfo("BOOTSTRAP: bad seed: " + e.getMessage()); } } yacyCore.log.logInfo("BOOTSTRAP: " + lc + " seeds from seed-list URL " + seedListFileURL + ", AGE=" + (header.age() / 3600000) + "h"); diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java index 16cafeac8..ee8689788 100644 --- a/source/de/anomic/yacy/yacyClient.java +++ b/source/de/anomic/yacy/yacyClient.java @@ -165,11 +165,16 @@ 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, false); - if (otherPeer == null || !otherPeer.hash.equals(otherHash)) { - yacyCore.log.logInfo("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null) ? ("seed=" + seed) : otherPeer.getName()) + "' wrong"); - return -1; // no success - } + try { + otherPeer = yacySeed.genRemoteSeed(seed, salt, false); + if (!otherPeer.hash.equals(otherHash)) { + yacyCore.log.logInfo("yacyClient.publishMySeed: consistency error: otherPeer.hash = " + otherPeer.hash + ", otherHash = " + otherHash); + return -1; // no success + } + } catch (IOException e) { + yacyCore.log.logInfo("yacyClient.publishMySeed: consistency error: other seed bad:" + e.getMessage() + ", seed=" + seed); + return -1; // no success + } } } @@ -227,13 +232,19 @@ public final class yacyClient { int i = 0; int count = 0; String seedStr; + yacySeed s; while ((seedStr = result.get("seed" + i++)) != null) { // integrate new seed into own database // the first seed, "seed0" is the seed of the responding peer if (seedStr.length() > yacySeed.maxsize) { yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")"); } else { - if (peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, salt, false), (i == 1))) count++; + try { + s = yacySeed.genRemoteSeed(seedStr, salt, false); + if (peerActions.peerArrival(s, (i == 1))) count++; + } catch (IOException e) { + yacyCore.log.logInfo("hello/client: rejected contacting seed; bad (" + e.getMessage() + ")"); + } } } return count; diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index 9f717d150..9a8cc404c 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -764,27 +764,26 @@ public class yacySeed implements Cloneable { return hash.getBytes(); } - public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed) { + public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed) throws IOException { // this method is used to convert the external representation of a seed into a seed object // yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key); // check protocol and syntax of seed - if (seedStr == null || seedStr.length() == 0) return null; + if (seedStr == null) throw new IOException("seedStr == null"); + if (seedStr.length() == 0) throw new IOException("seedStr.length() == 0"); final String seed = crypt.simpleDecode(seedStr, key); - if (seed == null || seed.length() == 0) return null; + if (seed == null) throw new IOException("seed == null"); + if (seed.length() == 0) throw new IOException("seed.length() == 0"); // extract hash final ConcurrentHashMap dna = MapTools.string2map(seed, ","); final String hash = dna.remove(yacySeed.HASH); - if (hash == null) return null; + if (hash == null) throw new IOException("hash == null"); final yacySeed resultSeed = new yacySeed(hash, dna); // check semantics of content final String testResult = resultSeed.isProper(ownSeed); - if (testResult != null) { - if (yacyCore.log.isFinest()) yacyCore.log.logFinest("seed is not proper (" + testResult + "): " + resultSeed); - return null; - } + if (testResult != null) throw new IOException("seed is not proper (" + testResult + "): " + resultSeed); // seed ok return resultSeed; @@ -874,7 +873,7 @@ public class yacySeed implements Cloneable { fr.read(b, 0, b.length); fr.close(); final yacySeed mySeed = genRemoteSeed(new String(b), null, true); - if (mySeed == null) return null; + assert mySeed != null; // in case of an error, an IOException is thrown mySeed.dna.put(yacySeed.IP, ""); // set own IP as unknown return mySeed; }