Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
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
orbiter3b578a28efc2
diff --git a/build.xml b/build.xmlindex efa447228..f411ca417 100644--- a/build.xml+++ b/build.xml@@ -749,6 +749,7 @@<delete dir="${release_mac}" failonerror="false" verbose="false" /></target>+ <!-- to use the deb command the following debian packages must be installed: dpkg-dev debhelper m4 --><target name="deb" depends="init" description="Creates a debian package"><!-- replacing the old with the new revision number --><replaceregexp file="debian/changelog"diff --git a/htroot/Status.java b/htroot/Status.javaindex 7e6e456ec..6b0aaab1d 100644--- a/htroot/Status.java+++ b/htroot/Status.java@@ -94,8 +94,6 @@ public class Status {}redirect = true;} else if (post.containsKey("ResetTraffic")) {-// ByteCountInputStream.resetCount();-// ByteCountOutputStream.resetCount();ByteCount.resetCount();redirect = true;} else if (post.containsKey("popup")) {@@ -153,7 +151,6 @@ public class Status {}-// version information//final String versionstring = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1"));final String versionstring = yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex 2a8df04e5..61ff899b5 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -91,7 +91,7 @@ public final class hello {}yacySeed remoteSeed;try {- remoteSeed = yacySeed.genRemoteSeed(seed, key, true);+ remoteSeed = yacySeed.genRemoteSeed(seed, key, true, ias.getHostAddress());} catch (IOException e) {yacyCore.log.logInfo("hello/server: bad seed: " + e.getMessage() + ", time_dnsResolve=" + time_dnsResolve);prop.put("message", "bad seed: " + e.getMessage());diff --git a/htroot/yacy/message.java b/htroot/yacy/message.javaindex 849d52e9d..c90e43b0c 100644--- a/htroot/yacy/message.java+++ b/htroot/yacy/message.java@@ -30,11 +30,13 @@import java.io.File;import java.io.IOException;import java.io.PrintWriter;+import java.net.InetAddress;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Locale;import net.yacy.cora.document.UTF8;+import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;import net.yacy.kelondro.logging.Log;@@ -67,7 +69,9 @@ public final class message {final String process = post.get("process", "permission");final String key = post.get("key", "");-+ final String clientip = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "<unknown>"); // 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 timeyacySeed 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 seedsreturn prop;diff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex 0669e373c..e219a9f79 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -180,7 +180,7 @@ public final class search {// store accessing peeryacySeed 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.javaindex 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.javaindex 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.javaindex 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<yacySeed>, Comparator<yac* @return the IP or null*/public final String getIP() {- String ip = get(yacySeed.IP, "localhost");- return (ip == null || ip.length() == 0) ? "localhost" : ip;+ String ip = get(yacySeed.IP, "127.0.0.1");+ return (ip == null || ip.length() == 0) ? "127.0.0.1" : ip;}/*** try to get the peertype<br>@@ -475,7 +475,7 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac*/public final String getPublicAddress() {String ip = this.getIP();- if (ip == null || ip.length() < 8 || ip.length() > 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<yacySeed>, Comparator<yacreturn UTF8.getBytes(hash);}- public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed) throws IOException {+ public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed, String patchIP) 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);@@ -790,7 +790,14 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yacfinal yacySeed resultSeed = new yacySeed(hash, dna);// check semantics of content- final String testResult = resultSeed.isProper(ownSeed);+ String testResult = resultSeed.isProper(ownSeed);+ if (testResult != null && patchIP != null) {+ // in case that this proper-Test fails and a patchIP is given+ // then replace the given IP in the resultSeed with given patchIP+ // this is done if a remote peer reports its IP in a wrong way (maybe fraud attempt)+ resultSeed.setIP(patchIP);+ testResult = resultSeed.isProper(ownSeed);+ }if (testResult != null) throw new IOException("seed is not proper (" + testResult + "): " + resultSeed);// seed ok@@ -883,7 +890,7 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yacfinal char[] b = new char[(int) f.length()];fr.read(b, 0, b.length);fr.close();- final yacySeed mySeed = genRemoteSeed(new String(b), null, true);+ final yacySeed mySeed = genRemoteSeed(new String(b), null, true, null);assert mySeed != null; // in case of an error, an IOException is thrownmySeed.dna.put(yacySeed.IP, ""); // set own IP as unknownreturn mySeed;diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.javaindex 7cb1fa8c1..74a63df67 100644--- a/source/de/anomic/yacy/yacySeedDB.java+++ b/source/de/anomic/yacy/yacySeedDB.java@@ -260,6 +260,10 @@ public final class yacySeedDB implements AlternativeDomainNames {if (this.mySeed == null) {if (this.sizeConnected() == 0) try {Thread.sleep(5000);} catch (final InterruptedException e) {} // wait for initinitMySeed();+ // check if my seed has an IP assigned+ if (this.myIP() == null || this.myIP().length() == 0) {+ this.mySeed.setIP(Domains.myPublicLocalIP().getHostAddress());+ }}return this.mySeed;}