Your network configuration is in private mode. Your peer seed will not be published.
+
+ #(/hintStatusPrivate)#
diff --git a/htroot/Status.java b/htroot/Status.java
index 36e359039..ab9243c60 100644
--- a/htroot/Status.java
+++ b/htroot/Status.java
@@ -46,67 +46,73 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
-public class Status {
+public class Status
+{
private static final String SEEDSERVER = "seedServer";
private static final String PEERSTATUS = "peerStatus";
- public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ public static serverObjects respond(
+ final RequestHeader header,
+ final serverObjects post,
+ final serverSwitch env) {
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard) env;
// check if the basic configuration was accessed before and forward
prop.put("forwardToConfigBasic", 0);
- if ((post == null || !post.containsKey("noforward")) &&
- sb.getConfig("server.servlets.submitted", "").indexOf("ConfigBasic.html",0) < 0 &&
- Seed.isDefaultPeerName(sb.peers.mySeed().getName())) {
+ if ( (post == null || !post.containsKey("noforward"))
+ && sb.getConfig("server.servlets.submitted", "").indexOf("ConfigBasic.html", 0) < 0
+ && Seed.isDefaultPeerName(sb.peers.mySeed().getName()) ) {
// forward to ConfigBasic
prop.put("forwardToConfigBasic", 1);
}
- if (post != null) post.remove("noforward");
+ if ( post != null ) {
+ post.remove("noforward");
+ }
- if (post != null && post.size() > 0) {
- if (sb.adminAuthenticated(header) < 2) {
- prop.put("AUTHENTICATE","admin log-in");
+ if ( post != null && post.size() > 0 ) {
+ if ( sb.adminAuthenticated(header) < 2 ) {
+ prop.put("AUTHENTICATE", "admin log-in");
return prop;
}
boolean redirect = false;
- if (post.containsKey("login")) {
- prop.put("LOCATION","");
+ if ( post.containsKey("login") ) {
+ prop.put("LOCATION", "");
return prop;
- } else if (post.containsKey("pauseCrawlJob")) {
+ } else if ( post.containsKey("pauseCrawlJob") ) {
final String jobType = post.get("jobType");
- if ("localCrawl".equals(jobType)) {
+ if ( "localCrawl".equals(jobType) ) {
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
- } else if ("remoteTriggeredCrawl".equals(jobType)) {
+ } else if ( "remoteTriggeredCrawl".equals(jobType) ) {
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
}
redirect = true;
- } else if (post.containsKey("continueCrawlJob")) {
+ } else if ( post.containsKey("continueCrawlJob") ) {
final String jobType = post.get("jobType");
- if ("localCrawl".equals(jobType)) {
+ if ( "localCrawl".equals(jobType) ) {
sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
- } else if ("remoteTriggeredCrawl".equals(jobType)) {
+ } else if ( "remoteTriggeredCrawl".equals(jobType) ) {
sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
}
redirect = true;
- } else if (post.containsKey("ResetTraffic")) {
+ } else if ( post.containsKey("ResetTraffic") ) {
ByteCount.resetCount();
redirect = true;
- } else if (post.containsKey("popup")) {
+ } else if ( post.containsKey("popup") ) {
final boolean trigger_enabled = post.getBoolean("popup", false);
sb.setConfig("browserPopUpTrigger", trigger_enabled);
redirect = true;
- } else if (post.containsKey("tray")) {
+ } else if ( post.containsKey("tray") ) {
final boolean trigger_enabled = post.getBoolean("tray", false);
sb.setConfig("trayIcon", trigger_enabled);
redirect = true;
}
- if (redirect) {
- prop.put("LOCATION","");
- return prop;
+ if ( redirect ) {
+ prop.put("LOCATION", "");
+ return prop;
}
}
@@ -114,7 +120,7 @@ public class Status {
sb.updateMySeed();
final boolean adminaccess = sb.adminAuthenticated(header) >= 2;
- if (adminaccess) {
+ if ( adminaccess ) {
prop.put("showPrivateTable", "1");
prop.put("privateStatusTable", "Status_p.inc");
} else {
@@ -123,26 +129,28 @@ public class Status {
}
// password protection
- if ((sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0) && (!sb.getConfigBool("adminAccountForLocalhost", false))) {
+ if ( (sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0)
+ && (!sb.getConfigBool("adminAccountForLocalhost", false)) ) {
prop.put("protection", "0"); // not protected
prop.put("urgentSetPassword", "1");
} else {
prop.put("protection", "1"); // protected
}
- if (sb.getConfigBool("adminAccountForLocalhost", false)) {
+ if ( sb.getConfigBool("adminAccountForLocalhost", false) ) {
prop.put("unrestrictedLocalAccess", 1);
}
// resource observer status
- if (adminaccess) {
- if (!sb.observer.getDiskAvailable()){
+ if ( adminaccess ) {
+ if ( !sb.observer.getDiskAvailable() ) {
final String minFree = Formatter.bytesToString(sb.observer.getMinFreeDiskSpace());
prop.put("warningDiskSpaceLow", "1");
prop.put("warningDiskSpaceLow_minSpace", minFree);
}
- if (!sb.observer.getMemoryAvailable()){
- final String minFree = Formatter.bytesToString(sb.observer.getMinFreeMemory() * 1024L * 1024L);
+ if ( !sb.observer.getMemoryAvailable() ) {
+ final String minFree =
+ Formatter.bytesToString(sb.observer.getMinFreeMemory() * 1024L * 1024L);
prop.put("warningMemoryLow", "1");
prop.put("warningMemoryLow_minSpace", minFree);
}
@@ -151,25 +159,26 @@ public class Status {
// version information
//final String versionstring = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1"));
- final String versionstring = yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();
+ final String versionstring =
+ yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();
prop.put("versionpp", versionstring);
// place some more hints
- if ((adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() == 0)) {
+ if ( (adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() == 0) ) {
prop.put("hintCrawlStart", "1");
}
- if ((adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() > 500)) {
+ if ( (adminaccess) && (sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount() > 500) ) {
prop.put("hintCrawlMonitor", "1");
}
// hostname and port
final String extendedPortString = sb.getConfig("port", "8090");
- final int pos = extendedPortString.indexOf(':',0);
- prop.put("port",serverCore.getPortNr(extendedPortString));
- if (pos != -1) {
+ final int pos = extendedPortString.indexOf(':', 0);
+ prop.put("port", serverCore.getPortNr(extendedPortString));
+ if ( pos != -1 ) {
prop.put("extPortFormat", "1");
- prop.putHTML("extPortFormat_extPort",extendedPortString);
+ prop.putHTML("extPortFormat_extPort", extendedPortString);
} else {
prop.put("extPortFormat", "0");
}
@@ -177,9 +186,9 @@ public class Status {
prop.put("host", hostIP != null ? hostIP.getHostAddress() : "Unkown IP");
// ssl support
- prop.put("sslSupport",sb.getConfig("keyStore", "").length() == 0 ? "0" : "1");
+ prop.put("sslSupport", sb.getConfig("keyStore", "").length() == 0 ? "0" : "1");
- if (sb.getConfigBool("remoteProxyUse", false)) {
+ if ( sb.getConfigBool("remoteProxyUse", false) ) {
prop.put("remoteProxy", "1");
prop.putXML("remoteProxy_host", sb.getConfig("remoteProxyHost", ""));
prop.putXML("remoteProxy_port", sb.getConfig("remoteProxyPort", ""));
@@ -191,22 +200,24 @@ public class Status {
// peer information
String thisHash = "";
final String thisName = sb.peers.mySeed().getName();
- if (sb.peers.mySeed() == null) {
+ if ( sb.peers.mySeed() == null ) {
thisHash = "not assigned";
- prop.put("peerAddress", "0"); // not assigned
+ prop.put("peerAddress", "0"); // not assigned
prop.put("peerStatistics", "0"); // unknown
} else {
final long uptime = 60000 * sb.peers.mySeed().getLong(Seed.UPTIME, 0L);
prop.put("peerStatistics", "1");
prop.put("peerStatistics_uptime", PeerActions.formatInterval(uptime));
prop.putNum("peerStatistics_pagesperminute", sb.peers.mySeed().getPPM());
- prop.putNum("peerStatistics_queriesperhour", Math.round(6000d * sb.peers.mySeed().getQPM()) / 100d);
+ prop.putNum(
+ "peerStatistics_queriesperhour",
+ Math.round(6000d * sb.peers.mySeed().getQPM()) / 100d);
prop.putNum("peerStatistics_links", sb.peers.mySeed().getLinkCount());
prop.put("peerStatistics_words", Formatter.number(sb.peers.mySeed().getWordCount()));
prop.putNum("peerStatistics_disconnects", sb.peers.peerActions.disconnects);
prop.put("peerStatistics_connects", Formatter.number(sb.peers.mySeed().get(Seed.CCOUNT, "0")));
thisHash = sb.peers.mySeed().hash;
- if (sb.peers.mySeed().getPublicAddress() == null) {
+ if ( sb.peers.mySeed().getPublicAddress() == null ) {
prop.put("peerAddress", "0"); // not assigned + instructions
prop.put("warningGoOnline", "1");
} else {
@@ -215,17 +226,25 @@ public class Status {
prop.putXML("peerAddress_peername", sb.peers.mySeed().getName().toLowerCase());
}
}
- final String peerStatus = ((sb.peers.mySeed() == null) ? Seed.PEERTYPE_VIRGIN : sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN));
- if (Seed.PEERTYPE_VIRGIN.equals(peerStatus) && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))) {
+ final String peerStatus =
+ ((sb.peers.mySeed() == null) ? Seed.PEERTYPE_VIRGIN : sb.peers.mySeed().get(
+ Seed.PEERTYPE,
+ Seed.PEERTYPE_VIRGIN));
+
+ if ( Seed.PEERTYPE_VIRGIN.equals(peerStatus)
+ && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))
+ && !SwitchboardConstants.CLUSTER_MODE_PRIVATE_PEER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) {
prop.put(PEERSTATUS, "0");
prop.put("urgentStatusVirgin", "1");
- } else if (Seed.PEERTYPE_JUNIOR.equals(peerStatus) && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))) {
+ } else if ( Seed.PEERTYPE_JUNIOR.equals(peerStatus)
+ && "freeworld".equals(sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""))
+ && !SwitchboardConstants.CLUSTER_MODE_PRIVATE_PEER.equals(sb.getConfig(SwitchboardConstants.CLUSTER_MODE, ""))) {
prop.put(PEERSTATUS, "1");
prop.put("warningStatusJunior", "1");
- } else if (Seed.PEERTYPE_SENIOR.equals(peerStatus)) {
+ } else if ( Seed.PEERTYPE_SENIOR.equals(peerStatus) ) {
prop.put(PEERSTATUS, "2");
prop.put("hintStatusSenior", "1");
- } else if (Seed.PEERTYPE_PRINCIPAL.equals(peerStatus)) {
+ } else if ( Seed.PEERTYPE_PRINCIPAL.equals(peerStatus) ) {
prop.put(PEERSTATUS, "3");
prop.put("hintStatusPrincipal", "1");
prop.put("hintStatusPrincipal_seedURL", sb.peers.mySeed().get(Seed.SEEDLISTURL, "?"));
@@ -234,50 +253,52 @@ public class Status {
prop.put("hash", thisHash);
final String seedUploadMethod = sb.getConfig("seedUploadMethod", "");
- if (!"none".equalsIgnoreCase(seedUploadMethod) ||
- ("".equals(seedUploadMethod) && (sb.getConfig("seedFTPPassword", "").length() > 0 ||
- sb.getConfig("seedFilePath", "").length() > 0))) {
- if ("".equals(seedUploadMethod)) {
- if (sb.getConfig("seedFTPPassword", "").length() > 0) {
- sb.setConfig("seedUploadMethod","Ftp");
+ if ( !"none".equalsIgnoreCase(seedUploadMethod)
+ || ("".equals(seedUploadMethod) && (sb.getConfig("seedFTPPassword", "").length() > 0 || sb
+ .getConfig("seedFilePath", "")
+ .length() > 0)) ) {
+ if ( "".equals(seedUploadMethod) ) {
+ if ( sb.getConfig("seedFTPPassword", "").length() > 0 ) {
+ sb.setConfig("seedUploadMethod", "Ftp");
}
- if (sb.getConfig("seedFilePath", "").length() > 0) {
- sb.setConfig("seedUploadMethod","File");
+ if ( sb.getConfig("seedFilePath", "").length() > 0 ) {
+ sb.setConfig("seedUploadMethod", "File");
}
}
- if ("ftp".equalsIgnoreCase(seedUploadMethod)) {
+ if ( "ftp".equalsIgnoreCase(seedUploadMethod) ) {
prop.put(SEEDSERVER, "1"); // enabled
prop.putHTML("seedServer_seedServer", sb.getConfig("seedFTPServer", ""));
- } else if ("scp".equalsIgnoreCase(seedUploadMethod)) {
+ } else if ( "scp".equalsIgnoreCase(seedUploadMethod) ) {
prop.put(SEEDSERVER, "1"); // enabled
prop.putHTML("seedServer_seedServer", sb.getConfig("seedScpServer", ""));
- } else if ("file".equalsIgnoreCase(seedUploadMethod)) {
+ } else if ( "file".equalsIgnoreCase(seedUploadMethod) ) {
prop.put(SEEDSERVER, "2"); // enabled
prop.putHTML("seedServer_seedFile", sb.getConfig("seedFilePath", ""));
}
- prop.put("seedServer_lastUpload",
- PeerActions.formatInterval(System.currentTimeMillis() - sb.peers.lastSeedUpload_timeStamp));
+ prop.put(
+ "seedServer_lastUpload",
+ PeerActions.formatInterval(System.currentTimeMillis() - sb.peers.lastSeedUpload_timeStamp));
} else {
prop.put(SEEDSERVER, "0"); // disabled
}
- if (sb.peers != null && sb.peers.sizeConnected() > 0){
+ if ( sb.peers != null && sb.peers.sizeConnected() > 0 ) {
prop.put("otherPeers", "1");
prop.putNum("otherPeers_num", sb.peers.sizeConnected());
- }else{
+ } else {
prop.put("otherPeers", "0"); // not online
}
- if (!sb.getConfigBool("browserPopUpTrigger", false)) {
+ if ( !sb.getConfigBool("browserPopUpTrigger", false) ) {
prop.put("popup", "0");
} else {
prop.put("popup", "1");
}
- if (!OS.isWindows) {
- prop.put("tray", "2");
- } else if (!sb.getConfigBool("trayIcon", false)) {
+ if ( !OS.isWindows ) {
+ prop.put("tray", "2");
+ } else if ( !sb.getConfigBool("trayIcon", false) ) {
prop.put("tray", "0");
} else {
prop.put("tray", "1");
@@ -305,18 +326,26 @@ public class Status {
final int loaderPercent = (loaderMaxCount == 0) ? 0 : loaderJobCount * 100 / loaderMaxCount;
prop.putNum("loaderQueueSize", loaderJobCount);
prop.putNum("loaderQueueMax", loaderMaxCount);
- prop.put("loaderQueuePercent", (loaderPercent>100) ? 100 : loaderPercent);
-
- prop.putNum("localCrawlQueueSize", sb.getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL).getJobCount());
- prop.put("localCrawlPaused",sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL) ? "1" : "0");
-
- prop.putNum("remoteTriggeredCrawlQueueSize", sb.getThread(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL).getJobCount());
- prop.put("remoteTriggeredCrawlPaused",sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL) ? "1" : "0");
+ prop.put("loaderQueuePercent", (loaderPercent > 100) ? 100 : loaderPercent);
+
+ prop.putNum("localCrawlQueueSize", sb
+ .getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)
+ .getJobCount());
+ prop.put("localCrawlPaused", sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)
+ ? "1"
+ : "0");
+
+ prop.putNum(
+ "remoteTriggeredCrawlQueueSize",
+ sb.getThread(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL).getJobCount());
+ prop.put(
+ "remoteTriggeredCrawlPaused",
+ sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL) ? "1" : "0");
prop.putNum("stackCrawlQueueSize", sb.crawlStacker.size());
// return rewrite properties
- prop.put("date",(new Date()).toString());
+ prop.put("date", (new Date()).toString());
return prop;
}
}
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 52e78ae82..046706203 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -81,38 +81,45 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.servletProperties;
-public class yacysearch {
+public class yacysearch
+{
- public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ public static serverObjects respond(
+ final RequestHeader header,
+ final serverObjects post,
+ final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
sb.localSearchLastAccess = System.currentTimeMillis();
- final boolean searchAllowed = sb.getConfigBool("publicSearchpage", true) || sb.verifyAuthentication(header);
+ final boolean searchAllowed =
+ sb.getConfigBool("publicSearchpage", true) || sb.verifyAuthentication(header);
boolean authenticated = sb.adminAuthenticated(header) >= 2;
- if (!authenticated) {
+ if ( !authenticated ) {
final UserDB.Entry user = sb.userDB.getUser(header);
authenticated = (user != null && user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT));
}
final boolean localhostAccess = sb.accessFromLocalhost(header);
final String promoteSearchPageGreeting =
- (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ?
- env.getConfig("network.unit.description", "") :
- env.getConfig(SwitchboardConstants.GREETING, "");
+ (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ? env.getConfig(
+ "network.unit.description",
+ "") : env.getConfig(SwitchboardConstants.GREETING, "");
final String client = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the search client who initiated the search
// get query
- final String originalquerystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim();
- String querystring = originalquerystring.replace('+', ' ').replace('*', ' ').trim();
- CacheStrategy snippetFetchStrategy = (post == null) ? null : CacheStrategy.parse(post.get("verify", "cacheonly"));
+ final String originalquerystring =
+ (post == null) ? "" : post.get("query", post.get("search", "")).trim();
+ String querystring = originalquerystring.replace('+', ' ').replace('*', ' ').trim();
+ CacheStrategy snippetFetchStrategy =
+ (post == null) ? null : CacheStrategy.parse(post.get("verify", "cacheonly"));
final servletProperties prop = new servletProperties();
prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
// get segment
Segment indexSegment = null;
- if (post != null && post.containsKey("segment")) {
+ if ( post != null && post.containsKey("segment") ) {
final String segmentName = post.get("segment");
- if (sb.indexSegments.segmentExist(segmentName)) {
+ if ( sb.indexSegments.segmentExist(segmentName) ) {
indexSegment = sb.indexSegments.segment(segmentName);
}
} else {
@@ -124,9 +131,13 @@ public class yacysearch {
final boolean rss = EXT.equals("rss");
final boolean json = EXT.equals("json");
prop.put("promoteSearchPageGreeting", promoteSearchPageGreeting);
- prop.put("promoteSearchPageGreeting.homepage", sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
- prop.put("promoteSearchPageGreeting.smallImage", sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));
- if (post == null || indexSegment == null || env == null || !searchAllowed) {
+ prop.put(
+ "promoteSearchPageGreeting.homepage",
+ sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
+ prop.put(
+ "promoteSearchPageGreeting.smallImage",
+ sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));
+ if ( post == null || indexSegment == null || env == null || !searchAllowed ) {
// we create empty entries for template strings
prop.put("searchagain", "0");
prop.put("former", "");
@@ -140,8 +151,12 @@ public class yacysearch {
prop.put("constraint", "");
prop.put("cat", "href");
prop.put("depth", "0");
- prop.put("search.verify", (post == null) ? sb.getConfig("search.verify", "iffresh") : post.get("verify", "iffresh"));
- prop.put("search.navigation", (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
+ prop.put(
+ "search.verify",
+ (post == null) ? sb.getConfig("search.verify", "iffresh") : post.get("verify", "iffresh"));
+ prop.put(
+ "search.navigation",
+ (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
prop.put("contentdom", "text");
prop.put("contentdomCheckText", "1");
prop.put("contentdomCheckAudio", "0");
@@ -162,17 +177,17 @@ public class yacysearch {
}
// check for JSONP
- if (post.containsKey("callback")) {
- final String jsonp = post.get("callback")+ "([";
- prop.put("jsonp-start", jsonp);
- prop.put("jsonp-end", "])");
+ if ( post.containsKey("callback") ) {
+ final String jsonp = post.get("callback") + "([";
+ prop.put("jsonp-start", jsonp);
+ prop.put("jsonp-end", "])");
} else {
- prop.put("jsonp-start", "");
- prop.put("jsonp-end", "");
+ prop.put("jsonp-start", "");
+ prop.put("jsonp-end", "");
}
// Adding CORS Access header for yacysearch.rss output
- if (rss) {
+ if ( rss ) {
final ResponseHeader outgoingHeader = new ResponseHeader();
outgoingHeader.put(HeaderFramework.CORS_ALLOW_ORIGIN, "*");
prop.setOutgoingHeader(outgoingHeader);
@@ -180,40 +195,53 @@ public class yacysearch {
// collect search attributes
- int maximumRecords = Math.min((authenticated) ? (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline() ? 100 : 5000) : (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline() ? 20 : 1000), post.getInt("maximumRecords", post.getInt("count", 10))); // SRU syntax with old property as alternative
+ int maximumRecords =
+ Math.min(
+ (authenticated)
+ ? (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline()
+ ? 100
+ : 5000) : (snippetFetchStrategy != null
+ && snippetFetchStrategy.isAllowedToFetchOnline() ? 20 : 1000),
+ post.getInt("maximumRecords", post.getInt("count", 10))); // SRU syntax with old property as alternative
int startRecord = post.getInt("startRecord", post.getInt("offset", 0));
boolean global = post.get("resource", "local").equals("global") && sb.peers.sizeConnected() > 0;
- final boolean indexof = (post != null && post.get("indexof","").equals("on"));
+ final boolean indexof = (post != null && post.get("indexof", "").equals("on"));
final String originalUrlMask;
- if (post.containsKey("urlmaskfilter")) {
+ if ( post.containsKey("urlmaskfilter") ) {
originalUrlMask = post.get("urlmaskfilter", ".*");
} else {
originalUrlMask = ".*";
}
String prefermask = (post == null) ? "" : post.get("prefermaskfilter", "");
- if (!prefermask.isEmpty() && prefermask.indexOf(".*",0) < 0) {
+ if ( !prefermask.isEmpty() && prefermask.indexOf(".*", 0) < 0 ) {
prefermask = ".*" + prefermask + ".*";
}
- Bitfield constraint = (post != null && post.containsKey("constraint") && !post.get("constraint", "").isEmpty()) ? new Bitfield(4, post.get("constraint", "______")) : null;
- if (indexof) {
+ Bitfield constraint =
+ (post != null && post.containsKey("constraint") && !post.get("constraint", "").isEmpty())
+ ? new Bitfield(4, post.get("constraint", "______"))
+ : null;
+ if ( indexof ) {
constraint = new Bitfield(4);
constraint.set(Condenser.flag_cat_indexof, true);
}
// SEARCH
- final boolean clustersearch = sb.isRobinsonMode() && (sb.getConfig("cluster.mode", "").equals("privatecluster") || sb.getConfig("cluster.mode", "").equals("publiccluster"));
- final boolean indexReceiveGranted = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true) || sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, true) || clustersearch;
+ final boolean clustersearch = sb.isRobinsonMode() && sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "").equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER);
+ final boolean indexReceiveGranted =
+ sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true)
+ || sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, true)
+ || clustersearch;
global = global && indexReceiveGranted; // if the user does not want indexes from remote peers, it cannot be a global searchnn
// increase search statistic counter
- if (!global) {
+ if ( !global ) {
// we count only searches on the local peer here, because global searches
// are counted on the target peer to preserve privacy of the searcher
- if (authenticated) {
+ if ( authenticated ) {
// local or authenticated search requests are counted separately
// because they are not part of a public available peer statistic
sb.searchQueriesRobinsonFromLocal++;
@@ -225,63 +253,102 @@ public class yacysearch {
}
// find search domain
- final ContentDomain contentdom = ContentDomain.contentdomParser(post == null ? "text" : post.get("contentdom", "text"));
+ final ContentDomain contentdom =
+ ContentDomain.contentdomParser(post == null ? "text" : post.get("contentdom", "text"));
// patch until better search profiles are available
- if (contentdom == ContentDomain.TEXT) {
- if (maximumRecords > 50 && maximumRecords < 100) maximumRecords = 10;
+ if ( contentdom == ContentDomain.TEXT ) {
+ if ( maximumRecords > 50 && maximumRecords < 100 ) {
+ maximumRecords = 10;
+ }
} else {
- if (maximumRecords <= 32) maximumRecords = 64;
+ if ( maximumRecords <= 32 ) {
+ maximumRecords = 64;
+ }
}
// check the search tracker
TreeSet trackerHandles = sb.localSearchTracker.get(client);
- if (trackerHandles == null) {
+ if ( trackerHandles == null ) {
trackerHandles = new TreeSet();
}
boolean block = false;
- if (Domains.matchesList(client, sb.networkBlacklist)) {
+ if ( Domains.matchesList(client, sb.networkBlacklist) ) {
global = false;
- if (snippetFetchStrategy != null) {
+ if ( snippetFetchStrategy != null ) {
snippetFetchStrategy = null;
}
block = true;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: BLACKLISTED CLIENT FROM " + client + " gets no permission to search");
- } else if (Domains.matchesList(client, sb.networkWhitelist)) {
- Log.logInfo("LOCAL_SEARCH", "ACCESS CONTROL: WHITELISTED CLIENT FROM " + client + " gets no search restrictions");
- } else if (!authenticated && !localhostAccess) {
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: BLACKLISTED CLIENT FROM "
+ + client
+ + " gets no permission to search");
+ } else if ( Domains.matchesList(client, sb.networkWhitelist) ) {
+ Log.logInfo("LOCAL_SEARCH", "ACCESS CONTROL: WHITELISTED CLIENT FROM "
+ + client
+ + " gets no search restrictions");
+ } else if ( !authenticated && !localhostAccess ) {
// in case that we do a global search or we want to fetch snippets, we check for DoS cases
- synchronized (trackerHandles) {
- final int accInThreeSeconds = trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 3000)).size();
- final int accInOneMinute = trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 60000)).size();
- final int accInTenMinutes = trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 600000)).size();
+ synchronized ( trackerHandles ) {
+ final int accInThreeSeconds =
+ trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 3000)).size();
+ final int accInOneMinute =
+ trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 60000)).size();
+ final int accInTenMinutes =
+ trackerHandles.tailSet(Long.valueOf(System.currentTimeMillis() - 600000)).size();
// protections against too strong YaCy network load, reduces remote search
- if (global) {
- if (accInTenMinutes >= 60 || accInOneMinute >= 6 || accInThreeSeconds >= 1) {
+ if ( global ) {
+ if ( accInTenMinutes >= 60 || accInOneMinute >= 6 || accInThreeSeconds >= 1 ) {
global = false;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM " + client + ": " + accInThreeSeconds + "/3s, " + accInOneMinute + "/60s, " + accInTenMinutes + "/600s, " + " requests, disallowed global search");
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM "
+ + client
+ + ": "
+ + accInThreeSeconds
+ + "/3s, "
+ + accInOneMinute
+ + "/60s, "
+ + accInTenMinutes
+ + "/600s, "
+ + " requests, disallowed global search");
}
}
// protection against too many remote server snippet loads (protects traffic on server)
- if (snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline()) {
- if (accInTenMinutes >= 20 || accInOneMinute >= 4 || accInThreeSeconds >= 1) {
+ if ( snippetFetchStrategy != null && snippetFetchStrategy.isAllowedToFetchOnline() ) {
+ if ( accInTenMinutes >= 20 || accInOneMinute >= 4 || accInThreeSeconds >= 1 ) {
snippetFetchStrategy = CacheStrategy.CACHEONLY;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM " + client + ": " + accInThreeSeconds + "/3s, " + accInOneMinute + "/60s, " + accInTenMinutes + "/600s, " + " requests, disallowed remote snippet loading");
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM "
+ + client
+ + ": "
+ + accInThreeSeconds
+ + "/3s, "
+ + accInOneMinute
+ + "/60s, "
+ + accInTenMinutes
+ + "/600s, "
+ + " requests, disallowed remote snippet loading");
}
}
// general load protection
- if (accInTenMinutes >= 3000 || accInOneMinute >= 600 || accInThreeSeconds >= 60) {
+ if ( accInTenMinutes >= 3000 || accInOneMinute >= 600 || accInThreeSeconds >= 60 ) {
block = true;
- Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM " + client + ": " + accInThreeSeconds + "/3s, " + accInOneMinute + "/60s, " + accInTenMinutes + "/600s, " + " requests, disallowed search");
+ Log.logWarning("LOCAL_SEARCH", "ACCESS CONTROL: CLIENT FROM "
+ + client
+ + ": "
+ + accInThreeSeconds
+ + "/3s, "
+ + accInOneMinute
+ + "/60s, "
+ + accInTenMinutes
+ + "/600s, "
+ + " requests, disallowed search");
}
}
}
- if (!block && (post == null || post.get("cat", "href").equals("href"))) {
+ if ( !block && (post == null || post.get("cat", "href").equals("href")) ) {
String urlmask = null;
// check available memory and clean up if necessary
- if (!MemoryControl.request(8000000L, false)) {
+ if ( !MemoryControl.request(8000000L, false) ) {
indexSegment.urlMetadata().clearCache();
SearchEventCache.cleanupEvents(true);
}
@@ -289,83 +356,85 @@ public class yacysearch {
final RankingProfile ranking = sb.getRanking();
final StringBuilder modifier = new StringBuilder(20);
- if (querystring.indexOf("/near",0) >= 0) {
- querystring = querystring.replace("/near", "");
- ranking.coeff_worddistance = RankingProfile.COEFF_MAX;
- modifier.append("/near ");
+ if ( querystring.indexOf("/near", 0) >= 0 ) {
+ querystring = querystring.replace("/near", "");
+ ranking.coeff_worddistance = RankingProfile.COEFF_MAX;
+ modifier.append("/near ");
}
- if (querystring.indexOf("/date",0) >= 0) {
+ if ( querystring.indexOf("/date", 0) >= 0 ) {
querystring = querystring.replace("/date", "");
ranking.coeff_date = RankingProfile.COEFF_MAX;
modifier.append("/date ");
}
- if (querystring.indexOf("/http",0) >= 0) {
+ if ( querystring.indexOf("/http", 0) >= 0 ) {
querystring = querystring.replace("/http", "");
urlmask = "https?://.*";
modifier.append("/http ");
}
- if (querystring.indexOf("/https",0) >= 0) {
+ if ( querystring.indexOf("/https", 0) >= 0 ) {
querystring = querystring.replace("/https", "");
urlmask = "https?://.*";
modifier.append("/https ");
}
- if (querystring.indexOf("/ftp",0) >= 0) {
+ if ( querystring.indexOf("/ftp", 0) >= 0 ) {
querystring = querystring.replace("/ftp", "");
urlmask = "ftp://.*";
modifier.append("/ftp ");
}
- if (querystring.indexOf("/smb",0) >= 0) {
+ if ( querystring.indexOf("/smb", 0) >= 0 ) {
querystring = querystring.replace("/smb", "");
urlmask = "smb://.*";
modifier.append("/smb ");
}
- if (querystring.indexOf("/file",0) >= 0) {
+ if ( querystring.indexOf("/file", 0) >= 0 ) {
querystring = querystring.replace("/file", "");
urlmask = "file://.*";
modifier.append("/file ");
}
- if (querystring.indexOf("/location",0) >= 0) {
+ if ( querystring.indexOf("/location", 0) >= 0 ) {
querystring = querystring.replace("/location", "");
- if (constraint == null) {
+ if ( constraint == null ) {
constraint = new Bitfield(4);
}
constraint.set(Condenser.flag_cat_haslocation, true);
modifier.append("/location ");
}
- final int lrp = querystring.indexOf("/language/",0);
+ final int lrp = querystring.indexOf("/language/", 0);
String language = "";
- if (lrp >= 0) {
- if (querystring.length() >= (lrp + 12)) {
+ if ( lrp >= 0 ) {
+ if ( querystring.length() >= (lrp + 12) ) {
language = querystring.substring(lrp + 10, lrp + 12);
}
querystring = querystring.replace("/language/" + language, "");
language = language.toLowerCase();
modifier.append("/language/").append(language).append(" ");
}
- final int inurl = querystring.indexOf("inurl:",0);
- if (inurl >= 0) {
+ final int inurl = querystring.indexOf("inurl:", 0);
+ if ( inurl >= 0 ) {
int ftb = querystring.indexOf(' ', inurl);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
final String urlstr = querystring.substring(inurl + 6, ftb);
querystring = querystring.replace("inurl:" + urlstr, "");
- if (!urlstr.isEmpty()) {
+ if ( !urlstr.isEmpty() ) {
urlmask = urlmask == null ? ".*" + urlstr + ".*" : urlmask + urlstr + ".*";
}
modifier.append("inurl:").append(urlstr).append(" ");
}
- final int filetype = querystring.indexOf("filetype:",0);
- if (filetype >= 0) {
+ final int filetype = querystring.indexOf("filetype:", 0);
+ if ( filetype >= 0 ) {
int ftb = querystring.indexOf(' ', filetype);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
String ft = querystring.substring(filetype + 9, ftb);
querystring = querystring.replace("filetype:" + ft, "");
- while (!ft.isEmpty() && ft.charAt(0) == '.') ft = ft.substring(1);
- if (!ft.isEmpty()) {
- if (urlmask == null) {
+ while ( !ft.isEmpty() && ft.charAt(0) == '.' ) {
+ ft = ft.substring(1);
+ }
+ if ( !ft.isEmpty() ) {
+ if ( urlmask == null ) {
urlmask = ".*\\." + ft;
} else {
urlmask = urlmask + ".*\\." + ft;
@@ -374,133 +443,136 @@ public class yacysearch {
modifier.append("filetype:").append(ft).append(" ");
}
String tenant = null;
- if (post.containsKey("tenant")) {
+ if ( post.containsKey("tenant") ) {
tenant = post.get("tenant");
- if (tenant != null && tenant.isEmpty()) {
+ if ( tenant != null && tenant.isEmpty() ) {
tenant = null;
}
- if (tenant != null) {
- if (urlmask == null) {
+ if ( tenant != null ) {
+ if ( urlmask == null ) {
urlmask = ".*" + tenant + ".*";
- } else urlmask = ".*" + tenant + urlmask;
+ } else {
+ urlmask = ".*" + tenant + urlmask;
+ }
}
}
- final int site = querystring.indexOf("site:",0);
+ final int site = querystring.indexOf("site:", 0);
String sitehash = null;
String sitehost = null;
- if (site >= 0) {
+ if ( site >= 0 ) {
int ftb = querystring.indexOf(' ', site);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
sitehost = querystring.substring(site + 5, ftb);
querystring = querystring.replace("site:" + sitehost, "");
- while (sitehost.length() > 0 && sitehost.charAt(0) == '.') {
+ while ( sitehost.length() > 0 && sitehost.charAt(0) == '.' ) {
sitehost = sitehost.substring(1);
}
- while (sitehost.endsWith(".")) {
+ while ( sitehost.endsWith(".") ) {
sitehost = sitehost.substring(0, sitehost.length() - 1);
}
sitehash = DigestURI.hosthash(sitehost);
modifier.append("site:").append(sitehost).append(" ");
}
- final int heuristicScroogle = querystring.indexOf("/heuristic/scroogle",0);
- if (heuristicScroogle >= 0) {
+ final int heuristicScroogle = querystring.indexOf("/heuristic/scroogle", 0);
+ if ( heuristicScroogle >= 0 ) {
querystring = querystring.replace("/heuristic/scroogle", "");
modifier.append("/heuristic/scroogle ");
}
- final int heuristicBlekko = querystring.indexOf("/heuristic/blekko",0);
- if (heuristicBlekko >= 0) {
+ final int heuristicBlekko = querystring.indexOf("/heuristic/blekko", 0);
+ if ( heuristicBlekko >= 0 ) {
querystring = querystring.replace("/heuristic/blekko", "");
modifier.append("/heuristic/blekko ");
}
- final int authori = querystring.indexOf("author:",0);
- String authorhash = null;
- if (authori >= 0) {
- // check if the author was given with single quotes or without
- final boolean quotes = (querystring.charAt(authori + 7) == (char) 39);
- String author;
- if (quotes) {
+ final int authori = querystring.indexOf("author:", 0);
+ String authorhash = null;
+ if ( authori >= 0 ) {
+ // check if the author was given with single quotes or without
+ final boolean quotes = (querystring.charAt(authori + 7) == (char) 39);
+ String author;
+ if ( quotes ) {
int ftb = querystring.indexOf((char) 39, authori + 8);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length() + 1;
}
author = querystring.substring(authori + 8, ftb);
querystring = querystring.replace("author:'" + author + "'", "");
modifier.append("author:'").append(author).append("' ");
- } else {
+ } else {
int ftb = querystring.indexOf(' ', authori);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
author = querystring.substring(authori + 7, ftb);
querystring = querystring.replace("author:" + author, "");
modifier.append("author:").append(author).append(" ");
- }
- authorhash = ASCII.String(Word.word2hash(author));
+ }
+ authorhash = ASCII.String(Word.word2hash(author));
}
- final int tld = querystring.indexOf("tld:",0);
- if (tld >= 0) {
+ final int tld = querystring.indexOf("tld:", 0);
+ if ( tld >= 0 ) {
int ftb = querystring.indexOf(' ', tld);
- if (ftb == -1) {
+ if ( ftb == -1 ) {
ftb = querystring.length();
}
String domain = querystring.substring(tld + 4, ftb);
querystring = querystring.replace("tld:" + domain, "");
modifier.append("tld:").append(domain).append(" ");
- while (domain.length() > 0 && domain.charAt(0) == '.') {
+ while ( domain.length() > 0 && domain.charAt(0) == '.' ) {
domain = domain.substring(1);
}
- if (domain.indexOf('.',0) < 0) {
+ if ( domain.indexOf('.', 0) < 0 ) {
domain = "\\." + domain;
} // is tld
- if (domain.length() > 0) {
+ if ( domain.length() > 0 ) {
urlmask = "[a-zA-Z]*://[^/]*" + domain + "/.*" + ((urlmask != null) ? urlmask : "");
}
}
- if (urlmask == null || urlmask.isEmpty()) {
+ if ( urlmask == null || urlmask.isEmpty() ) {
urlmask = originalUrlMask;
} //if no urlmask was given
// read the language from the language-restrict option 'lr'
// if no one is given, use the user agent or the system language as default
language = (post == null) ? language : post.get("lr", language);
- if (language.startsWith("lang_")) {
+ if ( language.startsWith("lang_") ) {
language = language.substring(5);
}
- if (!ISO639.exists(language)) {
+ if ( !ISO639.exists(language) ) {
// find out language of the user by reading of the user-agent string
String agent = header.get(HeaderFramework.ACCEPT_LANGUAGE);
- if (agent == null) {
+ if ( agent == null ) {
agent = System.getProperty("user.language");
}
language = (agent == null) ? "en" : ISO639.userAgentLanguageDetection(agent);
- if (language == null) {
+ if ( language == null ) {
language = "en";
}
}
// navigation
- final String navigation = (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "");
+ final String navigation =
+ (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "");
// the query
final TreeSet[] query = QueryParams.cleanQuery(querystring.trim()); // converts also umlaute
- final int maxDistance = (querystring.indexOf('"',0) >= 0) ? query.length - 1 : Integer.MAX_VALUE;
+ final int maxDistance = (querystring.indexOf('"', 0) >= 0) ? query.length - 1 : Integer.MAX_VALUE;
// filter out stopwords
final SortedSet filtered = SetTools.joinConstructive(query[0], Switchboard.stopwords);
- if (!filtered.isEmpty()) {
+ if ( !filtered.isEmpty() ) {
SetTools.excludeDestructive(query[0], Switchboard.stopwords);
}
// if a minus-button was hit, remove a special reference first
- if (post != null && post.containsKey("deleteref")) {
+ if ( post != null && post.containsKey("deleteref") ) {
try {
- if (!sb.verifyAuthentication(header)) {
+ if ( !sb.verifyAuthentication(header) ) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
@@ -510,37 +582,45 @@ public class yacysearch {
indexSegment.termIndex().remove(Word.words2hashesHandles(query[0]), delHash.getBytes());
// make new news message with negative voting
- if (!sb.isRobinsonMode()) {
+ if ( !sb.isRobinsonMode() ) {
final Map map = new HashMap();
map.put("urlhash", delHash);
map.put("vote", "negative");
map.put("refid", "");
- sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map);
+ sb.peers.newsPool.publishMyNews(
+ sb.peers.mySeed(),
+ NewsPool.CATEGORY_SURFTIPP_VOTE_ADD,
+ map);
}
// delete the search history since this still shows the entry
SearchEventCache.delete(delHash);
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
}
}
// if a plus-button was hit, create new voting message
- if (post != null && post.containsKey("recommendref")) {
- if (!sb.verifyAuthentication(header)) {
+ if ( post != null && post.containsKey("recommendref") ) {
+ if ( !sb.verifyAuthentication(header) ) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
final String recommendHash = post.get("recommendref", ""); // urlhash
final URIMetadataRow urlentry = indexSegment.urlMetadata().load(UTF8.getBytes(recommendHash));
- if (urlentry != null) {
+ if ( urlentry != null ) {
Document[] documents = null;
try {
- documents = sb.loader.loadDocuments(sb.loader.request(urlentry.url(), true, false), CacheStrategy.IFEXIST, 5000, Integer.MAX_VALUE);
- } catch (final IOException e) {
- } catch (final Parser.Failure e) {
+ documents =
+ sb.loader.loadDocuments(
+ sb.loader.request(urlentry.url(), true, false),
+ CacheStrategy.IFEXIST,
+ 5000,
+ Integer.MAX_VALUE);
+ } catch ( final IOException e ) {
+ } catch ( final Parser.Failure e ) {
}
- if (documents != null) {
+ if ( documents != null ) {
// create a news message
final Map map = new HashMap();
map.put("url", urlentry.url().toNormalform(false, true).replace(',', '|'));
@@ -548,24 +628,33 @@ public class yacysearch {
map.put("description", documents[0].dc_title().replace(',', ' '));
map.put("author", documents[0].dc_creator());
map.put("tags", documents[0].dc_subject(' '));
- sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_SURFTIPP_ADD, map);
+ sb.peers.newsPool.publishMyNews(
+ sb.peers.mySeed(),
+ NewsPool.CATEGORY_SURFTIPP_ADD,
+ map);
documents[0].close();
}
}
}
// if a bookmarks-button was hit, create new bookmark entry
- if (post != null && post.containsKey("bookmarkref")) {
- if (!sb.verifyAuthentication(header)) {
+ if ( post != null && post.containsKey("bookmarkref") ) {
+ if ( !sb.verifyAuthentication(header) ) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
final String bookmarkHash = post.get("bookmarkref", ""); // urlhash
final URIMetadataRow urlentry = indexSegment.urlMetadata().load(UTF8.getBytes(bookmarkHash));
- if (urlentry != null) {
+ if ( urlentry != null ) {
try {
- sb.tables.bookmarks.createBookmark(sb.loader, urlentry.url(), YMarkTables.USER_ADMIN, true, "searchresult", "/search");
- } catch (final Throwable e) {
+ sb.tables.bookmarks.createBookmark(
+ sb.loader,
+ urlentry.url(),
+ YMarkTables.USER_ADMIN,
+ true,
+ "searchresult",
+ "/search");
+ } catch ( final Throwable e ) {
}
}
}
@@ -577,7 +666,7 @@ public class yacysearch {
// check filters
try {
Pattern.compile(urlmask);
- } catch (final PatternSyntaxException ex) {
+ } catch ( final PatternSyntaxException ex ) {
Log.logWarning("SEARCH", "Illegal URL mask, not a valid regex: " + urlmask);
prop.put("urlmaskerror", 1);
prop.putHTML("urlmaskerror_urlmask", urlmask);
@@ -586,14 +675,15 @@ public class yacysearch {
try {
Pattern.compile(prefermask);
- } catch (final PatternSyntaxException ex) {
+ } catch ( final PatternSyntaxException ex ) {
Log.logWarning("SEARCH", "Illegal prefer mask, not a valid regex: " + prefermask);
prop.put("prefermaskerror", 1);
prop.putHTML("prefermaskerror_prefermask", prefermask);
prefermask = "";
}
- final QueryParams theQuery = new QueryParams(
+ final QueryParams theQuery =
+ new QueryParams(
originalquerystring,
queryHashes,
Word.words2hashesHandles(query[1]),
@@ -610,8 +700,9 @@ public class yacysearch {
maximumRecords,
startRecord,
urlmask,
- clustersearch && global ? QueryParams.Searchdom.CLUSTER :
- (global && indexReceiveGranted ? QueryParams.Searchdom.GLOBAL : QueryParams.Searchdom.LOCAL),
+ clustersearch && global ? QueryParams.Searchdom.CLUSTER : (global && indexReceiveGranted
+ ? QueryParams.Searchdom.GLOBAL
+ : QueryParams.Searchdom.LOCAL),
20,
constraint,
true,
@@ -624,9 +715,16 @@ public class yacysearch {
indexSegment,
ranking,
header.get(RequestHeader.USER_AGENT, ""),
- sb.getConfigBool(SwitchboardConstants.SEARCH_VERIFY_DELETE, false) && sb.getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false) && sb.peers.mySeed().getFlagAcceptRemoteIndex());
+ sb.getConfigBool(SwitchboardConstants.SEARCH_VERIFY_DELETE, false)
+ && sb.getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false)
+ && sb.peers.mySeed().getFlagAcceptRemoteIndex());
EventTracker.delete(EventTracker.EClass.SEARCH);
- EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(theQuery.id(true), SearchEvent.Type.INITIALIZATION, "", 0, 0), false);
+ EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(
+ theQuery.id(true),
+ SearchEvent.Type.INITIALIZATION,
+ "",
+ 0,
+ 0), false);
// tell all threads to do nothing for a specific time
sb.intermissionAllThreads(3000);
@@ -635,44 +733,81 @@ public class yacysearch {
theQuery.filterOut(Switchboard.blueList);
// log
- Log.logInfo("LOCAL_SEARCH", "INIT WORD SEARCH: " + theQuery.queryString + ":" + QueryParams.hashSet2hashString(theQuery.queryHashes) + " - " + theQuery.neededResults() + " links to be computed, " + theQuery.displayResults() + " lines to be displayed");
- EventChannel.channels(EventChannel.LOCALSEARCH).addMessage(new RSSMessage("Local Search Request", theQuery.queryString, ""));
+ Log.logInfo(
+ "LOCAL_SEARCH",
+ "INIT WORD SEARCH: "
+ + theQuery.queryString
+ + ":"
+ + QueryParams.hashSet2hashString(theQuery.queryHashes)
+ + " - "
+ + theQuery.neededResults()
+ + " links to be computed, "
+ + theQuery.displayResults()
+ + " lines to be displayed");
+ EventChannel.channels(EventChannel.LOCALSEARCH).addMessage(
+ new RSSMessage("Local Search Request", theQuery.queryString, ""));
final long timestamp = System.currentTimeMillis();
// create a new search event
- if (SearchEventCache.getEvent(theQuery.id(false)) == null) {
+ if ( SearchEventCache.getEvent(theQuery.id(false)) == null ) {
theQuery.setOffset(0); // in case that this is a new search, always start without a offset
startRecord = 0;
}
- final SearchEvent theSearch = SearchEventCache.getEvent(
- theQuery, sb.peers, sb.tables, (sb.isRobinsonMode()) ? sb.clusterhashes : null, false, sb.loader,
- (int) sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_USER, sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_DEFAULT, 10)),
- sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_USER, sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_DEFAULT, 3000)),
- (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_ROBINSON, 0),
- (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_MULTIWORD, 0));
-
- if (startRecord == 0) {
- if (sitehost != null && sb.getConfigBool("heuristic.site", false) && authenticated) {
+ final SearchEvent theSearch =
+ SearchEventCache.getEvent(
+ theQuery,
+ sb.peers,
+ sb.tables,
+ (sb.isRobinsonMode()) ? sb.clusterhashes : null,
+ false,
+ sb.loader,
+ (int) sb.getConfigLong(
+ SwitchboardConstants.REMOTESEARCH_MAXCOUNT_USER,
+ sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXCOUNT_DEFAULT, 10)),
+ sb.getConfigLong(
+ SwitchboardConstants.REMOTESEARCH_MAXTIME_USER,
+ sb.getConfigLong(SwitchboardConstants.REMOTESEARCH_MAXTIME_DEFAULT, 3000)),
+ (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_ROBINSON, 0),
+ (int) sb.getConfigLong(SwitchboardConstants.DHT_BURST_MULTIWORD, 0));
+
+ if ( startRecord == 0 ) {
+ if ( sitehost != null && sb.getConfigBool("heuristic.site", false) && authenticated ) {
sb.heuristicSite(theSearch, sitehost);
}
- if ((heuristicScroogle >= 0 || sb.getConfigBool("heuristic.scroogle", false)) && authenticated) {
+ if ( (heuristicScroogle >= 0 || sb.getConfigBool("heuristic.scroogle", false))
+ && authenticated ) {
sb.heuristicScroogle(theSearch);
}
- if ((heuristicBlekko >= 0 || sb.getConfigBool("heuristic.blekko", false)) && authenticated) {
+ if ( (heuristicBlekko >= 0 || sb.getConfigBool("heuristic.blekko", false)) && authenticated ) {
sb.heuristicRSS("http://blekko.com/ws/$+/rss", theSearch, "blekko");
}
}
// log
- Log.logInfo("LOCAL_SEARCH", "EXIT WORD SEARCH: " + theQuery.queryString + " - " +
- "local-unfiltered(" + theSearch.getRankingResult().getLocalIndexCount() + "), " +
- "local_miss(" + theSearch.getRankingResult().getMissCount() + "), " +
- "local_sortout(" + theSearch.getRankingResult().getSortOutCount() + "), " +
- "remote(" + theSearch.getRankingResult().getRemoteResourceSize() + ") links found, " +
- (System.currentTimeMillis() - timestamp) + " ms");
+ Log.logInfo("LOCAL_SEARCH", "EXIT WORD SEARCH: "
+ + theQuery.queryString
+ + " - "
+ + "local-unfiltered("
+ + theSearch.getRankingResult().getLocalIndexCount()
+ + "), "
+ + "local_miss("
+ + theSearch.getRankingResult().getMissCount()
+ + "), "
+ + "local_sortout("
+ + theSearch.getRankingResult().getSortOutCount()
+ + "), "
+ + "remote("
+ + theSearch.getRankingResult().getRemoteResourceSize()
+ + ") links found, "
+ + (System.currentTimeMillis() - timestamp)
+ + " ms");
// prepare search statistics
- theQuery.resultcount = theSearch.getRankingResult().getLocalIndexCount() - theSearch.getRankingResult().getMissCount() - theSearch.getRankingResult().getSortOutCount() + theSearch.getRankingResult().getRemoteIndexCount();
+ theQuery.resultcount =
+ theSearch.getRankingResult().getLocalIndexCount()
+ - theSearch.getRankingResult().getMissCount()
+ - theSearch.getRankingResult().getSortOutCount()
+ + theSearch.getRankingResult().getRemoteIndexCount();
theQuery.searchtime = System.currentTimeMillis() - timestamp;
theQuery.urlretrievaltime = theSearch.result().getURLRetrievalTime();
theQuery.snippetcomputationtime = theSearch.result().getSnippetComputationTime();
@@ -682,22 +817,29 @@ public class yacysearch {
final int meanMax = (post != null) ? post.getInt("meanCount", 0) : 0;
prop.put("meanCount", meanMax);
- if (meanMax > 0 && !json && !rss) {
- final DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), new StringBuilder(querystring));
- final Iterator meanIt = didYouMean.getSuggestions(100, 5).iterator();
+ if ( meanMax > 0 && !json && !rss ) {
+ final DidYouMean didYouMean =
+ new DidYouMean(indexSegment.termIndex(), new StringBuilder(querystring));
+ final Iterator meanIt = didYouMean.getSuggestions(100, 5).iterator();
int meanCount = 0;
String suggestion;
- while( meanCount0 ? 1:0);
+ prop.put("didYouMean_suggestions_" + (meanCount - 1) + "_sep", "");
+ prop.put("didYouMean", meanCount > 0 ? 1 : 0);
prop.put("didYouMean_suggestions", meanCount);
} else {
prop.put("didYouMean", 0);
@@ -705,16 +847,18 @@ public class yacysearch {
// find geographic info
final SortedSet coordinates = LibraryProvider.geoLoc.find(originalquerystring, false);
- if (coordinates == null || coordinates.isEmpty() || startRecord > 0) {
+ if ( coordinates == null || coordinates.isEmpty() || startRecord > 0 ) {
prop.put("geoinfo", "0");
} else {
int i = 0;
- for (final Location c: coordinates) {
+ for ( final Location c : coordinates ) {
prop.put("geoinfo_loc_" + i + "_lon", Math.round(c.lon() * 10000.0f) / 10000.0f);
prop.put("geoinfo_loc_" + i + "_lat", Math.round(c.lat() * 10000.0f) / 10000.0f);
prop.put("geoinfo_loc_" + i + "_name", c.getName());
i++;
- if (i >= 10) break;
+ if ( i >= 10 ) {
+ break;
+ }
}
prop.put("geoinfo_loc", i);
prop.put("geoinfo", "1");
@@ -722,47 +866,79 @@ public class yacysearch {
// update the search tracker
try {
- synchronized (trackerHandles) {
+ synchronized ( trackerHandles ) {
trackerHandles.add(theQuery.time);
- while (trackerHandles.size() > 600) {
- if (!trackerHandles.remove(trackerHandles.first())) break;
+ while ( trackerHandles.size() > 600 ) {
+ if ( !trackerHandles.remove(trackerHandles.first()) ) {
+ break;
+ }
}
}
sb.localSearchTracker.put(client, trackerHandles);
- if (sb.localSearchTracker.size() > 100) {
+ if ( sb.localSearchTracker.size() > 100 ) {
sb.localSearchTracker.remove(sb.localSearchTracker.keys().nextElement());
}
- if (MemoryControl.shortStatus()) sb.localSearchTracker.clear();
- } catch (final Exception e) {
+ if ( MemoryControl.shortStatus() ) {
+ sb.localSearchTracker.clear();
+ }
+ } catch ( final Exception e ) {
Log.logException(e);
}
- final int indexcount = theSearch.getRankingResult().getLocalIndexCount() - theSearch.getRankingResult().getMissCount() - theSearch.getRankingResult().getSortOutCount() + theSearch.getRankingResult().getRemoteIndexCount();
+ final int indexcount =
+ theSearch.getRankingResult().getLocalIndexCount()
+ - theSearch.getRankingResult().getMissCount()
+ - theSearch.getRankingResult().getSortOutCount()
+ + theSearch.getRankingResult().getRemoteIndexCount();
prop.put("num-results_offset", startRecord == 0 ? 0 : startRecord + 1);
- prop.put("num-results_itemscount", Formatter.number(startRecord + theSearch.getQuery().itemsPerPage > indexcount ? startRecord + indexcount % theSearch.getQuery().itemsPerPage : startRecord + theSearch.getQuery().itemsPerPage, true));
+ prop.put("num-results_itemscount", Formatter.number(
+ startRecord + theSearch.getQuery().itemsPerPage > indexcount ? startRecord
+ + indexcount
+ % theSearch.getQuery().itemsPerPage : startRecord + theSearch.getQuery().itemsPerPage,
+ true));
prop.put("num-results_itemsPerPage", maximumRecords);
prop.put("num-results_totalcount", Formatter.number(indexcount, true));
- prop.put("num-results_globalresults", global && (indexReceiveGranted || clustersearch) ? "1" : "0");
- prop.put("num-results_globalresults_localResourceSize", Formatter.number(theSearch.getRankingResult().getLocalIndexCount(), true));
- prop.put("num-results_globalresults_localMissCount", Formatter.number(theSearch.getRankingResult().getMissCount(), true));
- prop.put("num-results_globalresults_remoteResourceSize", Formatter.number(theSearch.getRankingResult().getRemoteResourceSize(), true));
- prop.put("num-results_globalresults_remoteIndexCount", Formatter.number(theSearch.getRankingResult().getRemoteIndexCount(), true));
- prop.put("num-results_globalresults_remotePeerCount", Formatter.number(theSearch.getRankingResult().getRemotePeerCount(), true));
+ prop.put("num-results_globalresults", global && (indexReceiveGranted || clustersearch)
+ ? "1"
+ : "0");
+ prop.put(
+ "num-results_globalresults_localResourceSize",
+ Formatter.number(theSearch.getRankingResult().getLocalIndexCount(), true));
+ prop.put(
+ "num-results_globalresults_localMissCount",
+ Formatter.number(theSearch.getRankingResult().getMissCount(), true));
+ prop.put(
+ "num-results_globalresults_remoteResourceSize",
+ Formatter.number(theSearch.getRankingResult().getRemoteResourceSize(), true));
+ prop.put(
+ "num-results_globalresults_remoteIndexCount",
+ Formatter.number(theSearch.getRankingResult().getRemoteIndexCount(), true));
+ prop.put(
+ "num-results_globalresults_remotePeerCount",
+ Formatter.number(theSearch.getRankingResult().getRemotePeerCount(), true));
// compose page navigation
final StringBuilder resnav = new StringBuilder(200);
final int thispage = startRecord / theQuery.displayResults();
- if (thispage == 0) {
- resnav.append(" ");
+ if ( thispage == 0 ) {
+ resnav
+ .append(" ");
} else {
- resnav.append(" ");
+ resnav.append(" ");
}
final int numberofpages = Math.min(10, 1 + ((indexcount - 1) / theQuery.displayResults()));
- for (int i = 0; i < numberofpages; i++) {
- if (i == thispage) {
+ for ( int i = 0; i < numberofpages; i++ ) {
+ if ( i == thispage ) {
resnav.append(" ");
} else {
resnav.append(" ");
}
}
- if (thispage >= numberofpages) {
- resnav.append("");
+ if ( thispage >= numberofpages ) {
+ resnav
+ .append("");
} else {
resnav.append("");
+ resnav.append(QueryParams.navurl(
+ "html",
+ thispage + 1,
+ theQuery,
+ null,
+ originalUrlMask,
+ navigation).toString());
+ resnav
+ .append("\">");
}
final String resnavs = resnav.toString();
prop.put("num-results_resnav", resnavs);
@@ -791,24 +977,29 @@ public class yacysearch {
prop.put("pageNavBottom_resnav", resnavs);
// generate the search result lines; the content will be produced by another servlet
- for (int i = 0; i < theQuery.displayResults(); i++) {
+ for ( int i = 0; i < theQuery.displayResults(); i++ ) {
prop.put("results_" + i + "_item", startRecord + i);
prop.put("results_" + i + "_eventID", theQuery.id(false));
}
prop.put("results", theQuery.displayResults());
- prop.put("resultTable", (contentdom == ContentDomain.APP || contentdom == ContentDomain.AUDIO || contentdom == ContentDomain.VIDEO) ? 1 : 0);
+ prop
+ .put(
+ "resultTable",
+ (contentdom == ContentDomain.APP || contentdom == ContentDomain.AUDIO || contentdom == ContentDomain.VIDEO)
+ ? 1
+ : 0);
prop.put("eventID", theQuery.id(false)); // for bottomline
// process result of search
- if (!filtered.isEmpty()) {
+ if ( !filtered.isEmpty() ) {
prop.put("excluded", "1");
prop.putHTML("excluded_stopwords", filtered.toString());
} else {
prop.put("excluded", "0");
}
- if (prop == null || prop.isEmpty()) {
- if (post.get("query", post.get("search", "")).length() < 2) {
+ if ( prop == null || prop.isEmpty() ) {
+ if ( post.get("query", post.get("search", "")).length() < 2 ) {
prop.put("num-results", "2"); // no results - at least 2 chars
} else {
prop.put("num-results", "1"); // no results
@@ -822,7 +1013,7 @@ public class yacysearch {
// adding some additional properties needed for the rss feed
String hostName = header.get("Host", "localhost");
- if (hostName.indexOf(':',0) == -1) {
+ if ( hostName.indexOf(':', 0) == -1 ) {
hostName += ":" + serverCore.getPortNr(env.getConfig("port", "8090"));
}
prop.put("searchBaseURL", "http://" + hostName + "/yacysearch.html");
@@ -838,10 +1029,20 @@ public class yacysearch {
prop.putHTML("prefermaskfilter", prefermask);
prop.put("indexof", (indexof) ? "on" : "off");
prop.put("constraint", (constraint == null) ? "" : constraint.exportB64());
- prop.put("search.verify", snippetFetchStrategy == null ? sb.getConfig("search.verify", "iffresh") : snippetFetchStrategy.toName());
- prop.put("search.navigation", (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
+ prop.put("search.verify", snippetFetchStrategy == null
+ ? sb.getConfig("search.verify", "iffresh")
+ : snippetFetchStrategy.toName());
+ prop.put(
+ "search.navigation",
+ (post == null) ? sb.getConfig("search.navigation", "all") : post.get("nav", "all"));
prop.put("contentdom", (post == null ? "text" : post.get("contentdom", "text")));
- prop.put("searchdomswitches", sb.getConfigBool("search.text", true) || sb.getConfigBool("search.audio", true) || sb.getConfigBool("search.video", true) || sb.getConfigBool("search.image", true) || sb.getConfigBool("search.app", true) ? 1 : 0);
+ prop.put(
+ "searchdomswitches",
+ sb.getConfigBool("search.text", true)
+ || sb.getConfigBool("search.audio", true)
+ || sb.getConfigBool("search.video", true)
+ || sb.getConfigBool("search.image", true)
+ || sb.getConfigBool("search.app", true) ? 1 : 0);
prop.put("searchdomswitches_searchtext", sb.getConfigBool("search.text", true) ? 1 : 0);
prop.put("searchdomswitches_searchaudio", sb.getConfigBool("search.audio", true) ? 1 : 0);
prop.put("searchdomswitches_searchvideo", sb.getConfigBool("search.video", true) ? 1 : 0);
diff --git a/source/de/anomic/crawler/CrawlQueues.java b/source/de/anomic/crawler/CrawlQueues.java
index 935636d4c..5daaddad9 100644
--- a/source/de/anomic/crawler/CrawlQueues.java
+++ b/source/de/anomic/crawler/CrawlQueues.java
@@ -142,11 +142,19 @@ public class CrawlQueues {
* @return if the hash exists, the name of the database is returned, otherwise null is returned
*/
public String urlExists(final byte[] hash) {
- if (this.delegatedURL.exists(hash)) return "delegated";
- if (this.errorURL.exists(hash)) return "errors";
- if (this.noticeURL.existsInStack(hash)) return "crawler";
+ if (this.delegatedURL.exists(hash)) {
+ return "delegated";
+ }
+ if (this.errorURL.exists(hash)) {
+ return "errors";
+ }
+ if (this.noticeURL.existsInStack(hash)) {
+ return "crawler";
+ }
for (final Loader worker: this.workers.values()) {
- if (Base64Order.enhancedCoder.equal(worker.request.url().hash(), hash)) return "worker";
+ if (Base64Order.enhancedCoder.equal(worker.request.url().hash(), hash)) {
+ return "worker";
+ }
}
return null;
}
@@ -159,16 +167,26 @@ public class CrawlQueues {
public DigestURI getURL(final byte[] urlhash) {
assert urlhash != null;
- if (urlhash == null || urlhash.length == 0) return null;
+ if (urlhash == null || urlhash.length == 0) {
+ return null;
+ }
ZURL.Entry ee = this.delegatedURL.get(urlhash);
- if (ee != null) return ee.url();
+ if (ee != null) {
+ return ee.url();
+ }
ee = this.errorURL.get(urlhash);
- if (ee != null) return ee.url();
+ if (ee != null) {
+ return ee.url();
+ }
for (final Loader w: this.workers.values()) {
- if (Base64Order.enhancedCoder.equal(w.request.url().hash(), urlhash)) return w.request.url();
+ if (Base64Order.enhancedCoder.equal(w.request.url().hash(), urlhash)) {
+ return w.request.url();
+ }
}
final Request ne = this.noticeURL.get(urlhash);
- if (ne != null) return ne.url();
+ if (ne != null) {
+ return ne.url();
+ }
return null;
}
@@ -176,7 +194,9 @@ public class CrawlQueues {
// wait for all workers to finish
final int timeout = (int) this.sb.getConfigLong("crawler.clientTimeout", 10000);
for (final Loader w: this.workers.values()) {
- if (w.age() > timeout) w.interrupt();
+ if (w.age() > timeout) {
+ w.interrupt();
+ }
}
}
@@ -185,7 +205,9 @@ public class CrawlQueues {
final Request[] e = new Request[this.workers.size()];
int i = 0;
for (final Loader w: this.workers.values()) {
- if (i >= e.length) break;
+ if (i >= e.length) {
+ break;
+ }
e[i++] = w.request;
}
return e;
@@ -199,8 +221,7 @@ public class CrawlQueues {
public boolean coreCrawlJob() {
final boolean robinsonPrivateCase = (this.sb.isRobinsonMode() &&
- !this.sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "").equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER) &&
- !this.sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "").equals(SwitchboardConstants.CLUSTER_MODE_PRIVATE_CLUSTER));
+ !this.sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "").equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER));
if ((robinsonPrivateCase || coreCrawlJobSize() <= 20) && limitCrawlJobSize() > 0) {
// move some tasks to the core crawl job so we have something to do
@@ -216,12 +237,16 @@ public class CrawlQueues {
final String queueCheckCore = loadIsPossible(NoticedURL.StackType.CORE);
final String queueCheckNoload = loadIsPossible(NoticedURL.StackType.NOLOAD);
if (queueCheckCore != null && queueCheckNoload != null) {
- if (this.log.isFine()) this.log.logFine("omitting de-queue/local: " + queueCheckCore + ":" + queueCheckNoload);
+ if (this.log.isFine()) {
+ this.log.logFine("omitting de-queue/local: " + queueCheckCore + ":" + queueCheckNoload);
+ }
return false;
}
if (isPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) {
- if (this.log.isFine()) this.log.logFine("omitting de-queue/local: paused");
+ if (this.log.isFine()) {
+ this.log.logFine("omitting de-queue/local: paused");
+ }
return false;
}
@@ -238,7 +263,9 @@ public class CrawlQueues {
if (this.noticeURL.stackSize(NoticedURL.StackType.NOLOAD) > 0) {
// get one entry that will not be loaded, just indexed
urlEntry = this.noticeURL.pop(NoticedURL.StackType.NOLOAD, true, this.sb.crawler);
- if (urlEntry == null) continue;
+ if (urlEntry == null) {
+ continue;
+ }
final String profileHandle = urlEntry.profileHandle();
if (profileHandle == null) {
this.log.logSevere(stats + ": NULL PROFILE HANDLE '" + urlEntry.profileHandle() + "' for URL " + urlEntry.url());
@@ -259,7 +286,9 @@ public class CrawlQueues {
}
urlEntry = this.noticeURL.pop(NoticedURL.StackType.CORE, true, this.sb.crawler);
- if (urlEntry == null) continue;
+ if (urlEntry == null) {
+ continue;
+ }
final String profileHandle = urlEntry.profileHandle();
// System.out.println("DEBUG plasmaSwitchboard.processCrawling:
// profileHandle = " + profileHandle + ", urlEntry.url = " + urlEntry.url());
@@ -271,7 +300,9 @@ public class CrawlQueues {
return true;
} catch (final IOException e) {
this.log.logSevere(stats + ": CANNOT FETCH ENTRY: " + e.getMessage(), e);
- if (e.getMessage().indexOf("hash is null",0) > 0) this.noticeURL.clear(NoticedURL.StackType.CORE);
+ if (e.getMessage().indexOf("hash is null",0) > 0) {
+ this.noticeURL.clear(NoticedURL.StackType.CORE);
+ }
}
}
return true;
@@ -293,7 +324,7 @@ public class CrawlQueues {
final DigestURI url = urlEntry.url();
final String urlProtocol = url.getProtocol();
if (this.sb.loader.isSupportedProtocol(urlProtocol)) {
- if (this.log.isFine())
+ if (this.log.isFine()) {
this.log.logFine(stats + ": URL=" + urlEntry.url()
+ ", initiator=" + ((urlEntry.initiator() == null) ? "" : ASCII.String(urlEntry.initiator()))
+ ", crawlOrder=" + ((profile.remoteIndexing()) ? "true" : "false")
@@ -302,6 +333,7 @@ public class CrawlQueues {
+ ", must-match=" + profile.urlMustMatchPattern().toString()
+ ", must-not-match=" + profile.urlMustNotMatchPattern().toString()
+ ", permission=" + ((this.sb.peers == null) ? "undefined" : (((this.sb.peers.mySeed().isSenior()) || (this.sb.peers.mySeed().isPrincipal())) ? "true" : "false")));
+ }
// work off one Crawl stack entry
if (urlEntry == null || urlEntry.url() == null) {
@@ -387,23 +419,31 @@ public class CrawlQueues {
}
// check again
if (this.workers.size() >= this.sb.getConfigLong(SwitchboardConstants.CRAWLER_THREADS_ACTIVE_MAX, 20)) {
- if (this.log.isFine()) this.log.logFine("remoteCrawlLoaderJob: too many processes in loader queue, dismissed (" + "cacheLoader=" + this.workers.size() + "), httpClients = " + ConnectionInfo.getCount());
+ if (this.log.isFine()) {
+ this.log.logFine("remoteCrawlLoaderJob: too many processes in loader queue, dismissed (" + "cacheLoader=" + this.workers.size() + "), httpClients = " + ConnectionInfo.getCount());
+ }
return false;
}
final String cautionCause = this.sb.onlineCaution();
if (cautionCause != null) {
- if (this.log.isFine()) this.log.logFine("remoteCrawlLoaderJob: online caution for " + cautionCause + ", omitting processing");
+ if (this.log.isFine()) {
+ this.log.logFine("remoteCrawlLoaderJob: online caution for " + cautionCause + ", omitting processing");
+ }
return false;
}
if (remoteTriggeredCrawlJobSize() > 200) {
- if (this.log.isFine()) this.log.logFine("remoteCrawlLoaderJob: the remote-triggered crawl job queue is filled, omitting processing");
+ if (this.log.isFine()) {
+ this.log.logFine("remoteCrawlLoaderJob: the remote-triggered crawl job queue is filled, omitting processing");
+ }
return false;
}
if (coreCrawlJobSize() > 0 /*&& sb.indexingStorageProcessor.queueSize() > 0*/) {
- if (this.log.isFine()) this.log.logFine("remoteCrawlLoaderJob: a local crawl is running, omitting processing");
+ if (this.log.isFine()) {
+ this.log.logFine("remoteCrawlLoaderJob: a local crawl is running, omitting processing");
+ }
return false;
}
@@ -414,27 +454,37 @@ public class CrawlQueues {
final Iterator e = PeerSelection.getProvidesRemoteCrawlURLs(this.sb.peers);
while (e.hasNext()) {
seed = e.next();
- if (seed != null) this.remoteCrawlProviderHashes.add(seed.hash);
+ if (seed != null) {
+ this.remoteCrawlProviderHashes.add(seed.hash);
+ }
}
}
}
- if (this.remoteCrawlProviderHashes.isEmpty()) return false;
+ if (this.remoteCrawlProviderHashes.isEmpty()) {
+ return false;
+ }
// take one entry from the provider list and load the entries from the remote peer
seed = null;
String hash = null;
while (seed == null && !this.remoteCrawlProviderHashes.isEmpty()) {
hash = this.remoteCrawlProviderHashes.remove(this.remoteCrawlProviderHashes.size() - 1);
- if (hash == null) continue;
+ if (hash == null) {
+ continue;
+ }
seed = this.sb.peers.get(hash);
- if (seed == null) continue;
+ if (seed == null) {
+ continue;
+ }
// check if the peer is inside our cluster
if ((this.sb.isRobinsonMode()) && (!this.sb.isInMyCluster(seed))) {
seed = null;
continue;
}
}
- if (seed == null) return false;
+ if (seed == null) {
+ return false;
+ }
// we know a peer which should provide remote crawl entries. load them now.
final RSSFeed feed = Protocol.queryRemoteCrawlURLs(this.sb.peers, seed, 60, 8000);
@@ -467,7 +517,9 @@ public class CrawlQueues {
final String urlRejectReason = this.sb.crawlStacker.urlInAcceptedDomain(url);
if (urlRejectReason == null) {
// stack url
- if (this.sb.getLog().isFinest()) this.sb.getLog().logFinest("crawlOrder: stack: url='" + url + "'");
+ if (this.sb.getLog().isFinest()) {
+ this.sb.getLog().logFinest("crawlOrder: stack: url='" + url + "'");
+ }
this.sb.crawlStacker.enqueueEntry(new Request(
ASCII.getBytes(hash),
url,
@@ -510,12 +562,16 @@ public class CrawlQueues {
// or there is no global crawl on the stack
final String queueCheck = loadIsPossible(NoticedURL.StackType.REMOTE);
if (queueCheck != null) {
- if (this.log.isFinest()) this.log.logFinest("omitting de-queue/remote: " + queueCheck);
+ if (this.log.isFinest()) {
+ this.log.logFinest("omitting de-queue/remote: " + queueCheck);
+ }
return false;
}
if (isPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL)) {
- if (this.log.isFinest()) this.log.logFinest("omitting de-queue/remote: paused");
+ if (this.log.isFinest()) {
+ this.log.logFinest("omitting de-queue/remote: paused");
+ }
return false;
}
@@ -532,7 +588,9 @@ public class CrawlQueues {
return true;
} catch (final IOException e) {
this.log.logSevere(stats + ": CANNOT FETCH ENTRY: " + e.getMessage(), e);
- if (e.getMessage().indexOf("hash is null",0) > 0) this.noticeURL.clear(NoticedURL.StackType.REMOTE);
+ if (e.getMessage().indexOf("hash is null",0) > 0) {
+ this.noticeURL.clear(NoticedURL.StackType.REMOTE);
+ }
return true;
}
}
@@ -599,7 +657,9 @@ public class CrawlQueues {
final Response response = CrawlQueues.this.sb.loader.load(this.request, e == null ? CacheStrategy.IFEXIST : e.cacheStrategy(), true);
if (response == null) {
this.request.setStatus("error", WorkflowJob.STATUS_FINISHED);
- if (CrawlQueues.this.log.isFine()) CrawlQueues.this.log.logFine("problem loading " + this.request.url().toString() + ": no content (possibly caused by cache policy)");
+ if (CrawlQueues.this.log.isFine()) {
+ CrawlQueues.this.log.logFine("problem loading " + this.request.url().toString() + ": no content (possibly caused by cache policy)");
+ }
result = "no content (possibly caused by cache policy)";
} else {
this.request.setStatus("loaded", WorkflowJob.STATUS_RUNNING);
@@ -609,7 +669,9 @@ public class CrawlQueues {
}
} catch (final IOException e) {
this.request.setStatus("error", WorkflowJob.STATUS_FINISHED);
- if (CrawlQueues.this.log.isFine()) CrawlQueues.this.log.logFine("problem loading " + this.request.url().toString() + ": " + e.getMessage());
+ if (CrawlQueues.this.log.isFine()) {
+ CrawlQueues.this.log.logFine("problem loading " + this.request.url().toString() + ": " + e.getMessage());
+ }
result = "load error - " + e.getMessage();
}
diff --git a/source/net/yacy/peers/Network.java b/source/net/yacy/peers/Network.java
index a7d3cc209..fb99b599b 100644
--- a/source/net/yacy/peers/Network.java
+++ b/source/net/yacy/peers/Network.java
@@ -61,16 +61,18 @@ import net.yacy.peers.operation.yacySeedUploadFtp;
import net.yacy.peers.operation.yacySeedUploadScp;
import net.yacy.peers.operation.yacySeedUploader;
import net.yacy.search.Switchboard;
+import net.yacy.search.SwitchboardConstants;
import de.anomic.server.serverCore;
-public class Network {
+public class Network
+{
// statics
public static final ThreadGroup publishThreadGroup = new ThreadGroup("publishThreadGroup");
public static final HashMap seedUploadMethods = new HashMap();
public static final Log log = new Log("YACY");
public static long lastOnlineTime = 0;
- /** pseudo-random key derived from a time-interval while YaCy startup*/
+ /** pseudo-random key derived from a time-interval while YaCy startup */
public static long speedKey = 0;
public static long magic = System.currentTimeMillis();
public static final Map amIAccessibleDB = new ConcurrentHashMap(); // Holds PeerHash / yacyAccessible Relations
@@ -105,10 +107,10 @@ public class Network {
// ensure that correct IP is used
final String staticIP = sb.getConfig("staticIP", "");
- if (staticIP.length() != 0 && Seed.isProperIP(staticIP) == null) {
+ if ( staticIP.length() != 0 && Seed.isProperIP(staticIP) == null ) {
serverCore.useStaticIP = true;
sb.peers.mySeed().setIP(staticIP);
- log.logInfo("staticIP set to "+ staticIP);
+ log.logInfo("staticIP set to " + staticIP);
} else {
serverCore.useStaticIP = false;
}
@@ -127,7 +129,9 @@ public class Network {
}
public final void publishSeedList() {
- if (log.isFine()) log.logFine("yacyCore.publishSeedList: Triggered Seed Publish");
+ if ( log.isFine() ) {
+ log.logFine("yacyCore.publishSeedList: Triggered Seed Publish");
+ }
/*
if (oldIPStamp.equals((String) seedDB.mySeed.get(yacySeed.IP, "127.0.0.1")))
@@ -138,45 +142,48 @@ public class Network {
yacyCore.log.logDebug("***DEBUG publishSeedList: I can reach myself");
*/
- if ((this.sb.peers.lastSeedUpload_myIP.equals(this.sb.peers.mySeed().getIP())) &&
- (this.sb.peers.lastSeedUpload_seedDBSize == this.sb.peers.sizeConnected()) &&
- (canReachMyself()) &&
- (System.currentTimeMillis() - this.sb.peers.lastSeedUpload_timeStamp < 1000 * 60 * 60 * 24) &&
- (this.sb.peers.mySeed().isPrincipal())
- ) {
- if (log.isFine()) log.logFine("yacyCore.publishSeedList: not necessary to publish: oldIP is equal, sizeConnected is equal and I can reach myself under the old IP.");
+ if ( (this.sb.peers.lastSeedUpload_myIP.equals(this.sb.peers.mySeed().getIP()))
+ && (this.sb.peers.lastSeedUpload_seedDBSize == this.sb.peers.sizeConnected())
+ && (canReachMyself())
+ && (System.currentTimeMillis() - this.sb.peers.lastSeedUpload_timeStamp < 1000 * 60 * 60 * 24)
+ && (this.sb.peers.mySeed().isPrincipal()) ) {
+ if ( log.isFine() ) {
+ log
+ .logFine("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 ...
final String seedUploadMethod = this.sb.getConfig("seedUploadMethod", "");
- if (
- (!seedUploadMethod.equalsIgnoreCase("none")) ||
- ((seedUploadMethod.equals("")) && (this.sb.getConfig("seedFTPPassword", "").length() > 0)) ||
- ((seedUploadMethod.equals("")) && (this.sb.getConfig("seedFilePath", "").length() > 0))
- ) {
- if (seedUploadMethod.equals("")) {
- if (this.sb.getConfig("seedFTPPassword", "").length() > 0) {
+ if ( (!seedUploadMethod.equalsIgnoreCase("none"))
+ || ((seedUploadMethod.equals("")) && (this.sb.getConfig("seedFTPPassword", "").length() > 0))
+ || ((seedUploadMethod.equals("")) && (this.sb.getConfig("seedFilePath", "").length() > 0)) ) {
+ if ( seedUploadMethod.equals("") ) {
+ if ( this.sb.getConfig("seedFTPPassword", "").length() > 0 ) {
this.sb.setConfig("seedUploadMethod", "Ftp");
}
- if (this.sb.getConfig("seedFilePath", "").length() > 0) {
+ if ( this.sb.getConfig("seedFilePath", "").length() > 0 ) {
this.sb.setConfig("seedUploadMethod", "File");
}
}
// we want to be a principal...
saveSeedList(this.sb);
} else {
- if (seedUploadMethod.equals("")) {
+ if ( seedUploadMethod.equals("") ) {
this.sb.setConfig("seedUploadMethod", "none");
}
- if (log.isFine()) log.logFine("yacyCore.publishSeedList: No uploading method configured");
+ if ( log.isFine() ) {
+ log.logFine("yacyCore.publishSeedList: No uploading method configured");
+ }
return;
}
}
public final void peerPing() {
- if ((this.sb.isRobinsonMode()) && (this.sb.getConfig("cluster.mode", "").equals("privatepeer"))) {
+ if ( (this.sb.isRobinsonMode())
+ && (this.sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "").equals(SwitchboardConstants.CLUSTER_MODE_PRIVATE_PEER)) ) {
// in case this peer is a privat peer we omit the peer ping
// all other robinson peer types do a peer ping:
// the privatecluster does the ping to the other cluster members
@@ -189,42 +196,54 @@ public class Network {
this.sb.updateMySeed();
// publish own seed to other peer, this can every peer, but makes only sense for senior peers
- if (this.sb.peers.sizeConnected() == 0) {
+ if ( this.sb.peers.sizeConnected() == 0 ) {
// reload the seed lists
this.sb.loadSeedLists();
- log.logInfo("re-initialized seed list. received " + this.sb.peers.sizeConnected() + " new peer(s)");
+ log.logInfo("re-initialized seed list. received "
+ + this.sb.peers.sizeConnected()
+ + " new peer(s)");
}
final int newSeeds = publishMySeed(false);
- if (newSeeds > 0) {
- log.logInfo("received " + newSeeds + " new peer(s), know a total of " + this.sb.peers.sizeConnected() + " different peers");
+ if ( newSeeds > 0 ) {
+ log.logInfo("received "
+ + newSeeds
+ + " new peer(s), know a total of "
+ + this.sb.peers.sizeConnected()
+ + " different peers");
}
}
private boolean canReachMyself() { // TODO: check if this method is necessary - depending on the used router it will not work
// returns true if we can reach ourself under our known peer address
// if we cannot reach ourself, we call a forced publishMySeed and return false
- final long[] callback = Protocol.queryUrlCount(this.sb.peers.mySeed());
- if (callback[0] >= 0 && callback[1] == magic) {
+ final long[] callback = Protocol.queryUrlCount(this.sb.peers.mySeed());
+ if ( callback[0] >= 0 && callback[1] == magic ) {
this.sb.peers.mySeed().setLastSeenUTC();
return true;
}
log.logInfo("re-connect own seed");
final String oldAddress = this.sb.peers.mySeed().getPublicAddress();
- /*final int newSeeds =*/ publishMySeed(true);
+ /*final int newSeeds =*/publishMySeed(true);
return (oldAddress != null && oldAddress.equals(this.sb.peers.mySeed().getPublicAddress()));
}
// use our own formatter to prevent concurrency locks with other processes
- private final static GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second);
+ private final static GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(
+ GenericFormatter.FORMAT_SHORT_SECOND,
+ GenericFormatter.time_second);
- protected class publishThread extends Thread {
+ protected class publishThread extends Thread
+ {
int added;
private final Seed seed;
private final Semaphore sync;
private final List syncList;
- public publishThread(final ThreadGroup tg, final Seed seed,
- final Semaphore sync, final List syncList) throws InterruptedException {
+ public publishThread(
+ final ThreadGroup tg,
+ final Seed seed,
+ final Semaphore sync,
+ final List syncList) throws InterruptedException {
super(tg, "PublishSeed_" + seed.getName());
this.sync = sync;
@@ -235,50 +254,106 @@ public class Network {
this.added = 0;
}
+ @Override
public final void run() {
try {
- this.added = Protocol.hello(Network.this.sb.peers.mySeed(), Network.this.sb.peers.peerActions, this.seed.getClusterAddress(), this.seed.hash, this.seed.getName());
- if (this.added < 0) {
+ this.added =
+ Protocol.hello(
+ Network.this.sb.peers.mySeed(),
+ Network.this.sb.peers.peerActions,
+ this.seed.getClusterAddress(),
+ this.seed.hash,
+ this.seed.getName());
+ if ( this.added < 0 ) {
// no or wrong response, delete that address
final String cause = "peer ping to peer resulted in error response (added < 0)";
- log.logInfo("publish: disconnected " + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR) + " peer '" + this.seed.getName() + "' from " + this.seed.getPublicAddress() + ": " + cause);
+ log.logInfo("publish: disconnected "
+ + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR)
+ + " peer '"
+ + this.seed.getName()
+ + "' from "
+ + this.seed.getPublicAddress()
+ + ": "
+ + cause);
Network.this.sb.peers.peerActions.peerDeparture(this.seed, cause);
} else {
// success! we have published our peer to a senior peer
// update latest news from the other peer
- log.logInfo("publish: handshaked " + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR) + " peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress());
+ log.logInfo("publish: handshaked "
+ + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR)
+ + " peer '"
+ + this.seed.getName()
+ + "' at "
+ + this.seed.getPublicAddress());
// check if seed's lastSeen has been updated
final Seed newSeed = Network.this.sb.peers.getConnected(this.seed.hash);
- if (newSeed != null) {
- if (!newSeed.isOnline()) {
- if (log.isFine()) log.logFine("publish: recently handshaked " + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR) +
- " peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress() + " is not online." +
- " Removing Peer from connected");
+ if ( newSeed != null ) {
+ if ( !newSeed.isOnline() ) {
+ if ( log.isFine() ) {
+ log.logFine("publish: recently handshaked "
+ + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR)
+ + " peer '"
+ + this.seed.getName()
+ + "' at "
+ + this.seed.getPublicAddress()
+ + " is not online."
+ + " Removing Peer from connected");
+ }
Network.this.sb.peers.peerActions.peerDeparture(newSeed, "peer not online");
- } else
- if (newSeed.getLastSeenUTC() < (System.currentTimeMillis() - 10000)) {
+ } else if ( newSeed.getLastSeenUTC() < (System.currentTimeMillis() - 10000) ) {
// update last seed date
- if (newSeed.getLastSeenUTC() >= this.seed.getLastSeenUTC()) {
- if (log.isFine()) log.logFine("publish: recently handshaked " + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR) +
- " peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress() + " with old LastSeen: '" +
- my_SHORT_SECOND_FORMATTER.format(new Date(newSeed.getLastSeenUTC())) + "'");
+ if ( newSeed.getLastSeenUTC() >= this.seed.getLastSeenUTC() ) {
+ if ( log.isFine() ) {
+ log
+ .logFine("publish: recently handshaked "
+ + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR)
+ + " peer '"
+ + this.seed.getName()
+ + "' at "
+ + this.seed.getPublicAddress()
+ + " with old LastSeen: '"
+ + my_SHORT_SECOND_FORMATTER.format(new Date(newSeed
+ .getLastSeenUTC())) + "'");
+ }
newSeed.setLastSeenUTC();
Network.this.sb.peers.peerActions.peerArrival(newSeed, true);
} else {
- if (log.isFine()) log.logFine("publish: recently handshaked " + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR) +
- " peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress() + " with old LastSeen: '" +
- my_SHORT_SECOND_FORMATTER.format(new Date(newSeed.getLastSeenUTC())) + "', this is more recent: '" +
- my_SHORT_SECOND_FORMATTER.format(new Date(this.seed.getLastSeenUTC())) + "'");
+ if ( log.isFine() ) {
+ log
+ .logFine("publish: recently handshaked "
+ + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR)
+ + " peer '"
+ + this.seed.getName()
+ + "' at "
+ + this.seed.getPublicAddress()
+ + " with old LastSeen: '"
+ + my_SHORT_SECOND_FORMATTER.format(new Date(newSeed
+ .getLastSeenUTC()))
+ + "', this is more recent: '"
+ + my_SHORT_SECOND_FORMATTER.format(new Date(this.seed
+ .getLastSeenUTC()))
+ + "'");
+ }
this.seed.setLastSeenUTC();
Network.this.sb.peers.peerActions.peerArrival(this.seed, true);
}
}
} else {
- if (log.isFine()) log.logFine("publish: recently handshaked " + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR) + " peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress() + " not in connectedDB");
+ if ( log.isFine() ) {
+ log.logFine("publish: recently handshaked "
+ + this.seed.get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR)
+ + " peer '"
+ + this.seed.getName()
+ + "' at "
+ + this.seed.getPublicAddress()
+ + " not in connectedDB");
+ }
}
}
- } catch (final Exception e) {
- log.logSevere("publishThread: error with target seed " + this.seed.toString() + ": " + e.getMessage(), e);
+ } catch ( final Exception e ) {
+ log.logSevere(
+ "publishThread: error with target seed " + this.seed.toString() + ": " + e.getMessage(),
+ e);
} finally {
this.syncList.add(this);
this.sync.release();
@@ -310,41 +385,54 @@ public class Network {
int attempts = this.sb.peers.sizeConnected();
// getting a list of peers to contact
- if (this.sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN).equals(Seed.PEERTYPE_VIRGIN)) {
- if (attempts > PING_INITIAL) { attempts = PING_INITIAL; }
+ if ( this.sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN).equals(Seed.PEERTYPE_VIRGIN) ) {
+ if ( attempts > PING_INITIAL ) {
+ attempts = PING_INITIAL;
+ }
final Map ch = Switchboard.getSwitchboard().clusterhashes;
- seeds = PeerSelection.seedsByAge(this.sb.peers, true, attempts - ((ch == null) ? 0 : ch.size())); // best for fast connection
+ seeds =
+ PeerSelection.seedsByAge(this.sb.peers, true, attempts - ((ch == null) ? 0 : ch.size())); // best for fast connection
// add also all peers from cluster if this is a public robinson cluster
- if (ch != null) {
+ if ( ch != null ) {
final Iterator> i = ch.entrySet().iterator();
String hash;
Map.Entry entry;
Seed seed;
- while (i.hasNext()) {
+ while ( i.hasNext() ) {
entry = i.next();
hash = ASCII.String(entry.getKey());
seed = seeds.get(hash);
- if (seed == null) {
+ if ( seed == null ) {
seed = this.sb.peers.get(hash);
- if (seed == null) continue;
+ if ( seed == null ) {
+ continue;
+ }
}
seed.setAlternativeAddress(entry.getValue());
seeds.put(hash, seed);
- }
+ }
}
} else {
int diff = PING_MIN_DBSIZE - amIAccessibleDB.size();
- if (diff > PING_MIN_RUNNING) {
+ if ( diff > PING_MIN_RUNNING ) {
diff = Math.min(diff, PING_MAX_RUNNING);
- if (attempts > diff) { attempts = diff; }
+ if ( attempts > diff ) {
+ attempts = diff;
+ }
} else {
- if (attempts > PING_MIN_RUNNING) { attempts = PING_MIN_RUNNING; }
+ if ( attempts > PING_MIN_RUNNING ) {
+ attempts = PING_MIN_RUNNING;
+ }
}
seeds = PeerSelection.seedsByAge(this.sb.peers, false, attempts); // best for seed list maintenance/cleaning
}
- if (seeds == null || seeds.isEmpty()) { return 0; }
- if (seeds.size() < attempts) { attempts = seeds.size(); }
+ if ( seeds == null || seeds.isEmpty() ) {
+ return 0;
+ }
+ if ( seeds.size() < attempts ) {
+ attempts = seeds.size();
+ }
// This will try to get Peers that are not currently in amIAccessibleDB
final Iterator si = seeds.values().iterator();
@@ -353,12 +441,12 @@ public class Network {
// include a YaCyNews record to my seed
try {
final NewsDB.Record record = this.sb.peers.newsPool.myPublication();
- if (record == null) {
+ if ( record == null ) {
this.sb.peers.mySeed().put("news", "");
} else {
this.sb.peers.mySeed().put("news", de.anomic.tools.crypt.simpleEncode(record.toString()));
}
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
log.logSevere("publishMySeed: problem with news encoding", e);
}
this.sb.peers.mySeed().setUnusedFlags();
@@ -371,20 +459,25 @@ public class Network {
// going through the peer list and starting a new publisher thread for each peer
int i = 0;
- while (si.hasNext()) {
+ while ( si.hasNext() ) {
seed = si.next();
- if (seed == null) {
+ if ( seed == null ) {
sync.acquire();
continue;
}
i++;
final String address = seed.getClusterAddress();
- if (log.isFine()) log.logFine("HELLO #" + i + " to peer '" + seed.get(Seed.NAME, "") + "' at " + address); // debug
+ if ( log.isFine() ) {
+ log.logFine("HELLO #" + i + " to peer '" + seed.get(Seed.NAME, "") + "' at " + address); // debug
+ }
final String seederror = seed.isProper(false);
- if ((address == null) || (seederror != null)) {
+ if ( (address == null) || (seederror != null) ) {
// we don't like that address, delete it
- this.sb.peers.peerActions.peerDeparture(seed, "peer ping to peer resulted in address = " + address + "; seederror = " + seederror);
+ this.sb.peers.peerActions.peerDeparture(seed, "peer ping to peer resulted in address = "
+ + address
+ + "; seederror = "
+ + seederror);
sync.acquire();
} else {
// starting a new publisher thread
@@ -394,13 +487,13 @@ public class Network {
}
// receiving the result of all started publisher threads
- for (int j = 0; j < contactedSeedCount; j++) {
+ for ( int j = 0; j < contactedSeedCount; j++ ) {
// waiting for the next thread to finish
sync.acquire();
// if this is true something is wrong ...
- if (syncList.isEmpty()) {
+ if ( syncList.isEmpty() ) {
log.logWarning("PeerPing: syncList.isEmpty()==true");
continue;
//return 0;
@@ -410,9 +503,9 @@ public class Network {
final publishThread t = (publishThread) syncList.remove(0);
// getting the amount of new reported seeds
- if (t.added >= 0) {
- if (newSeeds == -1) {
- newSeeds = t.added;
+ if ( t.added >= 0 ) {
+ if ( newSeeds == -1 ) {
+ newSeeds = t.added;
} else {
newSeeds += t.added;
}
@@ -423,33 +516,41 @@ public class Network {
int notaccessible = 0;
final long cutofftime = System.currentTimeMillis() - PING_MAX_DBAGE;
final int dbSize;
- synchronized (amIAccessibleDB) {
+ synchronized ( amIAccessibleDB ) {
dbSize = amIAccessibleDB.size();
final Iterator ai = amIAccessibleDB.keySet().iterator();
- while (ai.hasNext()) {
+ while ( ai.hasNext() ) {
final Accessible ya = amIAccessibleDB.get(ai.next());
- if (ya.lastUpdated < cutofftime) {
+ if ( ya.lastUpdated < cutofftime ) {
ai.remove();
} else {
- if (ya.IWasAccessed) {
+ if ( ya.IWasAccessed ) {
accessible++;
} else {
notaccessible++;
}
}
}
- if (log.isFine()) log.logFine("DBSize before -> after Cleanup: " + dbSize + " -> " + amIAccessibleDB.size());
+ if ( log.isFine() ) {
+ log
+ .logFine("DBSize before -> after Cleanup: "
+ + dbSize
+ + " -> "
+ + amIAccessibleDB.size());
+ }
}
- log.logInfo("PeerPing: I am accessible for " + accessible +
- " peer(s), not accessible for " + notaccessible + " peer(s).");
+ log.logInfo("PeerPing: I am accessible for "
+ + accessible
+ + " peer(s), not accessible for "
+ + notaccessible
+ + " peer(s).");
- if ((accessible + notaccessible) > 0) {
+ if ( (accessible + notaccessible) > 0 ) {
final String newPeerType;
// At least one other Peer told us our type
- if ((accessible >= PING_MIN_PEERSEEN) ||
- (accessible >= notaccessible)) {
+ if ( (accessible >= PING_MIN_PEERSEEN) || (accessible >= notaccessible) ) {
// We can be reached from a majority of other Peers
- if (this.sb.peers.mySeed().isPrincipal()) {
+ if ( this.sb.peers.mySeed().isPrincipal() ) {
newPeerType = Seed.PEERTYPE_PRINCIPAL;
} else {
newPeerType = Seed.PEERTYPE_SENIOR;
@@ -458,10 +559,14 @@ public class Network {
// We cannot be reached from the outside
newPeerType = Seed.PEERTYPE_JUNIOR;
}
- if (this.sb.peers.mySeed().orVirgin().equals(newPeerType)) {
+ if ( this.sb.peers.mySeed().orVirgin().equals(newPeerType) ) {
log.logInfo("PeerPing: myType is " + this.sb.peers.mySeed().orVirgin());
} else {
- log.logInfo("PeerPing: changing myType from '" + this.sb.peers.mySeed().orVirgin() + "' to '" + newPeerType + "'");
+ log.logInfo("PeerPing: changing myType from '"
+ + this.sb.peers.mySeed().orVirgin()
+ + "' to '"
+ + newPeerType
+ + "'");
this.sb.peers.mySeed().put(Seed.PEERTYPE, newPeerType);
}
} else {
@@ -474,24 +579,33 @@ public class Network {
this.sb.peers.saveMySeed();
// if we have an address, we do nothing
- if (this.sb.peers.mySeed().isProper(true) == null && !force) { return 0; }
- if (newSeeds > 0) return newSeeds;
+ if ( this.sb.peers.mySeed().isProper(true) == null && !force ) {
+ return 0;
+ }
+ if ( newSeeds > 0 ) {
+ return newSeeds;
+ }
// still no success: ask own NAT or internet responder
//final boolean DI604use = switchboard.getConfig("DI604use", "false").equals("true");
//final String DI604pw = switchboard.getConfig("DI604pw", "");
- final String ip = this.sb.getConfig("staticIP", "");
+ final String ip = this.sb.getConfig("staticIP", "");
//if (ip.equals("")) ip = natLib.retrieveIP(DI604use, DI604pw);
// yacyCore.log.logDebug("DEBUG: new IP=" + ip);
- if (Seed.isProperIP(ip) == null) this.sb.peers.mySeed().setIP(ip);
- if (this.sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR).equals(Seed.PEERTYPE_JUNIOR)) // ???????????????
+ if ( Seed.isProperIP(ip) == null ) {
+ this.sb.peers.mySeed().setIP(ip);
+ }
+ if ( this.sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR).equals(Seed.PEERTYPE_JUNIOR) ) {
this.sb.peers.mySeed().put(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR); // to start bootstraping, we need to be recognised as PEERTYPE_SENIOR peer
- log.logInfo("publish: no recipient found, our address is " +
- ((this.sb.peers.mySeed().getPublicAddress() == null) ? "unknown" : this.sb.peers.mySeed().getPublicAddress()));
+ }
+ log.logInfo("publish: no recipient found, our address is "
+ + ((this.sb.peers.mySeed().getPublicAddress() == null) ? "unknown" : this.sb.peers
+ .mySeed()
+ .getPublicAddress()));
this.sb.peers.saveMySeed();
return 0;
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
try {
log.logInfo("publish: Interruption detected while publishing my seed.");
@@ -499,32 +613,50 @@ public class Network {
Thread.interrupted();
// interrupt all already started publishThreads
- log.logInfo("publish: Signaling shutdown to " + Network.publishThreadGroup.activeCount() + " remaining publishing threads ...");
+ log.logInfo("publish: Signaling shutdown to "
+ + Network.publishThreadGroup.activeCount()
+ + " remaining publishing threads ...");
Network.publishThreadGroup.interrupt();
// waiting some time for the publishThreads to finish execution
- try { Thread.sleep(500); } catch (final InterruptedException ex) {}
+ try {
+ Thread.sleep(500);
+ } catch ( final InterruptedException ex ) {
+ }
// getting the amount of remaining publishing threads
- int threadCount = Network.publishThreadGroup.activeCount();
+ int threadCount = Network.publishThreadGroup.activeCount();
final Thread[] threadList = new Thread[threadCount];
threadCount = Network.publishThreadGroup.enumerate(threadList);
// we need to use a timeout here because of missing interruptable session threads ...
- if (log.isFine()) log.logFine("publish: Waiting for " + Network.publishThreadGroup.activeCount() + " remaining publishing threads to finish shutdown ...");
- for (int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++) {
+ if ( log.isFine() ) {
+ log.logFine("publish: Waiting for "
+ + Network.publishThreadGroup.activeCount()
+ + " remaining publishing threads to finish shutdown ...");
+ }
+ for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
final Thread currentThread = threadList[currentThreadIdx];
- if (currentThread.isAlive()) {
- if (log.isFine()) log.logFine("publish: Waiting for remaining publishing thread '" + currentThread.getName() + "' to finish shutdown");
- try { currentThread.join(500); } catch (final InterruptedException ex) {}
+ if ( currentThread.isAlive() ) {
+ if ( log.isFine() ) {
+ log.logFine("publish: Waiting for remaining publishing thread '"
+ + currentThread.getName()
+ + "' to finish shutdown");
+ }
+ try {
+ currentThread.join(500);
+ } catch ( final InterruptedException ex ) {
+ }
}
}
log.logInfo("publish: Shutdown off all remaining publishing thread finished.");
- } catch (final Exception ee) {
- log.logWarning("publish: Unexpected error while trying to shutdown all remaining publishing threads.", e);
+ } catch ( final Exception ee ) {
+ log.logWarning(
+ "publish: Unexpected error while trying to shutdown all remaining publishing threads.",
+ e);
}
return 0;
@@ -533,25 +665,27 @@ public class Network {
@SuppressWarnings("unchecked")
public static HashMap getSeedUploadMethods() {
- synchronized (Network.seedUploadMethods) {
+ synchronized ( Network.seedUploadMethods ) {
return (HashMap) Network.seedUploadMethods.clone();
}
}
public static yacySeedUploader getSeedUploader(final String methodname) {
String className = null;
- synchronized (Network.seedUploadMethods) {
- if (Network.seedUploadMethods.containsKey(methodname)) {
+ synchronized ( Network.seedUploadMethods ) {
+ if ( Network.seedUploadMethods.containsKey(methodname) ) {
className = Network.seedUploadMethods.get(methodname);
}
}
- if (className == null) { return null; }
+ if ( className == null ) {
+ return null;
+ }
try {
final Class> uploaderClass = Class.forName(className);
final Object uploader = uploaderClass.newInstance();
return (yacySeedUploader) uploader;
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
return null;
}
}
@@ -559,19 +693,32 @@ public class Network {
public static void loadSeedUploadMethods() {
yacySeedUploader uploader;
uploader = new yacySeedUploadFile();
- Network.seedUploadMethods.put(uploader.getClass().getSimpleName().substring("yacySeedUpload".length()), uploader.getClass().getCanonicalName());
+ Network.seedUploadMethods.put(uploader
+ .getClass()
+ .getSimpleName()
+ .substring("yacySeedUpload".length()), uploader.getClass().getCanonicalName());
uploader = new yacySeedUploadFtp();
- Network.seedUploadMethods.put(uploader.getClass().getSimpleName().substring("yacySeedUpload".length()), uploader.getClass().getCanonicalName());
+ Network.seedUploadMethods.put(uploader
+ .getClass()
+ .getSimpleName()
+ .substring("yacySeedUpload".length()), uploader.getClass().getCanonicalName());
uploader = new yacySeedUploadScp();
- Network.seedUploadMethods.put(uploader.getClass().getSimpleName().substring("yacySeedUpload".length()), uploader.getClass().getCanonicalName());
+ Network.seedUploadMethods.put(uploader
+ .getClass()
+ .getSimpleName()
+ .substring("yacySeedUpload".length()), uploader.getClass().getCanonicalName());
}
public static boolean changeSeedUploadMethod(final String method) {
- if (method == null || method.length() == 0) { return false; }
+ if ( method == null || method.length() == 0 ) {
+ return false;
+ }
- if (method.equalsIgnoreCase("none")) { return true; }
+ if ( method.equalsIgnoreCase("none") ) {
+ return true;
+ }
- synchronized (Network.seedUploadMethods) {
+ synchronized ( Network.seedUploadMethods ) {
return Network.seedUploadMethods.containsKey(method);
}
}
@@ -582,7 +729,7 @@ public class Network {
String logt;
// be shure that we have something to say
- if (sb.peers.mySeed().getPublicAddress() == null) {
+ if ( sb.peers.mySeed().getPublicAddress() == null ) {
final String errorMsg = "We have no valid IP address until now";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
@@ -592,27 +739,30 @@ public class Network {
String seedUploadMethod = sb.getConfig("seedUploadMethod", "");
// for backward compatiblity ....
- if (seedUploadMethod.equalsIgnoreCase("Ftp") ||
- (seedUploadMethod.equals("") &&
- sb.getConfig("seedFTPPassword", "").length() > 0)) {
+ if ( seedUploadMethod.equalsIgnoreCase("Ftp")
+ || (seedUploadMethod.equals("") && sb.getConfig("seedFTPPassword", "").length() > 0) ) {
seedUploadMethod = "Ftp";
sb.setConfig("seedUploadMethod", seedUploadMethod);
- } else if (seedUploadMethod.equalsIgnoreCase("File") ||
- (seedUploadMethod.equals("") &&
- sb.getConfig("seedFilePath", "").length() > 0)) {
+ } else if ( seedUploadMethod.equalsIgnoreCase("File")
+ || (seedUploadMethod.equals("") && sb.getConfig("seedFilePath", "").length() > 0) ) {
seedUploadMethod = "File";
sb.setConfig("seedUploadMethod", seedUploadMethod);
}
// determine the seed uploader that should be used ...
- if (seedUploadMethod.equalsIgnoreCase("none")) { return "no uploader specified"; }
+ if ( seedUploadMethod.equalsIgnoreCase("none") ) {
+ return "no uploader specified";
+ }
final yacySeedUploader uploader = getSeedUploader(seedUploadMethod);
- if (uploader == null) {
- final String errorMsg = "Unable to get the proper uploader-class for seed uploading method '" + seedUploadMethod + "'.";
+ if ( uploader == null ) {
+ final String errorMsg =
+ "Unable to get the proper uploader-class for seed uploading method '"
+ + seedUploadMethod
+ + "'.";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
@@ -621,35 +771,51 @@ public class Network {
DigestURI seedURL;
try {
final String seedURLStr = sb.peers.mySeed().get(Seed.SEEDLISTURL, "");
- if (seedURLStr.length() == 0) { throw new MalformedURLException("The seed-file url must not be empty."); }
- if (!(
- seedURLStr.toLowerCase().startsWith("http://") ||
- seedURLStr.toLowerCase().startsWith("https://")
- )) {
+ if ( seedURLStr.length() == 0 ) {
+ throw new MalformedURLException("The seed-file url must not be empty.");
+ }
+ if ( !(seedURLStr.toLowerCase().startsWith("http://") || seedURLStr.toLowerCase().startsWith(
+ "https://")) ) {
throw new MalformedURLException("Unsupported protocol.");
}
seedURL = new DigestURI(seedURLStr);
- } catch (final MalformedURLException e) {
- final String errorMsg = "Malformed seed file URL '" + sb.peers.mySeed().get(Seed.SEEDLISTURL, "") + "'. " + e.getMessage();
+ } catch ( final MalformedURLException e ) {
+ final String errorMsg =
+ "Malformed seed file URL '"
+ + sb.peers.mySeed().get(Seed.SEEDLISTURL, "")
+ + "'. "
+ + e.getMessage();
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// upload the seed-list using the configured uploader class
String prevStatus = sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR);
- if (prevStatus.equals(Seed.PEERTYPE_PRINCIPAL)) { prevStatus = Seed.PEERTYPE_SENIOR; }
+ if ( prevStatus.equals(Seed.PEERTYPE_PRINCIPAL) ) {
+ prevStatus = Seed.PEERTYPE_SENIOR;
+ }
try {
sb.peers.mySeed().put(Seed.PEERTYPE, Seed.PEERTYPE_PRINCIPAL); // this information shall also be uploaded
- if (log.isFine()) log.logFine("SaveSeedList: Using seed uploading method '" + seedUploadMethod + "' for seed-list uploading." +
- "\n\tPrevious peerType is '" + sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR) + "'.");
+ if ( log.isFine() ) {
+ log.logFine("SaveSeedList: Using seed uploading method '"
+ + seedUploadMethod
+ + "' for seed-list uploading."
+ + "\n\tPrevious peerType is '"
+ + sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR)
+ + "'.");
+ }
logt = sb.peers.uploadSeedList(uploader, sb, sb.peers, seedURL);
- if (logt != null) {
- if (logt.indexOf("Error",0) >= 0) {
+ if ( logt != null ) {
+ if ( logt.indexOf("Error", 0) >= 0 ) {
sb.peers.mySeed().put(Seed.PEERTYPE, prevStatus);
- final String errorMsg = "SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error",0) + 6);
+ final String errorMsg =
+ "SaveSeedList: seed upload failed using "
+ + uploader.getClass().getName()
+ + " (error): "
+ + logt.substring(logt.indexOf("Error", 0) + 6);
log.logSevere(errorMsg);
return errorMsg;
}
@@ -659,7 +825,7 @@ public class Network {
// finally, set the principal status
sb.setConfig("yacyStatus", Seed.PEERTYPE_PRINCIPAL);
return null;
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
sb.peers.mySeed().put(Seed.PEERTYPE, prevStatus);
sb.setConfig("yacyStatus", prevStatus);
final String errorMsg = "SaveSeedList: Seed upload failed (IO error): " + e.getMessage();
diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.java
index 86d79ac00..d04c6eae6 100644
--- a/source/net/yacy/peers/Seed.java
+++ b/source/net/yacy/peers/Seed.java
@@ -77,7 +77,8 @@ import net.yacy.search.Switchboard;
import de.anomic.tools.bitfield;
import de.anomic.tools.crypt;
-public class Seed implements Cloneable, Comparable, Comparator {
+public class Seed implements Cloneable, Comparable, Comparator
+{
public static String ANON_PREFIX = "_anon";
@@ -89,7 +90,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* substance "rI" (received index/words)
*/
- public static final String INDEX_IN = "rI";
+ public static final String INDEX_IN = "rI";
/**
* substance "sU" (send URLs)
*/
@@ -97,11 +98,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* substance "rU" (received URLs)
*/
- public static final String URL_IN = "rU";
- /**
- * substance "private"
- */
- public static final String PEERTYPE_PRIVATE = "private";
+ public static final String URL_IN = "rU";
/**
* substance "virgin"
*/
@@ -124,52 +121,52 @@ public class Seed implements Cloneable, Comparable, Comparator {
public static final String PEERTYPE = "PeerType";
/** static/dynamic (if the IP changes often for any reason) */
- private static final String IPTYPE = "IPType";
- private static final String FLAGS = "Flags";
+ private static final String IPTYPE = "IPType";
+ private static final String FLAGS = "Flags";
private static final String FLAGSZERO = "____";
/** the applications version */
- public static final String VERSION = "Version";
+ public static final String VERSION = "Version";
- public static final String YOURTYPE = "yourtype";
- public static final String LASTSEEN = "LastSeen";
- private static final String USPEED = "USpeed";
+ public static final String YOURTYPE = "yourtype";
+ public static final String LASTSEEN = "LastSeen";
+ private static final String USPEED = "USpeed";
/** the name of the peer (user-set) */
- public static final String NAME = "Name";
- private static final String HASH = "Hash";
+ public static final String NAME = "Name";
+ private static final String HASH = "Hash";
/** Birthday - first startup */
- private static final String BDATE = "BDate";
+ private static final String BDATE = "BDate";
/** UTC-Offset */
- public static final String UTC = "UTC";
- private static final String PEERTAGS = "Tags";
+ public static final String UTC = "UTC";
+ private static final String PEERTAGS = "Tags";
/** the speed of indexing (pages/minute) of the peer */
- public static final String ISPEED = "ISpeed";
+ public static final String ISPEED = "ISpeed";
/** the speed of retrieval (queries/minute) of the peer */
- public static final String RSPEED = "RSpeed";
+ public static final String RSPEED = "RSpeed";
/** the number of minutes that the peer is up in minutes/day (moving average MA30) */
- public static final String UPTIME = "Uptime";
+ public static final String UPTIME = "Uptime";
/** the number of links that the peer has stored (LURL's) */
- public static final String LCOUNT = "LCount";
+ public static final String LCOUNT = "LCount";
/** the number of links that the peer has noticed, but not loaded (NURL's) */
- public static final String NCOUNT = "NCount";
+ public static final String NCOUNT = "NCount";
/** the number of links that the peer provides for remote crawls (ZURL's) */
- public static final String RCOUNT = "RCount";
+ public static final String RCOUNT = "RCount";
/** the number of different words the peer has indexed */
- public static final String ICOUNT = "ICount";
+ public static final String ICOUNT = "ICount";
/** the number of seeds that the peer has stored */
- public static final String SCOUNT = "SCount";
+ public static final String SCOUNT = "SCount";
/** the number of clients that the peer connects (connects/hour as double) */
- public static final String CCOUNT = "CCount";
- public static final String IP = "IP";
- public static final String PORT = "Port";
+ public static final String CCOUNT = "CCount";
+ public static final String IP = "IP";
+ public static final String PORT = "Port";
public static final String SEEDLISTURL = "seedURL";
/** zero-value */
- private static final String ZERO = "0";
+ private static final String ZERO = "0";
- private static final int FLAG_DIRECT_CONNECT = 0;
- private static final int FLAG_ACCEPT_REMOTE_CRAWL = 1;
- private static final int FLAG_ACCEPT_REMOTE_INDEX = 2;
+ private static final int FLAG_DIRECT_CONNECT = 0;
+ private static final int FLAG_ACCEPT_REMOTE_CRAWL = 1;
+ private static final int FLAG_ACCEPT_REMOTE_INDEX = 2;
public static final String DFLT_NETWORK_UNIT = "freeworld";
public static final String DFLT_NETWORK_GROUP = "";
@@ -179,7 +176,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
// class variables
/** the peer-hash */
public String hash;
- /** a set of identity founding values, eg. IP, name of the peer, YaCy-version, ...*/
+ /** a set of identity founding values, eg. IP, name of the peer, YaCy-version, ... */
private final ConcurrentMap dna;
private String alternativeIP = null;
private long birthdate; // keep this value in ram since it is often used and may cause lockings in concurrent situations.
@@ -190,7 +187,9 @@ public class Seed implements Cloneable, Comparable, Comparator {
this.hash = theHash;
this.dna = theDna;
final String flags = this.dna.get(Seed.FLAGS);
- if ((flags == null) || (flags.length() != 4)) { this.dna.put(Seed.FLAGS, Seed.FLAGSZERO); }
+ if ( (flags == null) || (flags.length() != 4) ) {
+ this.dna.put(Seed.FLAGS, Seed.FLAGSZERO);
+ }
this.dna.put(Seed.NAME, checkPeerName(get(Seed.NAME, "∅")));
this.birthdate = -1; // this means 'not yet parsed', parse that later when it is used
}
@@ -216,12 +215,12 @@ public class Seed implements Cloneable, Comparable, Comparator {
this.dna.put(Seed.VERSION, Seed.ZERO);
// settings that is created during the 'hello' phase - in first contact
- this.dna.put(Seed.IP, ""); // 123.234.345.456
+ this.dna.put(Seed.IP, ""); // 123.234.345.456
this.dna.put(Seed.PORT, "∅");
this.dna.put(Seed.IPTYPE, "∅");
// settings that can only be computed by visiting peer
- this.dna.put(Seed.USPEED, Seed.ZERO); // the computated uplink speed of the peer
+ this.dna.put(Seed.USPEED, Seed.ZERO); // the computated uplink speed of the peer
// settings that are needed to organize the seed round-trip
this.dna.put(Seed.FLAGS, Seed.FLAGSZERO);
@@ -232,9 +231,9 @@ public class Seed implements Cloneable, Comparable, Comparator {
// index transfer
this.dna.put(Seed.INDEX_OUT, Seed.ZERO); // send index
- this.dna.put(Seed.INDEX_IN, Seed.ZERO); // received index
- this.dna.put(Seed.URL_OUT, Seed.ZERO); // send URLs
- this.dna.put(Seed.URL_IN, Seed.ZERO); // received URLs
+ this.dna.put(Seed.INDEX_IN, Seed.ZERO); // received index
+ this.dna.put(Seed.URL_OUT, Seed.ZERO); // send URLs
+ this.dna.put(Seed.URL_IN, Seed.ZERO); // received URLs
// default first filling
this.dna.put(Seed.BDATE, GenericFormatter.SHORT_SECOND_FORMATTER.format());
@@ -247,10 +246,12 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* check the peer name: protect against usage as XSS hack
+ *
* @param id
* @return a checked name without "<" and ">"
*/
private final static Pattern tp = Pattern.compile("<|>");
+
public static String checkPeerName(String name) {
name = tp.matcher(name).replaceAll("_");
return name;
@@ -258,14 +259,21 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* generate a default peer name
+ *
* @return
*/
private static String defaultPeerName() {
- return ANON_PREFIX + OS.infoKey() + "-" + (System.currentTimeMillis() % 77777777L) + "-" + Network.speedKey;
+ return ANON_PREFIX
+ + OS.infoKey()
+ + "-"
+ + (System.currentTimeMillis() % 77777777L)
+ + "-"
+ + Network.speedKey;
}
/**
* Checks for the static fragments of a generated default peer name, such as the string 'dpn'
+ *
* @see #makeDefaultPeerName()
* @param name the peer name to check for default peer name compliance
* @return whether the given peer name may be a default generated peer name
@@ -275,95 +283,154 @@ public class Seed implements Cloneable, Comparable, Comparator {
}
/**
- * used when doing routing within a cluster; this can assign a ip and a port
- * that is used instead the address stored in the seed DNA
+ * used when doing routing within a cluster; this can assign a ip and a port that is used instead the
+ * address stored in the seed DNA
*/
public void setAlternativeAddress(final String ipport) {
- if (ipport == null) return;
+ if ( ipport == null ) {
+ return;
+ }
final int p = ipport.indexOf(':');
- if (p < 0) this.alternativeIP = ipport; else this.alternativeIP = ipport.substring(0, p);
+ if ( p < 0 ) {
+ this.alternativeIP = ipport;
+ } else {
+ this.alternativeIP = ipport.substring(0, p);
+ }
}
/**
* try to get the IP
+ *
* @return the IP or null
*/
public final String getIP() {
final String ip = get(Seed.IP, "127.0.0.1");
return (ip == null || ip.length() == 0) ? "127.0.0.1" : ip;
}
+
/**
* try to get the peertype
+ *
* @return the peertype or null
*/
- public final String getPeerType() { return get(Seed.PEERTYPE, ""); }
+ public final String getPeerType() {
+ return get(Seed.PEERTYPE, "");
+ }
+
/**
* try to get the peertype
+ *
* @return the peertype or "virgin"
*/
- public final String orVirgin() { return get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN); }
+ public final String orVirgin() {
+ return get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN);
+ }
+
/**
* try to get the peertype
+ *
* @return the peertype or "junior"
*/
- public final String orJunior() { return get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR); }
+ public final String orJunior() {
+ return get(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR);
+ }
+
/**
* try to get the peertype
+ *
* @return the peertype or "senior"
*/
- public final String orSenior() { return get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR); }
+ public final String orSenior() {
+ return get(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR);
+ }
+
/**
* try to get the peertype
+ *
* @return the peertype or "principal"
*/
- public final String orPrincipal() { return get(Seed.PEERTYPE, Seed.PEERTYPE_PRINCIPAL); }
+ public final String orPrincipal() {
+ return get(Seed.PEERTYPE, Seed.PEERTYPE_PRINCIPAL);
+ }
/**
* Get a value from the peer's DNA (its set of peer defining values, e.g. IP, name, version, ...)
+ *
* @param key the key for the value to fetch
* @param dflt the default value
*/
public final String get(final String key, final String dflt) {
final Object o = this.dna.get(key);
- if (o == null) { return dflt; }
+ if ( o == null ) {
+ return dflt;
+ }
return (String) o;
}
public final float getFloat(final String key, final float dflt) {
final Object o = this.dna.get(key);
- if (o == null) { return dflt; }
- if (o instanceof String) try {
- return Float.parseFloat((String) o);
- } catch (final NumberFormatException e) {
- return dflt;
- } else if (o instanceof Float) {
+ if ( o == null ) {
+ return dflt;
+ }
+ if ( o instanceof String ) {
+ try {
+ return Float.parseFloat((String) o);
+ } catch ( final NumberFormatException e ) {
+ return dflt;
+ }
+ } else if ( o instanceof Float ) {
return ((Float) o).floatValue();
- } else return dflt;
+ } else {
+ return dflt;
+ }
}
public final long getLong(final String key, final long dflt) {
final Object o = this.dna.get(key);
- if (o == null) { return dflt; }
- if (o instanceof String) try {
- return Long.parseLong((String) o);
- } catch (final NumberFormatException e) {
- return dflt;
- } else if (o instanceof Long) {
+ if ( o == null ) {
+ return dflt;
+ }
+ if ( o instanceof String ) {
+ try {
+ return Long.parseLong((String) o);
+ } catch ( final NumberFormatException e ) {
+ return dflt;
+ }
+ } else if ( o instanceof Long ) {
return ((Long) o).longValue();
- } else if (o instanceof Integer) {
+ } else if ( o instanceof Integer ) {
return ((Integer) o).intValue();
- } else return dflt;
+ } else {
+ return dflt;
+ }
+ }
+
+ public final void setIP(final String ip) {
+ this.dna.put(Seed.IP, ip);
+ }
+
+ public final void setPort(final String port) {
+ this.dna.put(Seed.PORT, port);
+ }
+
+ public final void setType(final String type) {
+ this.dna.put(Seed.PEERTYPE, type);
+ }
+
+ public final void setJunior() {
+ this.dna.put(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR);
}
- public final void setIP(final String ip) { this.dna.put(Seed.IP, ip); }
- public final void setPort(final String port) { this.dna.put(Seed.PORT, port); }
- public final void setType(final String type) { this.dna.put(Seed.PEERTYPE, type); }
- public final void setJunior() { this.dna.put(Seed.PEERTYPE, Seed.PEERTYPE_JUNIOR); }
- public final void setSenior() { this.dna.put(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR); }
- public final void setPrincipal() { this.dna.put(Seed.PEERTYPE, Seed.PEERTYPE_PRINCIPAL); }
+ public final void setSenior() {
+ this.dna.put(Seed.PEERTYPE, Seed.PEERTYPE_SENIOR);
+ }
+
+ public final void setPrincipal() {
+ this.dna.put(Seed.PEERTYPE, Seed.PEERTYPE_PRINCIPAL);
+ }
public final void put(final String key, final String value) {
- synchronized (this.dna) {
+ synchronized ( this.dna ) {
this.dna.put(key, value);
}
}
@@ -374,7 +441,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
}
public final void setName(final String name) {
- synchronized (this.dna) {
+ synchronized ( this.dna ) {
this.dna.put(Seed.NAME, checkPeerName(name));
}
}
@@ -389,42 +456,53 @@ public class Seed implements Cloneable, Comparable, Comparator {
public final void incSI(final int count) {
String v = this.dna.get(Seed.INDEX_OUT);
- if (v == null) { v = Seed.ZERO; }
+ if ( v == null ) {
+ v = Seed.ZERO;
+ }
this.dna.put(Seed.INDEX_OUT, Long.toString(Long.parseLong(v) + count));
}
public final void incRI(final int count) {
String v = this.dna.get(Seed.INDEX_IN);
- if (v == null) { v = Seed.ZERO; }
+ if ( v == null ) {
+ v = Seed.ZERO;
+ }
this.dna.put(Seed.INDEX_IN, Long.toString(Long.parseLong(v) + count));
}
public final void incSU(final int count) {
String v = this.dna.get(Seed.URL_OUT);
- if (v == null) { v = Seed.ZERO; }
+ if ( v == null ) {
+ v = Seed.ZERO;
+ }
this.dna.put(Seed.URL_OUT, Long.toString(Long.parseLong(v) + count));
}
public final void incRU(final int count) {
String v = this.dna.get(Seed.URL_IN);
- if (v == null) { v = Seed.ZERO; }
+ if ( v == null ) {
+ v = Seed.ZERO;
+ }
this.dna.put(Seed.URL_IN, Long.toString(Long.parseLong(v) + count));
}
- public final void resetCounters(){
- this.dna.put(Seed.INDEX_OUT, Seed.ZERO);
- this.dna.put(Seed.INDEX_IN, Seed.ZERO);
- this.dna.put(Seed.URL_OUT, Seed.ZERO);
- this.dna.put(Seed.URL_IN, Seed.ZERO);
+ public final void resetCounters() {
+ this.dna.put(Seed.INDEX_OUT, Seed.ZERO);
+ this.dna.put(Seed.INDEX_IN, Seed.ZERO);
+ this.dna.put(Seed.URL_OUT, Seed.ZERO);
+ this.dna.put(Seed.URL_IN, Seed.ZERO);
}
/**
* 12 * 6 bit = 72 bit = 24 characters octal-hash
- *
Octal hashes are used for cache-dumps that are DHT-ready
*
- * Cause: the natural order of octal hashes are the same as the b64-order of b64Hashes.
- * a hexhash cannot be used in such cases, and b64Hashes are not appropriate for file names
+ * Octal hashes are used for cache-dumps that are DHT-ready
+ *
+ *
+ * Cause: the natural order of octal hashes are the same as the b64-order of b64Hashes. a hexhash cannot
+ * be used in such cases, and b64Hashes are not appropriate for file names
*
+ *
* @param b64Hash a base64 hash
* @return the octal representation of the given base64 hash
*/
@@ -434,11 +512,14 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* 12 * 6 bit = 72 bit = 18 characters hex-hash
+ *
* @param b64Hash a base64 hash
* @return the hexadecimal representation of the given base64 hash
*/
public static String b64Hash2hexHash(final String b64Hash) {
- if (b64Hash.length() > 12) return "";
+ if ( b64Hash.length() > 12 ) {
+ return "";
+ }
// the hash string represents 12 * 6 bit = 72 bits. This is too much for a long integer.
return Digest.encodeHex(Base64Order.enhancedCoder.decode(b64Hash));
}
@@ -453,19 +534,21 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* The returned version follows this pattern: MAJORVERSION . MINORVERSION 0 SVN REVISION
+ *
* @return the YaCy version of this peer as a float or 0 if no valid value could be retrieved
- * from this yacySeed object
+ * from this yacySeed object
*/
public final float getVersion() {
try {
return Float.parseFloat(get(Seed.VERSION, Seed.ZERO));
- } catch (final NumberFormatException e) {
+ } catch ( final NumberFormatException e ) {
return 0;
}
}
/**
* get the SVN version of the peer
+ *
* @return
*/
public final int getRevision() {
@@ -474,14 +557,18 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* @return the public address of the peer as IP:port string or null if no valid values for
- * either the IP or the port could be retrieved from this yacySeed object
+ * either the IP or the port could be retrieved from this yacySeed object
*/
public final String getPublicAddress() {
String ip = getIP();
- if (ip == null || ip.length() < 8 || ip.length() > 60) ip = "127.0.0.1";
+ if ( ip == null || ip.length() < 8 || ip.length() > 60 ) {
+ ip = "127.0.0.1";
+ }
final String port = this.dna.get(Seed.PORT);
- if (port == null || port.length() < 2 || port.length() > 5) return null;
+ if ( port == null || port.length() < 2 || port.length() > 5 ) {
+ return null;
+ }
final StringBuilder sb = new StringBuilder(ip.length() + port.length() + 1);
sb.append(ip);
@@ -492,16 +579,21 @@ public class Seed implements Cloneable, Comparable, Comparator {
/**
* If this seed is part of a cluster, the peer has probably the {@linkplain #alternativeIP} object set to
- * a local IP. If this is present and the public IP of this peer is identical to the public IP of the own seed,
- * construct an address using this IP; otherwise return the public address
+ * a local IP. If this is present and the public IP of this peer is identical to the public IP of the own
+ * seed, construct an address using this IP; otherwise return the public address
+ *
* @see #getPublicAddress()
* @return the alternative IP:port if present, else the public address
*/
public final String getClusterAddress() {
- if (this.alternativeIP == null) return getPublicAddress();
+ if ( this.alternativeIP == null ) {
+ return getPublicAddress();
+ }
final String port = this.dna.get(Seed.PORT);
- if ((port == null) || (port.length() < 2)) return null;
+ if ( (port == null) || (port.length() < 2) ) {
+ return null;
+ }
return this.alternativeIP + ":" + port;
}
@@ -516,7 +608,9 @@ public class Seed implements Cloneable, Comparable, Comparator {
/** @return the portnumber of this seed or -1 if not present */
public final int getPort() {
final String port = this.dna.get(Seed.PORT);
- if (port == null) return -1;
+ if ( port == null ) {
+ return -1;
+ }
/*if (port.length() < 2) return -1; It is possible to use port 0-9*/
return Integer.parseInt(port);
}
@@ -526,10 +620,13 @@ public class Seed implements Cloneable, Comparable, Comparator {
// because java thinks it must apply the UTC offset to the current time,
// to create a string that looks like our current time, it adds the local UTC offset to the
// time. To create a corrected UTC Date string, we first subtract the local UTC offset.
- final GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); // use our own formatter to prevent concurrency locks with other processes
- final String ls = my_SHORT_SECOND_FORMATTER.format(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/));
+ final GenericFormatter my_SHORT_SECOND_FORMATTER =
+ new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); // use our own formatter to prevent concurrency locks with other processes
+ final String ls =
+ my_SHORT_SECOND_FORMATTER
+ .format(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/));
//System.out.println("SETTING LAST-SEEN of " + this.getName() + " to " + ls);
- this.dna.put(Seed.LASTSEEN, ls );
+ this.dna.put(Seed.LASTSEEN, ls);
}
/**
@@ -537,7 +634,8 @@ public class Seed implements Cloneable, Comparable, Comparator {
*/
public final long getLastSeenUTC() {
try {
- final GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); // use our own formatter to prevent concurrency locks with other processes
+ final GenericFormatter my_SHORT_SECOND_FORMATTER =
+ new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); // use our own formatter to prevent concurrency locks with other processes
final long t = my_SHORT_SECOND_FORMATTER.parse(get(Seed.LASTSEEN, "20040101000000")).getTime();
// getTime creates a UTC time number. But in this case java thinks, that the given
// time string is a local time, which has a local UTC offset applied.
@@ -546,15 +644,16 @@ public class Seed implements Cloneable, Comparable, Comparator {
// of the local UTC offset is wrong. We correct this here by adding the local UTC
// offset again.
return t /*+ DateFormatter.UTCDiff()*/;
- } catch (final java.text.ParseException e) { // in case of an error make seed look old!!!
+ } catch ( final java.text.ParseException e ) { // in case of an error make seed look old!!!
return System.currentTimeMillis() - AbstractFormatter.dayMillis;
- } catch (final java.lang.NumberFormatException e) {
+ } catch ( final java.lang.NumberFormatException e ) {
return System.currentTimeMillis() - AbstractFormatter.dayMillis;
}
}
/**
* test if the lastSeen time of the seed has a time-out
+ *
* @param milliseconds the maximum age of the last-seen value
* @return true, if the time between the last-seen time and now is greater then the given time-out
*/
@@ -564,12 +663,15 @@ public class Seed implements Cloneable, Comparable, Comparator {
}
public final long getBirthdate() {
- if (this.birthdate > 0) return this.birthdate;
+ if ( this.birthdate > 0 ) {
+ return this.birthdate;
+ }
long b;
try {
- final GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); // use our own formatter to prevent concurrency locks with other processes
+ final GenericFormatter my_SHORT_SECOND_FORMATTER =
+ new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); // use our own formatter to prevent concurrency locks with other processes
b = my_SHORT_SECOND_FORMATTER.parse(get(Seed.BDATE, "20040101000000")).getTime();
- } catch (final ParseException e) {
+ } catch ( final ParseException e ) {
b = System.currentTimeMillis();
}
this.birthdate = b;
@@ -591,11 +693,15 @@ public class Seed implements Cloneable, Comparable, Comparator {
public boolean matchPeerTags(final HandleSet searchHashes) {
final String peertags = get(PEERTAGS, "");
- if (peertags.equals("*")) return true;
+ if ( peertags.equals("*") ) {
+ return true;
+ }
final Set tags = MapTools.string2set(peertags, "|");
final Iterator i = tags.iterator();
- while (i.hasNext()) {
- if (searchHashes.has(Word.word2hash(i.next()))) return true;
+ while ( i.hasNext() ) {
+ if ( searchHashes.has(Word.word2hash(i.next())) ) {
+ return true;
+ }
}
return false;
}
@@ -603,7 +709,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
public int getPPM() {
try {
return Integer.parseInt(get(Seed.ISPEED, Seed.ZERO));
- } catch (final NumberFormatException e) {
+ } catch ( final NumberFormatException e ) {
return 0;
}
}
@@ -611,7 +717,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
public float getQPM() {
try {
return Float.parseFloat(get(Seed.RSPEED, Seed.ZERO));
- } catch (final NumberFormatException e) {
+ } catch ( final NumberFormatException e ) {
return 0f;
}
}
@@ -619,7 +725,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
public final long getLinkCount() {
try {
return getLong(Seed.LCOUNT, 0);
- } catch (final NumberFormatException e) {
+ } catch ( final NumberFormatException e ) {
return 0;
}
}
@@ -627,7 +733,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
public final long getWordCount() {
try {
return getLong(Seed.ICOUNT, 0);
- } catch (final NumberFormatException e) {
+ } catch ( final NumberFormatException e ) {
return 0;
}
}
@@ -639,52 +745,79 @@ public class Seed implements Cloneable, Comparable, Comparator {
private void setFlag(final int flag, final boolean value) {
String flags = get(Seed.FLAGS, Seed.FLAGSZERO);
- if (flags.length() != 4) { flags = Seed.FLAGSZERO; }
+ if ( flags.length() != 4 ) {
+ flags = Seed.FLAGSZERO;
+ }
final bitfield f = new bitfield(UTF8.getBytes(flags));
f.set(flag, value);
this.dna.put(Seed.FLAGS, UTF8.String(f.getBytes()));
}
- public final void setFlagDirectConnect(final boolean value) { setFlag(FLAG_DIRECT_CONNECT, value); }
- public final void setFlagAcceptRemoteCrawl(final boolean value) { setFlag(FLAG_ACCEPT_REMOTE_CRAWL, value); }
- public final void setFlagAcceptRemoteIndex(final boolean value) { setFlag(FLAG_ACCEPT_REMOTE_INDEX, value); }
- public final boolean getFlagDirectConnect() { return getFlag(0); }
+ public final void setFlagDirectConnect(final boolean value) {
+ setFlag(FLAG_DIRECT_CONNECT, value);
+ }
+
+ public final void setFlagAcceptRemoteCrawl(final boolean value) {
+ setFlag(FLAG_ACCEPT_REMOTE_CRAWL, value);
+ }
+
+ public final void setFlagAcceptRemoteIndex(final boolean value) {
+ setFlag(FLAG_ACCEPT_REMOTE_INDEX, value);
+ }
+
+ public final boolean getFlagDirectConnect() {
+ return getFlag(0);
+ }
+
public final boolean getFlagAcceptRemoteCrawl() {
//if (getVersion() < 0.300) return false;
//if (getVersion() < 0.334) return true;
return getFlag(1);
}
+
public final boolean getFlagAcceptRemoteIndex() {
//if (getVersion() < 0.335) return false;
return getFlag(2);
}
+
public final void setUnusedFlags() {
- for (int i = 4; i < 24; i++) { setFlag(i, true); }
+ for ( int i = 4; i < 24; i++ ) {
+ setFlag(i, true);
+ }
}
+
public final boolean isType(final String type) {
return get(Seed.PEERTYPE, "").equals(type);
}
+
public final boolean isVirgin() {
return get(Seed.PEERTYPE, "").equals(Seed.PEERTYPE_VIRGIN);
}
+
public final boolean isJunior() {
return get(Seed.PEERTYPE, "").equals(Seed.PEERTYPE_JUNIOR);
}
+
public final boolean isSenior() {
return get(Seed.PEERTYPE, "").equals(Seed.PEERTYPE_SENIOR);
}
+
public final boolean isPrincipal() {
return get(Seed.PEERTYPE, "").equals(Seed.PEERTYPE_PRINCIPAL);
}
+
public final boolean isPotential() {
return isVirgin() || isJunior();
}
+
public final boolean isActive() {
return isSenior() || isPrincipal();
}
+
public final boolean isOnline() {
return isSenior() || isPrincipal();
}
+
public final boolean isOnline(final String type) {
return type.equals(Seed.PEERTYPE_SENIOR) || type.equals(Seed.PEERTYPE_PRINCIPAL);
}
@@ -695,7 +828,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
private static byte[] bestGap(final SeedDB seedDB) {
final byte[] randomHash = randomHash();
- if (seedDB == null || seedDB.sizeConnected() <= 2) {
+ if ( seedDB == null || seedDB.sizeConnected() <= 2 ) {
// use random hash
return randomHash;
}
@@ -704,15 +837,21 @@ public class Seed implements Cloneable, Comparable, Comparator {
// take one gap; prefer biggest but take also another smaller by chance
String interval = null;
- while (!gaps.isEmpty()) {
+ while ( !gaps.isEmpty() ) {
interval = gaps.remove(gaps.lastKey());
- if (random.nextBoolean()) break;
+ if ( random.nextBoolean() ) {
+ break;
+ }
+ }
+ if ( interval == null ) {
+ return randomHash();
}
- if (interval == null) return randomHash();
// find dht position and size of gap
- final long left = FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(interval.substring(0, 12)), null);
- final long right = FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(interval.substring(12)), null);
+ final long left =
+ FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(interval.substring(0, 12)), null);
+ final long right =
+ FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(interval.substring(12)), null);
final long gap8 = FlatWordPartitionScheme.dhtDistance(left, right) >> 3; // 1/8 of a gap
final long gapx = gap8 + (Math.abs(random.nextLong()) % (6 * gap8));
final long gappos = (Long.MAX_VALUE - left >= gapx) ? left + gapx : (left - Long.MAX_VALUE) + gapx;
@@ -725,11 +864,13 @@ public class Seed implements Cloneable, Comparable, Comparator {
System.arraycopy(computedHash, 0, combined, 0, 2);
System.arraycopy(randomHash, 2, combined, 2, 10);
// patch for the 'first sector' problem
- if (combined[0] == 'A' || combined[1] == 'D') { // for some strange reason there are too many of them
+ if ( combined[0] == 'A' || combined[1] == 'D' ) { // for some strange reason there are too many of them
combined[1] = randomHash[1];
}
// finally check if the hash is already known
- while (seedDB.hasConnected(combined) || seedDB.hasDisconnected(combined) || seedDB.hasPotential(combined)) {
+ while ( seedDB.hasConnected(combined)
+ || seedDB.hasDisconnected(combined)
+ || seedDB.hasPotential(combined) ) {
// if we are lucky then this loop will never run
combined = randomHash();
}
@@ -737,28 +878,32 @@ public class Seed implements Cloneable, Comparable, Comparator {
}
private static TreeMap hashGaps(final SeedDB seedDB) {
- final TreeMapgaps = new TreeMap();
- if (seedDB == null) return gaps;
+ final TreeMap gaps = new TreeMap();
+ if ( seedDB == null ) {
+ return gaps;
+ }
final Iterator i = seedDB.seedsConnected(true, false, null, (float) 0.0);
long l;
Seed s0 = null, s1, first = null;
- while (i.hasNext()) {
+ while ( i.hasNext() ) {
s1 = i.next();
- if (s0 == null) {
+ if ( s0 == null ) {
s0 = s1;
first = s0;
continue;
}
- l = FlatWordPartitionScheme.dhtDistance(
+ l =
+ FlatWordPartitionScheme.dhtDistance(
FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(s0.hash), null),
FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(s1.hash), null));
gaps.put(l, s0.hash + s1.hash);
s0 = s1;
}
// compute also the last gap
- if ((first != null) && (s0 != null)) {
- l = FlatWordPartitionScheme.dhtDistance(
+ if ( (first != null) && (s0 != null) ) {
+ l =
+ FlatWordPartitionScheme.dhtDistance(
FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(s0.hash), null),
FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(first.hash), null));
gaps.put(l, s0.hash + first.hash);
@@ -789,38 +934,58 @@ public class Seed implements Cloneable, Comparable, Comparator {
public static byte[] randomHash() {
final String hash =
- Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(Long.toString(random.nextLong()))).substring(0, 6) +
- Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(Long.toString(random.nextLong()))).substring(0, 6);
+ Base64Order.enhancedCoder
+ .encode(Digest.encodeMD5Raw(Long.toString(random.nextLong())))
+ .substring(0, 6)
+ + Base64Order.enhancedCoder
+ .encode(Digest.encodeMD5Raw(Long.toString(random.nextLong())))
+ .substring(0, 6);
return ASCII.getBytes(hash);
}
- public static Seed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed, final String patchIP) throws IOException {
+ public static Seed genRemoteSeed(
+ final String seedStr,
+ final String key,
+ final boolean ownSeed,
+ final String patchIP) throws IOException {
// this method is used to convert the external representation of a seed into a seed object
// yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key);
// check protocol and syntax of seed
- if (seedStr == null) throw new IOException("seedStr == null");
- if (seedStr.length() == 0) throw new IOException("seedStr.length() == 0");
+ if ( seedStr == null ) {
+ throw new IOException("seedStr == null");
+ }
+ if ( seedStr.length() == 0 ) {
+ throw new IOException("seedStr.length() == 0");
+ }
final String seed = crypt.simpleDecode(seedStr, key);
- if (seed == null) throw new IOException("seed == null");
- if (seed.length() == 0) throw new IOException("seed.length() == 0");
+ if ( seed == null ) {
+ throw new IOException("seed == null");
+ }
+ if ( seed.length() == 0 ) {
+ throw new IOException("seed.length() == 0");
+ }
// extract hash
final ConcurrentHashMap dna = MapTools.string2map(seed, ",");
final String hash = dna.remove(Seed.HASH);
- if (hash == null) throw new IOException("hash == null");
+ if ( hash == null ) {
+ throw new IOException("hash == null");
+ }
final Seed resultSeed = new Seed(hash, dna);
// check semantics of content
String testResult = resultSeed.isProper(ownSeed);
- if (testResult != null && patchIP != null) {
+ if ( testResult != null && patchIP != null ) {
// in case that this proper-Test fails and a patchIP is given
// then replace the given IP in the resultSeed with given patchIP
// this is done if a remote peer reports its IP in a wrong way (maybe fraud attempt)
resultSeed.setIP(patchIP);
testResult = resultSeed.isProper(ownSeed);
}
- if (testResult != null) throw new IOException("seed is not proper (" + testResult + "): " + resultSeed);
+ if ( testResult != null ) {
+ throw new IOException("seed is not proper (" + testResult + "): " + resultSeed);
+ }
// seed ok
return resultSeed;
@@ -831,37 +996,53 @@ public class Seed implements Cloneable, Comparable, Comparator {
// checks if everything is ok with that seed
// check hash
- if (this.hash == null) return "hash is null";
- if (this.hash.length() != Word.commonHashLength) return "wrong hash length (" + this.hash.length() + ")";
+ if ( this.hash == null ) {
+ return "hash is null";
+ }
+ if ( this.hash.length() != Word.commonHashLength ) {
+ return "wrong hash length (" + this.hash.length() + ")";
+ }
// name
final String peerName = this.dna.get(Seed.NAME);
- if (peerName == null) return "no peer name given";
+ if ( peerName == null ) {
+ return "no peer name given";
+ }
this.dna.put(Seed.NAME, checkPeerName(peerName));
// type
final String peerType = getPeerType();
- if ((peerType == null) ||
- !(peerType.equals(Seed.PEERTYPE_VIRGIN) || peerType.equals(Seed.PEERTYPE_JUNIOR)
- || peerType.equals(Seed.PEERTYPE_SENIOR) || peerType.equals(Seed.PEERTYPE_PRINCIPAL)))
+ if ( (peerType == null)
+ || !(peerType.equals(Seed.PEERTYPE_VIRGIN)
+ || peerType.equals(Seed.PEERTYPE_JUNIOR)
+ || peerType.equals(Seed.PEERTYPE_SENIOR) || peerType.equals(Seed.PEERTYPE_PRINCIPAL)) ) {
return "invalid peerType '" + peerType + "'";
+ }
// check IP
- if (!checkOwnIP) {
+ if ( !checkOwnIP ) {
// checking of IP is omitted if we read the own seed file
final String ipCheck = isProperIP(getIP());
- if (ipCheck != null) return ipCheck;
+ if ( ipCheck != null ) {
+ return ipCheck;
+ }
}
// seedURL
final String seedURL = this.dna.get(SEEDLISTURL);
- if (seedURL != null && seedURL.length() > 0) {
- if (!seedURL.startsWith("http://") && !seedURL.startsWith("https://")) return "wrong protocol for seedURL";
+ if ( seedURL != null && seedURL.length() > 0 ) {
+ if ( !seedURL.startsWith("http://") && !seedURL.startsWith("https://") ) {
+ return "wrong protocol for seedURL";
+ }
try {
final URL url = new URL(seedURL);
final String host = url.getHost();
- if (host.equals("localhost") || host.startsWith("127.") || (host.startsWith("0:0:0:0:0:0:0:1"))) return "seedURL in localhost rejected";
- } catch (final MalformedURLException e) {
+ if ( host.equals("localhost")
+ || host.startsWith("127.")
+ || (host.startsWith("0:0:0:0:0:0:0:1")) ) {
+ return "seedURL in localhost rejected";
+ }
+ } catch ( final MalformedURLException e ) {
return "seedURL malformed";
}
}
@@ -870,12 +1051,20 @@ public class Seed implements Cloneable, Comparable, Comparator {
public static final String isProperIP(final String ipString) {
// returns null if ipString is proper, a string with the cause otherwise
- if (ipString == null) return ipString + " -> IP is null";
- if (ipString.length() > 0 && ipString.length() < 8) return ipString + " -> IP is too short: ";
- if (Switchboard.getSwitchboard().isAllIPMode()) return null;
+ if ( ipString == null ) {
+ return ipString + " -> IP is null";
+ }
+ if ( ipString.length() > 0 && ipString.length() < 8 ) {
+ return ipString + " -> IP is too short: ";
+ }
+ if ( Switchboard.getSwitchboard().isAllIPMode() ) {
+ return null;
+ }
final boolean islocal = Domains.isLocal(ipString, null);
//if (islocal && Switchboard.getSwitchboard().isGlobalMode()) return ipString + " - local IP for global mode rejected";
- if (!islocal && Switchboard.getSwitchboard().isIntranetMode()) return ipString + " - global IP for intranet mode rejected";
+ if ( !islocal && Switchboard.getSwitchboard().isIntranetMode() ) {
+ return ipString + " - global IP for intranet mode rejected";
+ }
return null;
}
@@ -883,7 +1072,7 @@ public class Seed implements Cloneable, Comparable, Comparator {
public final String toString() {
final ConcurrentMap copymap = new ConcurrentHashMap();
copymap.putAll(this.dna);
- copymap.put(Seed.HASH, this.hash); // set hash into seed code structure
+ copymap.put(Seed.HASH, this.hash); // set hash into seed code structure
return MapTools.map2string(copymap, ",", true); // generate string representation
}
@@ -894,7 +1083,11 @@ public class Seed implements Cloneable, Comparable, Comparator {
final String b = crypt.simpleEncode(r, key, 'b');
// the compressed string may be longer that the uncompressed if there is too much overhead for compression meta-info
// take simply that string that is shorter
- if (b.length() < z.length()) return b; else return z;
+ if ( b.length() < z.length() ) {
+ return b;
+ } else {
+ return z;
+ }
}
public final void save(final File f) throws IOException {
@@ -927,8 +1120,12 @@ public class Seed implements Cloneable, Comparable, Comparator {
// TODO Auto-generated method stub
final int o1 = hashCode();
final int o2 = arg0.hashCode();
- if (o1 > o2) return 1;
- if (o2 > o1) return -1;
+ if ( o1 > o2 ) {
+ return 1;
+ }
+ if ( o2 > o1 ) {
+ return -1;
+ }
return 0;
}
@@ -944,13 +1141,13 @@ public class Seed implements Cloneable, Comparable, Comparator {
public static void main(final String[] args) {
final ScoreMap s = new ClusteredScoreMap();
- for (int i = 0; i < 10000; i++) {
+ for ( int i = 0; i < 10000; i++ ) {
final byte[] b = randomHash();
s.inc(0xff & Base64Order.enhancedCoder.decodeByte(b[0]));
//System.out.println(ASCII.String(b));
}
final Iterator i = s.keys(false);
- while (i.hasNext()) {
+ while ( i.hasNext() ) {
System.out.println(i.next());
}
}
diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java
index 01cabe127..8713de8eb 100644
--- a/source/net/yacy/search/Switchboard.java
+++ b/source/net/yacy/search/Switchboard.java
@@ -183,19 +183,20 @@ import de.anomic.tools.CryptoLib;
import de.anomic.tools.UPnP;
import de.anomic.tools.crypt;
-public final class Switchboard extends serverSwitch {
+public final class Switchboard extends serverSwitch
+{
// load slots
- public static int xstackCrawlSlots = 2000;
- public static long lastPPMUpdate = System.currentTimeMillis()- 30000;
- private static final int dhtMaxContainerCount = 500;
- private int dhtMaxReferenceCount = 1000;
+ public static int xstackCrawlSlots = 2000;
+ public static long lastPPMUpdate = System.currentTimeMillis() - 30000;
+ private static final int dhtMaxContainerCount = 500;
+ private int dhtMaxReferenceCount = 1000;
// colored list management
- public static SortedSet badwords = new TreeSet(NaturalOrder.naturalComparator);
- public static SortedSet stopwords = new TreeSet(NaturalOrder.naturalComparator);
- public static SortedSet blueList = null;
- public static HandleSet badwordHashes = null;
+ public static SortedSet badwords = new TreeSet(NaturalOrder.naturalComparator);
+ public static SortedSet stopwords = new TreeSet(NaturalOrder.naturalComparator);
+ public static SortedSet blueList = null;
+ public static HandleSet badwordHashes = null;
public static HandleSet blueListHashes = null;
public static HandleSet stopwordHashes = null;
public static Blacklist urlBlacklist = null;
@@ -203,46 +204,46 @@ public final class Switchboard extends serverSwitch {
public static WikiParser wikiParser = null;
// storage management
- public File htCachePath;
- public final File dictionariesPath;
- public File listsPath;
- public File htDocsPath;
- public File workPath;
- public File releasePath;
- public File networkRoot;
- public File queuesRoot;
- public File surrogatesInPath;
- public File surrogatesOutPath;
- public Segments indexSegments;
- public LoaderDispatcher loader;
- public CrawlSwitchboard crawler;
- public CrawlQueues crawlQueues;
- public CrawlStacker crawlStacker;
- public MessageBoard messageDB;
- public WikiBoard wikiDB;
- public BlogBoard blogDB;
- public BlogBoardComments blogCommentDB;
- public RobotsTxt robots;
- public Map outgoingCookies, incomingCookies;
- public volatile long proxyLastAccess, localSearchLastAccess, remoteSearchLastAccess;
- public Network yc;
- public ResourceObserver observer;
- public UserDB userDB;
- public BookmarksDB bookmarksDB;
- public WebStructureGraph webStructure;
- public ConcurrentHashMap> localSearchTracker, remoteSearchTracker; // mappings from requesting host to a TreeSet of Long(access time)
- public long indexedPages = 0;
- public int searchQueriesRobinsonFromLocal = 0; // absolute counter of all local queries submitted on this peer from a local or autheticated used
- public int searchQueriesRobinsonFromRemote = 0; // absolute counter of all local queries submitted on this peer from a remote IP without authentication
- public float searchQueriesGlobal = 0f; // partial counter of remote queries (1/number-of-requested-peers)
- public SortedMap clusterhashes; // map of peerhash(String)/alternative-local-address as ip:port or only ip (String) or null if address in seed should be used
- public URLLicense licensedURLs;
- public List networkWhitelist, networkBlacklist;
- public FilterEngine domainList;
- private Dispatcher dhtDispatcher;
- public LinkedBlockingQueue trail;
- public SeedDB peers;
- public WorkTables tables;
+ public File htCachePath;
+ public final File dictionariesPath;
+ public File listsPath;
+ public File htDocsPath;
+ public File workPath;
+ public File releasePath;
+ public File networkRoot;
+ public File queuesRoot;
+ public File surrogatesInPath;
+ public File surrogatesOutPath;
+ public Segments indexSegments;
+ public LoaderDispatcher loader;
+ public CrawlSwitchboard crawler;
+ public CrawlQueues crawlQueues;
+ public CrawlStacker crawlStacker;
+ public MessageBoard messageDB;
+ public WikiBoard wikiDB;
+ public BlogBoard blogDB;
+ public BlogBoardComments blogCommentDB;
+ public RobotsTxt robots;
+ public Map outgoingCookies, incomingCookies;
+ public volatile long proxyLastAccess, localSearchLastAccess, remoteSearchLastAccess;
+ public Network yc;
+ public ResourceObserver observer;
+ public UserDB userDB;
+ public BookmarksDB bookmarksDB;
+ public WebStructureGraph webStructure;
+ public ConcurrentHashMap> localSearchTracker, remoteSearchTracker; // mappings from requesting host to a TreeSet of Long(access time)
+ public long indexedPages = 0;
+ public int searchQueriesRobinsonFromLocal = 0; // absolute counter of all local queries submitted on this peer from a local or autheticated used
+ public int searchQueriesRobinsonFromRemote = 0; // absolute counter of all local queries submitted on this peer from a remote IP without authentication
+ public float searchQueriesGlobal = 0f; // partial counter of remote queries (1/number-of-requested-peers)
+ public SortedMap clusterhashes; // map of peerhash(String)/alternative-local-address as ip:port or only ip (String) or null if address in seed should be used
+ public URLLicense licensedURLs;
+ public List networkWhitelist, networkBlacklist;
+ public FilterEngine domainList;
+ private Dispatcher dhtDispatcher;
+ public LinkedBlockingQueue trail;
+ public SeedDB peers;
+ public WorkTables tables;
public WorkflowProcessor indexingDocumentProcessor;
public WorkflowProcessor indexingCondensementProcessor;
@@ -263,16 +264,20 @@ public final class Switchboard extends serverSwitch {
private static Switchboard sb = null;
- public Switchboard(final File dataPath, final File appPath, final String initPath, final String configPath) throws IOException {
+ public Switchboard(final File dataPath, final File appPath, final String initPath, final String configPath)
+ throws IOException {
super(dataPath, appPath, initPath, configPath);
// check if port is already occupied
final int port = getConfigInt("port", 8090);
try {
- if (TimeoutRequest.ping("127.0.0.1", port, 500)) {
- throw new RuntimeException("a server is already running on the YaCy port " + port + "; possibly another YaCy process has not terminated yet. Please stop YaCy before running a new instance.");
+ if ( TimeoutRequest.ping("127.0.0.1", port, 500) ) {
+ throw new RuntimeException(
+ "a server is already running on the YaCy port "
+ + port
+ + "; possibly another YaCy process has not terminated yet. Please stop YaCy before running a new instance.");
}
- } catch (final ExecutionException e1) {
+ } catch ( final ExecutionException e1 ) {
}
MemoryTracker.startSystemProfiling();
@@ -285,7 +290,7 @@ public final class Switchboard extends serverSwitch {
Seed.ANON_PREFIX = getConfig("peernameprefix", "_anon");
// UPnP port mapping
- if (getConfigBool(SwitchboardConstants.UPNP_ENABLED, false)) {
+ if ( getConfigBool(SwitchboardConstants.UPNP_ENABLED, false) ) {
InstantBusyThread.oneTimeJob(UPnP.class, "addPortMapping", UPnP.log, 0);
}
@@ -297,24 +302,30 @@ public final class Switchboard extends serverSwitch {
// memory configuration
this.useTailCache = getConfigBool("ramcopy", true);
- if (MemoryControl.available() > 1024 * 1024 * 1024 * 1) {
+ if ( MemoryControl.available() > 1024 * 1024 * 1024 * 1 ) {
this.useTailCache = true;
}
this.exceed134217727 = getConfigBool("exceed134217727", true);
- if (MemoryControl.available() > 1024 * 1024 * 1024 * 2) {
+ if ( MemoryControl.available() > 1024 * 1024 * 1024 * 2 ) {
this.exceed134217727 = true;
}
// load values from configs
- final File indexPath = getDataPath(SwitchboardConstants.INDEX_PRIMARY_PATH, SwitchboardConstants.INDEX_PATH_DEFAULT);
+ final File indexPath =
+ getDataPath(SwitchboardConstants.INDEX_PRIMARY_PATH, SwitchboardConstants.INDEX_PATH_DEFAULT);
this.log.logConfig("Index Primary Path: " + indexPath.toString());
- this.listsPath = getDataPath(SwitchboardConstants.LISTS_PATH, SwitchboardConstants.LISTS_PATH_DEFAULT);
+ this.listsPath =
+ getDataPath(SwitchboardConstants.LISTS_PATH, SwitchboardConstants.LISTS_PATH_DEFAULT);
this.log.logConfig("Lists Path: " + this.listsPath.toString());
- this.htDocsPath = getDataPath(SwitchboardConstants.HTDOCS_PATH, SwitchboardConstants.HTDOCS_PATH_DEFAULT);
+ this.htDocsPath =
+ getDataPath(SwitchboardConstants.HTDOCS_PATH, SwitchboardConstants.HTDOCS_PATH_DEFAULT);
this.log.logConfig("HTDOCS Path: " + this.htDocsPath.toString());
- this.workPath = getDataPath(SwitchboardConstants.WORK_PATH, SwitchboardConstants.WORK_PATH_DEFAULT);
+ this.workPath = getDataPath(SwitchboardConstants.WORK_PATH, SwitchboardConstants.WORK_PATH_DEFAULT);
this.log.logConfig("Work Path: " + this.workPath.toString());
- this.dictionariesPath = getDataPath(SwitchboardConstants.DICTIONARY_SOURCE_PATH, SwitchboardConstants.DICTIONARY_SOURCE_PATH_DEFAULT);
+ this.dictionariesPath =
+ getDataPath(
+ SwitchboardConstants.DICTIONARY_SOURCE_PATH,
+ SwitchboardConstants.DICTIONARY_SOURCE_PATH_DEFAULT);
this.log.logConfig("Dictionaries Path:" + this.dictionariesPath.toString());
// init global host name cache
@@ -322,7 +333,7 @@ public final class Switchboard extends serverSwitch {
Domains.init(new File(this.workPath, "globalhosts.list"));
// init sessionid name file
- final String sessionidNamesFile = getConfig("sessionidNamesFile","defaults/sessionid.names");
+ final String sessionidNamesFile = getConfig("sessionidNamesFile", "defaults/sessionid.names");
this.log.logConfig("Loading sessionid file " + sessionidNamesFile);
MultiProtocolURI.initSessionIDNames(FileUtils.loadList(new File(getAppPath(), sessionidNamesFile)));
@@ -348,7 +359,10 @@ public final class Switchboard extends serverSwitch {
// start indexing management
this.log.logConfig("Starting Indexing Management");
final String networkName = getConfig(SwitchboardConstants.NETWORK_NAME, "");
- final long fileSizeMax = (OS.isWindows) ? sb.getConfigLong("filesize.max.win", Integer.MAX_VALUE) : sb.getConfigLong("filesize.max.other", Integer.MAX_VALUE);
+ final long fileSizeMax =
+ (OS.isWindows) ? sb.getConfigLong("filesize.max.win", Integer.MAX_VALUE) : sb.getConfigLong(
+ "filesize.max.other",
+ Integer.MAX_VALUE);
final int redundancy = (int) sb.getConfigLong("network.unit.dhtredundancy.senior", 1);
final int partitionExponent = (int) sb.getConfigLong("network.unit.dht.partitionExponent", 0);
this.networkRoot = new File(new File(indexPath, networkName), "NETWORK");
@@ -356,7 +370,8 @@ public final class Switchboard extends serverSwitch {
this.networkRoot.mkdirs();
this.queuesRoot.mkdirs();
final File mySeedFile = new File(this.networkRoot, SeedDB.DBFILE_OWN_SEED);
- this.peers = new SeedDB(
+ this.peers =
+ new SeedDB(
this.networkRoot,
"seed.new.heap",
"seed.old.heap",
@@ -371,8 +386,12 @@ public final class Switchboard extends serverSwitch {
ReferenceContainer.maxReferences = getConfigInt("index.maxReferences", 0);
final File oldSingleSegment = new File(new File(indexPath, networkName), "TEXT");
final File newSegmentsPath = new File(new File(indexPath, networkName), "SEGMENTS");
- Segments.migrateOld(oldSingleSegment, newSegmentsPath, getConfig(SwitchboardConstants.SEGMENT_PUBLIC, "default"));
- this.indexSegments = new Segments(
+ Segments.migrateOld(
+ oldSingleSegment,
+ newSegmentsPath,
+ getConfig(SwitchboardConstants.SEGMENT_PUBLIC, "default"));
+ this.indexSegments =
+ new Segments(
this.log,
newSegmentsPath,
wordCacheMaxCount,
@@ -384,23 +403,22 @@ public final class Switchboard extends serverSwitch {
// load domainList
try {
- this.domainList = null;
- if(!getConfig("network.unit.domainlist", "").equals("")) {
- final Reader r = getConfigFileFromWebOrLocally(getConfig("network.unit.domainlist", ""), getAppPath().getAbsolutePath(), new File(this.networkRoot, "domainlist.txt"));
- this.domainList = new FilterEngine();
- this.domainList.loadList(new BufferedReader(r), null);
- }
- } catch (final FileNotFoundException e) {
- this.log.logSevere("CONFIG: domainlist not found: " + e.getMessage());
- } catch (final IOException e) {
- this.log.logSevere("CONFIG: error while retrieving domainlist: " + e.getMessage());
- }
+ this.domainList = null;
+ if ( !getConfig("network.unit.domainlist", "").equals("") ) {
+ final Reader r =
+ getConfigFileFromWebOrLocally(getConfig("network.unit.domainlist", ""), getAppPath()
+ .getAbsolutePath(), new File(this.networkRoot, "domainlist.txt"));
+ this.domainList = new FilterEngine();
+ this.domainList.loadList(new BufferedReader(r), null);
+ }
+ } catch ( final FileNotFoundException e ) {
+ this.log.logSevere("CONFIG: domainlist not found: " + e.getMessage());
+ } catch ( final IOException e ) {
+ this.log.logSevere("CONFIG: error while retrieving domainlist: " + e.getMessage());
+ }
// create a crawler
- this.crawler = new CrawlSwitchboard(
- networkName,
- this.log,
- this.queuesRoot);
+ this.crawler = new CrawlSwitchboard(networkName, this.log, this.queuesRoot);
// start yacy core
this.log.logConfig("Starting YaCy Protocol Core");
@@ -409,7 +427,8 @@ public final class Switchboard extends serverSwitch {
//final long startedSeedListAquisition = System.currentTimeMillis();
// init a DHT transmission dispatcher
- this.dhtDispatcher = (this.peers.sizeConnected() == 0) ? null : new Dispatcher(
+ this.dhtDispatcher =
+ (this.peers.sizeConnected() == 0) ? null : new Dispatcher(
this.indexSegments.segment(Segments.Process.LOCALCRAWLING),
this.peers,
true,
@@ -425,48 +444,63 @@ public final class Switchboard extends serverSwitch {
this.webStructure = new WebStructureGraph(new File(this.queuesRoot, "webStructure.map"));
// configuring list path
- if (!(this.listsPath.exists())) {
+ if ( !(this.listsPath.exists()) ) {
this.listsPath.mkdirs();
}
// load coloured lists
- if (blueList == null) {
+ if ( blueList == null ) {
// read only once upon first instantiation of this class
- final String f = getConfig(SwitchboardConstants.LIST_BLUE, SwitchboardConstants.LIST_BLUE_DEFAULT);
+ final String f =
+ getConfig(SwitchboardConstants.LIST_BLUE, SwitchboardConstants.LIST_BLUE_DEFAULT);
final File plasmaBlueListFile = new File(f);
- if (f != null) blueList = SetTools.loadList(plasmaBlueListFile, NaturalOrder.naturalComparator); else blueList= new TreeSet();
+ if ( f != null ) {
+ blueList = SetTools.loadList(plasmaBlueListFile, NaturalOrder.naturalComparator);
+ } else {
+ blueList = new TreeSet();
+ }
blueListHashes = Word.words2hashesHandles(blueList);
- this.log.logConfig("loaded blue-list from file " + plasmaBlueListFile.getName() + ", " +
- blueList.size() + " entries, " +
- ppRamString(plasmaBlueListFile.length()/1024));
+ this.log.logConfig("loaded blue-list from file "
+ + plasmaBlueListFile.getName()
+ + ", "
+ + blueList.size()
+ + " entries, "
+ + ppRamString(plasmaBlueListFile.length() / 1024));
}
// load blacklist
this.log.logConfig("Loading blacklist ...");
- final File blacklistsPath = getDataPath(SwitchboardConstants.LISTS_PATH, SwitchboardConstants.LISTS_PATH_DEFAULT);
+ final File blacklistsPath =
+ getDataPath(SwitchboardConstants.LISTS_PATH, SwitchboardConstants.LISTS_PATH_DEFAULT);
urlBlacklist = new Blacklist(blacklistsPath);
ListManager.switchboard = this;
ListManager.listsPath = blacklistsPath;
ListManager.reloadBlacklists();
// load badwords (to filter the topwords)
- if (badwords == null || badwords.isEmpty()) {
+ if ( badwords == null || badwords.isEmpty() ) {
final File badwordsFile = new File(appPath, SwitchboardConstants.LIST_BADWORDS_DEFAULT);
badwords = SetTools.loadList(badwordsFile, NaturalOrder.naturalComparator);
badwordHashes = Word.words2hashesHandles(badwords);
- this.log.logConfig("loaded badwords from file " + badwordsFile.getName() +
- ", " + badwords.size() + " entries, " +
- ppRamString(badwordsFile.length()/1024));
+ this.log.logConfig("loaded badwords from file "
+ + badwordsFile.getName()
+ + ", "
+ + badwords.size()
+ + " entries, "
+ + ppRamString(badwordsFile.length() / 1024));
}
// load stopwords
- if (stopwords == null || stopwords.isEmpty()) {
+ if ( stopwords == null || stopwords.isEmpty() ) {
final File stopwordsFile = new File(appPath, SwitchboardConstants.LIST_STOPWORDS_DEFAULT);
stopwords = SetTools.loadList(stopwordsFile, NaturalOrder.naturalComparator);
stopwordHashes = Word.words2hashesHandles(stopwords);
- this.log.logConfig("loaded stopwords from file " + stopwordsFile.getName() + ", " +
- stopwords.size() + " entries, " +
- ppRamString(stopwordsFile.length()/1024));
+ this.log.logConfig("loaded stopwords from file "
+ + stopwordsFile.getName()
+ + ", "
+ + stopwords.size()
+ + " entries, "
+ + ppRamString(stopwordsFile.length() / 1024));
}
// load ranking from distribution
@@ -516,27 +550,36 @@ public final class Switchboard extends serverSwitch {
// load the robots.txt db
this.log.logConfig("Initializing robots.txt DB");
this.robots = new RobotsTxt(this.tables);
- this.log.logConfig("Loaded robots.txt DB: " + this.robots.size() + " entries");
+ this.log.logConfig("Loaded robots.txt DB: " + this.robots.size() + " entries");
// start a cache manager
this.log.logConfig("Starting HT Cache Manager");
// create the cache directory
- this.htCachePath = getDataPath(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT);
+ this.htCachePath =
+ getDataPath(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT);
this.log.logInfo("HTCACHE Path = " + this.htCachePath.getAbsolutePath());
- final long maxCacheSize = 1024 * 1024 * Long.parseLong(getConfig(SwitchboardConstants.PROXY_CACHE_SIZE, "2")); // this is megabyte
+ final long maxCacheSize =
+ 1024 * 1024 * Long.parseLong(getConfig(SwitchboardConstants.PROXY_CACHE_SIZE, "2")); // this is megabyte
Cache.init(this.htCachePath, this.peers.mySeed().hash, maxCacheSize);
// create the surrogates directories
- this.surrogatesInPath = getDataPath(SwitchboardConstants.SURROGATES_IN_PATH, SwitchboardConstants.SURROGATES_IN_PATH_DEFAULT);
+ this.surrogatesInPath =
+ getDataPath(
+ SwitchboardConstants.SURROGATES_IN_PATH,
+ SwitchboardConstants.SURROGATES_IN_PATH_DEFAULT);
this.log.logInfo("surrogates.in Path = " + this.surrogatesInPath.getAbsolutePath());
this.surrogatesInPath.mkdirs();
- this.surrogatesOutPath = getDataPath(SwitchboardConstants.SURROGATES_OUT_PATH, SwitchboardConstants.SURROGATES_OUT_PATH_DEFAULT);
+ this.surrogatesOutPath =
+ getDataPath(
+ SwitchboardConstants.SURROGATES_OUT_PATH,
+ SwitchboardConstants.SURROGATES_OUT_PATH_DEFAULT);
this.log.logInfo("surrogates.out Path = " + this.surrogatesOutPath.getAbsolutePath());
this.surrogatesOutPath.mkdirs();
// create the release download directory
- this.releasePath = getDataPath(SwitchboardConstants.RELEASE_PATH, SwitchboardConstants.RELEASE_PATH_DEFAULT);
+ this.releasePath =
+ getDataPath(SwitchboardConstants.RELEASE_PATH, SwitchboardConstants.RELEASE_PATH_DEFAULT);
this.releasePath.mkdirs();
this.log.logInfo("RELEASE Path = " + this.releasePath.getAbsolutePath());
@@ -553,30 +596,38 @@ public final class Switchboard extends serverSwitch {
this.log.logConfig("Loading User DB");
final File userDbFile = new File(getDataPath(), "DATA/SETTINGS/user.heap");
this.userDB = new UserDB(userDbFile);
- this.log.logConfig("Loaded User DB from file " + userDbFile.getName() +
- ", " + this.userDB.size() + " entries" +
- ", " + ppRamString(userDbFile.length()/1024));
+ this.log.logConfig("Loaded User DB from file "
+ + userDbFile.getName()
+ + ", "
+ + this.userDB.size()
+ + " entries"
+ + ", "
+ + ppRamString(userDbFile.length() / 1024));
// init html parser evaluation scheme
File parserPropertiesPath = new File("defaults/");
String[] settingsList = parserPropertiesPath.list();
- for (final String l: settingsList) {
- if (l.startsWith("parser.") && l.endsWith(".properties")) Evaluation.add(new File(parserPropertiesPath, l));
+ for ( final String l : settingsList ) {
+ if ( l.startsWith("parser.") && l.endsWith(".properties") ) {
+ Evaluation.add(new File(parserPropertiesPath, l));
+ }
}
parserPropertiesPath = new File(getDataPath(), "DATA/SETTINGS/");
settingsList = parserPropertiesPath.list();
- for (final String l: settingsList) {
- if (l.startsWith("parser.") && l.endsWith(".properties")) Evaluation.add(new File(parserPropertiesPath, l));
+ for ( final String l : settingsList ) {
+ if ( l.startsWith("parser.") && l.endsWith(".properties") ) {
+ Evaluation.add(new File(parserPropertiesPath, l));
+ }
}
// init bookmarks DB: needs more time since this does a DNS lookup for each Bookmark.
// Can be started concurrently
- new Thread(){
+ new Thread() {
@Override
public void run() {
try {
initBookmarks();
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
}
}
@@ -588,9 +639,12 @@ public final class Switchboard extends serverSwitch {
// prepare a solr index profile switch list
final File solrBackupProfile = new File("defaults/solr.keys.list");
- final String schemename = getConfig("federated.service.solr.indexing.schemefile", "solr.keys.default.list");
+ final String schemename =
+ getConfig("federated.service.solr.indexing.schemefile", "solr.keys.default.list");
final File solrWorkProfile = new File(getDataPath(), "DATA/SETTINGS/" + schemename);
- if (!solrWorkProfile.exists()) FileUtils.copy(solrBackupProfile, solrWorkProfile);
+ if ( !solrWorkProfile.exists() ) {
+ FileUtils.copy(solrBackupProfile, solrWorkProfile);
+ }
final SolrScheme backupScheme = new SolrScheme(solrBackupProfile);
final SolrScheme workingScheme = new SolrScheme(solrWorkProfile);
@@ -599,11 +653,18 @@ public final class Switchboard extends serverSwitch {
workingScheme.fill(backupScheme);
// set up the solr interface
- final String solrurls = getConfig("federated.service.solr.indexing.url", "http://127.0.0.1:8983/solr");
- final boolean usesolr = getConfigBool("federated.service.solr.indexing.enabled", false) & solrurls.length() > 0;
+ final String solrurls =
+ getConfig("federated.service.solr.indexing.url", "http://127.0.0.1:8983/solr");
+ final boolean usesolr =
+ getConfigBool("federated.service.solr.indexing.enabled", false) & solrurls.length() > 0;
try {
- this.indexSegments.segment(Segments.Process.LOCALCRAWLING).connectSolr((usesolr) ? new SolrShardingConnector(solrurls, workingScheme, SolrShardingSelection.Method.MODULO_HOST_MD5, 10000) : null);
- } catch (final IOException e) {
+ this.indexSegments.segment(Segments.Process.LOCALCRAWLING).connectSolr(
+ (usesolr) ? new SolrShardingConnector(
+ solrurls,
+ workingScheme,
+ SolrShardingSelection.Method.MODULO_HOST_MD5,
+ 10000) : null);
+ } catch ( final IOException e ) {
Log.logException(e);
this.indexSegments.segment(Segments.Process.LOCALCRAWLING).connectSolr(null);
}
@@ -611,12 +672,15 @@ public final class Switchboard extends serverSwitch {
// start a loader
this.log.logConfig("Starting Crawl Loader");
this.loader = new LoaderDispatcher(this);
- final Map oaiFriends = OAIListFriendsLoader.loadListFriendsSources(new File("defaults/oaiListFriendsSource.xml"), getDataPath());
+ final Map oaiFriends =
+ OAIListFriendsLoader.loadListFriendsSources(
+ new File("defaults/oaiListFriendsSource.xml"),
+ getDataPath());
OAIListFriendsLoader.init(this.loader, oaiFriends);
this.crawlQueues = new CrawlQueues(this, this.queuesRoot);
this.crawlQueues.noticeURL.setMinimumDelta(
- getConfigLong("minimumLocalDelta", this.crawlQueues.noticeURL.getMinimumLocalDelta()),
- getConfigLong("minimumGlobalDelta", this.crawlQueues.noticeURL.getMinimumGlobalDelta()));
+ getConfigLong("minimumLocalDelta", this.crawlQueues.noticeURL.getMinimumLocalDelta()),
+ getConfigLong("minimumGlobalDelta", this.crawlQueues.noticeURL.getMinimumGlobalDelta()));
/*
* Creating sync objects and loading status for the crawl jobs
@@ -624,15 +688,28 @@ public final class Switchboard extends serverSwitch {
* b) remote triggered crawl
* c) global crawl trigger
*/
- this.crawlJobsStatus.put(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL, new Object[]{
+ this.crawlJobsStatus.put(
+ SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL,
+ new Object[] {
new Object(),
- Boolean.valueOf(getConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL + "_isPaused", "false"))});
- this.crawlJobsStatus.put(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL, new Object[]{
+ Boolean.valueOf(getConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL + "_isPaused", "false"))
+ });
+ this.crawlJobsStatus.put(
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL,
+ new Object[] {
new Object(),
- Boolean.valueOf(getConfig(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL + "_isPaused", "false"))});
- this.crawlJobsStatus.put(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER, new Object[]{
+ Boolean.valueOf(getConfig(
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL + "_isPaused",
+ "false"))
+ });
+ this.crawlJobsStatus.put(
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER,
+ new Object[] {
new Object(),
- Boolean.valueOf(getConfig(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER + "_isPaused", "false"))});
+ Boolean.valueOf(getConfig(
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER + "_isPaused",
+ "false"))
+ });
// init cookie-Monitor
this.log.logConfig("Starting Cookie Monitor");
@@ -644,15 +721,22 @@ public final class Switchboard extends serverSwitch {
this.remoteSearchTracker = new ConcurrentHashMap>();
// init messages: clean up message symbol
- final File notifierSource = new File(getAppPath(), getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT) + "/env/grafics/empty.gif");
- final File notifierDest = new File(getDataPath(SwitchboardConstants.HTDOCS_PATH, SwitchboardConstants.HTDOCS_PATH_DEFAULT), "notifier.gif");
+ final File notifierSource =
+ new File(getAppPath(), getConfig(
+ SwitchboardConstants.HTROOT_PATH,
+ SwitchboardConstants.HTROOT_PATH_DEFAULT) + "/env/grafics/empty.gif");
+ final File notifierDest =
+ new File(
+ getDataPath(SwitchboardConstants.HTDOCS_PATH, SwitchboardConstants.HTDOCS_PATH_DEFAULT),
+ "notifier.gif");
try {
FileUtils.copy(notifierSource, notifierDest);
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
}
// init nameCacheNoCachingList
- Domains.setNoCachingPatterns(getConfig(SwitchboardConstants.HTTPC_NAME_CACHE_CACHING_PATTERNS_NO,""));
+ Domains
+ .setNoCachingPatterns(getConfig(SwitchboardConstants.HTTPC_NAME_CACHE_CACHING_PATTERNS_NO, ""));
// generate snippets cache
this.log.logConfig("Initializing Snippet Cache");
@@ -664,7 +748,8 @@ public final class Switchboard extends serverSwitch {
InstantBusyThread.oneTimeJob(ResourceObserver.class, "initThread", ResourceObserver.log, 0);
// initializing the stackCrawlThread
- this.crawlStacker = new CrawlStacker(
+ this.crawlStacker =
+ new CrawlStacker(
this.crawlQueues,
this.crawler,
this.indexSegments.segment(Segments.Process.LOCALCRAWLING),
@@ -680,8 +765,8 @@ public final class Switchboard extends serverSwitch {
// that an automatic authorization of localhost is done, because in this case crawls from local
// addresses are blocked to prevent attack szenarios where remote pages contain links to localhost
// addresses that can steer a YaCy peer
- if ((getConfigBool("adminAccountForLocalhost", false))) {
- if (getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").startsWith("0000")) {
+ if ( (getConfigBool("adminAccountForLocalhost", false)) ) {
+ if ( getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").startsWith("0000") ) {
// the password was set automatically with a random value.
// We must remove that here to prevent that a user cannot log in any more
setConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "");
@@ -698,101 +783,185 @@ public final class Switchboard extends serverSwitch {
this.clusterhashes = this.peers.clusterHashes(getConfig("cluster.peers.yacydomain", ""));
// deploy blocking threads
- this.indexingStorageProcessor = new WorkflowProcessor(
+ this.indexingStorageProcessor =
+ new WorkflowProcessor(
"storeDocumentIndex",
"This is the sequencing step of the indexing queue. Files are written as streams, too much councurrency would destroy IO performance. In this process the words are written to the RWI cache, which flushes if it is full.",
- new String[]{"RWI/Cache/Collections"},
- this, "storeDocumentIndex", 2 * WorkflowProcessor.availableCPU, null, 1 /*Math.max(1, WorkflowProcessor.availableCPU / 2)*/);
- this.indexingAnalysisProcessor = new WorkflowProcessor(
+ new String[] {
+ "RWI/Cache/Collections"
+ },
+ this,
+ "storeDocumentIndex",
+ 2 * WorkflowProcessor.availableCPU,
+ null,
+ 1 /*Math.max(1, WorkflowProcessor.availableCPU / 2)*/);
+ this.indexingAnalysisProcessor =
+ new WorkflowProcessor(
"webStructureAnalysis",
"This just stores the link structure of the document into a web structure database.",
- new String[]{"storeDocumentIndex"},
- this, "webStructureAnalysis", 2 * WorkflowProcessor.availableCPU, this.indexingStorageProcessor, WorkflowProcessor.availableCPU);
- this.indexingCondensementProcessor = new WorkflowProcessor(
+ new String[] {
+ "storeDocumentIndex"
+ },
+ this,
+ "webStructureAnalysis",
+ 2 * WorkflowProcessor.availableCPU,
+ this.indexingStorageProcessor,
+ WorkflowProcessor.availableCPU);
+ this.indexingCondensementProcessor =
+ new WorkflowProcessor(
"condenseDocument",
"This does a structural analysis of plain texts: markup of headlines, slicing into phrases (i.e. sentences), markup with position, counting of words, calculation of term frequency.",
- new String[]{"webStructureAnalysis"},
- this, "condenseDocument", 4 * WorkflowProcessor.availableCPU, this.indexingAnalysisProcessor, WorkflowProcessor.availableCPU);
- this.indexingDocumentProcessor = new WorkflowProcessor(
+ new String[] {
+ "webStructureAnalysis"
+ },
+ this,
+ "condenseDocument",
+ 4 * WorkflowProcessor.availableCPU,
+ this.indexingAnalysisProcessor,
+ WorkflowProcessor.availableCPU);
+ this.indexingDocumentProcessor =
+ new WorkflowProcessor(
"parseDocument",
"This does the parsing of the newly loaded documents from the web. The result is not only a plain text document, but also a list of URLs that are embedded into the document. The urls are handed over to the CrawlStacker. This process has two child process queues!",
- new String[]{"condenseDocument", "CrawlStacker"},
- this, "parseDocument", 4 * WorkflowProcessor.availableCPU, this.indexingCondensementProcessor, WorkflowProcessor.availableCPU);
+ new String[] {
+ "condenseDocument", "CrawlStacker"
+ },
+ this,
+ "parseDocument",
+ 4 * WorkflowProcessor.availableCPU,
+ this.indexingCondensementProcessor,
+ WorkflowProcessor.availableCPU);
// deploy busy threads
this.log.logConfig("Starting Threads");
MemoryControl.gc(10000, "plasmaSwitchboard, help for profiler"); // help for profiler - thq
- deployThread(SwitchboardConstants.CLEANUP, "Cleanup", "simple cleaning process for monitoring information", null,
- new InstantBusyThread(
- this,
- SwitchboardConstants.CLEANUP_METHOD_START,
- SwitchboardConstants.CLEANUP_METHOD_JOBCOUNT,
- SwitchboardConstants.CLEANUP_METHOD_FREEMEM,
- 60000, Long.MAX_VALUE, 10000, Long.MAX_VALUE),
- 60000); // all 5 Minutes, wait 1 minute until first run
- deployThread(SwitchboardConstants.SURROGATES, "Surrogates", "A thread that polls the SURROGATES path and puts all Documents in one surroagte file into the indexing queue.", null,
- new InstantBusyThread(
- this,
- SwitchboardConstants.SURROGATES_METHOD_START,
- SwitchboardConstants.SURROGATES_METHOD_JOBCOUNT,
- SwitchboardConstants.SURROGATES_METHOD_FREEMEM,
- 20000, Long.MAX_VALUE, 0, Long.MAX_VALUE),
- 10000);
- deployThread(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL, "Remote Crawl Job", "thread that performes a single crawl/indexing step triggered by a remote peer", "/IndexCreateWWWRemoteQueue_p.html",
- new InstantBusyThread(
- this.crawlQueues,
- SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_METHOD_START,
- SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_METHOD_JOBCOUNT,
- SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_METHOD_FREEMEM,
- 0, Long.MAX_VALUE, 0, Long.MAX_VALUE),
- 10000);
- deployThread(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER, "Remote Crawl URL Loader", "thread that loads remote crawl lists from other peers", null,
- new InstantBusyThread(
- this.crawlQueues,
- SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_METHOD_START,
- SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_METHOD_JOBCOUNT,
- SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_METHOD_FREEMEM,
- 10000, Long.MAX_VALUE, 10000, Long.MAX_VALUE),
- 10000); // error here?
- deployThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL, "Local Crawl", "thread that performes a single crawl step from the local crawl queue", "/IndexCreateWWWLocalQueue_p.html",
- new InstantBusyThread(
- this.crawlQueues,
- SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_METHOD_START,
- SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_METHOD_JOBCOUNT,
- SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_METHOD_FREEMEM,
- 0, Long.MAX_VALUE, 0, Long.MAX_VALUE),
- 10000);
- deployThread(SwitchboardConstants.SEED_UPLOAD, "Seed-List Upload", "task that a principal peer performes to generate and upload a seed-list to a ftp account", null,
- new InstantBusyThread(
- this.yc,
- SwitchboardConstants.SEED_UPLOAD_METHOD_START,
- SwitchboardConstants.SEED_UPLOAD_METHOD_JOBCOUNT,
- SwitchboardConstants.SEED_UPLOAD_METHOD_FREEMEM,
- 600000, Long.MAX_VALUE, 300000, Long.MAX_VALUE),
- 180000);
- deployThread(SwitchboardConstants.PEER_PING, "YaCy Core", "this is the p2p-control and peer-ping task", null,
- new InstantBusyThread(
- this.yc,
- SwitchboardConstants.PEER_PING_METHOD_START,
- SwitchboardConstants.PEER_PING_METHOD_JOBCOUNT,
- SwitchboardConstants.PEER_PING_METHOD_FREEMEM,
- 30000, Long.MAX_VALUE, 30000, Long.MAX_VALUE),
- 2000);
- deployThread(SwitchboardConstants.INDEX_DIST, "DHT Distribution", "selection, transfer and deletion of index entries that are not searched on your peer, but on others", null,
- new InstantBusyThread(
- this,
- SwitchboardConstants.INDEX_DIST_METHOD_START,
- SwitchboardConstants.INDEX_DIST_METHOD_JOBCOUNT,
- SwitchboardConstants.INDEX_DIST_METHOD_FREEMEM,
- 10000, Long.MAX_VALUE, 1000, Long.MAX_VALUE),
- 5000,
- Long.parseLong(getConfig(SwitchboardConstants.INDEX_DIST_IDLESLEEP , "5000")),
- Long.parseLong(getConfig(SwitchboardConstants.INDEX_DIST_BUSYSLEEP , "0")),
- Long.parseLong(getConfig(SwitchboardConstants.INDEX_DIST_MEMPREREQ , "1000000")));
+ deployThread(
+ SwitchboardConstants.CLEANUP,
+ "Cleanup",
+ "simple cleaning process for monitoring information",
+ null,
+ new InstantBusyThread(
+ this,
+ SwitchboardConstants.CLEANUP_METHOD_START,
+ SwitchboardConstants.CLEANUP_METHOD_JOBCOUNT,
+ SwitchboardConstants.CLEANUP_METHOD_FREEMEM,
+ 60000,
+ Long.MAX_VALUE,
+ 10000,
+ Long.MAX_VALUE),
+ 60000); // all 5 Minutes, wait 1 minute until first run
+ deployThread(
+ SwitchboardConstants.SURROGATES,
+ "Surrogates",
+ "A thread that polls the SURROGATES path and puts all Documents in one surroagte file into the indexing queue.",
+ null,
+ new InstantBusyThread(
+ this,
+ SwitchboardConstants.SURROGATES_METHOD_START,
+ SwitchboardConstants.SURROGATES_METHOD_JOBCOUNT,
+ SwitchboardConstants.SURROGATES_METHOD_FREEMEM,
+ 20000,
+ Long.MAX_VALUE,
+ 0,
+ Long.MAX_VALUE),
+ 10000);
+ deployThread(
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL,
+ "Remote Crawl Job",
+ "thread that performes a single crawl/indexing step triggered by a remote peer",
+ "/IndexCreateWWWRemoteQueue_p.html",
+ new InstantBusyThread(
+ this.crawlQueues,
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_METHOD_START,
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_METHOD_JOBCOUNT,
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_METHOD_FREEMEM,
+ 0,
+ Long.MAX_VALUE,
+ 0,
+ Long.MAX_VALUE),
+ 10000);
+ deployThread(
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER,
+ "Remote Crawl URL Loader",
+ "thread that loads remote crawl lists from other peers",
+ null,
+ new InstantBusyThread(
+ this.crawlQueues,
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_METHOD_START,
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_METHOD_JOBCOUNT,
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_METHOD_FREEMEM,
+ 10000,
+ Long.MAX_VALUE,
+ 10000,
+ Long.MAX_VALUE),
+ 10000); // error here?
+ deployThread(
+ SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL,
+ "Local Crawl",
+ "thread that performes a single crawl step from the local crawl queue",
+ "/IndexCreateWWWLocalQueue_p.html",
+ new InstantBusyThread(
+ this.crawlQueues,
+ SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_METHOD_START,
+ SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_METHOD_JOBCOUNT,
+ SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_METHOD_FREEMEM,
+ 0,
+ Long.MAX_VALUE,
+ 0,
+ Long.MAX_VALUE),
+ 10000);
+ deployThread(
+ SwitchboardConstants.SEED_UPLOAD,
+ "Seed-List Upload",
+ "task that a principal peer performes to generate and upload a seed-list to a ftp account",
+ null,
+ new InstantBusyThread(
+ this.yc,
+ SwitchboardConstants.SEED_UPLOAD_METHOD_START,
+ SwitchboardConstants.SEED_UPLOAD_METHOD_JOBCOUNT,
+ SwitchboardConstants.SEED_UPLOAD_METHOD_FREEMEM,
+ 600000,
+ Long.MAX_VALUE,
+ 300000,
+ Long.MAX_VALUE),
+ 180000);
+ deployThread(
+ SwitchboardConstants.PEER_PING,
+ "YaCy Core",
+ "this is the p2p-control and peer-ping task",
+ null,
+ new InstantBusyThread(
+ this.yc,
+ SwitchboardConstants.PEER_PING_METHOD_START,
+ SwitchboardConstants.PEER_PING_METHOD_JOBCOUNT,
+ SwitchboardConstants.PEER_PING_METHOD_FREEMEM,
+ 30000,
+ Long.MAX_VALUE,
+ 30000,
+ Long.MAX_VALUE),
+ 2000);
+ deployThread(
+ SwitchboardConstants.INDEX_DIST,
+ "DHT Distribution",
+ "selection, transfer and deletion of index entries that are not searched on your peer, but on others",
+ null,
+ new InstantBusyThread(
+ this,
+ SwitchboardConstants.INDEX_DIST_METHOD_START,
+ SwitchboardConstants.INDEX_DIST_METHOD_JOBCOUNT,
+ SwitchboardConstants.INDEX_DIST_METHOD_FREEMEM,
+ 10000,
+ Long.MAX_VALUE,
+ 1000,
+ Long.MAX_VALUE),
+ 5000,
+ Long.parseLong(getConfig(SwitchboardConstants.INDEX_DIST_IDLESLEEP, "5000")),
+ Long.parseLong(getConfig(SwitchboardConstants.INDEX_DIST_BUSYSLEEP, "0")),
+ Long.parseLong(getConfig(SwitchboardConstants.INDEX_DIST_MEMPREREQ, "1000000")));
// set network-specific performance attributes
- if (this.firstInit) {
+ if ( this.firstInit ) {
setRemotecrawlPPM(Math.max(1, (int) getConfigLong("network.unit.remotecrawl.speed", 60)));
}
@@ -811,31 +980,47 @@ public final class Switchboard extends serverSwitch {
}
private void setDefaultSegments() {
- this.indexSegments.setSegment(Segments.Process.RECEIPTS, getConfig(SwitchboardConstants.SEGMENT_RECEIPTS, "default"));
- this.indexSegments.setSegment(Segments.Process.QUERIES, getConfig(SwitchboardConstants.SEGMENT_QUERIES, "default"));
- this.indexSegments.setSegment(Segments.Process.DHTIN, getConfig(SwitchboardConstants.SEGMENT_DHTIN, "default"));
- this.indexSegments.setSegment(Segments.Process.DHTOUT, getConfig(SwitchboardConstants.SEGMENT_DHTOUT, "default"));
- this.indexSegments.setSegment(Segments.Process.PROXY, getConfig(SwitchboardConstants.SEGMENT_PROXY, "default"));
- this.indexSegments.setSegment(Segments.Process.LOCALCRAWLING, getConfig(SwitchboardConstants.SEGMENT_LOCALCRAWLING, "default"));
- this.indexSegments.setSegment(Segments.Process.REMOTECRAWLING, getConfig(SwitchboardConstants.SEGMENT_REMOTECRAWLING, "default"));
- this.indexSegments.setSegment(Segments.Process.PUBLIC, getConfig(SwitchboardConstants.SEGMENT_PUBLIC, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.RECEIPTS,
+ getConfig(SwitchboardConstants.SEGMENT_RECEIPTS, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.QUERIES,
+ getConfig(SwitchboardConstants.SEGMENT_QUERIES, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.DHTIN,
+ getConfig(SwitchboardConstants.SEGMENT_DHTIN, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.DHTOUT,
+ getConfig(SwitchboardConstants.SEGMENT_DHTOUT, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.PROXY,
+ getConfig(SwitchboardConstants.SEGMENT_PROXY, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.LOCALCRAWLING,
+ getConfig(SwitchboardConstants.SEGMENT_LOCALCRAWLING, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.REMOTECRAWLING,
+ getConfig(SwitchboardConstants.SEGMENT_REMOTECRAWLING, "default"));
+ this.indexSegments.setSegment(
+ Segments.Process.PUBLIC,
+ getConfig(SwitchboardConstants.SEGMENT_PUBLIC, "default"));
}
public int getIndexingProcessorsQueueSize() {
- return
- this.indexingDocumentProcessor.queueSize() +
- this.indexingCondensementProcessor.queueSize() +
- this.indexingAnalysisProcessor.queueSize() +
- this.indexingStorageProcessor.queueSize();
+ return this.indexingDocumentProcessor.queueSize()
+ + this.indexingCondensementProcessor.queueSize()
+ + this.indexingAnalysisProcessor.queueSize()
+ + this.indexingStorageProcessor.queueSize();
}
public void overwriteNetworkDefinition() throws FileNotFoundException, IOException {
// load network configuration into settings
- String networkUnitDefinition = getConfig("network.unit.definition", "defaults/yacy.network.freeworld.unit");
+ String networkUnitDefinition =
+ getConfig("network.unit.definition", "defaults/yacy.network.freeworld.unit");
// patch old values
- if (networkUnitDefinition.equals("yacy.network.unit")) {
+ if ( networkUnitDefinition.equals("yacy.network.unit") ) {
networkUnitDefinition = "defaults/yacy.network.freeworld.unit";
setConfig("network.unit.definition", networkUnitDefinition);
}
@@ -844,13 +1029,15 @@ public final class Switchboard extends serverSwitch {
final Iterator ki = configKeys();
final ArrayList d = new ArrayList();
String k;
- while (ki.hasNext()) {
+ while ( ki.hasNext() ) {
k = ki.next();
- if (k.startsWith("network.unit.update.location") || k.startsWith("network.unit.bootstrap")) {
+ if ( k.startsWith("network.unit.update.location") || k.startsWith("network.unit.bootstrap") ) {
d.add(k);
}
}
- for (final String s : d) removeConfig(s); // must be removed afterwards otherwise a ki.remove() would not remove the property on file
+ for ( final String s : d ) {
+ removeConfig(s); // must be removed afterwards otherwise a ki.remove() would not remove the property on file
+ }
// include additional network definition properties into our settings
// note that these properties cannot be set in the application because they are
@@ -858,7 +1045,10 @@ public final class Switchboard extends serverSwitch {
// the network definition should be made either consistent for all peers,
// or independently using a bootstrap URL
Map initProps;
- final Reader netDefReader = getConfigFileFromWebOrLocally(networkUnitDefinition, getAppPath().getAbsolutePath(), new File(this.workPath, "network.definition.backup"));
+ final Reader netDefReader =
+ getConfigFileFromWebOrLocally(networkUnitDefinition, getAppPath().getAbsolutePath(), new File(
+ this.workPath,
+ "network.definition.backup"));
initProps = FileUtils.table(netDefReader);
setConfig(initProps);
@@ -867,34 +1057,36 @@ public final class Switchboard extends serverSwitch {
CryptoLib cryptoLib;
try {
cryptoLib = new CryptoLib();
- while (true) {
+ while ( true ) {
final String location = getConfig("network.unit.update.location" + i, "");
- if (location.isEmpty()) {
+ if ( location.isEmpty() ) {
break;
}
DigestURI locationURL;
try {
// try to parse url
locationURL = new DigestURI(location);
- } catch (final MalformedURLException e) {
+ } catch ( final MalformedURLException e ) {
break;
}
PublicKey publicKey = null;
// get public key if it's in config
try {
- final String publicKeyString = getConfig("network.unit.update.location" + i + ".key", null);
- if (publicKeyString != null) {
- final byte[] publicKeyBytes = Base64Order.standardCoder.decode(publicKeyString.trim());
+ final String publicKeyString =
+ getConfig("network.unit.update.location" + i + ".key", null);
+ if ( publicKeyString != null ) {
+ final byte[] publicKeyBytes =
+ Base64Order.standardCoder.decode(publicKeyString.trim());
publicKey = cryptoLib.getPublicKeyFromBytes(publicKeyBytes);
}
- } catch (final InvalidKeySpecException e) {
+ } catch ( final InvalidKeySpecException e ) {
Log.logException(e);
}
final yacyUpdateLocation updateLocation = new yacyUpdateLocation(locationURL, publicKey);
yacyRelease.latestReleaseLocations.add(updateLocation);
i++;
}
- } catch (final NoSuchAlgorithmException e1) {
+ } catch ( final NoSuchAlgorithmException e1 ) {
// TODO Auto-generated catch block
Log.logException(e1);
}
@@ -925,8 +1117,12 @@ public final class Switchboard extends serverSwitch {
}
*/
// write the YaCy network identification inside the yacybot client user agent to distinguish networks
- String newagent = ClientIdentification.generateYaCyBot(getConfig(SwitchboardConstants.NETWORK_NAME, "") + (isRobinsonMode() ? "-" : "/") + getConfig(SwitchboardConstants.NETWORK_DOMAIN, "global"));
- if (!getConfigBool("network.unit.dht", false) && getConfig("network.unit.tenant.agent", "").length() > 0) {
+ String newagent =
+ ClientIdentification.generateYaCyBot(getConfig(SwitchboardConstants.NETWORK_NAME, "")
+ + (isRobinsonMode() ? "-" : "/")
+ + getConfig(SwitchboardConstants.NETWORK_DOMAIN, "global"));
+ if ( !getConfigBool("network.unit.dht", false)
+ && getConfig("network.unit.tenant.agent", "").length() > 0 ) {
newagent = getConfig("network.unit.tenant.agent", "").trim();
this.log.logInfo("new user agent: '" + newagent + "'");
}
@@ -937,11 +1133,11 @@ public final class Switchboard extends serverSwitch {
this.log.logInfo("SWITCH NETWORK: switching to '" + networkDefinition + "'");
// pause crawls
final boolean lcp = crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
- if (!lcp) {
+ if ( !lcp ) {
pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
}
final boolean rcp = crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
- if (!rcp) {
+ if ( !rcp ) {
pauseCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
}
// trigger online caution
@@ -951,12 +1147,14 @@ public final class Switchboard extends serverSwitch {
SearchEventCache.cleanupEvents(true);
// switch the networks
- synchronized (this) {
+ synchronized ( this ) {
// shut down
this.crawler.close();
- if (this.dhtDispatcher != null) this.dhtDispatcher.close();
- synchronized (this.indexSegments) {
+ if ( this.dhtDispatcher != null ) {
+ this.dhtDispatcher.close();
+ }
+ synchronized ( this.indexSegments ) {
this.indexSegments.close();
}
this.crawlStacker.announceClose();
@@ -968,9 +1166,13 @@ public final class Switchboard extends serverSwitch {
// new properties
setConfig("network.unit.definition", networkDefinition);
overwriteNetworkDefinition();
- final File indexPrimaryPath = getDataPath(SwitchboardConstants.INDEX_PRIMARY_PATH, SwitchboardConstants.INDEX_PATH_DEFAULT);
- final int wordCacheMaxCount = (int) getConfigLong(SwitchboardConstants.WORDCACHE_MAX_COUNT, 20000);
- final long fileSizeMax = (OS.isWindows) ? sb.getConfigLong("filesize.max.win", (long) Integer.MAX_VALUE) : sb.getConfigLong("filesize.max.other", (long) Integer.MAX_VALUE);
+ final File indexPrimaryPath =
+ getDataPath(SwitchboardConstants.INDEX_PRIMARY_PATH, SwitchboardConstants.INDEX_PATH_DEFAULT);
+ final int wordCacheMaxCount =
+ (int) getConfigLong(SwitchboardConstants.WORDCACHE_MAX_COUNT, 20000);
+ final long fileSizeMax =
+ (OS.isWindows) ? sb.getConfigLong("filesize.max.win", (long) Integer.MAX_VALUE) : sb
+ .getConfigLong("filesize.max.other", (long) Integer.MAX_VALUE);
final int redundancy = (int) sb.getConfigLong("network.unit.dhtredundancy.senior", 1);
final int partitionExponent = (int) sb.getConfigLong("network.unit.dht.partitionExponent", 0);
final String networkName = getConfig(SwitchboardConstants.NETWORK_NAME, "");
@@ -989,12 +1191,13 @@ public final class Switchboard extends serverSwitch {
// relocate
this.peers.relocate(
- this.networkRoot,
- redundancy,
- partitionExponent,
- this.useTailCache,
- this.exceed134217727);
- this.indexSegments = new Segments(
+ this.networkRoot,
+ redundancy,
+ partitionExponent,
+ this.useTailCache,
+ this.exceed134217727);
+ this.indexSegments =
+ new Segments(
this.log,
new File(new File(indexPrimaryPath, networkName), "SEGMENTS"),
wordCacheMaxCount,
@@ -1006,13 +1209,11 @@ public final class Switchboard extends serverSwitch {
this.crawlQueues.relocate(this.queuesRoot); // cannot be closed because the busy threads are working with that object
// create a crawler
- this.crawler = new CrawlSwitchboard(
- networkName,
- this.log,
- this.queuesRoot);
+ this.crawler = new CrawlSwitchboard(networkName, this.log, this.queuesRoot);
// init a DHT transmission dispatcher
- this.dhtDispatcher = (this.peers.sizeConnected() == 0) ? null : new Dispatcher(
+ this.dhtDispatcher =
+ (this.peers.sizeConnected() == 0) ? null : new Dispatcher(
this.indexSegments.segment(Segments.Process.LOCALCRAWLING),
this.peers,
true,
@@ -1021,22 +1222,24 @@ public final class Switchboard extends serverSwitch {
// create new web structure
this.webStructure = new WebStructureGraph(new File(this.queuesRoot, "webStructure.map"));
-
// load domainList
try {
- this.domainList = null;
- if(!getConfig("network.unit.domainlist", "").equals("")) {
- final Reader r = getConfigFileFromWebOrLocally(getConfig("network.unit.domainlist", ""), getAppPath().getAbsolutePath(), new File(this.networkRoot, "domainlist.txt"));
- this.domainList = new FilterEngine();
- this.domainList.loadList(new BufferedReader(r), null);
- }
- } catch (final FileNotFoundException e) {
- this.log.logSevere("CONFIG: domainlist not found: " + e.getMessage());
- } catch (final IOException e) {
- this.log.logSevere("CONFIG: error while retrieving domainlist: " + e.getMessage());
- }
-
- this.crawlStacker = new CrawlStacker(
+ this.domainList = null;
+ if ( !getConfig("network.unit.domainlist", "").equals("") ) {
+ final Reader r =
+ getConfigFileFromWebOrLocally(getConfig("network.unit.domainlist", ""), getAppPath()
+ .getAbsolutePath(), new File(this.networkRoot, "domainlist.txt"));
+ this.domainList = new FilterEngine();
+ this.domainList.loadList(new BufferedReader(r), null);
+ }
+ } catch ( final FileNotFoundException e ) {
+ this.log.logSevere("CONFIG: domainlist not found: " + e.getMessage());
+ } catch ( final IOException e ) {
+ this.log.logSevere("CONFIG: error while retrieving domainlist: " + e.getMessage());
+ }
+
+ this.crawlStacker =
+ new CrawlStacker(
this.crawlQueues,
this.crawler,
this.indexSegments.segment(Segments.Process.LOCALCRAWLING),
@@ -1051,7 +1254,8 @@ public final class Switchboard extends serverSwitch {
// start up crawl jobs
continueCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
continueCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
- this.log.logInfo("SWITCH NETWORK: FINISHED START UP, new network is now '" + networkDefinition + "'.");
+ this.log
+ .logInfo("SWITCH NETWORK: FINISHED START UP, new network is now '" + networkDefinition + "'.");
// set the network-specific remote crawl ppm
setRemotecrawlPPM(Math.max(1, (int) getConfigLong("network.unit.remotecrawl.speed", 60)));
@@ -1063,14 +1267,19 @@ public final class Switchboard extends serverSwitch {
// propagate to crawler
final BusyThread rct = getThread(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
setConfig(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_BUSYSLEEP, newBusySleep);
- setConfig(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_IDLESLEEP, Math.min(10000, newBusySleep * 10));
+ setConfig(
+ SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_IDLESLEEP,
+ Math.min(10000, newBusySleep * 10));
rct.setBusySleep(getConfigLong(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_BUSYSLEEP, 1000));
- rct.setIdleSleep(getConfigLong(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_IDLESLEEP, 10000));
+ rct
+ .setIdleSleep(getConfigLong(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_IDLESLEEP, 10000));
// propagate to loader
final BusyThread rcl = getThread(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER);
setConfig(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_BUSYSLEEP, newBusySleep * 4);
- setConfig(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_IDLESLEEP, Math.min(10000, newBusySleep * 20));
+ setConfig(
+ SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_IDLESLEEP,
+ Math.min(10000, newBusySleep * 20));
rcl.setBusySleep(getConfigLong(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_BUSYSLEEP, 1000));
rcl.setIdleSleep(getConfigLong(SwitchboardConstants.CRAWLJOB_REMOTE_CRAWL_LOADER_IDLESLEEP, 10000));
}
@@ -1079,47 +1288,69 @@ public final class Switchboard extends serverSwitch {
this.log.logConfig("Starting Message Board");
final File messageDbFile = new File(this.workPath, "message.heap");
this.messageDB = new MessageBoard(messageDbFile);
- this.log.logConfig("Loaded Message Board DB from file " + messageDbFile.getName() +
- ", " + this.messageDB.size() + " entries" +
- ", " + ppRamString(messageDbFile.length()/1024));
+ this.log.logConfig("Loaded Message Board DB from file "
+ + messageDbFile.getName()
+ + ", "
+ + this.messageDB.size()
+ + " entries"
+ + ", "
+ + ppRamString(messageDbFile.length() / 1024));
}
public void initWiki() throws IOException {
this.log.logConfig("Starting Wiki Board");
final File wikiDbFile = new File(this.workPath, "wiki.heap");
this.wikiDB = new WikiBoard(wikiDbFile, new File(this.workPath, "wiki-bkp.heap"));
- this.log.logConfig("Loaded Wiki Board DB from file " + wikiDbFile.getName() +
- ", " + this.wikiDB.size() + " entries" +
- ", " + ppRamString(wikiDbFile.length()/1024));
+ this.log.logConfig("Loaded Wiki Board DB from file "
+ + wikiDbFile.getName()
+ + ", "
+ + this.wikiDB.size()
+ + " entries"
+ + ", "
+ + ppRamString(wikiDbFile.length() / 1024));
}
public void initBlog() throws IOException {
this.log.logConfig("Starting Blog");
final File blogDbFile = new File(this.workPath, "blog.heap");
this.blogDB = new BlogBoard(blogDbFile);
- this.log.logConfig("Loaded Blog DB from file " + blogDbFile.getName() +
- ", " + this.blogDB.size() + " entries" +
- ", " + ppRamString(blogDbFile.length()/1024));
+ this.log.logConfig("Loaded Blog DB from file "
+ + blogDbFile.getName()
+ + ", "
+ + this.blogDB.size()
+ + " entries"
+ + ", "
+ + ppRamString(blogDbFile.length() / 1024));
final File blogCommentDbFile = new File(this.workPath, "blogComment.heap");
this.blogCommentDB = new BlogBoardComments(blogCommentDbFile);
- this.log.logConfig("Loaded Blog-Comment DB from file " + blogCommentDbFile.getName() +
- ", " + this.blogCommentDB.size() + " entries" +
- ", " + ppRamString(blogCommentDbFile.length()/1024));
+ this.log.logConfig("Loaded Blog-Comment DB from file "
+ + blogCommentDbFile.getName()
+ + ", "
+ + this.blogCommentDB.size()
+ + " entries"
+ + ", "
+ + ppRamString(blogCommentDbFile.length() / 1024));
}
- public void initBookmarks() throws IOException{
+ public void initBookmarks() throws IOException {
this.log.logConfig("Loading Bookmarks DB");
final File bookmarksFile = new File(this.workPath, "bookmarks.heap");
final File tagsFile = new File(this.workPath, "bookmarkTags.heap");
final File datesFile = new File(this.workPath, "bookmarkDates.heap");
tagsFile.delete();
this.bookmarksDB = new BookmarksDB(bookmarksFile, datesFile);
- this.log.logConfig("Loaded Bookmarks DB from files "+ bookmarksFile.getName()+ ", "+tagsFile.getName());
- this.log.logConfig(this.bookmarksDB.tagsSize()+" Tag, "+this.bookmarksDB.bookmarksSize()+" Bookmarks");
+ this.log.logConfig("Loaded Bookmarks DB from files "
+ + bookmarksFile.getName()
+ + ", "
+ + tagsFile.getName());
+ this.log.logConfig(this.bookmarksDB.tagsSize()
+ + " Tag, "
+ + this.bookmarksDB.bookmarksSize()
+ + " Bookmarks");
}
- public static Switchboard getSwitchboard(){
+ public static Switchboard getSwitchboard() {
return sb;
}
@@ -1137,6 +1368,7 @@ public final class Switchboard extends serverSwitch {
/**
* in nocheck mode the isLocal property is not checked to omit DNS lookup. Can only be done in allip mode
+ *
* @return
*/
public boolean isIPNoCheckMode() {
@@ -1147,14 +1379,19 @@ public final class Switchboard extends serverSwitch {
// we are in robinson mode, if we do not exchange index by dht distribution
// we need to take care that search requests and remote indexing requests go only
// to the peers in the same cluster, if we run a robinson cluster.
- return (this.peers != null && this.peers.sizeConnected() == 0) || (!getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, false) && !getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false));
+ return (this.peers != null && this.peers.sizeConnected() == 0)
+ || (!getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, false) && !getConfigBool(
+ SwitchboardConstants.INDEX_RECEIVE_ALLOW,
+ false));
}
public boolean isPublicRobinson() {
// robinson peers may be member of robinson clusters, which can be public or private
// this does not check the robinson attribute, only the specific subtype of the cluster
- final String clustermode = getConfig(SwitchboardConstants.CLUSTER_MODE, SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER);
- return (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER)) || (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER));
+ final String clustermode =
+ getConfig(SwitchboardConstants.CLUSTER_MODE, SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER);
+ return (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER))
+ || (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER));
}
public boolean isInMyCluster(final String peer) {
@@ -1162,14 +1399,15 @@ public final class Switchboard extends serverSwitch {
// depending on the robinson cluster type, the peer String may be a peerhash (b64-hash)
// or a ip:port String or simply a ip String
// if this robinson mode does not define a cluster membership, false is returned
- if (peer == null) return false;
- if (!isRobinsonMode()) return false;
- final String clustermode = getConfig(SwitchboardConstants.CLUSTER_MODE, SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER);
- if (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PRIVATE_CLUSTER)) {
- // check if we got the request from a peer in the private cluster
- final String network = getConfig(SwitchboardConstants.CLUSTER_PEERS_IPPORT, "");
- return network.indexOf(peer) >= 0;
- } else if (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER)) {
+ if ( peer == null ) {
+ return false;
+ }
+ if ( !isRobinsonMode() ) {
+ return false;
+ }
+ final String clustermode =
+ getConfig(SwitchboardConstants.CLUSTER_MODE, SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER);
+ if ( clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER) ) {
// check if we got the request from a peer in the public cluster
return this.clusterhashes.containsKey(ASCII.getBytes(peer));
} else {
@@ -1180,14 +1418,15 @@ public final class Switchboard extends serverSwitch {
public boolean isInMyCluster(final Seed seed) {
// check if the given peer is in the own network, if this is a robinson cluster
// if this robinson mode does not define a cluster membership, false is returned
- if (seed == null) return false;
- if (!isRobinsonMode()) return false;
- final String clustermode = getConfig(SwitchboardConstants.CLUSTER_MODE, SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER);
- if (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PRIVATE_CLUSTER)) {
- // check if we got the request from a peer in the private cluster
- final String network = getConfig(SwitchboardConstants.CLUSTER_PEERS_IPPORT, "");
- return network.indexOf(seed.getPublicAddress()) >= 0;
- } else if (clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER)) {
+ if ( seed == null ) {
+ return false;
+ }
+ if ( !isRobinsonMode() ) {
+ return false;
+ }
+ final String clustermode =
+ getConfig(SwitchboardConstants.CLUSTER_MODE, SwitchboardConstants.CLUSTER_MODE_PUBLIC_PEER);
+ if ( clustermode.equals(SwitchboardConstants.CLUSTER_MODE_PUBLIC_CLUSTER) ) {
// check if we got the request from a peer in the public cluster
return this.clusterhashes.containsKey(ASCII.getBytes(seed.hash));
} else {
@@ -1199,7 +1438,9 @@ public final class Switchboard extends serverSwitch {
// tests if hash occurrs in any database
// if it exists, the name of the database is returned,
// if it not exists, null is returned
- if (this.indexSegments.urlMetadata(process).exists(hash)) return "loaded";
+ if ( this.indexSegments.urlMetadata(process).exists(hash) ) {
+ return "loaded";
+ }
return this.crawlQueues.urlExists(hash);
}
@@ -1210,83 +1451,108 @@ public final class Switchboard extends serverSwitch {
}
public DigestURI getURL(final Segments.Process process, final byte[] urlhash) {
- if (urlhash == null) return null;
- if (urlhash.length == 0) return null;
+ if ( urlhash == null ) {
+ return null;
+ }
+ if ( urlhash.length == 0 ) {
+ return null;
+ }
final URIMetadataRow le = this.indexSegments.urlMetadata(process).load(urlhash);
- if (le != null) {
+ if ( le != null ) {
return le.url();
}
return this.crawlQueues.getURL(urlhash);
}
public RankingProfile getRanking() {
- return (getConfig("rankingProfile", "").length() == 0) ?
- new RankingProfile(ContentDomain.TEXT) :
- new RankingProfile("", crypt.simpleDecode(sb.getConfig("rankingProfile", ""), null));
+ return (getConfig("rankingProfile", "").length() == 0)
+ ? new RankingProfile(ContentDomain.TEXT)
+ : new RankingProfile("", crypt.simpleDecode(sb.getConfig("rankingProfile", ""), null));
}
/**
- * checks if the proxy, the local search or remote search was accessed some time before
- * If no limit is exceeded, null is returned. If a limit is exceeded,
- * then the name of the service that caused the caution is returned
+ * checks if the proxy, the local search or remote search was accessed some time before If no limit is
+ * exceeded, null is returned. If a limit is exceeded, then the name of the service that caused the
+ * caution is returned
+ *
* @return
*/
public String onlineCaution() {
- if (System.currentTimeMillis() - this.proxyLastAccess < Integer.parseInt(getConfig(SwitchboardConstants.PROXY_ONLINE_CAUTION_DELAY, "100"))) return "proxy";
- if (System.currentTimeMillis() - this.localSearchLastAccess < Integer.parseInt(getConfig(SwitchboardConstants.LOCALSEACH_ONLINE_CAUTION_DELAY, "1000"))) return "localsearch";
- if (System.currentTimeMillis() - this.remoteSearchLastAccess < Integer.parseInt(getConfig(SwitchboardConstants.REMOTESEARCH_ONLINE_CAUTION_DELAY, "500"))) return"remotesearch";
+ if ( System.currentTimeMillis() - this.proxyLastAccess < Integer.parseInt(getConfig(
+ SwitchboardConstants.PROXY_ONLINE_CAUTION_DELAY,
+ "100")) ) {
+ return "proxy";
+ }
+ if ( System.currentTimeMillis() - this.localSearchLastAccess < Integer.parseInt(getConfig(
+ SwitchboardConstants.LOCALSEACH_ONLINE_CAUTION_DELAY,
+ "1000")) ) {
+ return "localsearch";
+ }
+ if ( System.currentTimeMillis() - this.remoteSearchLastAccess < Integer.parseInt(getConfig(
+ SwitchboardConstants.REMOTESEARCH_ONLINE_CAUTION_DELAY,
+ "500")) ) {
+ return "remotesearch";
+ }
return null;
}
/**
- * Creates a human readable string from a number which represents the size of a file.
- * The method has a side effect: It changes the input. Since the method is private and
- * only used in this class for values which are not used later, this should be OK in
- * this case, but one should never use this method without thinking about the side
- * effect. [MN]
+ * Creates a human readable string from a number which represents the size of a file. The method has a
+ * side effect: It changes the input. Since the method is private and only used in this class for values
+ * which are not used later, this should be OK in this case, but one should never use this method without
+ * thinking about the side effect. [MN]
+ *
* @param bytes the length of a file
* @return the length of a file in human readable form
*/
private static String ppRamString(long bytes) {
- if (bytes < 1024) return bytes + " KByte";
+ if ( bytes < 1024 ) {
+ return bytes + " KByte";
+ }
bytes = bytes / 1024;
- if (bytes < 1024) return bytes + " MByte";
+ if ( bytes < 1024 ) {
+ return bytes + " MByte";
+ }
bytes = bytes / 1024;
- if (bytes < 1024) return bytes + " GByte";
+ if ( bytes < 1024 ) {
+ return bytes + " GByte";
+ }
return (bytes / 1024) + "TByte";
}
/**
- * {@link CrawlProfiles Crawl Profiles} are saved independently from the queues themselves
- * and therefore have to be cleaned up from time to time. This method only performs the clean-up
- * if - and only if - the {@link IndexingStack switchboard},
- * {@link LoaderDispatcher loader} and {@link plasmaCrawlNURL local crawl} queues are all empty.
+ * {@link CrawlProfiles Crawl Profiles} are saved independently from the queues themselves and therefore
+ * have to be cleaned up from time to time. This method only performs the clean-up if - and only if - the
+ * {@link IndexingStack switchboard}, {@link LoaderDispatcher loader} and {@link plasmaCrawlNURL local
+ * crawl} queues are all empty.
*
- * Then it iterates through all existing {@link CrawlProfiles crawl profiles} and removes
- * all profiles which are not hard-coded.
+ * Then it iterates through all existing {@link CrawlProfiles crawl profiles} and removes all profiles
+ * which are not hard-coded.
*
*
- * If this method encounters DB-failures, the profile DB will be reseted and
- * true will be returned
+ * If this method encounters DB-failures, the profile DB will be reseted andtrue
+ * will be returned
*
+ *
* @see #CRAWL_PROFILE_PROXY hardcoded
* @see #CRAWL_PROFILE_REMOTE hardcoded
* @see #CRAWL_PROFILE_SNIPPET_TEXT hardcoded
* @see #CRAWL_PROFILE_SNIPPET_MEDIA hardcoded
- * @return whether this method has done something or not (i.e. because the queues have been filled
- * or there are no profiles left to clean up)
- * @throws InterruptedException if the current thread has been interrupted, i.e. by the
- * shutdown procedure
+ * @return whether this method has done something or not (i.e. because the queues have been filled or
+ * there are no profiles left to clean up)
+ * @throws InterruptedException if the current thread has been interrupted, i.e. by the shutdown
+ * procedure
*/
public boolean cleanProfiles() throws InterruptedException {
- if (getIndexingProcessorsQueueSize() > 0 ||
- this.crawlQueues.workerSize() > 0 ||
- this.crawlQueues.coreCrawlJobSize() > 0 ||
- this.crawlQueues.limitCrawlJobSize() > 0 ||
- this.crawlQueues.remoteTriggeredCrawlJobSize() > 0 ||
- (this.crawlStacker != null && !this.crawlStacker.isEmpty()) ||
- this.crawlQueues.noticeURL.notEmpty())
+ if ( getIndexingProcessorsQueueSize() > 0
+ || this.crawlQueues.workerSize() > 0
+ || this.crawlQueues.coreCrawlJobSize() > 0
+ || this.crawlQueues.limitCrawlJobSize() > 0
+ || this.crawlQueues.remoteTriggeredCrawlJobSize() > 0
+ || (this.crawlStacker != null && !this.crawlStacker.isEmpty())
+ || this.crawlQueues.noticeURL.notEmpty() ) {
return false;
+ }
return this.crawler.clear();
}
@@ -1303,7 +1569,9 @@ public final class Switchboard extends serverSwitch {
this.indexingCondensementProcessor.announceShutdown();
this.indexingAnalysisProcessor.announceShutdown();
this.indexingStorageProcessor.announceShutdown();
- if (this.dhtDispatcher != null) this.dhtDispatcher.close();
+ if ( this.dhtDispatcher != null ) {
+ this.dhtDispatcher.close();
+ }
this.indexingCondensementProcessor.awaitShutdown(12000);
this.indexingAnalysisProcessor.awaitShutdown(12000);
this.indexingStorageProcessor.awaitShutdown(12000);
@@ -1313,12 +1581,15 @@ public final class Switchboard extends serverSwitch {
this.blogDB.close();
this.blogCommentDB.close();
this.userDB.close();
- if (this.bookmarksDB != null) this.bookmarksDB.close(); // may null if concurrent initialization was not finished
+ if ( this.bookmarksDB != null ) {
+ this.bookmarksDB.close(); // may null if concurrent initialization was not finished
+ }
this.messageDB.close();
this.webStructure.close();
this.crawlQueues.close();
this.crawler.close();
- this.log.logConfig("SWITCHBOARD SHUTDOWN STEP 3: sending termination signal to database manager (stand by...)");
+ this.log
+ .logConfig("SWITCHBOARD SHUTDOWN STEP 3: sending termination signal to database manager (stand by...)");
this.indexSegments.close();
this.peers.close();
Cache.close();
@@ -1329,7 +1600,7 @@ public final class Switchboard extends serverSwitch {
Tray.removeTray();
try {
HTTPClient.closeConnectionManager();
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
Log.logException(e);
}
this.log.logConfig("SWITCHBOARD SHUTDOWN TERMINATED");
@@ -1337,6 +1608,7 @@ public final class Switchboard extends serverSwitch {
/**
* pass a response to the indexer
+ *
* @param response
* @return null if successful, an error message otherwise
*/
@@ -1344,20 +1616,22 @@ public final class Switchboard extends serverSwitch {
assert response != null;
// get next queue entry and start a queue processing
- if (response == null) {
- if (this.log.isFine()) {
+ if ( response == null ) {
+ if ( this.log.isFine() ) {
this.log.logFine("deQueue: queue entry is null");
}
return "queue entry is null";
}
- if (response.profile() == null) {
- if (this.log.isFine()) this.log.logFine("deQueue: profile is null");
+ if ( response.profile() == null ) {
+ if ( this.log.isFine() ) {
+ this.log.logFine("deQueue: profile is null");
+ }
return "profile is null";
}
// check if the document should be indexed based on proxy/crawler rules
String noIndexReason = "unspecified indexing error";
- if (response.processCase(this.peers.mySeed().hash) == EventOrigin.PROXY_LOAD) {
+ if ( response.processCase(this.peers.mySeed().hash) == EventOrigin.PROXY_LOAD ) {
// proxy-load
noIndexReason = response.shallIndexCacheForProxy();
} else {
@@ -1366,40 +1640,51 @@ public final class Switchboard extends serverSwitch {
}
// check if the parser supports the mime type
- if (noIndexReason == null) {
+ if ( noIndexReason == null ) {
noIndexReason = TextParser.supports(response.url(), response.getMimeType());
}
// check X-YACY-Index-Control
// With the X-YACY-Index-Control header set to "no-index" a client could disallow
// yacy to index the response returned as answer to a request
- if (noIndexReason == null && response.requestProhibitsIndexing()) {
+ if ( noIndexReason == null && response.requestProhibitsIndexing() ) {
noIndexReason = "X-YACY-Index-Control header prohibits indexing";
}
// check accepted domain / localhost accesses
- if (noIndexReason == null) {
+ if ( noIndexReason == null ) {
noIndexReason = this.crawlStacker.urlInAcceptedDomain(response.url());
}
// in the noIndexReason is set, indexing is not allowed
- if (noIndexReason != null) {
+ if ( noIndexReason != null ) {
// log cause and close queue
final DigestURI referrerURL = response.referrerURL();
//if (log.isFine()) log.logFine("deQueue: not indexed any word in URL " + response.url() + "; cause: " + noIndexReason);
- addURLtoErrorDB(response.url(), (referrerURL == null) ? null : referrerURL.hash(), response.initiator(), response.name(), FailCategory.FINAL_PROCESS_CONTEXT, noIndexReason);
+ addURLtoErrorDB(
+ response.url(),
+ (referrerURL == null) ? null : referrerURL.hash(),
+ response.initiator(),
+ response.name(),
+ FailCategory.FINAL_PROCESS_CONTEXT,
+ noIndexReason);
// finish this entry
return "not allowed: " + noIndexReason;
}
// put document into the concurrent processing queue
- if (this.log.isFinest()) {
- this.log.logFinest("deQueue: passing to indexing queue: " + response.url().toNormalform(true, false));
+ if ( this.log.isFinest() ) {
+ this.log.logFinest("deQueue: passing to indexing queue: "
+ + response.url().toNormalform(true, false));
}
try {
- this.indexingDocumentProcessor.enQueue(new indexingQueueEntry(Segments.Process.LOCALCRAWLING, response, null, null));
+ this.indexingDocumentProcessor.enQueue(new indexingQueueEntry(
+ Segments.Process.LOCALCRAWLING,
+ response,
+ null,
+ null));
return null;
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
Log.logException(e);
return "interrupted: " + e.getMessage();
}
@@ -1407,28 +1692,30 @@ public final class Switchboard extends serverSwitch {
public boolean processSurrogate(final String s) {
final File infile = new File(this.surrogatesInPath, s);
- if (!infile.exists() || !infile.canWrite() || !infile.canRead()) return false;
+ if ( !infile.exists() || !infile.canWrite() || !infile.canRead() ) {
+ return false;
+ }
final File outfile = new File(this.surrogatesOutPath, s);
//if (outfile.exists()) return false;
boolean moved = false;
- if (s.endsWith("xml.zip")) {
+ if ( s.endsWith("xml.zip") ) {
// open the zip file with all the xml files in it
try {
final InputStream is = new BufferedInputStream(new FileInputStream(infile));
final ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
- while ((entry = zis.getNextEntry()) != null) {
+ while ( (entry = zis.getNextEntry()) != null ) {
int size;
final byte[] buffer = new byte[2048];
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
+ while ( (size = zis.read(buffer, 0, buffer.length)) != -1 ) {
baos.write(buffer, 0, size);
}
baos.flush();
processSurrogate(new ByteArrayInputStream(baos.toByteArray()), entry.getName());
baos.close();
}
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
} finally {
moved = infile.renameTo(outfile);
@@ -1437,29 +1724,30 @@ public final class Switchboard extends serverSwitch {
} else {
try {
InputStream is = new BufferedInputStream(new FileInputStream(infile));
- if (s.endsWith(".gz")) {
+ if ( s.endsWith(".gz") ) {
is = new GZIPInputStream(is);
}
processSurrogate(is, infile.getName());
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
} finally {
moved = infile.renameTo(outfile);
- if (moved) {
+ if ( moved ) {
// check if this file is already compressed, if not, compress now
- if (!outfile.getName().endsWith(".gz")) {
+ if ( !outfile.getName().endsWith(".gz") ) {
final String gzname = outfile.getName() + ".gz";
final File gzfile = new File(outfile.getParentFile(), gzname);
try {
- final OutputStream os = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(gzfile)));
+ final OutputStream os =
+ new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(gzfile)));
FileUtils.copy(new BufferedInputStream(new FileInputStream(outfile)), os);
os.close();
- if (gzfile.exists()) {
+ if ( gzfile.exists() ) {
FileUtils.deletedelete(outfile);
}
- } catch (final FileNotFoundException e) {
+ } catch ( final FileNotFoundException e ) {
Log.logException(e);
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
}
}
@@ -1475,19 +1763,24 @@ public final class Switchboard extends serverSwitch {
readerThread.start();
DCEntry surrogate;
Response response;
- while ((surrogate = reader.take()) != DCEntry.poison) {
+ while ( (surrogate = reader.take()) != DCEntry.poison ) {
// check if url is in accepted domain
assert surrogate != null;
assert this.crawlStacker != null;
- final String urlRejectReason = this.crawlStacker.urlInAcceptedDomain(surrogate.getIdentifier(true));
- if (urlRejectReason != null) {
- this.log.logWarning("Rejected URL '" + surrogate.getIdentifier(true) + "': " + urlRejectReason);
+ final String urlRejectReason =
+ this.crawlStacker.urlInAcceptedDomain(surrogate.getIdentifier(true));
+ if ( urlRejectReason != null ) {
+ this.log.logWarning("Rejected URL '"
+ + surrogate.getIdentifier(true)
+ + "': "
+ + urlRejectReason);
continue;
}
// create a queue entry
final Document document = surrogate.document();
- final Request request = new Request(
+ final Request request =
+ new Request(
ASCII.getBytes(this.peers.mySeed().hash),
surrogate.getIdentifier(true),
null,
@@ -1497,15 +1790,17 @@ public final class Switchboard extends serverSwitch {
0,
0,
0,
- 0
- );
+ 0);
response = new Response(request, null, null, "200", this.crawler.defaultSurrogateProfile);
- final indexingQueueEntry queueEntry = new indexingQueueEntry(Segments.Process.SURROGATES, response, new Document[]{document}, null);
+ final indexingQueueEntry queueEntry =
+ new indexingQueueEntry(Segments.Process.SURROGATES, response, new Document[] {
+ document
+ }, null);
// place the queue entry into the concurrent process of the condenser (document analysis)
try {
this.indexingCondensementProcessor.enQueue(queueEntry);
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
Log.logException(e);
break;
}
@@ -1515,13 +1810,15 @@ public final class Switchboard extends serverSwitch {
public int surrogateQueueSize() {
// count surrogates
final String[] surrogatelist = this.surrogatesInPath.list();
- if (surrogatelist.length > 100) return 100;
+ if ( surrogatelist.length > 100 ) {
+ return 100;
+ }
int count = 0;
- for (final String s: surrogatelist) {
- if (s.endsWith(".xml")) {
+ for ( final String s : surrogatelist ) {
+ if ( s.endsWith(".xml") ) {
count++;
}
- if (count >= 100) {
+ if ( count >= 100 ) {
break;
}
}
@@ -1535,10 +1832,11 @@ public final class Switchboard extends serverSwitch {
public boolean surrogateProcess() {
// work off fresh entries from the proxy or from the crawler
final String cautionCause = onlineCaution();
- if (cautionCause != null) {
- if (this.log.isFine()) {
- this.log.logFine("deQueue: online caution for " + cautionCause
- + ", omitting resource stack processing");
+ if ( cautionCause != null ) {
+ if ( this.log.isFine() ) {
+ this.log.logFine("deQueue: online caution for "
+ + cautionCause
+ + ", omitting resource stack processing");
}
return false;
}
@@ -1546,36 +1844,42 @@ public final class Switchboard extends serverSwitch {
try {
// check surrogates
final String[] surrogatelist = this.surrogatesInPath.list();
- if (surrogatelist.length > 0) {
+ if ( surrogatelist.length > 0 ) {
// look if the is any xml inside
- for (final String surrogate: surrogatelist) {
+ for ( final String surrogate : surrogatelist ) {
// check for interruption
checkInterruption();
- if (surrogate.endsWith(".xml") || surrogate.endsWith(".xml.gz") || surrogate.endsWith(".xml.zip")) {
+ if ( surrogate.endsWith(".xml")
+ || surrogate.endsWith(".xml.gz")
+ || surrogate.endsWith(".xml.zip") ) {
// read the surrogate file and store entry in index
- if (processSurrogate(surrogate)) return true;
+ if ( processSurrogate(surrogate) ) {
+ return true;
+ }
}
}
}
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
return false;
}
return false;
}
- public static class indexingQueueEntry extends WorkflowJob {
+ public static class indexingQueueEntry extends WorkflowJob
+ {
public Segments.Process process;
public Response queueEntry;
public Document[] documents;
public Condenser[] condenser;
+
public indexingQueueEntry(
- final Segments.Process process,
- final Response queueEntry,
- final Document[] documents,
- final Condenser[] condenser) {
+ final Segments.Process process,
+ final Response queueEntry,
+ final Document[] documents,
+ final Condenser[] condenser) {
super();
this.process = process;
this.queueEntry = queueEntry;
@@ -1586,10 +1890,16 @@ public final class Switchboard extends serverSwitch {
public int cleanupJobSize() {
int c = 0;
- if ((this.crawlQueues.delegatedURL.stackSize() > 1000)) c++;
- if ((this.crawlQueues.errorURL.stackSize() > 1000)) c++;
- for (final EventOrigin origin: EventOrigin.values()) {
- if (ResultURLs.getStackSize(origin) > 1000) c++;
+ if ( (this.crawlQueues.delegatedURL.stackSize() > 1000) ) {
+ c++;
+ }
+ if ( (this.crawlQueues.errorURL.stackSize() > 1000) ) {
+ c++;
+ }
+ for ( final EventOrigin origin : EventOrigin.values() ) {
+ if ( ResultURLs.getStackSize(origin) > 1000 ) {
+ c++;
+ }
}
return c;
}
@@ -1597,63 +1907,80 @@ public final class Switchboard extends serverSwitch {
public boolean cleanupJob() {
try {
// clear caches if necessary
- if (!MemoryControl.request(8000000L, false)) {
- for (final Segment indexSegment: this.indexSegments) indexSegment.urlMetadata().clearCache();
+ if ( !MemoryControl.request(8000000L, false) ) {
+ for ( final Segment indexSegment : this.indexSegments ) {
+ indexSegment.urlMetadata().clearCache();
+ }
SearchEventCache.cleanupEvents(true);
this.trail.clear();
}
// set a random password if no password is configured
- if (getConfigBool("adminAccountForLocalhost", false) && getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0) {
+ if ( getConfigBool("adminAccountForLocalhost", false)
+ && getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0 ) {
// make a 'random' password
setConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "0000" + this.genRandomPassword());
setConfig("adminAccount", "");
}
// refresh recrawl dates
- try{
+ try {
CrawlProfile selentry;
- for (final byte[] handle: this.crawler.getActive()) {
+ for ( final byte[] handle : this.crawler.getActive() ) {
selentry = this.crawler.getActive(handle);
assert selentry.handle() != null : "profile.name = " + selentry.name();
- if (selentry.handle() == null) {
+ if ( selentry.handle() == null ) {
this.crawler.removeActive(handle);
continue;
}
boolean insert = false;
- if (selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_PROXY)) {
- selentry.put(CrawlProfile.RECRAWL_IF_OLDER,
- Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_PROXY_RECRAWL_CYCLE)));
+ if ( selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_PROXY) ) {
+ selentry.put(CrawlProfile.RECRAWL_IF_OLDER, Long.toString(CrawlProfile
+ .getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_PROXY_RECRAWL_CYCLE)));
insert = true;
}
- if (selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT)) {
- selentry.put(CrawlProfile.RECRAWL_IF_OLDER,
- Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT_RECRAWL_CYCLE)));
+ if ( selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT) ) {
+ selentry
+ .put(
+ CrawlProfile.RECRAWL_IF_OLDER,
+ Long.toString(CrawlProfile
+ .getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT_RECRAWL_CYCLE)));
insert = true;
}
- if (selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT)) {
- selentry.put(CrawlProfile.RECRAWL_IF_OLDER,
- Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT_RECRAWL_CYCLE)));
+ if ( selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT) ) {
+ selentry
+ .put(
+ CrawlProfile.RECRAWL_IF_OLDER,
+ Long.toString(CrawlProfile
+ .getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT_RECRAWL_CYCLE)));
insert = true;
}
- if (selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA)) {
- selentry.put(CrawlProfile.RECRAWL_IF_OLDER,
- Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA_RECRAWL_CYCLE)));
+ if ( selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA) ) {
+ selentry
+ .put(
+ CrawlProfile.RECRAWL_IF_OLDER,
+ Long.toString(CrawlProfile
+ .getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA_RECRAWL_CYCLE)));
insert = true;
}
- if (selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA)) {
- selentry.put(CrawlProfile.RECRAWL_IF_OLDER,
- Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA_RECRAWL_CYCLE)));
+ if ( selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA) ) {
+ selentry
+ .put(
+ CrawlProfile.RECRAWL_IF_OLDER,
+ Long.toString(CrawlProfile
+ .getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA_RECRAWL_CYCLE)));
insert = true;
}
- if (selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE)) {
- selentry.put(CrawlProfile.RECRAWL_IF_OLDER,
- Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE_RECRAWL_CYCLE)));
+ if ( selentry.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE) ) {
+ selentry.put(CrawlProfile.RECRAWL_IF_OLDER, Long.toString(CrawlProfile
+ .getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE_RECRAWL_CYCLE)));
insert = true;
}
- if (insert) this.crawler.putActive(UTF8.getBytes(selentry.handle()), selentry);
+ if ( insert ) {
+ this.crawler.putActive(UTF8.getBytes(selentry.handle()), selentry);
+ }
}
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
Log.logException(e);
}
@@ -1663,32 +1990,51 @@ public final class Switchboard extends serverSwitch {
final Date now = new Date();
try {
final Iterator plainIterator = this.tables.iterator(WorkTables.TABLE_API_NAME);
- final Iterator mapIterator = this.tables.orderBy(plainIterator, -1, WorkTables.TABLE_API_COL_DATE_RECORDING).iterator();
- while (mapIterator.hasNext()) {
+ final Iterator mapIterator =
+ this.tables
+ .orderBy(plainIterator, -1, WorkTables.TABLE_API_COL_DATE_RECORDING)
+ .iterator();
+ while ( mapIterator.hasNext() ) {
row = mapIterator.next();
- if (row == null) continue;
+ if ( row == null ) {
+ continue;
+ }
final Date date_next_exec = row.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, (Date) null);
- if (date_next_exec == null) continue;
- if (date_next_exec.after(now)) continue;
+ if ( date_next_exec == null ) {
+ continue;
+ }
+ if ( date_next_exec.after(now) ) {
+ continue;
+ }
pks.add(UTF8.String(row.getPK()));
}
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
}
- for (final String pk: pks) try {
- row = this.tables.select(WorkTables.TABLE_API_NAME, UTF8.getBytes(pk));
- WorkTables.calculateAPIScheduler(row, true); // calculate next update time
- this.tables.update(WorkTables.TABLE_API_NAME, row);
- } catch (final IOException e) {
- Log.logException(e);
- continue;
- } catch (final RowSpaceExceededException e) {
- Log.logException(e);
- continue;
+ for ( final String pk : pks ) {
+ try {
+ row = this.tables.select(WorkTables.TABLE_API_NAME, UTF8.getBytes(pk));
+ WorkTables.calculateAPIScheduler(row, true); // calculate next update time
+ this.tables.update(WorkTables.TABLE_API_NAME, row);
+ } catch ( final IOException e ) {
+ Log.logException(e);
+ continue;
+ } catch ( final RowSpaceExceededException e ) {
+ Log.logException(e);
+ continue;
+ }
}
- final Map callResult = this.tables.execAPICalls("localhost", (int) getConfigLong("port", 8090), getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, ""), pks);
- for (final Map.Entry call: callResult.entrySet()) {
- this.log.logInfo("Scheduler executed api call, response " + call.getValue() + ": " + call.getKey());
+ final Map callResult =
+ this.tables.execAPICalls(
+ "localhost",
+ (int) getConfigLong("port", 8090),
+ getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, ""),
+ pks);
+ for ( final Map.Entry call : callResult.entrySet() ) {
+ this.log.logInfo("Scheduler executed api call, response "
+ + call.getValue()
+ + ": "
+ + call.getKey());
}
// close unused connections
@@ -1696,28 +2042,35 @@ public final class Switchboard extends serverSwitch {
// clean up delegated stack
checkInterruption();
- if ((this.crawlQueues.delegatedURL.stackSize() > 1000)) {
- if (this.log.isFine()) {
- this.log.logFine("Cleaning Delegated-URLs report stack, " + this.crawlQueues.delegatedURL.stackSize() + " entries on stack");
+ if ( (this.crawlQueues.delegatedURL.stackSize() > 1000) ) {
+ if ( this.log.isFine() ) {
+ this.log.logFine("Cleaning Delegated-URLs report stack, "
+ + this.crawlQueues.delegatedURL.stackSize()
+ + " entries on stack");
}
this.crawlQueues.delegatedURL.clearStack();
}
// clean up error stack
checkInterruption();
- if ((this.crawlQueues.errorURL.stackSize() > 1000)) {
- if (this.log.isFine()) {
- this.log.logFine("Cleaning Error-URLs report stack, " + this.crawlQueues.errorURL.stackSize() + " entries on stack");
+ if ( (this.crawlQueues.errorURL.stackSize() > 1000) ) {
+ if ( this.log.isFine() ) {
+ this.log.logFine("Cleaning Error-URLs report stack, "
+ + this.crawlQueues.errorURL.stackSize()
+ + " entries on stack");
}
this.crawlQueues.errorURL.clearStack();
}
// clean up loadedURL stack
- for (final EventOrigin origin: EventOrigin.values()) {
+ for ( final EventOrigin origin : EventOrigin.values() ) {
checkInterruption();
- if (ResultURLs.getStackSize(origin) > 1000) {
- if (this.log.isFine()) {
- this.log.logFine("Cleaning Loaded-URLs report stack, " + ResultURLs.getStackSize(origin) + " entries on stack " + origin.getCode());
+ if ( ResultURLs.getStackSize(origin) > 1000 ) {
+ if ( this.log.isFine() ) {
+ this.log.logFine("Cleaning Loaded-URLs report stack, "
+ + ResultURLs.getStackSize(origin)
+ + " entries on stack "
+ + origin.getCode());
}
ResultURLs.clearStack(origin);
}
@@ -1733,64 +2086,77 @@ public final class Switchboard extends serverSwitch {
// clean up news
checkInterruption();
try {
- if (this.log.isFine()) {
- this.log.logFine("Cleaning Incoming News, " + this.peers.newsPool.size(NewsPool.INCOMING_DB) + " entries on stack");
+ if ( this.log.isFine() ) {
+ this.log.logFine("Cleaning Incoming News, "
+ + this.peers.newsPool.size(NewsPool.INCOMING_DB)
+ + " entries on stack");
}
this.peers.newsPool.automaticProcess(this.peers);
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
Log.logException(e);
}
- if (getConfigBool("cleanup.deletionProcessedNews", true)) {
+ if ( getConfigBool("cleanup.deletionProcessedNews", true) ) {
this.peers.newsPool.clear(NewsPool.PROCESSED_DB);
}
- if (getConfigBool("cleanup.deletionPublishedNews", true)) {
+ if ( getConfigBool("cleanup.deletionPublishedNews", true) ) {
this.peers.newsPool.clear(NewsPool.PUBLISHED_DB);
}
// clean up seed-dbs
- if (getConfigBool("routing.deleteOldSeeds.permission",true)) {
- final long deleteOldSeedsTime = getConfigLong("routing.deleteOldSeeds.time",7)*24*3600000;
- Iterator e = this.peers.seedsSortedDisconnected(true,Seed.LASTSEEN);
+ if ( getConfigBool("routing.deleteOldSeeds.permission", true) ) {
+ final long deleteOldSeedsTime =
+ getConfigLong("routing.deleteOldSeeds.time", 7) * 24 * 3600000;
+ Iterator e = this.peers.seedsSortedDisconnected(true, Seed.LASTSEEN);
Seed seed = null;
final List deleteQueue = new ArrayList();
checkInterruption();
// clean passive seeds
- while (e.hasNext()) {
+ while ( e.hasNext() ) {
seed = e.next();
- if (seed != null) {
+ if ( seed != null ) {
//list is sorted -> break when peers are too young to delete
- if (!seed.isLastSeenTimeout(deleteOldSeedsTime)) break;
+ if ( !seed.isLastSeenTimeout(deleteOldSeedsTime) ) {
+ break;
+ }
deleteQueue.add(seed.hash);
}
}
- for (int i = 0; i < deleteQueue.size(); ++i) this.peers.removeDisconnected(deleteQueue.get(i));
+ for ( int i = 0; i < deleteQueue.size(); ++i ) {
+ this.peers.removeDisconnected(deleteQueue.get(i));
+ }
deleteQueue.clear();
- e = this.peers.seedsSortedPotential(true,Seed.LASTSEEN);
+ e = this.peers.seedsSortedPotential(true, Seed.LASTSEEN);
checkInterruption();
// clean potential seeds
- while (e.hasNext()) {
+ while ( e.hasNext() ) {
seed = e.next();
- if (seed != null) {
+ if ( seed != null ) {
//list is sorted -> break when peers are too young to delete
- if (!seed.isLastSeenTimeout(deleteOldSeedsTime)) break;
+ if ( !seed.isLastSeenTimeout(deleteOldSeedsTime) ) {
+ break;
+ }
deleteQueue.add(seed.hash);
}
}
- for (int i = 0; i < deleteQueue.size(); ++i) this.peers.removePotential(deleteQueue.get(i));
+ for ( int i = 0; i < deleteQueue.size(); ++i ) {
+ this.peers.removePotential(deleteQueue.get(i));
+ }
}
// check if update is available and
// if auto-update is activated perform an automatic installation and restart
final yacyRelease updateVersion = yacyRelease.rulebasedUpdateInfo(false);
- if (updateVersion != null) {
+ if ( updateVersion != null ) {
// there is a version that is more recent. Load it and re-start with it
this.log.logInfo("AUTO-UPDATE: downloading more recent release " + updateVersion.getUrl());
final File downloaded = updateVersion.downloadRelease();
final boolean devenvironment = new File(this.getAppPath(), ".git").exists();
- if (devenvironment) {
- this.log.logInfo("AUTO-UPDATE: omitting update because this is a development environment");
- } else if ((downloaded == null) || (!downloaded.exists()) || (downloaded.length() == 0)) {
- this.log.logInfo("AUTO-UPDATE: omitting update because download failed (file cannot be found, is too small or signature is bad)");
+ if ( devenvironment ) {
+ this.log
+ .logInfo("AUTO-UPDATE: omitting update because this is a development environment");
+ } else if ( (downloaded == null) || (!downloaded.exists()) || (downloaded.length() == 0) ) {
+ this.log
+ .logInfo("AUTO-UPDATE: omitting update because download failed (file cannot be found, is too small or signature is bad)");
} else {
yacyRelease.deployRelease(downloaded);
terminate(10, "auto-update to install " + downloaded.getName());
@@ -1799,26 +2165,30 @@ public final class Switchboard extends serverSwitch {
}
// initiate broadcast about peer startup to spread supporter url
- if (!isRobinsonMode() && this.peers.newsPool.size(NewsPool.OUTGOING_DB) == 0) {
+ if ( !isRobinsonMode() && this.peers.newsPool.size(NewsPool.OUTGOING_DB) == 0 ) {
// read profile
final Properties profile = new Properties();
FileInputStream fileIn = null;
try {
fileIn = new FileInputStream(new File("DATA/SETTINGS/profile.txt"));
profile.load(fileIn);
- } catch(final IOException e) {
+ } catch ( final IOException e ) {
} finally {
- if (fileIn != null) {
+ if ( fileIn != null ) {
try {
fileIn.close();
- } catch (final Exception e) {}
+ } catch ( final Exception e ) {
+ }
}
}
final String homepage = (String) profile.get("homepage");
- if ((homepage != null) && (homepage.length() > 10)) {
+ if ( (homepage != null) && (homepage.length() > 10) ) {
final Properties news = new Properties();
news.put("homepage", profile.get("homepage"));
- this.peers.newsPool.publishMyNews(this.peers.mySeed(), NewsPool.CATEGORY_PROFILE_BROADCAST, news);
+ this.peers.newsPool.publishMyNews(
+ this.peers.mySeed(),
+ NewsPool.CATEGORY_PROFILE_BROADCAST,
+ news);
}
}
@@ -1826,20 +2196,21 @@ public final class Switchboard extends serverSwitch {
this.clusterhashes = this.peers.clusterHashes(getConfig("cluster.peers.yacydomain", ""));
// check if we are reachable and try to map port again if not (e.g. when router rebooted)
- if (getConfigBool(SwitchboardConstants.UPNP_ENABLED, false) && sb.peers.mySeed().isJunior()) {
- UPnP.addPortMapping();
+ if ( getConfigBool(SwitchboardConstants.UPNP_ENABLED, false) && sb.peers.mySeed().isJunior() ) {
+ UPnP.addPortMapping();
}
// after all clean up is done, check the resource usage
this.observer.resourceObserverJob();
// cleanup cached search failures
- if (getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false) && this.peers.mySeed().getFlagAcceptRemoteIndex()) {
+ if ( getConfigBool(SwitchboardConstants.NETWORK_SEARCHVERIFY, false)
+ && this.peers.mySeed().getFlagAcceptRemoteIndex() ) {
this.tables.cleanFailURLS(getConfigLong("cleanup.failedSearchURLtimeout", -1));
}
return true;
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
this.log.logInfo("cleanupJob: Shutdown detected");
return false;
}
@@ -1847,11 +2218,12 @@ public final class Switchboard extends serverSwitch {
/**
* With this function the crawling process can be paused
+ *
* @param jobType
*/
public void pauseCrawlJob(final String jobType) {
final Object[] status = this.crawlJobsStatus.get(jobType);
- synchronized(status[SwitchboardConstants.CRAWLJOB_SYNC]) {
+ synchronized ( status[SwitchboardConstants.CRAWLJOB_SYNC] ) {
status[SwitchboardConstants.CRAWLJOB_STATUS] = Boolean.TRUE;
}
setConfig(jobType + "_isPaused", "true");
@@ -1859,12 +2231,13 @@ public final class Switchboard extends serverSwitch {
/**
* Continue the previously paused crawling
+ *
* @param jobType
*/
public void continueCrawlJob(final String jobType) {
final Object[] status = this.crawlJobsStatus.get(jobType);
- synchronized(status[SwitchboardConstants.CRAWLJOB_SYNC]) {
- if (((Boolean)status[SwitchboardConstants.CRAWLJOB_STATUS]).booleanValue()) {
+ synchronized ( status[SwitchboardConstants.CRAWLJOB_SYNC] ) {
+ if ( ((Boolean) status[SwitchboardConstants.CRAWLJOB_STATUS]).booleanValue() ) {
status[SwitchboardConstants.CRAWLJOB_STATUS] = Boolean.FALSE;
status[SwitchboardConstants.CRAWLJOB_SYNC].notifyAll();
}
@@ -1878,8 +2251,8 @@ public final class Switchboard extends serverSwitch {
*/
public boolean crawlJobIsPaused(final String jobType) {
final Object[] status = this.crawlJobsStatus.get(jobType);
- synchronized(status[SwitchboardConstants.CRAWLJOB_SYNC]) {
- return ((Boolean)status[SwitchboardConstants.CRAWLJOB_STATUS]).booleanValue();
+ synchronized ( status[SwitchboardConstants.CRAWLJOB_SYNC] ) {
+ return ((Boolean) status[SwitchboardConstants.CRAWLJOB_STATUS]).booleanValue();
}
}
@@ -1887,19 +2260,19 @@ public final class Switchboard extends serverSwitch {
in.queueEntry.updateStatus(Response.QUEUE_STATE_PARSING);
// debug
- if (this.log.isFinest()) {
- this.log.logFinest("PARSE "+ in.queueEntry);
+ if ( this.log.isFinest() ) {
+ this.log.logFinest("PARSE " + in.queueEntry);
}
Document[] documents = null;
try {
documents = parseDocument(in.queueEntry);
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
documents = null;
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
documents = null;
}
- if (documents == null) {
+ if ( documents == null ) {
return null;
}
return new indexingQueueEntry(in.process, in.queueEntry, documents, null);
@@ -1909,38 +2282,70 @@ public final class Switchboard extends serverSwitch {
Document[] documents = null;
final EventOrigin processCase = response.processCase(this.peers.mySeed().hash);
- if (this.log.isFine()) {
- this.log.logFine("processResourceStack processCase=" + processCase +
- ", depth=" + response.depth() +
- ", maxDepth=" + ((response.profile() == null) ? "null" : Integer.toString(response.profile().depth())) +
- ", must-match=" + ((response.profile() == null) ? "null" : response.profile().urlMustMatchPattern().toString()) +
- ", must-not-match=" + ((response.profile() == null) ? "null" : response.profile().urlMustNotMatchPattern().toString()) +
- ", initiatorHash=" + ((response.initiator() == null) ? "null" : ASCII.String(response.initiator())) +
+ if ( this.log.isFine() ) {
+ this.log.logFine("processResourceStack processCase="
+ + processCase
+ + ", depth="
+ + response.depth()
+ + ", maxDepth="
+ + ((response.profile() == null) ? "null" : Integer.toString(response.profile().depth()))
+ + ", must-match="
+ + ((response.profile() == null) ? "null" : response
+ .profile()
+ .urlMustMatchPattern()
+ .toString())
+ + ", must-not-match="
+ + ((response.profile() == null) ? "null" : response
+ .profile()
+ .urlMustNotMatchPattern()
+ .toString())
+ + ", initiatorHash="
+ + ((response.initiator() == null) ? "null" : ASCII.String(response.initiator()))
+ +
//", responseHeader=" + ((entry.responseHeader() == null) ? "null" : entry.responseHeader().toString()) +
- ", url=" + response.url()); // DEBUG
+ ", url="
+ + response.url()); // DEBUG
}
// PARSE CONTENT
final long parsingStartTime = System.currentTimeMillis();
- if (response.getContent() == null) {
+ if ( response.getContent() == null ) {
// fetch the document from cache
response.setContent(Cache.getContent(response.url().hash()));
- if (response.getContent() == null) {
+ if ( response.getContent() == null ) {
this.log.logWarning("the resource '" + response.url() + "' is missing in the cache.");
- addURLtoErrorDB(response.url(), response.referrerHash(), response.initiator(), response.name(), FailCategory.FINAL_LOAD_CONTEXT, "missing in cache");
+ addURLtoErrorDB(
+ response.url(),
+ response.referrerHash(),
+ response.initiator(),
+ response.name(),
+ FailCategory.FINAL_LOAD_CONTEXT,
+ "missing in cache");
return null;
}
}
assert response.getContent() != null;
try {
// parse the document
- documents = TextParser.parseSource(response.url(), response.getMimeType(), response.getCharacterEncoding(), response.getContent(), response.profile().directDocByURL());
- if (documents == null) {
+ documents =
+ TextParser.parseSource(
+ response.url(),
+ response.getMimeType(),
+ response.getCharacterEncoding(),
+ response.getContent(),
+ response.profile().directDocByURL());
+ if ( documents == null ) {
throw new Parser.Failure("Parser returned null.", response.url());
}
- } catch (final Parser.Failure e) {
+ } catch ( final Parser.Failure e ) {
this.log.logWarning("Unable to parse the resource '" + response.url() + "'. " + e.getMessage());
- addURLtoErrorDB(response.url(), response.referrerHash(), response.initiator(), response.name(), FailCategory.FINAL_PROCESS_CONTEXT, e.getMessage());
+ addURLtoErrorDB(
+ response.url(),
+ response.referrerHash(),
+ response.initiator(),
+ response.name(),
+ FailCategory.FINAL_PROCESS_CONTEXT,
+ e.getMessage());
return null;
}
@@ -1948,10 +2353,8 @@ public final class Switchboard extends serverSwitch {
// put anchors on crawl stack
final long stackStartTime = System.currentTimeMillis();
- if (
- ((processCase == EventOrigin.PROXY_LOAD) || (processCase == EventOrigin.LOCAL_CRAWLING)) &&
- ((response.profile() == null) || (response.depth() < response.profile().depth()))
- ) {
+ if ( ((processCase == EventOrigin.PROXY_LOAD) || (processCase == EventOrigin.LOCAL_CRAWLING))
+ && ((response.profile() == null) || (response.depth() < response.profile().depth())) ) {
// get the hyperlinks
final Map hl = Document.getHyperlinks(documents);
@@ -1960,37 +2363,46 @@ public final class Switchboard extends serverSwitch {
// insert those hyperlinks to the crawler
MultiProtocolURI nextUrl;
- for (final Map.Entry nextEntry : hl.entrySet()) {
+ for ( final Map.Entry nextEntry : hl.entrySet() ) {
// check for interruption
checkInterruption();
// process the next hyperlink
nextUrl = nextEntry.getKey();
final String u = nextUrl.toNormalform(true, true, false, true);
- if (!(u.startsWith("http://") || u.startsWith("https://") || u.startsWith("ftp://") || u.startsWith("smb://") || u.startsWith("file://"))) continue;
+ if ( !(u.startsWith("http://")
+ || u.startsWith("https://")
+ || u.startsWith("ftp://")
+ || u.startsWith("smb://") || u.startsWith("file://")) ) {
+ continue;
+ }
// enqueue the hyperlink into the pre-notice-url db
try {
this.crawlStacker.enqueueEntry(new Request(
- response.initiator(),
- new DigestURI(u),
- response.url().hash(),
- nextEntry.getValue(),
- new Date(),
- response.profile().handle(),
- response.depth() + 1,
- 0,
- 0,
- response.size() < 0 ? 0 : response.size()
- ));
- } catch (final MalformedURLException e) {
+ response.initiator(),
+ new DigestURI(u),
+ response.url().hash(),
+ nextEntry.getValue(),
+ new Date(),
+ response.profile().handle(),
+ response.depth() + 1,
+ 0,
+ 0,
+ response.size() < 0 ? 0 : response.size()));
+ } catch ( final MalformedURLException e ) {
Log.logException(e);
}
}
final long stackEndTime = System.currentTimeMillis();
- if (this.log.isInfo()) {
- this.log.logInfo("CRAWL: ADDED " + hl.size() + " LINKS FROM " + response.url().toNormalform(false, true) +
- ", STACKING TIME = " + (stackEndTime-stackStartTime) +
- ", PARSING TIME = " + (parsingEndTime-parsingStartTime));
+ if ( this.log.isInfo() ) {
+ this.log.logInfo("CRAWL: ADDED "
+ + hl.size()
+ + " LINKS FROM "
+ + response.url().toNormalform(false, true)
+ + ", STACKING TIME = "
+ + (stackEndTime - stackStartTime)
+ + ", PARSING TIME = "
+ + (parsingEndTime - parsingStartTime));
}
}
return documents;
@@ -1998,22 +2410,38 @@ public final class Switchboard extends serverSwitch {
public indexingQueueEntry condenseDocument(final indexingQueueEntry in) {
in.queueEntry.updateStatus(Response.QUEUE_STATE_CONDENSING);
- if (this.indexSegments.segment(Segments.Process.LOCALCRAWLING).getSolr() != null && getConfigBool("federated.service.solr.indexing.enabled", false)/*in.queueEntry.profile().pushSolr()*/) {
+ if ( this.indexSegments.segment(Segments.Process.LOCALCRAWLING).getSolr() != null
+ && getConfigBool("federated.service.solr.indexing.enabled", false)/*in.queueEntry.profile().pushSolr()*/) {
// send the documents to solr
- for (final Document doc: in.documents) {
+ for ( final Document doc : in.documents ) {
try {
final String id = UTF8.String(new DigestURI(doc.dc_identifier(), null).hash());
final String iquh = UTF8.String(in.queueEntry.url().hash());
- if (!id.equals(iquh)) {
- this.log.logWarning("doc=" + id + ":" + doc.dc_identifier() + ", query=" + iquh + ":" + in.queueEntry.url());
+ if ( !id.equals(iquh) ) {
+ this.log.logWarning("doc="
+ + id
+ + ":"
+ + doc.dc_identifier()
+ + ", query="
+ + iquh
+ + ":"
+ + in.queueEntry.url());
// in case that this happens it appears that the doc id is the right one
}
try {
- this.indexSegments.segment(Segments.Process.LOCALCRAWLING).getSolr().add(id, in.queueEntry.getResponseHeader(), doc);
- } catch (final IOException e) {
- Log.logWarning("SOLR", "failed to send " + in.queueEntry.url().toNormalform(true, false) + " to solr: " + e.getMessage());
+ this.indexSegments
+ .segment(Segments.Process.LOCALCRAWLING)
+ .getSolr()
+ .add(id, in.queueEntry.getResponseHeader(), doc);
+ } catch ( final IOException e ) {
+ Log.logWarning(
+ "SOLR",
+ "failed to send "
+ + in.queueEntry.url().toNormalform(true, false)
+ + " to solr: "
+ + e.getMessage());
}
- } catch (final MalformedURLException e) {
+ } catch ( final MalformedURLException e ) {
Log.logException(e);
continue;
}
@@ -2021,59 +2449,81 @@ public final class Switchboard extends serverSwitch {
}
// check if we should accept the document for our index
- if (!getConfigBool("federated.service.yacy.indexing.enabled", false)) {
- if (this.log.isInfo()) {
- this.log.logInfo("Not Condensed Resource '" + in.queueEntry.url().toNormalform(false, true) + "': indexing not wanted by federated rule for YaCy");
+ if ( !getConfigBool("federated.service.yacy.indexing.enabled", false) ) {
+ if ( this.log.isInfo() ) {
+ this.log.logInfo("Not Condensed Resource '"
+ + in.queueEntry.url().toNormalform(false, true)
+ + "': indexing not wanted by federated rule for YaCy");
}
return new indexingQueueEntry(in.process, in.queueEntry, in.documents, null);
}
- if (!in.queueEntry.profile().indexText() && !in.queueEntry.profile().indexMedia()) {
- if (this.log.isInfo()) {
- this.log.logInfo("Not Condensed Resource '" + in.queueEntry.url().toNormalform(false, true) + "': indexing not wanted by crawl profile");
+ if ( !in.queueEntry.profile().indexText() && !in.queueEntry.profile().indexMedia() ) {
+ if ( this.log.isInfo() ) {
+ this.log.logInfo("Not Condensed Resource '"
+ + in.queueEntry.url().toNormalform(false, true)
+ + "': indexing not wanted by crawl profile");
}
return new indexingQueueEntry(in.process, in.queueEntry, in.documents, null);
}
final List doclist = new ArrayList();
// check which files may take part in the indexing process
- for (final Document document: in.documents) {
- if (document.indexingDenied()) {
- if (this.log.isInfo()) {
- this.log.logInfo("Not Condensed Resource '" + in.queueEntry.url().toNormalform(false, true) + "': denied by document-attached noindexing rule");
+ for ( final Document document : in.documents ) {
+ if ( document.indexingDenied() ) {
+ if ( this.log.isInfo() ) {
+ this.log.logInfo("Not Condensed Resource '"
+ + in.queueEntry.url().toNormalform(false, true)
+ + "': denied by document-attached noindexing rule");
}
- addURLtoErrorDB(in.queueEntry.url(), in.queueEntry.referrerHash(), in.queueEntry.initiator(), in.queueEntry.name(), FailCategory.FINAL_PROCESS_CONTEXT, "denied by document-attached noindexing rule");
+ addURLtoErrorDB(
+ in.queueEntry.url(),
+ in.queueEntry.referrerHash(),
+ in.queueEntry.initiator(),
+ in.queueEntry.name(),
+ FailCategory.FINAL_PROCESS_CONTEXT,
+ "denied by document-attached noindexing rule");
continue;
}
doclist.add(document);
}
- if (doclist.isEmpty()) return new indexingQueueEntry(in.process, in.queueEntry, in.documents, null);
+ if ( doclist.isEmpty() ) {
+ return new indexingQueueEntry(in.process, in.queueEntry, in.documents, null);
+ }
in.documents = doclist.toArray(new Document[doclist.size()]);
final Condenser[] condenser = new Condenser[in.documents.length];
- if (this.log.isFine()) {
+ if ( this.log.isFine() ) {
this.log.logFine("Condensing for '" + in.queueEntry.url().toNormalform(false, true) + "'");
}
- for (int i = 0; i < in.documents.length; i++) {
- condenser[i] = new Condenser(in.documents[i], in.queueEntry.profile().indexText(), in.queueEntry.profile().indexMedia(), LibraryProvider.dymLib);
+ for ( int i = 0; i < in.documents.length; i++ ) {
+ condenser[i] =
+ new Condenser(in.documents[i], in.queueEntry.profile().indexText(), in.queueEntry
+ .profile()
+ .indexMedia(), LibraryProvider.dymLib);
// update image result list statistics
// its good to do this concurrently here, because it needs a DNS lookup
// to compute a URL hash which is necessary for a double-check
final CrawlProfile profile = in.queueEntry.profile();
- ResultImages.registerImages(in.queueEntry.url(), in.documents[i], (profile == null) ? true : !profile.remoteIndexing());
+ ResultImages.registerImages(in.queueEntry.url(), in.documents[i], (profile == null)
+ ? true
+ : !profile.remoteIndexing());
}
return new indexingQueueEntry(in.process, in.queueEntry, in.documents, condenser);
}
public indexingQueueEntry webStructureAnalysis(final indexingQueueEntry in) {
in.queueEntry.updateStatus(Response.QUEUE_STATE_STRUCTUREANALYSIS);
- for (int i = 0; i < in.documents.length; i++) {
+ for ( int i = 0; i < in.documents.length; i++ ) {
assert this.webStructure != null;
assert in != null;
assert in.queueEntry != null;
assert in.documents != null;
assert in.queueEntry != null;
- this.webStructure.generateCitationReference(in.queueEntry.url(), in.documents[i], (in.condenser == null) ? null : in.condenser[i]); // [outlinksSame, outlinksOther]
+ this.webStructure.generateCitationReference(
+ in.queueEntry.url(),
+ in.documents[i],
+ (in.condenser == null) ? null : in.condenser[i]); // [outlinksSame, outlinksOther]
}
return in;
}
@@ -2081,15 +2531,27 @@ public final class Switchboard extends serverSwitch {
public void storeDocumentIndex(final indexingQueueEntry in) {
in.queueEntry.updateStatus(Response.QUEUE_STATE_INDEXSTORAGE);
// the condenser may be null in case that an indexing is not wanted (there may be a no-indexing flag in the file)
- if (in.condenser != null) {
- for (int i = 0; i < in.documents.length; i++) {
- storeDocumentIndex(in.process, in.queueEntry, in.documents[i], in.condenser[i], null, "crawler/indexing queue");
+ if ( in.condenser != null ) {
+ for ( int i = 0; i < in.documents.length; i++ ) {
+ storeDocumentIndex(
+ in.process,
+ in.queueEntry,
+ in.documents[i],
+ in.condenser[i],
+ null,
+ "crawler/indexing queue");
}
}
in.queueEntry.updateStatus(Response.QUEUE_STATE_FINISHED);
}
- private void storeDocumentIndex(final Segments.Process process, final Response queueEntry, final Document document, final Condenser condenser, final SearchEvent searchEvent, final String sourceName) {
+ private void storeDocumentIndex(
+ final Segments.Process process,
+ final Response queueEntry,
+ final Document document,
+ final Condenser condenser,
+ final SearchEvent searchEvent,
+ final String sourceName) {
//TODO: document must carry referer, size and last modified
@@ -2098,19 +2560,34 @@ public final class Switchboard extends serverSwitch {
final DigestURI url = new DigestURI(document.dc_source());
final DigestURI referrerURL = queueEntry.referrerURL();
EventOrigin processCase = queueEntry.processCase(this.peers.mySeed().hash);
- if (process == Segments.Process.SURROGATES) {
+ if ( process == Segments.Process.SURROGATES ) {
processCase = EventOrigin.SURROGATES;
}
- if (condenser == null || document.indexingDenied()) {
+ if ( condenser == null || document.indexingDenied() ) {
//if (this.log.isInfo()) log.logInfo("Not Indexed Resource '" + queueEntry.url().toNormalform(false, true) + "': denied by rule in document, process case=" + processCase);
- addURLtoErrorDB(url, (referrerURL == null) ? null : referrerURL.hash(), queueEntry.initiator(), dc_title, FailCategory.FINAL_PROCESS_CONTEXT, "denied by rule in document, process case=" + processCase);
+ addURLtoErrorDB(
+ url,
+ (referrerURL == null) ? null : referrerURL.hash(),
+ queueEntry.initiator(),
+ dc_title,
+ FailCategory.FINAL_PROCESS_CONTEXT,
+ "denied by rule in document, process case=" + processCase);
return;
}
- if (!queueEntry.profile().indexText() && !queueEntry.profile().indexMedia()) {
+ if ( !queueEntry.profile().indexText() && !queueEntry.profile().indexMedia() ) {
//if (this.log.isInfo()) log.logInfo("Not Indexed Resource '" + queueEntry.url().toNormalform(false, true) + "': denied by profile rule, process case=" + processCase + ", profile name = " + queueEntry.profile().name());
- addURLtoErrorDB(url, (referrerURL == null) ? null : referrerURL.hash(), queueEntry.initiator(), dc_title, FailCategory.FINAL_LOAD_CONTEXT, "denied by profile rule, process case=" + processCase + ", profile name = " + queueEntry.profile().name());
+ addURLtoErrorDB(
+ url,
+ (referrerURL == null) ? null : referrerURL.hash(),
+ queueEntry.initiator(),
+ dc_title,
+ FailCategory.FINAL_LOAD_CONTEXT,
+ "denied by profile rule, process case="
+ + processCase
+ + ", profile name = "
+ + queueEntry.profile().name());
return;
}
@@ -2120,7 +2597,8 @@ public final class Switchboard extends serverSwitch {
// STORE WORD INDEX
URIMetadataRow newEntry = null;
try {
- newEntry = this.indexSegments.segment(process).storeDocument(
+ newEntry =
+ this.indexSegments.segment(process).storeDocument(
url,
referrerURL,
queueEntry.lastModified(),
@@ -2130,16 +2608,36 @@ public final class Switchboard extends serverSwitch {
condenser,
searchEvent,
sourceName);
- final RSSFeed feed = EventChannel.channels(queueEntry.initiator() == null ? EventChannel.PROXY : Base64Order.enhancedCoder.equal(queueEntry.initiator(), ASCII.getBytes(this.peers.mySeed().hash)) ? EventChannel.LOCALINDEXING : EventChannel.REMOTEINDEXING);
- feed.addMessage(new RSSMessage("Indexed web page", dc_title, queueEntry.url().toNormalform(true, false)));
- } catch (final IOException e) {
+ final RSSFeed feed =
+ EventChannel.channels(queueEntry.initiator() == null
+ ? EventChannel.PROXY
+ : Base64Order.enhancedCoder.equal(
+ queueEntry.initiator(),
+ ASCII.getBytes(this.peers.mySeed().hash))
+ ? EventChannel.LOCALINDEXING
+ : EventChannel.REMOTEINDEXING);
+ feed.addMessage(new RSSMessage("Indexed web page", dc_title, queueEntry.url().toNormalform(
+ true,
+ false)));
+ } catch ( final IOException e ) {
//if (this.log.isFine()) log.logFine("Not Indexed Resource '" + queueEntry.url().toNormalform(false, true) + "': process case=" + processCase);
- addURLtoErrorDB(url, (referrerURL == null) ? null : referrerURL.hash(), queueEntry.initiator(), dc_title, FailCategory.FINAL_LOAD_CONTEXT, "error storing url: " + url.toNormalform(false, true) + "': process case=" + processCase + ", error = " + e.getMessage());
+ addURLtoErrorDB(
+ url,
+ (referrerURL == null) ? null : referrerURL.hash(),
+ queueEntry.initiator(),
+ dc_title,
+ FailCategory.FINAL_LOAD_CONTEXT,
+ "error storing url: "
+ + url.toNormalform(false, true)
+ + "': process case="
+ + processCase
+ + ", error = "
+ + e.getMessage());
return;
}
// store rss feeds in document into rss table
- for (final Map.Entry rssEntry : document.getRSS().entrySet()) {
+ for ( final Map.Entry rssEntry : document.getRSS().entrySet() ) {
final Tables.Data rssRow = new Tables.Data();
rssRow.put("referrer", url.hash());
rssRow.put("url", UTF8.getBytes(rssEntry.getKey().toNormalform(true, false)));
@@ -2147,24 +2645,23 @@ public final class Switchboard extends serverSwitch {
rssRow.put("recording_date", new Date());
try {
this.tables.update("rss", new DigestURI(rssEntry.getKey()).hash(), rssRow);
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
Log.logException(e);
}
}
// update url result list statistics
- ResultURLs.stack(
- newEntry, // loaded url db entry
- queueEntry.initiator(), // initiator peer hash
- UTF8.getBytes(this.peers.mySeed().hash), // executor peer hash
- processCase // process case
- );
+ ResultURLs.stack(newEntry, // loaded url db entry
+ queueEntry.initiator(), // initiator peer hash
+ UTF8.getBytes(this.peers.mySeed().hash), // executor peer hash
+ processCase // process case
+ );
// increment number of indexed urls
this.indexedPages++;
// update profiling info
- if (System.currentTimeMillis() - lastPPMUpdate > 20000) {
+ if ( System.currentTimeMillis() - lastPPMUpdate > 20000 ) {
// we don't want to do this too often
updateMySeed();
EventTracker.update(EventTracker.EClass.PPM, Long.valueOf(currentPPM()), true);
@@ -2173,26 +2670,31 @@ public final class Switchboard extends serverSwitch {
EventTracker.update(EventTracker.EClass.INDEX, url.toNormalform(true, false), false);
// if this was performed for a remote crawl request, notify requester
- if ((processCase == EventOrigin.GLOBAL_CRAWLING) && (queueEntry.initiator() != null)) {
+ if ( (processCase == EventOrigin.GLOBAL_CRAWLING) && (queueEntry.initiator() != null) ) {
final Seed initiatorPeer = this.peers.get(ASCII.String(queueEntry.initiator()));
- if (initiatorPeer != null) {
- if (this.clusterhashes != null) {
+ if ( initiatorPeer != null ) {
+ if ( this.clusterhashes != null ) {
initiatorPeer.setAlternativeAddress(this.clusterhashes.get(queueEntry.initiator()));
}
// start a thread for receipt sending to avoid a blocking here
- new Thread(new receiptSending(initiatorPeer, newEntry), "sending receipt to " + ASCII.String(queueEntry.initiator())).start();
+ new Thread(new receiptSending(initiatorPeer, newEntry), "sending receipt to "
+ + ASCII.String(queueEntry.initiator())).start();
}
}
}
- public final void addAllToIndex(final DigestURI url, final Map links, final SearchEvent searchEvent, final String heuristicName) {
+ public final void addAllToIndex(
+ final DigestURI url,
+ final Map links,
+ final SearchEvent searchEvent,
+ final String heuristicName) {
// add the landing page to the index. should not load that again since it should be in the cache
- if (url != null) {
+ if ( url != null ) {
try {
addToIndex(url, searchEvent, heuristicName);
- } catch (final IOException e) {
- } catch (final Parser.Failure e) {
+ } catch ( final IOException e ) {
+ } catch ( final Parser.Failure e ) {
}
}
@@ -2201,82 +2703,108 @@ public final class Switchboard extends serverSwitch {
final Map matcher = searchEvent.getQuery().separateMatches(links);
// take the matcher and load them all
- for (final Map.Entry entry: matcher.entrySet()) {
+ for ( final Map.Entry entry : matcher.entrySet() ) {
try {
addToIndex(new DigestURI(entry.getKey(), (byte[]) null), searchEvent, heuristicName);
- } catch (final IOException e) {
- } catch (final Parser.Failure e) {
+ } catch ( final IOException e ) {
+ } catch ( final Parser.Failure e ) {
}
}
// take then the no-matcher and load them also
- for (final Map.Entry entry: links.entrySet()) {
+ for ( final Map.Entry entry : links.entrySet() ) {
try {
addToIndex(new DigestURI(entry.getKey(), (byte[]) null), searchEvent, heuristicName);
- } catch (final IOException e) {
- } catch (final Parser.Failure e) {
+ } catch ( final IOException e ) {
+ } catch ( final Parser.Failure e ) {
}
}
}
/**
- * load the content of a URL, parse the content and add the content to the index
- * This process is started concurrently. The method returns immediately after the call.
+ * load the content of a URL, parse the content and add the content to the index This process is started
+ * concurrently. The method returns immediately after the call.
+ *
* @param url the url that shall be indexed
- * @param searchEvent (optional) a search event that shall get results from the indexed pages directly feeded. If object is null then it is ignored
+ * @param searchEvent (optional) a search event that shall get results from the indexed pages directly
+ * feeded. If object is null then it is ignored
* @throws IOException
* @throws Parser.Failure
*/
- public void addToIndex(final DigestURI url, final SearchEvent searchEvent, final String heuristicName) throws IOException, Parser.Failure {
+ public void addToIndex(final DigestURI url, final SearchEvent searchEvent, final String heuristicName)
+ throws IOException,
+ Parser.Failure {
final Segments.Process process = Segments.Process.LOCALCRAWLING;
- if (searchEvent != null) {
+ if ( searchEvent != null ) {
searchEvent.addHeuristic(url.hash(), heuristicName, true);
}
- if (this.indexSegments.segment(process).exists(url.hash())) return; // don't do double-work
+ if ( this.indexSegments.segment(process).exists(url.hash()) ) {
+ return; // don't do double-work
+ }
final Request request = this.loader.request(url, true, true);
final CrawlProfile profile = sb.crawler.getActive(ASCII.getBytes(request.profileHandle()));
final String acceptedError = this.crawlStacker.checkAcceptance(url, profile, 0);
- if (acceptedError != null) {
- this.log.logWarning("addToIndex: cannot load " + url.toNormalform(false, false) + ": " + acceptedError);
+ if ( acceptedError != null ) {
+ this.log.logWarning("addToIndex: cannot load "
+ + url.toNormalform(false, false)
+ + ": "
+ + acceptedError);
return;
}
new Thread() {
@Override
public void run() {
try {
- final Response response = Switchboard.this.loader.load(request, CacheStrategy.IFFRESH, true);
- if (response == null) {
+ final Response response =
+ Switchboard.this.loader.load(request, CacheStrategy.IFFRESH, true);
+ if ( response == null ) {
throw new IOException("response == null");
}
- if (response.getContent() == null) {
+ if ( response.getContent() == null ) {
throw new IOException("content == null");
}
- if (response.getResponseHeader() == null) {
+ if ( response.getResponseHeader() == null ) {
throw new IOException("header == null");
}
final Document[] documents = response.parse();
- if (documents != null) {
- for (final Document document: documents) {
- if (document.indexingDenied()) {
+ if ( documents != null ) {
+ for ( final Document document : documents ) {
+ if ( document.indexingDenied() ) {
throw new Parser.Failure("indexing is denied", url);
}
- final Condenser condenser = new Condenser(document, true, true, LibraryProvider.dymLib);
+ final Condenser condenser =
+ new Condenser(document, true, true, LibraryProvider.dymLib);
ResultImages.registerImages(url, document, true);
Switchboard.this.webStructure.generateCitationReference(url, document, condenser);
- storeDocumentIndex(process, response, document, condenser, searchEvent, "heuristic:" + heuristicName);
- Switchboard.this.log.logInfo("addToIndex fill of url " + url.toNormalform(true, true) + " finished");
+ storeDocumentIndex(
+ process,
+ response,
+ document,
+ condenser,
+ searchEvent,
+ "heuristic:" + heuristicName);
+ Switchboard.this.log.logInfo("addToIndex fill of url "
+ + url.toNormalform(true, true)
+ + " finished");
}
}
- } catch (final IOException e) {
- Switchboard.this.log.logWarning("addToIndex: failed loading " + url.toNormalform(false, false) + ": " + e.getMessage());
- } catch (final Parser.Failure e) {
- Switchboard.this.log.logWarning("addToIndex: failed parsing " + url.toNormalform(false, false) + ": " + e.getMessage());
+ } catch ( final IOException e ) {
+ Switchboard.this.log.logWarning("addToIndex: failed loading "
+ + url.toNormalform(false, false)
+ + ": "
+ + e.getMessage());
+ } catch ( final Parser.Failure e ) {
+ Switchboard.this.log.logWarning("addToIndex: failed parsing "
+ + url.toNormalform(false, false)
+ + ": "
+ + e.getMessage());
}
}
}.start();
}
- public class receiptSending implements Runnable {
+ public class receiptSending implements Runnable
+ {
private final Seed initiatorPeer;
private final URIMetadataRow reference;
@@ -2284,15 +2812,36 @@ public final class Switchboard extends serverSwitch {
this.initiatorPeer = initiatorPeer;
this.reference = reference;
}
+
public void run() {
final long t = System.currentTimeMillis();
- final Map response = Protocol.crawlReceipt(Switchboard.this.peers.mySeed(), this.initiatorPeer, "crawl", "fill", "indexed", this.reference, "");
- if (response == null) {
- Switchboard.this.log.logInfo("Sending crawl receipt for '" + this.reference.url().toNormalform(false, true) + "' to " + this.initiatorPeer.getName() + " FAILED, send time = " + (System.currentTimeMillis() - t));
+ final Map response =
+ Protocol.crawlReceipt(
+ Switchboard.this.peers.mySeed(),
+ this.initiatorPeer,
+ "crawl",
+ "fill",
+ "indexed",
+ this.reference,
+ "");
+ if ( response == null ) {
+ Switchboard.this.log.logInfo("Sending crawl receipt for '"
+ + this.reference.url().toNormalform(false, true)
+ + "' to "
+ + this.initiatorPeer.getName()
+ + " FAILED, send time = "
+ + (System.currentTimeMillis() - t));
return;
}
final String delay = response.get("delay");
- Switchboard.this.log.logInfo("Sending crawl receipt for '" + this.reference.url().toNormalform(false, true) + "' to " + this.initiatorPeer.getName() + " success, delay = " + delay + ", send time = " + (System.currentTimeMillis() - t));
+ Switchboard.this.log.logInfo("Sending crawl receipt for '"
+ + this.reference.url().toNormalform(false, true)
+ + "' to "
+ + this.initiatorPeer.getName()
+ + " success, delay = "
+ + delay
+ + ", send time = "
+ + (System.currentTimeMillis() - t));
}
}
@@ -2300,68 +2849,84 @@ public final class Switchboard extends serverSwitch {
// authorization for localhost, only if flag is set to grant localhost access as admin
final String clientIP = requestHeader.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "");
- if (!Domains.isLocalhost(clientIP)) return false;
+ if ( !Domains.isLocalhost(clientIP) ) {
+ return false;
+ }
final String refererHost = requestHeader.refererHost();
return refererHost == null || refererHost.length() == 0 || Domains.isLocalhost(refererHost);
}
/**
- * check authentication status for request
- * access shall be granted if return value >= 2;
- * these are the cases where an access is granted to protected pages:
- * - a password is not configured: auth-level 2
- * - access from localhost is granted and access comes from localhost: auth-level 3
- * - a password is configured and access comes from localhost
- * and the realm-value of a http-authentify String is equal to the stored base64MD5: auth-level 3
- * - a password is configured and access comes with matching http-authentify: auth-level 4
+ * check authentication status for request access shall be granted if return value >= 2; these are the
+ * cases where an access is granted to protected pages: - a password is not configured: auth-level 2 -
+ * access from localhost is granted and access comes from localhost: auth-level 3 - a password is
+ * configured and access comes from localhost and the realm-value of a http-authentify String is equal to
+ * the stored base64MD5: auth-level 3 - a password is configured and access comes with matching
+ * http-authentify: auth-level 4
+ *
* @param requestHeader
- * @return the auth-level as described above or 1 which means 'not authorized'. a 0 is returned in case of fraud attempts
+ * @return the auth-level as described above or 1 which means 'not authorized'. a 0 is returned in case of
+ * fraud attempts
*/
public int adminAuthenticated(final RequestHeader requestHeader) {
// authorization in case that there is no account stored
final String adminAccountBase64MD5 = getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "");
- if (adminAccountBase64MD5.length() == 0) return 2; // no password stored; this should not happen for older peers
+ if ( adminAccountBase64MD5.length() == 0 ) {
+ return 2; // no password stored; this should not happen for older peers
+ }
// authorization for localhost, only if flag is set to grant localhost access as admin
final boolean accessFromLocalhost = accessFromLocalhost(requestHeader);
- if (getConfigBool("adminAccountForLocalhost", false) && accessFromLocalhost) return 3; // soft-authenticated for localhost
+ if ( getConfigBool("adminAccountForLocalhost", false) && accessFromLocalhost ) {
+ return 3; // soft-authenticated for localhost
+ }
// get the authorization string from the header
final String realmProp = (requestHeader.get(RequestHeader.AUTHORIZATION, "xxxxxx")).trim();
final String realmValue = realmProp.substring(6);
// security check against too long authorization strings
- if (realmValue.length() > 256) return 0;
+ if ( realmValue.length() > 256 ) {
+ return 0;
+ }
// authorization by encoded password, only for localhost access
- if (accessFromLocalhost && (adminAccountBase64MD5.equals(realmValue))) return 3; // soft-authenticated for localhost
+ if ( accessFromLocalhost && (adminAccountBase64MD5.equals(realmValue)) ) {
+ return 3; // soft-authenticated for localhost
+ }
// authorization by hit in userDB
- if (this.userDB.hasAdminRight(realmProp, requestHeader.getHeaderCookies())) return 4; //return, because 4=max
+ if ( this.userDB.hasAdminRight(realmProp, requestHeader.getHeaderCookies()) ) {
+ return 4; //return, because 4=max
+ }
// authorization with admin keyword in configuration
- if (realmValue == null || realmValue.length() == 0) return 1;
- if (adminAccountBase64MD5.equals(Digest.encodeMD5Hex(realmValue))) return 4; // hard-authenticated, all ok
+ if ( realmValue == null || realmValue.length() == 0 ) {
+ return 1;
+ }
+ if ( adminAccountBase64MD5.equals(Digest.encodeMD5Hex(realmValue)) ) {
+ return 4; // hard-authenticated, all ok
+ }
return 1;
}
public boolean verifyAuthentication(final RequestHeader header) {
// handle access rights
- switch (adminAuthenticated(header)) {
- case 0: // wrong password given
- //try { Thread.sleep(3000); } catch (final InterruptedException e) { } // prevent brute-force
- return false;
- case 1: // no password given
- return false;
- case 2: // no password stored
- return true;
- case 3: // soft-authenticated for localhost only
- return true;
- case 4: // hard-authenticated, all ok
- return true;
- default:
- return false;
+ switch ( adminAuthenticated(header) ) {
+ case 0: // wrong password given
+ //try { Thread.sleep(3000); } catch (final InterruptedException e) { } // prevent brute-force
+ return false;
+ case 1: // no password given
+ return false;
+ case 2: // no password stored
+ return true;
+ case 3: // soft-authenticated for localhost only
+ return true;
+ case 4: // hard-authenticated, all ok
+ return true;
+ default:
+ return false;
}
}
@@ -2371,10 +2936,10 @@ public final class Switchboard extends serverSwitch {
// wantedPPM <= 10: low performance
// 10 < wantedPPM < 1000: custom performance
// 1000 <= wantedPPM : maximum performance
- if (wPPM <= 10) {
+ if ( wPPM <= 10 ) {
wPPM = 10;
}
- if (wPPM >= 30000) {
+ if ( wPPM >= 30000 ) {
wPPM = 30000;
}
final int newBusySleep = 60000 / wPPM; // for wantedPPM = 10: 6000; for wantedPPM = 1000: 60
@@ -2382,14 +2947,16 @@ public final class Switchboard extends serverSwitch {
BusyThread thread;
thread = getThread(SwitchboardConstants.INDEX_DIST);
- if (thread != null) {
- setConfig(SwitchboardConstants.INDEX_DIST_BUSYSLEEP , thread.setBusySleep(Math.max(2000, thread.setBusySleep(newBusySleep * 2))));
+ if ( thread != null ) {
+ setConfig(
+ SwitchboardConstants.INDEX_DIST_BUSYSLEEP,
+ thread.setBusySleep(Math.max(2000, thread.setBusySleep(newBusySleep * 2))));
thread.setIdleSleep(30000);
}
thread = getThread(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
- if (thread != null) {
- setConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP , thread.setBusySleep(newBusySleep));
+ if ( thread != null ) {
+ setConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, thread.setBusySleep(newBusySleep));
thread.setIdleSleep(2000);
}
}
@@ -2398,45 +2965,56 @@ public final class Switchboard extends serverSwitch {
// returns the access frequency in queries per hour for a given host and a specific tracker
final long timeInterval = 1000 * 60 * 60;
final SortedSet accessSet = tracker.get(host);
- if (accessSet == null) return 0;
+ if ( accessSet == null ) {
+ return 0;
+ }
return accessSet.tailSet(Long.valueOf(System.currentTimeMillis() - timeInterval)).size();
}
public String dhtShallTransfer(final String segment) {
final String cautionCause = onlineCaution();
- if (cautionCause != null) {
+ if ( cautionCause != null ) {
return "online caution for " + cautionCause + ", dht transmission";
}
- if (this.peers == null) {
+ if ( this.peers == null ) {
return "no DHT distribution: seedDB == null";
}
- if (this.peers.mySeed() == null) {
+ if ( this.peers.mySeed() == null ) {
return "no DHT distribution: mySeed == null";
}
- if (this.peers.mySeed().isVirgin()) {
+ if ( this.peers.mySeed().isVirgin() ) {
return "no DHT distribution: status is virgin";
}
- if (this.peers.noDHTActivity()) {
+ if ( this.peers.noDHTActivity() ) {
return "no DHT distribution: network too small";
}
- if (!getConfigBool("network.unit.dht", true)) {
+ if ( !getConfigBool("network.unit.dht", true) ) {
return "no DHT distribution: disabled by network.unit.dht";
}
- if (getConfig(SwitchboardConstants.INDEX_DIST_ALLOW, "false").equalsIgnoreCase("false")) {
+ if ( getConfig(SwitchboardConstants.INDEX_DIST_ALLOW, "false").equalsIgnoreCase("false") ) {
return "no DHT distribution: not enabled (per setting)";
}
final Segment indexSegment = this.indexSegments.segment(segment);
- if (indexSegment.urlMetadata().size() < 10) {
+ if ( indexSegment.urlMetadata().size() < 10 ) {
return "no DHT distribution: loadedURL.size() = " + indexSegment.urlMetadata().size();
}
- if (indexSegment.termIndex().sizesMax() < 100) {
- return "no DHT distribution: not enough words - wordIndex.size() = " + indexSegment.termIndex().sizesMax();
+ if ( indexSegment.termIndex().sizesMax() < 100 ) {
+ return "no DHT distribution: not enough words - wordIndex.size() = "
+ + indexSegment.termIndex().sizesMax();
}
- if ((getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, "false").equalsIgnoreCase("false")) && (this.crawlQueues.noticeURL.notEmptyLocal())) {
- return "no DHT distribution: crawl in progress: noticeURL.stackSize() = " + this.crawlQueues.noticeURL.size() + ", sbQueue.size() = " + getIndexingProcessorsQueueSize();
+ if ( (getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, "false")
+ .equalsIgnoreCase("false")) && (this.crawlQueues.noticeURL.notEmptyLocal()) ) {
+ return "no DHT distribution: crawl in progress: noticeURL.stackSize() = "
+ + this.crawlQueues.noticeURL.size()
+ + ", sbQueue.size() = "
+ + getIndexingProcessorsQueueSize();
}
- if ((getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, "false").equalsIgnoreCase("false")) && (getIndexingProcessorsQueueSize() > 1)) {
- return "no DHT distribution: indexing in progress: noticeURL.stackSize() = " + this.crawlQueues.noticeURL.size() + ", sbQueue.size() = " + getIndexingProcessorsQueueSize();
+ if ( (getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, "false")
+ .equalsIgnoreCase("false")) && (getIndexingProcessorsQueueSize() > 1) ) {
+ return "no DHT distribution: indexing in progress: noticeURL.stackSize() = "
+ + this.crawlQueues.noticeURL.size()
+ + ", sbQueue.size() = "
+ + getIndexingProcessorsQueueSize();
}
return null; // this means; yes, please do dht transfer
}
@@ -2446,10 +3024,12 @@ public final class Switchboard extends serverSwitch {
}
public boolean dhtTransferJob(final String segment) {
- if (this.dhtDispatcher == null) return false;
+ if ( this.dhtDispatcher == null ) {
+ return false;
+ }
final String rejectReason = dhtShallTransfer(segment);
- if (rejectReason != null) {
- if (this.log.isFine()) {
+ if ( rejectReason != null ) {
+ if ( this.log.isFine() ) {
this.log.logFine(rejectReason);
}
return false;
@@ -2457,34 +3037,39 @@ public final class Switchboard extends serverSwitch {
boolean hasDoneSomething = false;
final long kbytesUp = ConnectionInfo.getActiveUpbytes() / 1024;
// accumulate RWIs to transmission cloud
- if (this.dhtDispatcher.cloudSize() > this.peers.scheme.verticalPartitions() * 2) {
- this.log.logInfo("dhtTransferJob: no selection, too many entries in transmission cloud: " + this.dhtDispatcher.cloudSize());
- } else if (MemoryControl.available() < 1024*1024*25) {
- this.log.logInfo("dhtTransferJob: no selection, too less memory available : " + (MemoryControl.available() / 1024 / 1024) + " MB");
- } else if (ConnectionInfo.getLoadPercent() > 50) {
- this.log.logInfo("dhtTransferJob: too many connections in httpc pool : " + ConnectionInfo.getCount());
+ if ( this.dhtDispatcher.cloudSize() > this.peers.scheme.verticalPartitions() * 2 ) {
+ this.log.logInfo("dhtTransferJob: no selection, too many entries in transmission cloud: "
+ + this.dhtDispatcher.cloudSize());
+ } else if ( MemoryControl.available() < 1024 * 1024 * 25 ) {
+ this.log.logInfo("dhtTransferJob: no selection, too less memory available : "
+ + (MemoryControl.available() / 1024 / 1024)
+ + " MB");
+ } else if ( ConnectionInfo.getLoadPercent() > 50 ) {
+ this.log.logInfo("dhtTransferJob: too many connections in httpc pool : "
+ + ConnectionInfo.getCount());
// close unused connections
// Client.cleanup();
- } else if (kbytesUp > 128) {
+ } else if ( kbytesUp > 128 ) {
this.log.logInfo("dhtTransferJob: too much upload(1), currently uploading: " + kbytesUp + " Kb");
} else {
byte[] startHash = null, limitHash = null;
int tries = 10;
- while (tries-- > 0) {
+ while ( tries-- > 0 ) {
startHash = PeerSelection.selectTransferStart();
assert startHash != null;
limitHash = PeerSelection.limitOver(this.peers, startHash);
- if (limitHash != null) {
+ if ( limitHash != null ) {
break;
}
}
- if (limitHash == null || startHash == null) {
+ if ( limitHash == null || startHash == null ) {
this.log.logInfo("dhtTransferJob: approaching full DHT dispersion.");
return false;
}
this.log.logInfo("dhtTransferJob: selected " + ASCII.String(startHash) + " as start hash");
this.log.logInfo("dhtTransferJob: selected " + ASCII.String(limitHash) + " as limit hash");
- final boolean enqueued = this.dhtDispatcher.selectContainersEnqueueToCloud(
+ final boolean enqueued =
+ this.dhtDispatcher.selectContainersEnqueueToCloud(
startHash,
limitHash,
dhtMaxContainerCount,
@@ -2495,13 +3080,16 @@ public final class Switchboard extends serverSwitch {
}
// check if we can deliver entries to other peers
- if (this.dhtDispatcher.transmissionSize() >= 10) {
- this.log.logInfo("dhtTransferJob: no dequeueing from cloud to transmission: too many concurrent sessions: " + this.dhtDispatcher.transmissionSize());
- } else if (ConnectionInfo.getLoadPercent() > 75) {
- this.log.logInfo("dhtTransferJob: too many connections in httpc pool : " + ConnectionInfo.getCount());
+ if ( this.dhtDispatcher.transmissionSize() >= 10 ) {
+ this.log
+ .logInfo("dhtTransferJob: no dequeueing from cloud to transmission: too many concurrent sessions: "
+ + this.dhtDispatcher.transmissionSize());
+ } else if ( ConnectionInfo.getLoadPercent() > 75 ) {
+ this.log.logInfo("dhtTransferJob: too many connections in httpc pool : "
+ + ConnectionInfo.getCount());
// close unused connections
// Client.cleanup();
- } else if (kbytesUp > 256) {
+ } else if ( kbytesUp > 256 ) {
this.log.logInfo("dhtTransferJob: too much upload(2), currently uploading: " + kbytesUp + " Kb");
} else {
final boolean dequeued = this.dhtDispatcher.dequeueContainer();
@@ -2512,16 +3100,16 @@ public final class Switchboard extends serverSwitch {
}
private void addURLtoErrorDB(
- final DigestURI url,
- final byte[] referrerHash,
- final byte[] initiator,
- final String name,
- final FailCategory failCategory,
- final String failreason
- ) {
+ final DigestURI url,
+ final byte[] referrerHash,
+ final byte[] initiator,
+ final String name,
+ final FailCategory failCategory,
+ final String failreason) {
// assert initiator != null; // null == proxy
// create a new errorURL DB entry
- final Request bentry = new Request(
+ final Request bentry =
+ new Request(
initiator,
url,
referrerHash,
@@ -2540,7 +3128,7 @@ public final class Switchboard extends serverSwitch {
@Override
public void run() {
String r = host;
- if (r.indexOf("//",0) < 0) {
+ if ( r.indexOf("//", 0) < 0 ) {
r = "http://" + r;
}
@@ -2548,7 +3136,7 @@ public final class Switchboard extends serverSwitch {
DigestURI url;
try {
url = new DigestURI(r);
- } catch (final MalformedURLException e) {
+ } catch ( final MalformedURLException e ) {
Log.logException(e);
return;
}
@@ -2557,10 +3145,10 @@ public final class Switchboard extends serverSwitch {
searchEvent.getRankingResult().oneFeederStarted();
try {
links = Switchboard.this.loader.loadLinks(url, CacheStrategy.NOCACHE);
- if (links != null) {
+ if ( links != null ) {
final Iterator i = links.keySet().iterator();
- while (i.hasNext()) {
- if (!i.next().getHost().endsWith(host)) {
+ while ( i.hasNext() ) {
+ if ( !i.next().getHost().endsWith(host) ) {
i.remove();
}
}
@@ -2568,7 +3156,7 @@ public final class Switchboard extends serverSwitch {
// add all pages to the index
addAllToIndex(url, links, searchEvent, "site");
}
- } catch (final Throwable e) {
+ } catch ( final Throwable e ) {
Log.logException(e);
} finally {
searchEvent.getRankingResult().oneFeederTerminated();
@@ -2583,16 +3171,22 @@ public final class Switchboard extends serverSwitch {
public void run() {
QueryParams query = searchEvent.getQuery();
String queryString = query.queryString(true);
- final int meta = queryString.indexOf("heuristic:",0);
- if (meta >= 0) {
+ final int meta = queryString.indexOf("heuristic:", 0);
+ if ( meta >= 0 ) {
final int q = queryString.indexOf(' ', meta);
- queryString = (q >= 0) ? queryString.substring(0, meta) + queryString.substring(q + 1) : queryString.substring(0, meta);
+ queryString =
+ (q >= 0)
+ ? queryString.substring(0, meta) + queryString.substring(q + 1)
+ : queryString.substring(0, meta);
}
- final String urlString = "http://www.scroogle.org/cgi-bin/nbbw.cgi?Gw=" + queryString.trim().replaceAll(" ", "+") + "&n=2";
+ final String urlString =
+ "http://www.scroogle.org/cgi-bin/nbbw.cgi?Gw="
+ + queryString.trim().replaceAll(" ", "+")
+ + "&n=2";
final DigestURI url;
try {
url = new DigestURI(MultiProtocolURI.unescape(urlString));
- } catch (final MalformedURLException e1) {
+ } catch ( final MalformedURLException e1 ) {
Log.logWarning("heuristicScroogle", "url not well-formed: '" + urlString + "'");
return;
}
@@ -2601,18 +3195,20 @@ public final class Switchboard extends serverSwitch {
searchEvent.getRankingResult().oneFeederStarted();
try {
links = Switchboard.this.loader.loadLinks(url, CacheStrategy.NOCACHE);
- if (links != null) {
+ if ( links != null ) {
final Iterator i = links.keySet().iterator();
- while (i.hasNext()) {
- if (i.next().toNormalform(false, false).indexOf("scroogle",0) >= 0) {
+ while ( i.hasNext() ) {
+ if ( i.next().toNormalform(false, false).indexOf("scroogle", 0) >= 0 ) {
i.remove();
}
}
- Switchboard.this.log.logInfo("Heuristic: adding " + links.size() + " links from scroogle");
+ Switchboard.this.log.logInfo("Heuristic: adding "
+ + links.size()
+ + " links from scroogle");
// add all pages to the index
addAllToIndex(null, links, searchEvent, "scroogle");
}
- } catch (final Throwable e) {
+ } catch ( final Throwable e ) {
//Log.logException(e);
} finally {
searchEvent.getRankingResult().oneFeederTerminated();
@@ -2622,25 +3218,37 @@ public final class Switchboard extends serverSwitch {
}
// blekko pattern: http://blekko.com/ws/$+/rss
- public final void heuristicRSS(final String urlpattern, final SearchEvent searchEvent, final String feedName) {
+ public final void heuristicRSS(
+ final String urlpattern,
+ final SearchEvent searchEvent,
+ final String feedName) {
final int p = urlpattern.indexOf('$');
- if (p < 0) return;
+ if ( p < 0 ) {
+ return;
+ }
new Thread() {
@Override
public void run() {
QueryParams query = searchEvent.getQuery();
String queryString = query.queryString(true);
- final int meta = queryString.indexOf("heuristic:",0);
- if (meta >= 0) {
+ final int meta = queryString.indexOf("heuristic:", 0);
+ if ( meta >= 0 ) {
final int q = queryString.indexOf(' ', meta);
- if (q >= 0) queryString = queryString.substring(0, meta) + queryString.substring(q + 1); else queryString = queryString.substring(0, meta);
+ if ( q >= 0 ) {
+ queryString = queryString.substring(0, meta) + queryString.substring(q + 1);
+ } else {
+ queryString = queryString.substring(0, meta);
+ }
}
- final String urlString = urlpattern.substring(0, p) + queryString.trim().replaceAll(" ", "+") + urlpattern.substring(p + 1);
+ final String urlString =
+ urlpattern.substring(0, p)
+ + queryString.trim().replaceAll(" ", "+")
+ + urlpattern.substring(p + 1);
final DigestURI url;
try {
url = new DigestURI(MultiProtocolURI.unescape(urlString));
- } catch (final MalformedURLException e1) {
+ } catch ( final MalformedURLException e1 ) {
Log.logWarning("heuristicRSS", "url not well-formed: '" + urlString + "'");
return;
}
@@ -2649,24 +3257,31 @@ public final class Switchboard extends serverSwitch {
RSSReader rss = null;
searchEvent.getRankingResult().oneFeederStarted();
try {
- final Response response = sb.loader.load(sb.loader.request(url, true, false), CacheStrategy.NOCACHE, true);
+ final Response response =
+ sb.loader.load(sb.loader.request(url, true, false), CacheStrategy.NOCACHE, true);
final byte[] resource = (response == null) ? null : response.getContent();
//System.out.println("BLEKKO: " + UTF8.String(resource));
rss = resource == null ? null : RSSReader.parse(RSSFeed.DEFAULT_MAXSIZE, resource);
- if (rss != null) {
+ if ( rss != null ) {
final Map links = new TreeMap();
MultiProtocolURI uri;
- for (final RSSMessage message: rss.getFeed()) try {
- uri = new MultiProtocolURI(message.getLink());
- links.put(uri, message.getTitle());
- } catch (final MalformedURLException e) {
+ for ( final RSSMessage message : rss.getFeed() ) {
+ try {
+ uri = new MultiProtocolURI(message.getLink());
+ links.put(uri, message.getTitle());
+ } catch ( final MalformedURLException e ) {
+ }
}
- Log.logInfo("heuristicRSS", "Heuristic: adding " + links.size() + " links from '" + feedName + "' rss feed");
+ Log.logInfo("heuristicRSS", "Heuristic: adding "
+ + links.size()
+ + " links from '"
+ + feedName
+ + "' rss feed");
// add all pages to the index
addAllToIndex(null, links, searchEvent, feedName);
}
- } catch (final Throwable e) {
+ } catch ( final Throwable e ) {
//Log.logException(e);
} finally {
searchEvent.getRankingResult().oneFeederTerminated();
@@ -2683,14 +3298,17 @@ public final class Switchboard extends serverSwitch {
final long uptime = (System.currentTimeMillis() - serverCore.startupTime) / 1000;
return (this.searchQueriesRobinsonFromRemote + this.searchQueriesGlobal) * 60f / Math.max(uptime, 1f);
}
+
public float averageQPMGlobal() {
final long uptime = (System.currentTimeMillis() - serverCore.startupTime) / 1000;
return (this.searchQueriesGlobal) * 60f / Math.max(uptime, 1f);
}
+
public float averageQPMPrivateLocal() {
final long uptime = (System.currentTimeMillis() - serverCore.startupTime) / 1000;
return (this.searchQueriesRobinsonFromLocal) * 60f / Math.max(uptime, 1f);
}
+
public float averageQPMPublicLocal() {
final long uptime = (System.currentTimeMillis() - serverCore.startupTime) / 1000;
return (this.searchQueriesRobinsonFromRemote) * 60f / Math.max(uptime, 1f);
@@ -2703,13 +3321,18 @@ public final class Switchboard extends serverSwitch {
final long uptime = (System.currentTimeMillis() - serverCore.startupTime) / 1000;
this.peers.mySeed().put(Seed.ISPEED, Integer.toString(currentPPM()));
this.peers.mySeed().put(Seed.RSPEED, Float.toString(averageQPM()));
- this.peers.mySeed().put(Seed.UPTIME, Long.toString(uptime/60)); // the number of minutes that the peer is up in minutes/day (moving average MA30)
+ this.peers.mySeed().put(Seed.UPTIME, Long.toString(uptime / 60)); // the number of minutes that the peer is up in minutes/day (moving average MA30)
this.peers.mySeed().put(Seed.LCOUNT, Long.toString(this.indexSegments.URLCount())); // the number of links that the peer has stored (LURL's)
this.peers.mySeed().put(Seed.NCOUNT, Integer.toString(this.crawlQueues.noticeURL.size())); // the number of links that the peer has noticed, but not loaded (NURL's)
- this.peers.mySeed().put(Seed.RCOUNT, Integer.toString(this.crawlQueues.noticeURL.stackSize(NoticedURL.StackType.LIMIT))); // the number of links that the peer provides for remote crawling (ZURL's)
+ this.peers.mySeed().put(
+ Seed.RCOUNT,
+ Integer.toString(this.crawlQueues.noticeURL.stackSize(NoticedURL.StackType.LIMIT))); // the number of links that the peer provides for remote crawling (ZURL's)
this.peers.mySeed().put(Seed.ICOUNT, Long.toString(this.indexSegments.RWICount())); // the minimum number of words that the peer has indexed (as it says)
this.peers.mySeed().put(Seed.SCOUNT, Integer.toString(this.peers.sizeConnected())); // the number of seeds that the peer has stored
- this.peers.mySeed().put(Seed.CCOUNT, Float.toString(((int) ((this.peers.sizeConnected() + this.peers.sizeDisconnected() + this.peers.sizePotential()) * 60.0f / (uptime + 1.01f)) * 100.0f) / 100.0f)); // the number of clients that the peer connects (as connects/hour)
+ this.peers.mySeed().put(
+ Seed.CCOUNT,
+ Float.toString(((int) ((this.peers.sizeConnected() + this.peers.sizeDisconnected() + this.peers
+ .sizePotential()) * 60.0f / (uptime + 1.01f)) * 100.0f) / 100.0f)); // the number of clients that the peer connects (as connects/hour)
this.peers.mySeed().put(Seed.VERSION, yacyBuildProperties.getLongVersion());
this.peers.mySeed().setFlagDirectConnect(true);
this.peers.mySeed().setLastSeenUTC();
@@ -2722,12 +3345,12 @@ public final class Switchboard extends serverSwitch {
public void loadSeedLists() {
// uses the superseed to initialize the database with known seeds
- Seed ys;
- String seedListFileURL;
- DigestURI url;
- Iterator enu;
- int lc;
- final int sc = this.peers.sizeConnected();
+ Seed ys;
+ String seedListFileURL;
+ DigestURI url;
+ Iterator enu;
+ int lc;
+ final int sc = this.peers.sizeConnected();
ResponseHeader header;
final RequestHeader reqHeader = new RequestHeader();
@@ -2742,19 +3365,16 @@ public final class Switchboard extends serverSwitch {
// - use the superseed to further fill up the seedDB
int ssc = 0, c = 0;
- while (true) {
- if (Thread.currentThread().isInterrupted()) {
+ while ( true ) {
+ if ( Thread.currentThread().isInterrupted() ) {
break;
}
seedListFileURL = sb.getConfig("network.unit.bootstrap.seedlist" + c, "");
- if (seedListFileURL.length() == 0) {
+ if ( seedListFileURL.length() == 0 ) {
break;
}
c++;
- if (
- seedListFileURL.startsWith("http://") ||
- seedListFileURL.startsWith("https://")
- ) {
+ if ( seedListFileURL.startsWith("http://") || seedListFileURL.startsWith("https://") ) {
// load the seed list
try {
@@ -2769,44 +3389,67 @@ public final class Switchboard extends serverSwitch {
} else {
yacyCore.log.logWarning("BOOTSTRAP: seed-list URL " + seedListFileURL + " not available, no content");
}
- } else*/ if (header.lastModified() == null) {
- Network.log.logWarning("BOOTSTRAP: seed-list URL " + seedListFileURL + " not usable, last-modified is missing");
- } else if ((header.age() > 86400000) && (ssc > 0)) {
- Network.log.logInfo("BOOTSTRAP: seed-list URL " + seedListFileURL + " too old (" + (header.age() / 86400000) + " days)");
+ } else*/if ( header.lastModified() == null ) {
+ Network.log.logWarning("BOOTSTRAP: seed-list URL "
+ + seedListFileURL
+ + " not usable, last-modified is missing");
+ } else if ( (header.age() > 86400000) && (ssc > 0) ) {
+ Network.log.logInfo("BOOTSTRAP: seed-list URL "
+ + seedListFileURL
+ + " too old ("
+ + (header.age() / 86400000)
+ + " days)");
} else {
ssc++;
final byte[] content = client.GETbytes(url);
enu = FileUtils.strings(content);
lc = 0;
- while (enu.hasNext()) {
+ while ( enu.hasNext() ) {
try {
ys = Seed.genRemoteSeed(enu.next(), null, false, null);
- if ((ys != null) &&
- (!this.peers.mySeedIsDefined() || !this.peers.mySeed().hash.equals(ys.hash))) {
- final long lastseen = Math.abs((System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60);
- if (lastseen < 240) {
- if (this.peers.peerActions.connectPeer(ys, false)) {
- lc++;
- }
+ if ( (ys != null)
+ && (!this.peers.mySeedIsDefined() || !this.peers.mySeed().hash
+ .equals(ys.hash)) ) {
+ final long lastseen =
+ Math
+ .abs((System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60);
+ if ( lastseen < 240 ) {
+ if ( this.peers.peerActions.connectPeer(ys, false) ) {
+ lc++;
}
}
- } catch (final IOException e) {
+ }
+ } catch ( final IOException e ) {
Network.log.logInfo("BOOTSTRAP: bad seed: " + e.getMessage());
}
}
- Network.log.logInfo("BOOTSTRAP: " + lc + " seeds from seed-list URL " + seedListFileURL + ", AGE=" + (header.age() / 3600000) + "h");
+ Network.log.logInfo("BOOTSTRAP: "
+ + lc
+ + " seeds from seed-list URL "
+ + seedListFileURL
+ + ", AGE="
+ + (header.age() / 3600000)
+ + "h");
}
- } catch (final IOException e) {
+ } catch ( final IOException e ) {
// this is when wget fails, commonly because of timeout
- Network.log.logWarning("BOOTSTRAP: failed (1) to load seeds from seed-list URL " + seedListFileURL + ": " + e.getMessage());
- } catch (final Exception e) {
+ Network.log.logWarning("BOOTSTRAP: failed (1) to load seeds from seed-list URL "
+ + seedListFileURL
+ + ": "
+ + e.getMessage());
+ } catch ( final Exception e ) {
// this is when wget fails; may be because of missing internet connection
- Network.log.logSevere("BOOTSTRAP: failed (2) to load seeds from seed-list URL " + seedListFileURL + ": " + e.getMessage(), e);
+ Network.log.logSevere("BOOTSTRAP: failed (2) to load seeds from seed-list URL "
+ + seedListFileURL
+ + ": "
+ + e.getMessage(), e);
}
}
}
- Network.log.logInfo("BOOTSTRAP: " + (this.peers.sizeConnected() - sc) + " new seeds while bootstraping.");
+ Network.log.logInfo("BOOTSTRAP: "
+ + (this.peers.sizeConnected() - sc)
+ + " new seeds while bootstraping.");
}
public void initRemoteProxy() {
@@ -2816,7 +3459,7 @@ public final class Switchboard extends serverSwitch {
int port;
try {
port = Integer.parseInt(getConfig("remoteProxyPort", "3128"));
- } catch (final NumberFormatException e) {
+ } catch ( final NumberFormatException e ) {
port = 3128;
}
// create new config
@@ -2824,7 +3467,7 @@ public final class Switchboard extends serverSwitch {
ProxySettings.use4YaCy = true;
ProxySettings.port = port;
ProxySettings.host = host;
- ProxySettings.use = ((ProxySettings.host != null) && (ProxySettings.host.length() > 0));
+ ProxySettings.use = ((ProxySettings.host != null) && (ProxySettings.host.length() > 0));
// determining if remote proxy usage is enabled
ProxySettings.use = getConfigBool("remoteProxyUse", false);
@@ -2839,11 +3482,11 @@ public final class Switchboard extends serverSwitch {
ProxySettings.password = getConfig("remoteProxyPwd", "").trim();
// determining addresses for which the remote proxy should not be used
- final String remoteProxyNoProxy = getConfig("remoteProxyNoProxy","").trim();
+ final String remoteProxyNoProxy = getConfig("remoteProxyNoProxy", "").trim();
ProxySettings.noProxy = remoteProxyNoProxy.split(",");
// trim split entries
int i = 0;
- for (final String pattern: ProxySettings.noProxy) {
+ for ( final String pattern : ProxySettings.noProxy ) {
ProxySettings.noProxy[i] = pattern.trim();
i++;
}
@@ -2851,15 +3494,15 @@ public final class Switchboard extends serverSwitch {
public void checkInterruption() throws InterruptedException {
final Thread curThread = Thread.currentThread();
- if ((curThread instanceof WorkflowThread) && ((WorkflowThread)curThread).shutdownInProgress()) {
+ if ( (curThread instanceof WorkflowThread) && ((WorkflowThread) curThread).shutdownInProgress() ) {
throw new InterruptedException("Shutdown in progress ...");
- } else if (this.terminate || curThread.isInterrupted()) {
+ } else if ( this.terminate || curThread.isInterrupted() ) {
throw new InterruptedException("Shutdown in progress ...");
}
}
public void terminate(final long delay, final String reason) {
- if (delay <= 0) {
+ if ( delay <= 0 ) {
throw new IllegalArgumentException("The shutdown delay must be greater than 0.");
}
this.log.logInfo("caught delayed terminate request: " + reason);
@@ -2869,7 +3512,7 @@ public final class Switchboard extends serverSwitch {
public boolean shallTerminate() {
return this.terminate;
}
-
+
public void terminate(final String reason) {
this.terminate = true;
this.log.logInfo("caught terminate request: " + reason);
@@ -2886,9 +3529,7 @@ public final class Switchboard extends serverSwitch {
}
/**
- * loads the url as Map
- *
- * Strings like abc=123 are parsed as pair: abc => 123
+ * loads the url as Map Strings like abc=123 are parsed as pair: abc => 123
*
* @param url
* @return
@@ -2906,17 +3547,19 @@ public final class Switchboard extends serverSwitch {
// sending request
final Map result = FileUtils.table(client.GETbytes(url));
return (result == null) ? new HashMap() : result;
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
Log.logException(e);
return new HashMap();
}
}
}
-class delayedShutdown extends Thread {
+class delayedShutdown extends Thread
+{
private final Switchboard sb;
private final long delay;
private final String reason;
+
public delayedShutdown(final Switchboard sb, final long delay, final String reason) {
this.sb = sb;
this.delay = delay;
@@ -2927,9 +3570,9 @@ class delayedShutdown extends Thread {
public void run() {
try {
Thread.sleep(this.delay);
- } catch (final InterruptedException e) {
+ } catch ( final InterruptedException e ) {
this.sb.getLog().logInfo("interrupted delayed shutdown");
- } catch (final Exception e) {
+ } catch ( final Exception e ) {
Log.logException(e);
}
this.sb.terminate(this.reason);
diff --git a/source/net/yacy/search/SwitchboardConstants.java b/source/net/yacy/search/SwitchboardConstants.java
index 71c4a4187..7442a7148 100644
--- a/source/net/yacy/search/SwitchboardConstants.java
+++ b/source/net/yacy/search/SwitchboardConstants.java
@@ -278,8 +278,8 @@ public final class SwitchboardConstants {
public static final String CLUSTER_MODE = "cluster.mode";
public static final String CLUSTER_MODE_PUBLIC_CLUSTER = "publiccluster";
- public static final String CLUSTER_MODE_PRIVATE_CLUSTER = "privatecluster";
public static final String CLUSTER_MODE_PUBLIC_PEER = "publicpeer";
+ public static final String CLUSTER_MODE_PRIVATE_PEER = "privatepeer";
public static final String CLUSTER_PEERS_IPPORT = "cluster.peers.ipport";
public static final String DHT_BURST_ROBINSON = "network.unit.dht.burst.robinson";