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,21 +297,22 @@ 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) +
@ -327,7 +328,7 @@ public class yacyPeerActions {
// 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 {
@ -359,7 +360,7 @@ public class yacyPeerActions {
// has been disconnected then we compare the dates: // has been disconnected then we compare the dates:
// if the new peer has a LastSeen date, and that date is before // if the new peer has a LastSeen date, and that date is before
// the disconnection date, then we ignore the new peer // the disconnection date, then we ignore the new peer
if (!(direct)) { if (!direct) {
if (ctimeUTC0 < dtimeUTC0) { if (ctimeUTC0 < dtimeUTC0) {
// the disconnection was later, we reject the connection // the disconnection was later, we reject the connection
yacyCore.log.logFine("connect: rejecting disconnected peer '" + seed.getName() + "' from " + seed.getAddress()); 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 // this is a return of a lost peer
yacyCore.log.logFine("connect: returned KNOWN " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress()); yacyCore.log.logFine("connect: returned KNOWN " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
seedDB.addConnected(seed); this.seedDB.addConnected(seed);
return true; return true;
} else { } else {
yacySeed connectedSeed = seedDB.getConnected(seed.hash); final yacySeed connectedSeed = this.seedDB.getConnected(seed.hash);
if (connectedSeed != null) { if (connectedSeed != null) {
// the seed is known: this is an update // the seed is known: this is an update
try { try {
// if the old LastSeen date is later then the other // if the old LastSeen date is later then the other
// info, then we reject the info // 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() + "'"); yacyCore.log.logFine("connect: rejecting old info about peer '" + seed.getName() + "'");
return false; return false;
} }
@ -398,7 +399,7 @@ public class yacyPeerActions {
return true; return true;
} else { } else {
// the seed is new // 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 // seed from the same IP as the calling client: can be
// the case if there runs another one over a NAT // the case if there runs another one over a NAT
yacyCore.log.logFine("connect: saved NEW seed (myself IP) " + seed.getAddress()); 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()); yacyCore.log.logFine("connect: saved NEW " + peerType + " peer '" + seed.getName() + "' from " + seed.getAddress());
} }
if (peerType.equals(yacySeed.PEERTYPE_SENIOR)) if (peerType.equals(yacySeed.PEERTYPE_SENIOR))
seniorConnects++; // update statistics this.seniorConnects++; // update statistics
if (peerType.equals(yacySeed.PEERTYPE_PRINCIPAL)) if (peerType.equals(yacySeed.PEERTYPE_PRINCIPAL))
principalConnects++; // update statistics this.principalConnects++; // update statistics
seedDB.addConnected(seed); this.seedDB.addConnected(seed);
return true; return true;
} }
} }

Loading…
Cancel
Save