better protection against fraud peers

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3104 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent a44ef51a8b
commit d0c32c6aeb

@ -53,7 +53,6 @@ import java.io.PrintStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;

@ -280,21 +280,30 @@ public class yacyPeerActions {
if (seed == null) { if (seed == null) {
yacyCore.log.logSevere("connect: WRONG seed (NULL)"); yacyCore.log.logSevere("connect: WRONG seed (NULL)");
return false; return false;
} else if ((error = seed.isProper()) != null) { }
if ((error = seed.isProper()) != null) {
yacyCore.log.logSevere("connect: WRONG seed (" + seed.getName() + "/" + seed.hash + "): " + error); yacyCore.log.logSevere("connect: WRONG seed (" + seed.getName() + "/" + seed.hash + "): " + error);
return false; 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()); yacyCore.log.logInfo("connect: SELF reference " + seed.getAddress());
return false; return false;
} else { }
String peerType = seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN); String peerType = seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);
// reject unqualified seeds
if ((peerType.equals(yacySeed.PEERTYPE_VIRGIN)) || (peerType.equals(yacySeed.PEERTYPE_JUNIOR))) { if ((peerType.equals(yacySeed.PEERTYPE_VIRGIN)) || (peerType.equals(yacySeed.PEERTYPE_JUNIOR))) {
// reject unqualified seeds
yacyCore.log.logFine("connect: rejecting NOT QUALIFIED " + peerType + " seed " + seed.getName()); yacyCore.log.logFine("connect: rejecting NOT QUALIFIED " + peerType + " seed " + seed.getName());
return false; 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) { if (seed.get(yacySeed.LASTSEEN, "").length() < 14) {
// hack for peers that do not have a LastSeen date // hack for peers that do not have a LastSeen date
seed.put(yacySeed.LASTSEEN, "20040101000000"); seed.put(yacySeed.LASTSEEN, "20040101000000");
@ -406,7 +415,6 @@ public class yacyPeerActions {
} }
} }
} }
}
private final void disconnectPeer(yacySeed seed) { private final void disconnectPeer(yacySeed seed) {
// we do this if we did not get contact with the other peer // we do this if we did not get contact with the other peer

@ -63,6 +63,8 @@ import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -344,6 +346,7 @@ public class yacySeed {
} }
public final String getAddress() { public final String getAddress() {
// returns an ip:port string
String ip = (String) this.dna.get(yacySeed.IP); String ip = (String) this.dna.get(yacySeed.IP);
if (ip == null) { return null; } if (ip == null) { return null; }
if (ip.length() < 8) { return null; } // 10.0.0.0 if (ip.length() < 8) { return null; } // 10.0.0.0
@ -357,6 +360,33 @@ public class yacySeed {
return ip + ":" + port; 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() { public final long getUTCDiff() {
String utc = (String) this.dna.get(yacySeed.UTC); String utc = (String) this.dna.get(yacySeed.UTC);
if (utc == null) { utc = "+0130"; } if (utc == null) { utc = "+0130"; }

@ -526,6 +526,7 @@ public final class yacySeedDB {
boolean lookupPotential boolean lookupPotential
) { ) {
if (peerIP == null) return null;
yacySeed seed = null; yacySeed seed = null;
// local peer? // local peer?

Loading…
Cancel
Save