fix for wrong date (Lotus-1 Peer)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3111 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 18 years ago
parent 08ac4c5ed0
commit 9659c004c3

@ -273,23 +273,23 @@ public class yacyPeerActions {
return supsee;
}
final synchronized private boolean connectPeer(yacySeed seed, boolean direct) {
private synchronized boolean connectPeer(yacySeed seed, boolean direct) {
// store a remote peer's seed
// returns true if the peer is new and previously unknown
String error;
if (seed == null) {
yacyCore.log.logSevere("connect: WRONG seed (NULL)");
return false;
}
if ((error = seed.isProper()) != null) {
final String error = seed.isProper();
if (error != null) {
yacyCore.log.logSevere("connect: WRONG seed (" + seed.getName() + "/" + seed.hash + "): " + error);
return false;
}
if ((seedDB.mySeed != null) && (seed.hash.equals(seedDB.mySeed.hash))) {
if ((this.seedDB.mySeed != null) && (seed.hash.equals(this.seedDB.mySeed.hash))) {
yacyCore.log.logInfo("connect: SELF reference " + seed.getAddress());
return false;
}
String peerType = seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);
final String peerType = seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);
if ((peerType.equals(yacySeed.PEERTYPE_VIRGIN)) || (peerType.equals(yacySeed.PEERTYPE_JUNIOR))) {
// reject unqualified seeds
@ -297,21 +297,22 @@ public class yacyPeerActions {
return false;
}
yacySeed doubleSeed = seedDB.lookupByIP(seed.getInetAddress(), true, false, false);
final yacySeed doubleSeed = this.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
seed.put(yacySeed.LASTSEEN, "20040101000000");
yacyCore.log.logFine("connect: reset wrong date (" + seed.getName() + "/" + seed.hash + ")");
}
// connection time
long nowUTC0Time = System.currentTimeMillis(); // is better to have this value in a variable for debugging
long ctimeUTC0 = seed.getLastSeenTime();
final long nowUTC0Time = System.currentTimeMillis(); // is better to have this value in a variable for debugging
final long ctimeUTC0 = seed.getLastSeenTime();
// maybe correct it slightly
/*
* if (ctime > yacyCore.universalTime()) { ctime = ((2 * ctime) +
@ -327,7 +328,7 @@ public class yacyPeerActions {
// disconnection time
long dtimeUTC0;
yacySeed disconnectedSeed = seedDB.getDisconnected(seed.hash);
final yacySeed disconnectedSeed = seedDB.getDisconnected(seed.hash);
if (disconnectedSeed == null) {
dtimeUTC0 = 0; // never disconnected: virtually disconnected maximum time ago
} else {
@ -359,7 +360,7 @@ public class yacyPeerActions {
// has been disconnected then we compare the dates:
// if the new peer has a LastSeen date, and that date is before
// the disconnection date, then we ignore the new peer
if (!(direct)) {
if (!direct) {
if (ctimeUTC0 < dtimeUTC0) {
// the disconnection was later, we reject the connection
yacyCore.log.logFine("connect: rejecting disconnected peer '" + seed.getName() + "' from " + seed.getAddress());
@ -369,16 +370,16 @@ public class yacyPeerActions {
// this is a return of a lost peer
yacyCore.log.logFine("connect: returned KNOWN " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
seedDB.addConnected(seed);
this.seedDB.addConnected(seed);
return true;
} else {
yacySeed connectedSeed = seedDB.getConnected(seed.hash);
final yacySeed connectedSeed = this.seedDB.getConnected(seed.hash);
if (connectedSeed != null) {
// the seed is known: this is an update
try {
// if the old LastSeen date is later then the other
// info, then we reject the info
if ((ctimeUTC0 < (yacyCore.parseUniversalDate(connectedSeed.get(yacySeed.LASTSEEN, "20040101000000")).getTime() - connectedSeed.getUTCDiff() + serverDate.UTCDiff())) && (!(direct))) {
if ((ctimeUTC0 < (yacyCore.parseUniversalDate(connectedSeed.get(yacySeed.LASTSEEN, "20040101000000")).getTime() - connectedSeed.getUTCDiff() + serverDate.UTCDiff())) && (!direct)) {
yacyCore.log.logFine("connect: rejecting old info about peer '" + seed.getName() + "'");
return false;
}
@ -398,7 +399,7 @@ public class yacyPeerActions {
return true;
} else {
// the seed is new
if (seed.get(yacySeed.IP, "127.0.0.1").equals(seedDB.mySeed.get(yacySeed.IP, "127.0.0.1"))) {
if (seed.get(yacySeed.IP, "127.0.0.1").equals(this.seedDB.mySeed.get(yacySeed.IP, "127.0.0.1"))) {
// seed from the same IP as the calling client: can be
// the case if there runs another one over a NAT
yacyCore.log.logFine("connect: saved NEW seed (myself IP) " + seed.getAddress());
@ -407,10 +408,10 @@ public class yacyPeerActions {
yacyCore.log.logFine("connect: saved NEW " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
}
if (peerType.equals(yacySeed.PEERTYPE_SENIOR))
seniorConnects++; // update statistics
this.seniorConnects++; // update statistics
if (peerType.equals(yacySeed.PEERTYPE_PRINCIPAL))
principalConnects++; // update statistics
seedDB.addConnected(seed);
this.principalConnects++; // update statistics
this.seedDB.addConnected(seed);
return true;
}
}

Loading…
Cancel
Save