From 3b578a28efc2d819dd6439e0575967cdf936ef86 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 29 Apr 2011 10:58:12 +0000 Subject: [PATCH] some patches to prevent that empty or bad IP information is broadcasted - on client-side: fix bad IP reports from remote Peers by replacing their reported IP with their server IP if the reported IP is bad, broken or disallowed - on server-side: the same during a peer ping (here the ping'ed server acts also as client during the back-ping) and also when receiving a message or a search where the client sends also its seed. Here the IP is replaced by the client IP if the reported IP is broken or bad git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7687 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- build.xml | 1 + htroot/Status.java | 3 --- htroot/yacy/hello.java | 2 +- htroot/yacy/message.java | 8 ++++++-- htroot/yacy/search.java | 2 +- source/de/anomic/search/Switchboard.java | 2 +- source/de/anomic/yacy/yacyClient.java | 17 ++++++++++++++--- source/de/anomic/yacy/yacySeed.java | 19 +++++++++++++------ source/de/anomic/yacy/yacySeedDB.java | 4 ++++ 9 files changed, 41 insertions(+), 17 deletions(-) diff --git a/build.xml b/build.xml index efa447228..f411ca417 100644 --- a/build.xml +++ b/build.xml @@ -749,6 +749,7 @@ + "); // read an artificial header addendum + final InetAddress ias = Domains.dnsResolve(clientip); + final int messagesize = 10240; final int attachmentsize = 0; @@ -110,7 +114,7 @@ public final class message { //Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time yacySeed otherSeed; try { - otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false); + otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false, ias.getHostAddress()); } catch (IOException e) { prop.put("response", "-1"); // don't accept messages for bad seeds return prop; diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java index 0669e373c..e219a9f79 100644 --- a/htroot/yacy/search.java +++ b/htroot/yacy/search.java @@ -180,7 +180,7 @@ public final class search { // store accessing peer yacySeed remoteSeed; try { - remoteSeed = yacySeed.genRemoteSeed(oseed, key, false); + remoteSeed = yacySeed.genRemoteSeed(oseed, key, false, client); } catch (IOException e) { yacyCore.log.logInfo("yacy.search: access with bad seed: " + e.getMessage()); remoteSeed = null; diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java index 3b52f113a..24be89906 100644 --- a/source/de/anomic/search/Switchboard.java +++ b/source/de/anomic/search/Switchboard.java @@ -2661,7 +2661,7 @@ public final class Switchboard extends serverSwitch { lc = 0; while (enu.hasNext()) { try { - ys = yacySeed.genRemoteSeed(enu.next(), null, false); + ys = yacySeed.genRemoteSeed(enu.next(), null, false, null); if ((ys != null) && (!peers.mySeedIsDefined() || !peers.mySeed().hash.equals(ys.hash))) { final long lastseen = Math.abs((System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60); diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java index bb90e8d90..c82f81cd4 100644 --- a/source/de/anomic/yacy/yacyClient.java +++ b/source/de/anomic/yacy/yacyClient.java @@ -63,6 +63,7 @@ import net.yacy.cora.document.RSSMessage; import net.yacy.cora.document.RSSReader; import net.yacy.cora.document.UTF8; import net.yacy.cora.protocol.ClientIdentification; +import net.yacy.cora.protocol.Domains; import net.yacy.cora.protocol.http.HTTPClient; import net.yacy.cora.services.federated.opensearch.SRURSSConnector; import net.yacy.kelondro.data.meta.URIMetadataRow; @@ -174,7 +175,10 @@ public final class yacyClient { yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")"); } else { try { - otherPeer = yacySeed.genRemoteSeed(seed, salt, false); + int p = address.indexOf(':'); + if (p < 0) return -1; + String host = Domains.dnsResolve(address.substring(0, p)).getHostAddress(); + otherPeer = yacySeed.genRemoteSeed(seed, salt, false, host); if (!otherPeer.hash.equals(otherHash)) { yacyCore.log.logInfo("yacyClient.hello: consistency error: otherPeer.hash = " + otherPeer.hash + ", otherHash = " + otherHash); return -1; // no success @@ -248,7 +252,14 @@ public final class yacyClient { yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")"); } else { try { - s = yacySeed.genRemoteSeed(seedStr, salt, false); + if (i == 1) { + int p = address.indexOf(':'); + if (p < 0) return -1; + String host = Domains.dnsResolve(address.substring(0, p)).getHostAddress(); + s = yacySeed.genRemoteSeed(seedStr, salt, false, host); + } else { + s = yacySeed.genRemoteSeed(seedStr, salt, false, null); + } if (peerActions.peerArrival(s, (i == 1))) count++; } catch (IOException e) { yacyCore.log.logInfo("hello/client: rejected contacting seed; bad (" + e.getMessage() + ")"); @@ -272,7 +283,7 @@ public final class yacyClient { if (result == null || result.isEmpty()) { return null; } //final Date remoteTime = yacyCore.parseUniversalDate((String) result.get(yacySeed.MYTIME)); // read remote time - return yacySeed.genRemoteSeed(result.get("response"), salt, false); + return yacySeed.genRemoteSeed(result.get("response"), salt, false, target.getIP()); } catch (final Exception e) { yacyCore.log.logWarning("yacyClient.querySeed error:" + e.getMessage()); return null; diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index 285c92bfd..ae77ec4f4 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -295,8 +295,8 @@ public class yacySeed implements Cloneable, Comparable, Comparator @@ -475,7 +475,7 @@ public class yacySeed implements Cloneable, Comparable, Comparator 60) ip = "localhost"; + if (ip == null || ip.length() < 8 || ip.length() > 60) ip = "127.0.0.1"; final String port = this.dna.get(yacySeed.PORT); if (port == null || port.length() < 2 || port.length() > 5) return null; @@ -772,7 +772,7 @@ public class yacySeed implements Cloneable, Comparable, Comparator, Comparator