Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
better protection against fraud peers
orbiterd0c32c6aebd7
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.javaindex c4242ad3a..11662a86b 100644--- a/source/de/anomic/http/httpd.java+++ b/source/de/anomic/http/httpd.java@@ -53,7 +53,6 @@ import java.io.PrintStream;import java.lang.reflect.Constructor;import java.net.InetAddress;import java.net.MalformedURLException;-import java.net.SocketTimeoutException;import java.util.Arrays;import java.util.Date;import java.util.HashMap;diff --git a/source/de/anomic/yacy/yacyPeerActions.java b/source/de/anomic/yacy/yacyPeerActions.javaindex 1038713b0..e3ae00b84 100644--- a/source/de/anomic/yacy/yacyPeerActions.java+++ b/source/de/anomic/yacy/yacyPeerActions.java@@ -280,21 +280,30 @@ public class yacyPeerActions {if (seed == null) {yacyCore.log.logSevere("connect: WRONG seed (NULL)");return false;- } else if ((error = seed.isProper()) != null) {+ }+ if ((error = seed.isProper()) != null) {yacyCore.log.logSevere("connect: WRONG seed (" + seed.getName() + "/" + seed.hash + "): " + error);return false;- } else if ((seedDB.mySeed != null) && (seed.hash.equals(seedDB.mySeed.hash))) {+ }+ if ((seedDB.mySeed != null) && (seed.hash.equals(seedDB.mySeed.hash))) {yacyCore.log.logInfo("connect: SELF reference " + seed.getAddress());return false;- } else {- String peerType = seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);+ }+ String peerType = seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);++ if ((peerType.equals(yacySeed.PEERTYPE_VIRGIN)) || (peerType.equals(yacySeed.PEERTYPE_JUNIOR))) {// reject unqualified seeds- if ((peerType.equals(yacySeed.PEERTYPE_VIRGIN)) || (peerType.equals(yacySeed.PEERTYPE_JUNIOR))) {- yacyCore.log.logFine("connect: rejecting NOT QUALIFIED " + peerType + " seed " + seed.getName());- return false;- }+ yacyCore.log.logFine("connect: rejecting NOT QUALIFIED " + peerType + " seed " + seed.getName());+ return false;+ }- // we may store that seed, but still have different cases+ yacySeed doubleSeed = seedDB.lookupByIP(seed.getInetAddress(), true, false, false);+ if ((doubleSeed != null) && (doubleSeed.getPort() == seed.getPort()) && (!(doubleSeed.hash.equals(seed.hash)))) {+ // a user frauds with his peer different peer hashes+ yacyCore.log.logFine("connect: rejecting FRAUD (double hashes " + doubleSeed.hash + "/" + seed.hash + " on same port " + seed.getPort() + ") peer " + seed.getName());+ return false;+ }+if (seed.get(yacySeed.LASTSEEN, "").length() < 14) {// hack for peers that do not have a LastSeen dateseed.put(yacySeed.LASTSEEN, "20040101000000");@@ -405,7 +414,6 @@ public class yacyPeerActions {return true;}}- }}private final void disconnectPeer(yacySeed seed) {diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.javaindex bbf54c97c..585f971ee 100644--- a/source/de/anomic/yacy/yacySeed.java+++ b/source/de/anomic/yacy/yacySeed.java@@ -63,6 +63,8 @@ import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;+import java.net.InetAddress;+import java.net.UnknownHostException;import java.util.Date;import java.util.HashMap;import java.util.Map;@@ -344,7 +346,8 @@ public class yacySeed {}public final String getAddress() {- String ip = (String) this.dna.get(yacySeed.IP);+ // returns an ip:port string+ String ip = (String) this.dna.get(yacySeed.IP);if (ip == null) { return null; }if (ip.length() < 8) { return null; } // 10.0.0.0// if (ip.equals(yacyCore.seedDB.mySeed.dna.get(yacySeed.IP))) ip = "127.0.0.1";@@ -357,6 +360,33 @@ public class yacySeed {return ip + ":" + port;}+ public final InetAddress getInetAddress() {+ // returns the ip address+ String ip = (String) this.dna.get(yacySeed.IP);+ if (ip == null) return null;+ if (ip.length() < 8) return null;+ String[] ips = ip.split("\\.");+ if (ips.length != 4) return null;+ byte[] ipb = new byte[4];+ ipb[0] = (byte) Integer.parseInt(ips[0]);+ ipb[1] = (byte) Integer.parseInt(ips[1]);+ ipb[2] = (byte) Integer.parseInt(ips[2]);+ ipb[3] = (byte) Integer.parseInt(ips[3]);+ try {+ return InetAddress.getByAddress(ipb);+ } catch (UnknownHostException e) {+ return null;+ }+ }++ public final int getPort() {+ final String port = (String) this.dna.get(yacySeed.PORT);+ if (port == null) return -1;+ if (port.length() < 2) return -1;++ return Integer.parseInt(port);+ }+public final long getUTCDiff() {String utc = (String) this.dna.get(yacySeed.UTC);if (utc == null) { utc = "+0130"; }diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.javaindex 2c63a2b74..a82b8a0fe 100644--- a/source/de/anomic/yacy/yacySeedDB.java+++ b/source/de/anomic/yacy/yacySeedDB.java@@ -526,6 +526,7 @@ public final class yacySeedDB {boolean lookupPotential) {+ if (peerIP == null) return null;yacySeed seed = null;// local peer?