From 08e4334c1dcd900f3dfe429ab8ad4ce6fcac21ae Mon Sep 17 00:00:00 2001 From: theli Date: Tue, 28 Jun 2005 11:27:31 +0000 Subject: [PATCH] *) Status.java: showing amount of time since last upload of seed-file *) hello.java: adding additional output for principal-downgrade bug *) httpd.java, httpdFileHandler.java, httpdProxyHandler.java: improved errorhandling *) yacyCore.java: trying to fix principal-downgrade bug *) yacySeed.java: adding some constants git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@329 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Status.html | 6 ++- htroot/Status.java | 3 ++ htroot/yacy/hello.java | 3 ++ source/de/anomic/http/httpd.java | 23 ++++++++--- source/de/anomic/http/httpdFileHandler.java | 2 +- source/de/anomic/http/httpdProxyHandler.java | 2 +- source/de/anomic/yacy/yacyCore.java | 40 +++++++++++++------- source/de/anomic/yacy/yacySeed.java | 7 ++++ 8 files changed, 62 insertions(+), 24 deletions(-) diff --git a/htroot/Status.html b/htroot/Status.html index 2a93d2cb2..eb013460e 100644 --- a/htroot/Status.html +++ b/htroot/Status.html @@ -78,9 +78,11 @@ You can of course search the internet using the other p #(seedServer)# Disabled. To enable this you need a ftp account where you can upload files to a web space. If you do that, you become a YaCy root server. You can configure your account details on the Settings page. :: -Enabled: Updating periodically to server #[seedServer]# +Enabled: Updating periodically to server #[seedServer]#. +Last upload: #[lastUpload]# ago. :: -Enabled: Updating periodically to file #[seedFile]# +Enabled: Updating periodically to file #[seedFile]#. +Last upload: #[lastUpload]# ago. #(/seedServer)# Auto-popup on start-up diff --git a/htroot/Status.java b/htroot/Status.java index b34cf740f..e65e5bedc 100644 --- a/htroot/Status.java +++ b/htroot/Status.java @@ -157,6 +157,7 @@ public class Status { if (env.getConfig("seedFilePath","").length() > 0) env.setConfig("seedUploadMethod","File"); } + if (seedUploadMethod.equalsIgnoreCase("ftp")) { prop.put("seedServer", 1);//enabled prop.put("seedServer_seedServer", env.getConfig("seedFTPServer","")); @@ -167,6 +168,8 @@ public class Status { prop.put("seedServer", 2);//enabled prop.put("seedServer_seedFile", env.getConfig("seedFilePath","")); } + prop.put("seedServer_lastUpload", + serverDate.intervalToString(System.currentTimeMillis()-yacyCore.lastSeedUpload_timeStamp)); } else { prop.put("seedServer", 0);//disabled } diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.java index e33d95b57..de1d9d6c2 100644 --- a/htroot/yacy/hello.java +++ b/htroot/yacy/hello.java @@ -121,6 +121,9 @@ public class hello { // no connection here, instead store junior in connection cache if ((remoteSeed.hash != null) && (remoteSeed.isProper())) yacyCore.peerActions.peerPing(remoteSeed); } + if (!((String)prop.get("yourtype")).equals(remoteSeed.get("PeerType", "junior"))) { + yacyCore.log.logInfo("hello: changing remote peer '" + remoteSeed.getName() + "' [" + reportedip + "] peerType to '" + prop.get("yourtype") + "'."); + } String seeds = ""; diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java index 03dfc912e..54a8599b4 100644 --- a/source/de/anomic/http/httpd.java +++ b/source/de/anomic/http/httpd.java @@ -507,12 +507,25 @@ public final class httpd implements serverHandler { return this.prop.getProperty(CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION; } catch (Exception e) { - String errorMsg = "Unexpected Error. " + e.getClass().getName() + ": " + e.getMessage(); - this.log.logError(errorMsg,e); + logUnexpectedError(e); return serverCore.TERMINATE_CONNECTION; } } + private void logUnexpectedError(Exception e) { + if (e instanceof InterruptedException) { + this.log.logInfo("Interruption detected"); + } else { + String errorMsg = e.getMessage(); + if ((errorMsg != null) && (errorMsg.startsWith("Broken pipe") || errorMsg.startsWith("Connection reset"))) { + // client closed the connection, so we just end silently + this.log.logInfo("Client unexpectedly closed connection"); + } else { + this.log.logError("Unexpected Error. " + e.getClass().getName() + ": " + e.getMessage(),e); + } + } + } + public Boolean HEAD(String arg) throws IOException { try { parseQuery(httpHeader.METHOD_HEAD,arg); @@ -559,8 +572,7 @@ public final class httpd implements serverHandler { } return this.prop.getProperty(CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION; } catch (Exception e) { - String errorMsg = "Unexpected Error. " + e.getClass().getName() + ": " + e.getMessage(); - this.log.logError(errorMsg,e); + logUnexpectedError(e); return serverCore.TERMINATE_CONNECTION; } } @@ -629,8 +641,7 @@ public final class httpd implements serverHandler { //return serverCore.RESUME_CONNECTION; return this.prop.getProperty(CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION; } catch (Exception e) { - String errorMsg = "Unexpected Error. " + e.getClass().getName() + ": " + e.getMessage(); - this.log.logError(errorMsg,e); + logUnexpectedError(e); return serverCore.TERMINATE_CONNECTION; } } diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index c3070e0f1..747bc0882 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -488,7 +488,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http } } else { String errorMsg = e.getMessage(); - if ((errorMsg != null) && (errorMsg.startsWith("Broken pipe") || errorMsg.startsWith("Connection reset by peer"))) { + if ((errorMsg != null) && (errorMsg.startsWith("Broken pipe") || errorMsg.startsWith("Connection reset"))) { // client closed the connection, so we just end silently this.theLogger.logInfo("Client unexpectedly closed connection while processing query: " + path + "; '" + e.toString() + ":" + errorMsg + "'"); conProp.put(httpd.CONNECTION_PROP_PERSISTENT,"close"); diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.java index 35747d402..662a910fa 100644 --- a/source/de/anomic/http/httpdProxyHandler.java +++ b/source/de/anomic/http/httpdProxyHandler.java @@ -726,7 +726,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt // just do nothing, we leave it this way this.theLogger.logDebug("ignoring bad gzip trail for URL " + url + " (" + e.getMessage() + ")",e); this.forceConnectionClose(); - } else if ((remote != null)&&(remote.isClosed())) { + } else if ((remote != null)&&(remote.isClosed())) { // TODO: query for broken pipe errorMessage = "destination host unexpectedly closed connection"; } else { errorMessage = "Unexpected Error. " + e.getClass().getName() + ": " + e.getMessage(); diff --git a/source/de/anomic/yacy/yacyCore.java b/source/de/anomic/yacy/yacyCore.java index ff762509c..3d67e58c8 100644 --- a/source/de/anomic/yacy/yacyCore.java +++ b/source/de/anomic/yacy/yacyCore.java @@ -99,8 +99,12 @@ public class yacyCore { //public static boolean terminate = false; // class variables - private int seedCacheSizeStamp = 0; - private String oldIPStamp = ""; + private int lastSeedUpload_seedDBSize = 0; + public static long lastSeedUpload_timeStamp = System.currentTimeMillis(); + private String lastSeedUpload_myPeerType = ""; + private String lastSeedUpload_myIP = ""; + + private int onlineMode = 1; private plasmaSwitchboard switchboard; @@ -170,7 +174,7 @@ public class yacyCore { // create or init index sharing //shareManager = new yacyShare(switchboard); - seedCacheSizeStamp = seedDB.sizeConnected(); + lastSeedUpload_seedDBSize = seedDB.sizeConnected(); log.logSystem("CORE INITIALIZED"); // ATTENTION, VERY IMPORTANT: before starting the thread, the httpd yacy server must be running! @@ -212,8 +216,7 @@ public class yacyCore { public void publishSeedList() { - log.logDebug("triggered Seed Publish"); - + log.logDebug("yacyCore.publishSeedList: Triggered Seed Publish"); /* if (oldIPStamp.equals((String) seedDB.mySeed.get("IP", "127.0.0.1"))) @@ -224,12 +227,16 @@ public class yacyCore { System.out.println("***DEBUG publishSeedList: I can reach myself"); */ - if (!(!(oldIPStamp.equals(seedDB.mySeed.get("IP", "127.0.0.1")))) || - (seedCacheSizeStamp != seedDB.sizeConnected()) || - (!(canReachMyself()))) { - log.logDebug("not necessary to publish: oldIP is equal, sizeConnected is equal and I can reach myself under the old IP."); + if ( + (this.lastSeedUpload_myIP.equals(seedDB.mySeed.get("IP", "127.0.0.1"))) && + (this.lastSeedUpload_seedDBSize == seedDB.sizeConnected()) && + (canReachMyself()) && + (System.currentTimeMillis() - yacyCore.lastSeedUpload_timeStamp < 1000*60*60*24) && + (seedDB.mySeed.isPrincipal()) + ) { + log.logDebug("yacyCore.publishSeedList: not necessary to publish: oldIP is equal, sizeConnected is equal and I can reach myself under the old IP."); return; - } + } // getting the seed upload method that should be used ... String seedUploadMethod = this.switchboard.getConfig("seedUploadMethod",""); @@ -247,8 +254,13 @@ public class yacyCore { } // we want to be a principal... saveSeedList(); - this.seedCacheSizeStamp = seedDB.sizeConnected(); - this.oldIPStamp = seedDB.mySeed.get("IP", "127.0.0.1"); + + this.lastSeedUpload_seedDBSize = seedDB.sizeConnected(); + this.lastSeedUpload_timeStamp = System.currentTimeMillis(); + + this.lastSeedUpload_myIP = seedDB.mySeed.get("IP", "127.0.0.1"); + this.lastSeedUpload_myPeerType = seedDB.mySeed.get("PeerType", yacySeed.PEERTYPE_JUNIOR); + } else { if (seedUploadMethod.equals("")) this.switchboard.setConfig("seedUploadMethod","none"); log.logDebug("yacyCore.publishSeedList: No uploading method configured"); @@ -269,10 +281,10 @@ public class yacyCore { if (oldSize == 0) { // reload the seed lists peerActions.loadSeedLists(); - log.logInfo("re-initialized seed list. received " + seedDB.sizeConnected() + " new peers"); + log.logInfo("re-initialized seed list. received " + seedDB.sizeConnected() + " new peer(s)"); } int newSeeds = publishMySeed(false); - if (newSeeds > 0) log.logInfo("received " + newSeeds + " new peers, know a total of " + + if (newSeeds > 0) log.logInfo("received " + newSeeds + " new peer(s), know a total of " + seedDB.sizeConnected() + " different peers"); } diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index d48dcdf8d..66bec37fa 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -78,6 +78,13 @@ import de.anomic.tools.crypt; public class yacySeed { + public static final String PEERTYPE_VIRGIN = "virgin"; + public static final String PEERTYPE_JUNIOR = "junior"; + public static final String PEERTYPE_SENIOR = "senior"; + public static final String PEERTYPE_PRINCIPAL = "principal"; + + public static final String PEERTYPE = "PeerType"; + // class variables public String hash; private Map dna;