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; 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 // store a remote peer's seed
// returns true if the peer is new and previously unknown // returns true if the peer is new and previously unknown
String error;
if (seed == null) { if (seed == null) {
yacyCore.log.logSevere("connect: WRONG seed (NULL)"); yacyCore.log.logSevere("connect: WRONG seed (NULL)");
return false; 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); yacyCore.log.logSevere("connect: WRONG seed (" + seed.getName() + "/" + seed.hash + "): " + error);
return false; 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()); yacyCore.log.logInfo("connect: SELF reference " + seed.getAddress());
return false; 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))) { if ((peerType.equals(yacySeed.PEERTYPE_VIRGIN)) || (peerType.equals(yacySeed.PEERTYPE_JUNIOR))) {
// reject unqualified seeds // reject unqualified seeds
@ -297,123 +297,124 @@ public class yacyPeerActions {
return false; 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)))) { if ((doubleSeed != null) && (doubleSeed.getPort() == seed.getPort()) && (!(doubleSeed.hash.equals(seed.hash)))) {
// a user frauds with his peer different peer hashes // 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()); yacyCore.log.logFine("connect: rejecting FRAUD (double hashes " + doubleSeed.hash + "/" + seed.hash + " on same port " + seed.getPort() + ") peer " + seed.getName());
return false; 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");
} yacyCore.log.logFine("connect: reset wrong date (" + seed.getName() + "/" + seed.hash + ")");
}
// connection time // connection time
long nowUTC0Time = System.currentTimeMillis(); // is better to have this value in a variable for debugging final long nowUTC0Time = System.currentTimeMillis(); // is better to have this value in a variable for debugging
long ctimeUTC0 = seed.getLastSeenTime(); final long ctimeUTC0 = seed.getLastSeenTime();
// maybe correct it slightly // maybe correct it slightly
/* /*
* if (ctime > yacyCore.universalTime()) { ctime = ((2 * ctime) + * if (ctime > yacyCore.universalTime()) { ctime = ((2 * ctime) +
* yacyCore.universalTime()) / 3; seed.put(yacySeed.LASTSEEN, * yacyCore.universalTime()) / 3; seed.put(yacySeed.LASTSEEN,
* yacyCore.shortFormatter.format(new Date(ctime))); } * yacyCore.shortFormatter.format(new Date(ctime))); }
*/ */
if (Math.abs(nowUTC0Time - ctimeUTC0) > 60 * 60 * 24 * 1000) { if (Math.abs(nowUTC0Time - ctimeUTC0) > 60 * 60 * 24 * 1000) {
// the new connection is out-of-age, we reject the connection // the new connection is out-of-age, we reject the connection
yacyCore.log.logFine("connect: rejecting out-dated peer '" + seed.getName() + "' from " + seed.getAddress() + "; nowUTC0=" + nowUTC0Time + ", seedUTC0=" + ctimeUTC0 + ", TimeDiff=" + serverDate.intervalToString(Math.abs(nowUTC0Time - ctimeUTC0))); yacyCore.log.logFine("connect: rejecting out-dated peer '" + seed.getName() + "' from " + seed.getAddress() + "; nowUTC0=" + nowUTC0Time + ", seedUTC0=" + ctimeUTC0 + ", TimeDiff=" + serverDate.intervalToString(Math.abs(nowUTC0Time - ctimeUTC0)));
return false; return false;
} }
// disconnection time // disconnection time
long dtimeUTC0; long dtimeUTC0;
yacySeed disconnectedSeed = seedDB.getDisconnected(seed.hash); final yacySeed disconnectedSeed = seedDB.getDisconnected(seed.hash);
if (disconnectedSeed == null) { if (disconnectedSeed == null) {
dtimeUTC0 = 0; // never disconnected: virtually disconnected maximum time ago dtimeUTC0 = 0; // never disconnected: virtually disconnected maximum time ago
} else { } else {
try { try {
dtimeUTC0 = yacyCore.parseUniversalDate(disconnectedSeed.get("disconnected", "20040101000000")).getTime() - seed.getUTCDiff(); dtimeUTC0 = yacyCore.parseUniversalDate(disconnectedSeed.get("disconnected", "20040101000000")).getTime() - seed.getUTCDiff();
} catch (java.text.ParseException e) { } catch (java.text.ParseException e) {
dtimeUTC0 = 0; dtimeUTC0 = 0;
}
} }
}
if (direct) { if (direct) {
// remember the moment // remember the moment
// Date applies the local UTC offset, which is wrong // Date applies the local UTC offset, which is wrong
// we correct that by subtracting the local offset and adding // we correct that by subtracting the local offset and adding
// the remote offset. // the remote offset.
seed.setLastSeenTime(); seed.setLastSeenTime();
seed.setFlagDirectConnect(true); seed.setFlagDirectConnect(true);
} else { } else {
// set connection flag // set connection flag
if (Math.abs(nowUTC0Time - ctimeUTC0) > 120000) seed.setFlagDirectConnect(false); // 2 minutes if (Math.abs(nowUTC0Time - ctimeUTC0) > 120000) seed.setFlagDirectConnect(false); // 2 minutes
}
// update latest version number
if (seed.getVersion() > yacyCore.latestVersion) yacyCore.latestVersion = seed.getVersion();
// prepare to update
if (disconnectedSeed != null) {
// if the indirect connect aims to announce a peer that we know
// 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 (ctimeUTC0 < dtimeUTC0) {
// the disconnection was later, we reject the connection
yacyCore.log.logFine("connect: rejecting disconnected peer '" + seed.getName() + "' from " + seed.getAddress());
return false;
}
} }
// update latest version number // this is a return of a lost peer
if (seed.getVersion() > yacyCore.latestVersion) yacyCore.latestVersion = seed.getVersion(); yacyCore.log.logFine("connect: returned KNOWN " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
this.seedDB.addConnected(seed);
// prepare to update return true;
if (disconnectedSeed != null) { } else {
// if the indirect connect aims to announce a peer that we know final yacySeed connectedSeed = this.seedDB.getConnected(seed.hash);
// has been disconnected then we compare the dates: if (connectedSeed != null) {
// if the new peer has a LastSeen date, and that date is before // the seed is known: this is an update
// the disconnection date, then we ignore the new peer try {
if (!(direct)) { // if the old LastSeen date is later then the other
if (ctimeUTC0 < dtimeUTC0) { // info, then we reject the info
// the disconnection was later, we reject the connection if ((ctimeUTC0 < (yacyCore.parseUniversalDate(connectedSeed.get(yacySeed.LASTSEEN, "20040101000000")).getTime() - connectedSeed.getUTCDiff() + serverDate.UTCDiff())) && (!direct)) {
yacyCore.log.logFine("connect: rejecting disconnected peer '" + seed.getName() + "' from " + seed.getAddress()); yacyCore.log.logFine("connect: rejecting old info about peer '" + seed.getName() + "'");
return false; return false;
} }
}
// this is a return of a lost peer if (connectedSeed.getName() != seed.getName()) {
yacyCore.log.logFine("connect: returned KNOWN " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress()); // TODO: update seed name lookup cache
}
} catch (ParseException e) {
yacyCore.log.logFine("connect: rejecting wrong peer '" + seed.getName() + "' from " + seed.getAddress() + ". Cause: " + e.getMessage());
return false;
} catch (NumberFormatException e) {
yacyCore.log.logFine("connect: rejecting wrong peer '" + seed.getName() + "' from " + seed.getAddress() + ". Cause: " + e.getMessage());
return false;
}
yacyCore.log.logFine("connect: updated KNOWN " + ((direct) ? "direct " : "") + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
seedDB.addConnected(seed); seedDB.addConnected(seed);
return true; return true;
} else { } else {
yacySeed connectedSeed = seedDB.getConnected(seed.hash); // the seed is new
if (connectedSeed != null) { if (seed.get(yacySeed.IP, "127.0.0.1").equals(this.seedDB.mySeed.get(yacySeed.IP, "127.0.0.1"))) {
// the seed is known: this is an update // seed from the same IP as the calling client: can be
try { // the case if there runs another one over a NAT
// if the old LastSeen date is later then the other yacyCore.log.logFine("connect: saved NEW seed (myself IP) " + seed.getAddress());
// info, then we reject the info
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;
}
if (connectedSeed.getName() != seed.getName()) {
// TODO: update seed name lookup cache
}
} catch (ParseException e) {
yacyCore.log.logFine("connect: rejecting wrong peer '" + seed.getName() + "' from " + seed.getAddress() + ". Cause: " + e.getMessage());
return false;
} catch (NumberFormatException e) {
yacyCore.log.logFine("connect: rejecting wrong peer '" + seed.getName() + "' from " + seed.getAddress() + ". Cause: " + e.getMessage());
return false;
}
yacyCore.log.logFine("connect: updated KNOWN " + ((direct) ? "direct " : "") + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
seedDB.addConnected(seed);
return true;
} else { } else {
// the seed is new // completely new seed
if (seed.get(yacySeed.IP, "127.0.0.1").equals(seedDB.mySeed.get(yacySeed.IP, "127.0.0.1"))) { yacyCore.log.logFine("connect: saved NEW " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
// 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());
} else {
// completely new seed
yacyCore.log.logFine("connect: saved NEW " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
}
if (peerType.equals(yacySeed.PEERTYPE_SENIOR))
seniorConnects++; // update statistics
if (peerType.equals(yacySeed.PEERTYPE_PRINCIPAL))
principalConnects++; // update statistics
seedDB.addConnected(seed);
return true;
} }
if (peerType.equals(yacySeed.PEERTYPE_SENIOR))
this.seniorConnects++; // update statistics
if (peerType.equals(yacySeed.PEERTYPE_PRINCIPAL))
this.principalConnects++; // update statistics
this.seedDB.addConnected(seed);
return true;
} }
}
} }
private final void disconnectPeer(yacySeed seed) { private final void disconnectPeer(yacySeed seed) {

Loading…
Cancel
Save