Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
synchronization enhancements
orbiter23e81b28b2cf
diff --git a/source/de/anomic/yacy/yacyNewsPool.java b/source/de/anomic/yacy/yacyNewsPool.javaindex 9d9b55ef7..9524079e2 100644--- a/source/de/anomic/yacy/yacyNewsPool.java+++ b/source/de/anomic/yacy/yacyNewsPool.java@@ -57,16 +57,15 @@ import net.yacy.kelondro.data.meta.DigestURI;import net.yacy.kelondro.index.RowSpaceExceededException;import net.yacy.kelondro.logging.Log;import net.yacy.repository.Blacklist;-import de.anomic.search.Switchboard;public class yacyNewsPool {-+public static final int INCOMING_DB = 0;public static final int PROCESSED_DB = 1;public static final int OUTGOING_DB = 2;public static final int PUBLISHED_DB = 3;-+/* ========================================================================* CATEGORIES for YACY NEWS* ======================================================================== */@@ -90,10 +89,10 @@ public class yacyNewsPool {* a peer has done something bad (i.e. spammed) and gets a negative vote*/private static final String CATEGORY_PROFILE_VOTE_BAD = "prflebvt";-+/* ------------------------------------------------------------------------* CRAWLING related CATEGORIES- * ------------------------------------------------------------------------ */+ * ------------------------------------------------------------------------ *//*** a crawl with remote indexing was started*/@@ -106,10 +105,10 @@ public class yacyNewsPool {* a comment on a crawl with remote indexing*/private static final String CATEGORY_CRAWL_COMMENT = "crwlcomm";-+/* ------------------------------------------------------------------------* BLACKLIST related CATEGORIES- * ------------------------------------------------------------------------ */+ * ------------------------------------------------------------------------ *//*** a private blacklist entry was added*/@@ -126,10 +125,10 @@ public class yacyNewsPool {* a vote and comment on a private blacklist delete*/private static final String CATEGORY_BLACKLIST_VOTE_DEL = "blckldvt";-+/* ------------------------------------------------------------------------* FLIE-SHARE related CATEGORIES- * ------------------------------------------------------------------------ */+ * ------------------------------------------------------------------------ *//*** a file was added to the file share*/@@ -142,10 +141,10 @@ public class yacyNewsPool {* a comment to a file share entry*/private static final String CATEGORY_FILESHARE_COMMENT = "flshrcom";-+/* ------------------------------------------------------------------------* BOOKMARK related CATEGORIES- * ------------------------------------------------------------------------ */+ * ------------------------------------------------------------------------ *//*** a bookmark was added/created*/@@ -170,31 +169,31 @@ public class yacyNewsPool {* a vote and comment on a bookmark delete*/private static final String CATEGORY_BOOKMARK_VOTE_DEL = "bkmrkdvt";-+/* ------------------------------------------------------------------------* SURFTIPP related CATEGORIES- * ------------------------------------------------------------------------ */- /**+ * ------------------------------------------------------------------------ */+ /*** a surf tipp was added*/- public static final String CATEGORY_SURFTIPP_ADD = "stippadd";+ public static final String CATEGORY_SURFTIPP_ADD = "stippadd";/*** a vote and comment on a surf tipp*/public static final String CATEGORY_SURFTIPP_VOTE_ADD = "stippavt";-+/* ------------------------------------------------------------------------* WIKI related CATEGORIES- * ------------------------------------------------------------------------ */+ * ------------------------------------------------------------------------ *//*** a wiki page was updated*/public static final String CATEGORY_WIKI_UPDATE = "wiki_upd";- /**+ /*** a wiki page das deleted*/private static final String CATEGORY_WIKI_DEL = "wiki_del";-+/* ------------------------------------------------------------------------* BLOG related CATEGORIES* ------------------------------------------------------------------------ */@@ -206,33 +205,33 @@ public class yacyNewsPool {* a blog page das deleted*/private static final String CATEGORY_BLOG_DEL = "blog_del";-+/* ========================================================================* ARRAY of valid CATEGORIES- * ======================================================================== */+ * ======================================================================== */private static final String[] category = {// PROFILE related CATEGORIESCATEGORY_PROFILE_UPDATE,CATEGORY_PROFILE_BROADCAST,CATEGORY_PROFILE_VOTE_GOOD,CATEGORY_PROFILE_VOTE_BAD,-+// CRAWLING related CATEGORIES- CATEGORY_CRAWL_START,+ CATEGORY_CRAWL_START,CATEGORY_CRAWL_STOP,CATEGORY_CRAWL_COMMENT,-+// BLACKLIST related CATEGORIES- CATEGORY_BLACKLIST_ADD,+ CATEGORY_BLACKLIST_ADD,CATEGORY_BLACKLIST_VOTE_ADD,CATEGORY_BLACKLIST_DELETE,CATEGORY_BLACKLIST_VOTE_DEL,-- // FILESHARE related CATEGORIES++ // FILESHARE related CATEGORIESCATEGORY_FILESHARE_ADD,CATEGORY_FILESHARE_DEL,CATEGORY_FILESHARE_COMMENT,-+// BOOKMARK related CATEGORIESCATEGORY_BOOKMARK_ADD,CATEGORY_BOOKMARK_VOTE_ADD,@@ -240,15 +239,15 @@ public class yacyNewsPool {CATEGORY_BOOKMARK_VOTE_MOVE,CATEGORY_BOOKMARK_DEL,CATEGORY_BOOKMARK_VOTE_DEL,-+// SURFTIPP related CATEGORIESCATEGORY_SURFTIPP_ADD,CATEGORY_SURFTIPP_VOTE_ADD,-+// WIKI related CATEGORIECATEGORY_WIKI_UPDATE,CATEGORY_WIKI_DEL,-+// BLOG related CATEGORIESCATEGORY_BLOG_ADD,CATEGORY_BLOG_DEL@@ -263,75 +262,75 @@ public class yacyNewsPool {private final yacyNewsDB newsDB;private final yacyNewsQueue outgoingNews, publishedNews, incomingNews, processedNews;private final int maxDistribution;-+public yacyNewsPool(final File yacyDBPath,final boolean useTailCache,final boolean exceed134217727) {- newsDB = new yacyNewsDB(new File(yacyDBPath, "news1024.db"), 1024, useTailCache, exceed134217727);- outgoingNews = new yacyNewsQueue(new File(yacyDBPath, "newsOut.table"), newsDB);- publishedNews = new yacyNewsQueue(new File(yacyDBPath, "newsPublished.table"), newsDB);- incomingNews = new yacyNewsQueue(new File(yacyDBPath, "newsIn.table"), newsDB);- processedNews = new yacyNewsQueue(new File(yacyDBPath, "newsProcessed.table"), newsDB);- maxDistribution = 30;+ this.newsDB = new yacyNewsDB(new File(yacyDBPath, "news1024.db"), 1024, useTailCache, exceed134217727);+ this.outgoingNews = new yacyNewsQueue(new File(yacyDBPath, "newsOut.table"), this.newsDB);+ this.publishedNews = new yacyNewsQueue(new File(yacyDBPath, "newsPublished.table"), this.newsDB);+ this.incomingNews = new yacyNewsQueue(new File(yacyDBPath, "newsIn.table"), this.newsDB);+ this.processedNews = new yacyNewsQueue(new File(yacyDBPath, "newsProcessed.table"), this.newsDB);+ this.maxDistribution = 30;}-+public synchronized void close() {- newsDB.close();- outgoingNews.close();- publishedNews.close();- incomingNews.close();- processedNews.close();+ this.newsDB.close();+ this.outgoingNews.close();+ this.publishedNews.close();+ this.incomingNews.close();+ this.processedNews.close();}-+public Iterator<yacyNewsDB.Record> recordIterator(final int dbKey, final boolean up) {// returns an iterator of yacyNewsRecord-type objectsfinal yacyNewsQueue queue = switchQueue(dbKey);return queue.records(up);}-+public yacyNewsDB.Record parseExternal(final String external) {- return newsDB.newRecord(external);+ return this.newsDB.newRecord(external);}-+public void publishMyNews(final yacySeed mySeed, final String category, final Map<String, String> attributes) {- publishMyNews(newsDB.newRecord(mySeed, category, attributes));+ publishMyNews(this.newsDB.newRecord(mySeed, category, attributes));}-+public void publishMyNews(final yacySeed mySeed, final String category, final Properties attributes) {- publishMyNews(newsDB.newRecord(mySeed, category, attributes));+ publishMyNews(this.newsDB.newRecord(mySeed, category, attributes));}-+private void publishMyNews(final yacyNewsDB.Record record) {// this shall be called if our peer generated a new news record and wants to publish itif (record == null) return;try {- if (newsDB.get(record.id()) == null) {- incomingNews.push(record); // we want to see our own news..- outgoingNews.push(record); // .. and put it on the publishing list+ if (this.newsDB.get(record.id()) == null) {+ this.incomingNews.push(record); // we want to see our own news..+ this.outgoingNews.push(record); // .. and put it on the publishing list}} catch (final Exception e) {Log.logException(e);}}-+public yacyNewsDB.Record myPublication() throws IOException, RowSpaceExceededException {// generate a record for next peer-ping- if (outgoingNews.isEmpty()) return null;- final yacyNewsDB.Record record = outgoingNews.pop();+ if (this.outgoingNews.isEmpty()) return null;+ final yacyNewsDB.Record record = this.outgoingNews.pop();if (record == null) return null;-+record.incDistribution();-- if (record.distributed() >= maxDistribution) {++ if (record.distributed() >= this.maxDistribution) {// move record to its final position. This is only for history- publishedNews.push(record);+ this.publishedNews.push(record);} else {- outgoingNews.push(record);+ this.outgoingNews.push(record);}return record;}-+public void enqueueIncomingNews(final yacyNewsDB.Record record) throws IOException, RowSpaceExceededException {// called if a news is attached to a seed@@ -354,31 +353,33 @@ public class yacyNewsPool {return;}}-+// double-check with old news- if (newsDB.get(record.id()) != null) return;- incomingNews.push(record);-+ if (this.newsDB.get(record.id()) != null) return;+ this.incomingNews.push(record);+// add message to feed channel//RSSFeed.channels(yacyCore.channelName).addMessage(new RSSMessage("Incoming News: " + record.category() + " from " + record.originator(), record.attributes().toString()));}-+public int size(final int dbKey) {return switchQueue(dbKey).size();}-+public int automaticProcess(final yacySeedDB seedDB) throws IOException, InterruptedException, RowSpaceExceededException {// processes news in the incoming-db// returns number of processesyacyNewsDB.Record record;int pc = 0;synchronized (this.incomingNews) {- final Iterator<yacyNewsDB.Record> i = incomingNews.records(true);- Set<String> removeIDs = new HashSet<String>();+ final Iterator<yacyNewsDB.Record> i = this.incomingNews.records(true);+ final Set<String> removeIDs = new HashSet<String>();+ // this loop should not run too long! This may happen if the incoming news are long and not deleted after processing+ final long start = System.currentTimeMillis();while (i.hasNext()) {// check for interruptionif (Thread.currentThread().isInterrupted()) throw new InterruptedException("Shutdown in progress");-+// get next news recordrecord = i.next();if (automaticProcessP(seedDB, record)) {@@ -386,35 +387,40 @@ public class yacyNewsPool {removeIDs.add(record.id());pc++;}+ if (System.currentTimeMillis() - start > 100) break; // time-out for this to avoid deadlocks during concurrent peer-pings+ }+ for (final String id: removeIDs) {+ final yacyNewsDB.Record deletedRecord = this.incomingNews.remove(id);+ assert deletedRecord != null;}- for (final String id: removeIDs) incomingNews.remove(id);}return pc;}-+private boolean automaticProcessP(final yacySeedDB seedDB, final yacyNewsDB.Record record) {if (record == null) return false;if (record.category() == null) return true;- if ((System.currentTimeMillis() - record.created().getTime()) > (14 * MILLISECONDS_PER_DAY)) {+ final long created = record.created().getTime();+ if ((System.currentTimeMillis() - created) > (7L * MILLISECONDS_PER_DAY)) {// remove everything after 1 weekreturn true;}if ((record.category().equals(CATEGORY_WIKI_UPDATE)) &&- ((System.currentTimeMillis() - record.created().getTime()) > (3 * MILLISECONDS_PER_DAY))) {+ ((System.currentTimeMillis() - created) > (3L * MILLISECONDS_PER_DAY))) {return true;}if ((record.category().equals(CATEGORY_BLOG_ADD)) &&- ((System.currentTimeMillis() - record.created().getTime()) > (3 * MILLISECONDS_PER_DAY))) {+ ((System.currentTimeMillis() - created) > (3L * MILLISECONDS_PER_DAY))) {return true;}if ((record.category().equals(CATEGORY_PROFILE_UPDATE)) &&- ((System.currentTimeMillis() - record.created().getTime()) > (7 * MILLISECONDS_PER_DAY))) {+ ((System.currentTimeMillis() - created) > (3L * MILLISECONDS_PER_DAY))) {return true;}if ((record.category().equals(CATEGORY_CRAWL_START)) &&- ((System.currentTimeMillis() - record.created().getTime()) > (2 * MILLISECONDS_PER_DAY))) {+ ((System.currentTimeMillis() - created) > (3L * MILLISECONDS_PER_DAY))) {final yacySeed seed = seedDB.get(record.originator());- if (seed == null) return false;+ if (seed == null) return true;try {return (Integer.parseInt(seed.get(yacySeed.ISPEED, "-")) < 10);} catch (final NumberFormatException ee) {@@ -423,7 +429,7 @@ public class yacyNewsPool {}return false;}-+public synchronized yacyNewsDB.Record getSpecific(final int dbKey, final String category, final String key, final String value) {final yacyNewsQueue queue = switchQueue(dbKey);yacyNewsDB.Record record;@@ -456,31 +462,31 @@ public class yacyNewsPool {public synchronized yacyNewsDB.Record getByID(final int dbKey, final String id) {switch (dbKey) {- case INCOMING_DB: return incomingNews.get(id);- case PROCESSED_DB: return processedNews.get(id);- case OUTGOING_DB: return outgoingNews.get(id);- case PUBLISHED_DB: return publishedNews.get(id);+ case INCOMING_DB: return this.incomingNews.get(id);+ case PROCESSED_DB: return this.processedNews.get(id);+ case OUTGOING_DB: return this.outgoingNews.get(id);+ case PUBLISHED_DB: return this.publishedNews.get(id);}return null;}private yacyNewsQueue switchQueue(final int dbKey) {switch (dbKey) {- case INCOMING_DB: return incomingNews;- case PROCESSED_DB: return processedNews;- case OUTGOING_DB: return outgoingNews;- case PUBLISHED_DB: return publishedNews;+ case INCOMING_DB: return this.incomingNews;+ case PROCESSED_DB: return this.processedNews;+ case OUTGOING_DB: return this.outgoingNews;+ case PUBLISHED_DB: return this.publishedNews;}return null;}-+public void clear(final int dbKey) {// clear a tableswitch (dbKey) {- case INCOMING_DB: incomingNews.clear(); break;- case PROCESSED_DB: processedNews.clear(); break;- case OUTGOING_DB: outgoingNews.clear(); break;- case PUBLISHED_DB: publishedNews.clear(); break;+ case INCOMING_DB: this.incomingNews.clear(); break;+ case PROCESSED_DB: this.processedNews.clear(); break;+ case OUTGOING_DB: this.outgoingNews.clear(); break;+ case PUBLISHED_DB: this.publishedNews.clear(); break;}}@@ -488,10 +494,10 @@ public class yacyNewsPool {// this is called if a queue element shall be moved to another queue or off the queue// it depends on the dbKey how the record is handledswitch (dbKey) {- case INCOMING_DB: moveOff(incomingNews, processedNews, id); break;- case PROCESSED_DB: moveOff(processedNews, null,id); break;- case OUTGOING_DB: moveOff(outgoingNews, publishedNews, id); break;- case PUBLISHED_DB: moveOff(publishedNews, null, id); break;+ case INCOMING_DB: moveOff(this.incomingNews, this.processedNews, id); break;+ case PROCESSED_DB: moveOff(this.processedNews, null,id); break;+ case OUTGOING_DB: moveOff(this.outgoingNews, this.publishedNews, id); break;+ case PUBLISHED_DB: moveOff(this.publishedNews, null, id); break;}}@@ -503,20 +509,20 @@ public class yacyNewsPool {}if (toqueue != null) {toqueue.push(record);- } else if ((incomingNews.get(id) == null) && (processedNews.get(id) == null) && (outgoingNews.get(id) == null) && (publishedNews.get(id) == null)) {- newsDB.remove(id);+ } else if ((this.incomingNews.get(id) == null) && (this.processedNews.get(id) == null) && (this.outgoingNews.get(id) == null) && (this.publishedNews.get(id) == null)) {+ this.newsDB.remove(id);}return true;}-+public void moveOffAll(final int dbKey) throws IOException, RowSpaceExceededException {// this is called if a queue element shall be moved to another queue or off the queue// it depends on the dbKey how the record is handledswitch (dbKey) {- case INCOMING_DB: moveOffAll(incomingNews, processedNews); break;- case PROCESSED_DB: processedNews.clear(); break;- case OUTGOING_DB: moveOffAll(outgoingNews, publishedNews); break;- case PUBLISHED_DB: publishedNews.clear(); break;+ case INCOMING_DB: moveOffAll(this.incomingNews, this.processedNews); break;+ case PROCESSED_DB: this.processedNews.clear(); break;+ case OUTGOING_DB: moveOffAll(this.outgoingNews, this.publishedNews); break;+ case PUBLISHED_DB: this.publishedNews.clear(); break;}}@@ -535,5 +541,5 @@ public class yacyNewsPool {fromqueue.clear();return c;}-+}diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.javaindex 396d82c2a..8bf830b29 100644--- a/source/de/anomic/yacy/yacySeed.java+++ b/source/de/anomic/yacy/yacySeed.java@@ -51,7 +51,6 @@ import java.text.ParseException;import java.util.Comparator;import java.util.Date;import java.util.Iterator;-import java.util.Map;import java.util.Random;import java.util.Set;import java.util.TreeMap;@@ -374,7 +373,7 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac}/** @return the DNA-map of this peer */- public final Map<String, String> getMap() {+ public final ConcurrentMap<String, String> getMap() {return this.dna;}diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.javaindex 5be5dc29b..14523c0f1 100644--- a/source/de/anomic/yacy/yacySeedDB.java+++ b/source/de/anomic/yacy/yacySeedDB.java@@ -1,4 +1,4 @@-// yacySeedDB.java+// yacySeedDB.java// -------------------------------------// (C) by Michael Peter Christen; [email protected]// first published on http://www.anomic.de@@ -39,6 +39,7 @@ import java.util.Map;import java.util.Set;import java.util.TreeMap;import java.util.concurrent.ConcurrentHashMap;+import java.util.concurrent.ConcurrentMap;import net.yacy.cora.document.ASCII;import net.yacy.cora.document.UTF8;@@ -56,11 +57,8 @@ import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.order.Base64Order;import net.yacy.kelondro.util.FileUtils;import net.yacy.kelondro.util.kelondroException;--//import de.anomic.http.client.Client;import de.anomic.http.server.AlternativeDomainNames;import de.anomic.http.server.HTTPDemon;-//import de.anomic.http.server.ResponseContainer;import de.anomic.search.Switchboard;import de.anomic.server.serverCore;import de.anomic.server.serverSwitch;@@ -68,47 +66,47 @@ import de.anomic.yacy.dht.PartitionScheme;import de.anomic.yacy.dht.VerticalWordPartitionScheme;public final class yacySeedDB implements AlternativeDomainNames {-+// global staticsprivate static final int dhtActivityMagic = 32;-+/*** <p><code>public static final String <strong>DBFILE_OWN_SEED</strong> = "mySeed.txt"</code></p>* <p>Name of the file containing the database holding this peer's seed</p>*/public static final String DBFILE_OWN_SEED = "mySeed.txt";-+public static final String[] sortFields = new String[] {yacySeed.LCOUNT, yacySeed.RCOUNT, yacySeed.ICOUNT, yacySeed.UPTIME, yacySeed.VERSION, yacySeed.LASTSEEN};public static final String[] longaccFields = new String[] {yacySeed.LCOUNT, yacySeed.ICOUNT, yacySeed.ISPEED};public static final String[] doubleaccFields = new String[] {yacySeed.RSPEED};-+// class objectsprivate File seedActiveDBFile, seedPassiveDBFile, seedPotentialDBFile;private File myOwnSeedFile;private MapDataMining seedActiveDB, seedPassiveDB, seedPotentialDB;-+protected int lastSeedUpload_seedDBSize = 0;public long lastSeedUpload_timeStamp = System.currentTimeMillis();protected String lastSeedUpload_myIP = "";public yacyPeerActions peerActions;public yacyNewsPool newsPool;-+private int netRedundancy;public PartitionScheme scheme;-+private yacySeed mySeed; // my own seed- private Set<String> myBotIDs; // list of id's that this bot accepts as robots.txt identification+ private final Set<String> myBotIDs; // list of id's that this bot accepts as robots.txt identificationprivate final Hashtable<String, String> nameLookupCache; // a name-to-hash relationprivate final Hashtable<InetAddress, SoftReference<yacySeed>> ipLookupCache;-+public yacySeedDB(final File networkRoot,final String seedActiveDBFileName,final String seedPassiveDBFileName,final String seedPotentialDBFileName,- final File myOwnSeedFile,+ final File myOwnSeedFile,final int redundancy,final int partitionExponent,final boolean useTailCache,@@ -124,201 +122,201 @@ public final class yacySeedDB implements AlternativeDomainNames {this.myBotIDs.add("yacyproxy");this.netRedundancy = redundancy;this.scheme = new VerticalWordPartitionScheme(partitionExponent);-+// set up seed database- this.seedActiveDB = openSeedTable(seedActiveDBFile);- this.seedPassiveDB = openSeedTable(seedPassiveDBFile);- this.seedPotentialDB = openSeedTable(seedPotentialDBFile);-+ this.seedActiveDB = openSeedTable(this.seedActiveDBFile);+ this.seedPassiveDB = openSeedTable(this.seedPassiveDBFile);+ this.seedPotentialDB = openSeedTable(this.seedPotentialDBFile);+// start our virtual DNS service for yacy peers with empty cachethis.nameLookupCache = new Hashtable<String, String>();-+// cache for reverse name lookupthis.ipLookupCache = new Hashtable<InetAddress, SoftReference<yacySeed>>();-+// check if we are in the seedCaches: this can happen if someone else published our seedremoveMySeed();-+this.lastSeedUpload_seedDBSize = sizeConnected();// tell the httpdProxy how to find this table as address resolverHTTPDemon.setAlternativeResolver(this);-+// create or init news databasethis.newsPool = new yacyNewsPool(networkRoot, useTailCache, exceed134217727);-+// deploy peer actions- this.peerActions = new yacyPeerActions(this, newsPool);+ this.peerActions = new yacyPeerActions(this, this.newsPool);}-+public void relocate(- File newNetworkRoot,+ final File newNetworkRoot,final int redundancy,final int partitionExponent,final boolean useTailCache,final boolean exceed134217727) {-+// close old databasesthis.seedActiveDB.close();this.seedPassiveDB.close();this.seedPotentialDB.close();this.newsPool.close();this.peerActions.close();-+// open new according to the newNetworkRoot- this.seedActiveDBFile = new File(newNetworkRoot, seedActiveDBFile.getName());- this.seedPassiveDBFile = new File(newNetworkRoot, seedPassiveDBFile.getName());- this.seedPotentialDBFile = new File(newNetworkRoot, seedPotentialDBFile.getName());+ this.seedActiveDBFile = new File(newNetworkRoot, this.seedActiveDBFile.getName());+ this.seedPassiveDBFile = new File(newNetworkRoot, this.seedPassiveDBFile.getName());+ this.seedPotentialDBFile = new File(newNetworkRoot, this.seedPotentialDBFile.getName());// replace my (old) seed with new seed definition from other network// but keep the seed name- String peername = this.myName();+ final String peername = myName();this.mySeed = null; // my own seedthis.myOwnSeedFile = new File(newNetworkRoot, yacySeedDB.DBFILE_OWN_SEED);initMySeed();this.mySeed.setName(peername);-+this.netRedundancy = redundancy;this.scheme = new VerticalWordPartitionScheme(partitionExponent);-+// set up seed database- this.seedActiveDB = openSeedTable(seedActiveDBFile);- this.seedPassiveDB = openSeedTable(seedPassiveDBFile);- this.seedPotentialDB = openSeedTable(seedPotentialDBFile);-+ this.seedActiveDB = openSeedTable(this.seedActiveDBFile);+ this.seedPassiveDB = openSeedTable(this.seedPassiveDBFile);+ this.seedPotentialDB = openSeedTable(this.seedPotentialDBFile);+// start our virtual DNS service for yacy peers with empty cachethis.nameLookupCache.clear();-+// cache for reverse name lookupthis.ipLookupCache.clear();-+// check if we are in the seedCaches: this can happen if someone else published our seedremoveMySeed();-+this.lastSeedUpload_seedDBSize = sizeConnected();// tell the httpdProxy how to find this table as address resolverHTTPDemon.setAlternativeResolver(this);-+// create or init news databasethis.newsPool = new yacyNewsPool(newNetworkRoot, useTailCache, exceed134217727);-+// deploy peer actions- this.peerActions = new yacyPeerActions(this, newsPool);+ this.peerActions = new yacyPeerActions(this, this.newsPool);}-+private synchronized void initMySeed() {if (this.mySeed != null) return;-+// create or init own seed- if (myOwnSeedFile.length() > 0) try {+ if (this.myOwnSeedFile.length() > 0) try {// load existing identity- mySeed = yacySeed.load(myOwnSeedFile);- if (mySeed == null) throw new IOException("current seed is null");+ this.mySeed = yacySeed.load(this.myOwnSeedFile);+ if (this.mySeed == null) throw new IOException("current seed is null");} catch (final IOException e) {// create new identity- Log.logSevere("SEEDDB", "could not load stored mySeed.txt from " + myOwnSeedFile.toString() + ": " + e.getMessage() + ". creating new seed.", e);- mySeed = yacySeed.genLocalSeed(this);+ Log.logSevere("SEEDDB", "could not load stored mySeed.txt from " + this.myOwnSeedFile.toString() + ": " + e.getMessage() + ". creating new seed.", e);+ this.mySeed = yacySeed.genLocalSeed(this);try {- mySeed.save(myOwnSeedFile);+ this.mySeed.save(this.myOwnSeedFile);} catch (final IOException ee) {- Log.logSevere("SEEDDB", "error saving mySeed.txt (1) to " + myOwnSeedFile.toString() + ": " + ee.getMessage(), ee);+ Log.logSevere("SEEDDB", "error saving mySeed.txt (1) to " + this.myOwnSeedFile.toString() + ": " + ee.getMessage(), ee);Log.logException(ee);System.exit(-1);}} else {// create new identity- Log.logInfo("SEEDDB", "could not find stored mySeed.txt at " + myOwnSeedFile.toString() + ": " + ". creating new seed.");- mySeed = yacySeed.genLocalSeed(this);+ Log.logInfo("SEEDDB", "could not find stored mySeed.txt at " + this.myOwnSeedFile.toString() + ": " + ". creating new seed.");+ this.mySeed = yacySeed.genLocalSeed(this);try {- mySeed.save(myOwnSeedFile);+ this.mySeed.save(this.myOwnSeedFile);} catch (final IOException ee) {- Log.logSevere("SEEDDB", "error saving mySeed.txt (2) to " + myOwnSeedFile.toString() + ": " + ee.getMessage(), ee);+ Log.logSevere("SEEDDB", "error saving mySeed.txt (2) to " + this.myOwnSeedFile.toString() + ": " + ee.getMessage(), ee);Log.logException(ee);System.exit(-1);}}this.myBotIDs.add(this.mySeed.getName() + ".yacy");this.myBotIDs.add(this.mySeed.hash + ".yacyh");- mySeed.setIP(""); // we delete the old information to see what we have now- mySeed.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN); // markup startup condition+ this.mySeed.setIP(""); // we delete the old information to see what we have now+ this.mySeed.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN); // markup startup condition}public Set<String> myBotIDs() {return this.myBotIDs;}-+public int redundancy() {if (this.mySeed.isJunior()) return 1;return this.netRedundancy;}-+public boolean mySeedIsDefined() {return this.mySeed != null;}-+public yacySeed mySeed() {if (this.mySeed == null) {- if (this.sizeConnected() == 0) try {Thread.sleep(5000);} catch (final InterruptedException e) {} // wait for init+ if (sizeConnected() == 0) try {Thread.sleep(5000);} catch (final InterruptedException e) {} // wait for initinitMySeed();// check if my seed has an IP assigned- if (this.myIP() == null || this.myIP().length() == 0) {+ if (myIP() == null || myIP().length() == 0) {this.mySeed.setIP(Domains.myPublicLocalIP().getHostAddress());}}return this.mySeed;}-- public void setMyName(String name) {++ public void setMyName(final String name) {this.myBotIDs.remove(this.mySeed.getName() + ".yacy");this.mySeed.setName(name);this.myBotIDs.add(name + ".yacy");}-+public String myAlternativeAddress() {return mySeed().getName() + ".yacy";}-+public String myIP() {return mySeed().getIP();}-+public int myPort() {return mySeed().getPort();}-+public String myName() {- return mySeed.getName();+ return this.mySeed.getName();}-+public String myID() {- return mySeed.hash;+ return this.mySeed.hash;}-+public synchronized void removeMySeed() {- if (seedActiveDB.isEmpty() && seedPassiveDB.isEmpty() && seedPotentialDB.isEmpty()) return; // avoid that the own seed is initialized too early+ if (this.seedActiveDB.isEmpty() && this.seedPassiveDB.isEmpty() && this.seedPotentialDB.isEmpty()) return; // avoid that the own seed is initialized too earlyif (this.mySeed == null) initMySeed();try {- byte[] mySeedHash = ASCII.getBytes(mySeed.hash);- seedActiveDB.delete(mySeedHash);- seedPassiveDB.delete(mySeedHash);- seedPotentialDB.delete(mySeedHash);+ final byte[] mySeedHash = ASCII.getBytes(this.mySeed.hash);+ this.seedActiveDB.delete(mySeedHash);+ this.seedPassiveDB.delete(mySeedHash);+ this.seedPotentialDB.delete(mySeedHash);} catch (final IOException e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }}-+public void saveMySeed() {try {- this.mySeed().save(myOwnSeedFile);- } catch (final IOException e) { Log.logWarning("yacySeedDB", "could not save mySeed '"+ myOwnSeedFile +"': "+ e.getMessage()); }+ mySeed().save(this.myOwnSeedFile);+ } catch (final IOException e) { Log.logWarning("yacySeedDB", "could not save mySeed '"+ this.myOwnSeedFile +"': "+ e.getMessage()); }}-+public boolean noDHTActivity() {// for small networks, we don't perform DHT transmissions, because it is possible to search over all peers- return this.sizeConnected() <= dhtActivityMagic;+ return sizeConnected() <= dhtActivityMagic;}-+private synchronized MapDataMining openSeedTable(final File seedDBFile) {- final File parentDir = new File(seedDBFile.getParent());+ final File parentDir = new File(seedDBFile.getParent());if (!parentDir.exists()) {if(!parentDir.mkdirs())Log.logWarning("yacySeedDB", "could not create directories for "+ seedDBFile.getParent());@@ -330,14 +328,14 @@ public final class yacySeedDB implements AlternativeDomainNames {FileUtils.deletedelete(seedDBFile);try {return new MapDataMining(seedDBFile, Word.commonHashLength, Base64Order.enhancedCoder, 1024 * 512, 500, sortFields, longaccFields, doubleaccFields, this);- } catch (IOException e1) {+ } catch (final IOException e1) {Log.logException(e1);System.exit(-1);return null;}}}-+private synchronized MapDataMining resetSeedTable(MapDataMining seedDB, final File seedDBFile) {// this is an emergency function that should only be used if any problem with the// seed.db is detected@@ -350,34 +348,34 @@ public final class yacySeedDB implements AlternativeDomainNames {seedDB = openSeedTable(seedDBFile);return seedDB;}-- public synchronized void resetActiveTable() { seedActiveDB = resetSeedTable(seedActiveDB, seedActiveDBFile); }- private synchronized void resetPassiveTable() { seedPassiveDB = resetSeedTable(seedPassiveDB, seedPassiveDBFile); }- private synchronized void resetPotentialTable() { seedPotentialDB = resetSeedTable(seedPotentialDB, seedPotentialDBFile); }-++ public synchronized void resetActiveTable() { this.seedActiveDB = resetSeedTable(this.seedActiveDB, this.seedActiveDBFile); }+ private synchronized void resetPassiveTable() { this.seedPassiveDB = resetSeedTable(this.seedPassiveDB, this.seedPassiveDBFile); }+ private synchronized void resetPotentialTable() { this.seedPotentialDB = resetSeedTable(this.seedPotentialDB, this.seedPotentialDBFile); }+public void close() {- if (seedActiveDB != null) seedActiveDB.close();- if (seedPassiveDB != null) seedPassiveDB.close();- if (seedPotentialDB != null) seedPotentialDB.close();- newsPool.close();- peerActions.close();+ if (this.seedActiveDB != null) this.seedActiveDB.close();+ if (this.seedPassiveDB != null) this.seedPassiveDB.close();+ if (this.seedPotentialDB != null) this.seedPotentialDB.close();+ this.newsPool.close();+ this.peerActions.close();}-+public Iterator<yacySeed> seedsSortedConnected(final boolean up, final String field) {// enumerates seed-type objects: all seeds sequentially ordered by field- return new seedEnum(up, field, seedActiveDB);+ return new seedEnum(up, field, this.seedActiveDB);}-+public Iterator<yacySeed> seedsSortedDisconnected(final boolean up, final String field) {// enumerates seed-type objects: all seeds sequentially ordered by field- return new seedEnum(up, field, seedPassiveDB);+ return new seedEnum(up, field, this.seedPassiveDB);}-+public Iterator<yacySeed> seedsSortedPotential(final boolean up, final String field) {// enumerates seed-type objects: all seeds sequentially ordered by field- return new seedEnum(up, field, seedPotentialDB);+ return new seedEnum(up, field, this.seedPotentialDB);}-+public TreeMap<byte[], String> /* peer-b64-hashes/ipport */ clusterHashes(final String clusterdefinition) {// collects seeds according to cluster definition string, which consists of// comma-separated .yacy or .yacyh-domains@@ -392,13 +390,13 @@ public final class yacySeedDB implements AlternativeDomainNames {yacySeed seed;String hash, yacydom, ipport;int p;- for (int i = 0; i < addresses.length; i++) {- p = addresses[i].indexOf('=');+ for (final String addresse : addresses) {+ p = addresse.indexOf('=');if (p >= 0) {- yacydom = addresses[i].substring(0, p);- ipport = addresses[i].substring(p + 1);+ yacydom = addresse.substring(0, p);+ ipport = addresse.substring(p + 1);} else {- yacydom = addresses[i];+ yacydom = addresse;ipport = null;}if (yacydom.endsWith(".yacyh")) {@@ -419,27 +417,27 @@ public final class yacySeedDB implements AlternativeDomainNames {clustermap.put(ASCII.getBytes(seed.hash), ipport);}} else {- yacyCore.log.logWarning("cluster peer '" + addresses[i] + "' has wrong syntax. the name must end with .yacy or .yacyh");+ yacyCore.log.logWarning("cluster peer '" + addresse + "' has wrong syntax. the name must end with .yacy or .yacyh");}}return clustermap;}-+public Iterator<yacySeed> seedsConnected(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {// enumerates seed-type objects: all seeds sequentially without order- return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, seedActiveDB, minVersion);+ return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, this.seedActiveDB, minVersion);}-+private Iterator<yacySeed> seedsDisconnected(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {// enumerates seed-type objects: all seeds sequentially without order- return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, seedPassiveDB, minVersion);+ return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, this.seedPassiveDB, minVersion);}-+private Iterator<yacySeed> seedsPotential(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {// enumerates seed-type objects: all seeds sequentially without order- return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, seedPotentialDB, minVersion);+ return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, this.seedPotentialDB, minVersion);}-+public yacySeed anySeedVersion(final float minVersion) {// return just any seed that has a specific minimum version numberfinal Iterator<yacySeed> e = seedsConnected(true, true, yacySeed.randomHash(), minVersion);@@ -451,8 +449,8 @@ public final class yacySeedDB implements AlternativeDomainNames {* @param limit the time limit in minutes. 1440 minutes is a day* @return the number of peers seen in the given time*/- public int sizeActiveSince(long limit) {- int c = seedActiveDB.size();+ public int sizeActiveSince(final long limit) {+ int c = this.seedActiveDB.size();yacySeed seed;Iterator<yacySeed> i = seedsSortedDisconnected(false, yacySeed.LASTSEEN);while (i.hasNext()) {@@ -472,163 +470,163 @@ public final class yacySeedDB implements AlternativeDomainNames {}return c;}-+public int sizeConnected() {- return seedActiveDB.size();+ return this.seedActiveDB.size();}-+public int sizeDisconnected() {- return seedPassiveDB.size();+ return this.seedPassiveDB.size();}-+public int sizePotential() {- return seedPotentialDB.size();+ return this.seedPotentialDB.size();}-- public long countActiveURL() { return seedActiveDB.getLongAcc(yacySeed.LCOUNT); }- public long countActiveRWI() { return seedActiveDB.getLongAcc(yacySeed.ICOUNT); }- public long countActivePPM() { return seedActiveDB.getLongAcc(yacySeed.ISPEED); }- public float countActiveQPM() { return seedActiveDB.getFloatAcc(yacySeed.RSPEED); }- public long countPassiveURL() { return seedPassiveDB.getLongAcc(yacySeed.LCOUNT); }- public long countPassiveRWI() { return seedPassiveDB.getLongAcc(yacySeed.ICOUNT); }- public long countPotentialURL() { return seedPotentialDB.getLongAcc(yacySeed.LCOUNT); }- public long countPotentialRWI() { return seedPotentialDB.getLongAcc(yacySeed.ICOUNT); }-- public synchronized void addConnected(final yacySeed seed) {++ public long countActiveURL() { return this.seedActiveDB.getLongAcc(yacySeed.LCOUNT); }+ public long countActiveRWI() { return this.seedActiveDB.getLongAcc(yacySeed.ICOUNT); }+ public long countActivePPM() { return this.seedActiveDB.getLongAcc(yacySeed.ISPEED); }+ public float countActiveQPM() { return this.seedActiveDB.getFloatAcc(yacySeed.RSPEED); }+ public long countPassiveURL() { return this.seedPassiveDB.getLongAcc(yacySeed.LCOUNT); }+ public long countPassiveRWI() { return this.seedPassiveDB.getLongAcc(yacySeed.ICOUNT); }+ public long countPotentialURL() { return this.seedPotentialDB.getLongAcc(yacySeed.LCOUNT); }+ public long countPotentialRWI() { return this.seedPotentialDB.getLongAcc(yacySeed.ICOUNT); }++ public void addConnected(final yacySeed seed) {if (seed.isProper(false) != null) return;//seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));- try {- nameLookupCache.put(seed.getName(), seed.hash);- final Map<String, String> seedPropMap = seed.getMap();- synchronized (seedPropMap) {- seedActiveDB.insert(ASCII.getBytes(seed.hash), seedPropMap);+ synchronized (this) {+ try {+ this.nameLookupCache.put(seed.getName(), seed.hash);+ final ConcurrentMap<String, String> seedPropMap = seed.getMap();+ this.seedActiveDB.insert(ASCII.getBytes(seed.hash), seedPropMap);+ this.seedPassiveDB.delete(ASCII.getBytes(seed.hash));+ this.seedPotentialDB.delete(ASCII.getBytes(seed.hash));+ } catch (final Exception e) {+ yacyCore.log.logSevere("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);+ resetActiveTable();}- seedPassiveDB.delete(ASCII.getBytes(seed.hash));- seedPotentialDB.delete(ASCII.getBytes(seed.hash));- } catch (final Exception e) {- yacyCore.log.logSevere("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- resetActiveTable();}}- protected synchronized void addDisconnected(final yacySeed seed) {+ protected void addDisconnected(final yacySeed seed) {if (seed.isProper(false) != null) return;- try {- nameLookupCache.remove(seed.getName());- seedActiveDB.delete(ASCII.getBytes(seed.hash));- seedPotentialDB.delete(ASCII.getBytes(seed.hash));- } catch (final Exception e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }- //seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));- try {- final Map<String, String> seedPropMap = seed.getMap();- synchronized (seedPropMap) {- seedPassiveDB.insert(ASCII.getBytes(seed.hash), seedPropMap);+ synchronized (this) {+ try {+ this.nameLookupCache.remove(seed.getName());+ this.seedActiveDB.delete(ASCII.getBytes(seed.hash));+ this.seedPotentialDB.delete(ASCII.getBytes(seed.hash));+ } catch (final Exception e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }+ //seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));+ try {+ final ConcurrentMap<String, String> seedPropMap = seed.getMap();+ this.seedPassiveDB.insert(ASCII.getBytes(seed.hash), seedPropMap);+ } catch (final Exception e) {+ yacyCore.log.logSevere("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);+ resetPassiveTable();}- } catch (final Exception e) {- yacyCore.log.logSevere("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- resetPassiveTable();}}- protected synchronized void addPotential(final yacySeed seed) {+ protected void addPotential(final yacySeed seed) {if (seed.isProper(false) != null) return;- try {- nameLookupCache.remove(seed.getName());- seedActiveDB.delete(ASCII.getBytes(seed.hash));- seedPassiveDB.delete(ASCII.getBytes(seed.hash));- } catch (final Exception e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }- //seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));- try {- final Map<String, String> seedPropMap = seed.getMap();- synchronized (seedPropMap) {- seedPotentialDB.insert(ASCII.getBytes(seed.hash), seedPropMap);+ synchronized (this) {+ try {+ this.nameLookupCache.remove(seed.getName());+ this.seedActiveDB.delete(ASCII.getBytes(seed.hash));+ this.seedPassiveDB.delete(ASCII.getBytes(seed.hash));+ } catch (final Exception e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }+ //seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));+ try {+ final ConcurrentMap<String, String> seedPropMap = seed.getMap();+ this.seedPotentialDB.insert(ASCII.getBytes(seed.hash), seedPropMap);+ } catch (final Exception e) {+ yacyCore.log.logSevere("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);+ resetPotentialTable();}- } catch (final Exception e) {- yacyCore.log.logSevere("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- resetPotentialTable();}}public synchronized void removeDisconnected(final String peerHash) {- if(peerHash == null) return;+ if (peerHash == null) return;try {- seedPassiveDB.delete(ASCII.getBytes(peerHash));+ this.seedPassiveDB.delete(ASCII.getBytes(peerHash));} catch (final IOException e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }}-+public synchronized void removePotential(final String peerHash) {- if(peerHash == null) return;+ if (peerHash == null) return;try {- seedPotentialDB.delete(ASCII.getBytes(peerHash));+ this.seedPotentialDB.delete(ASCII.getBytes(peerHash));} catch (final IOException e) { Log.logWarning("yacySeedDB", "could not remove hash ("+ e.getClass() +"): "+ e.getMessage()); }}-+public boolean hasConnected(final byte[] hash) {- return seedActiveDB.containsKey(hash);+ return this.seedActiveDB.containsKey(hash);}public boolean hasDisconnected(final byte[] hash) {- return seedPassiveDB.containsKey(hash);+ return this.seedPassiveDB.containsKey(hash);}-+public boolean hasPotential(final byte[] hash) {- return seedPotentialDB.containsKey(hash);+ return this.seedPotentialDB.containsKey(hash);}-+private yacySeed get(final String hash, final MapDataMining database) {if (hash == null || hash.length() == 0) return null;- if ((this.mySeed != null) && (hash.equals(mySeed.hash))) return mySeed;- ConcurrentHashMap<String, String> entry = new ConcurrentHashMap<String, String>();+ if ((this.mySeed != null) && (hash.equals(this.mySeed.hash))) return this.mySeed;+ final ConcurrentHashMap<String, String> entry = new ConcurrentHashMap<String, String>();try {- Map<String, String> map = database.get(ASCII.getBytes(hash));+ final Map<String, String> map = database.get(ASCII.getBytes(hash));if (map == null) return null;entry.putAll(map);} catch (final IOException e) {Log.logException(e);return null;- } catch (RowSpaceExceededException e) {+ } catch (final RowSpaceExceededException e) {Log.logException(e);return null;}return new yacySeed(hash, entry);}-+public yacySeed getConnected(final String hash) {- return get(hash, seedActiveDB);+ return get(hash, this.seedActiveDB);}public yacySeed getDisconnected(final String hash) {- return get(hash, seedPassiveDB);+ return get(hash, this.seedPassiveDB);}-+public yacySeed getPotential(final String hash) {- return get(hash, seedPotentialDB);+ return get(hash, this.seedPotentialDB);}-+public yacySeed get(final String hash) {yacySeed seed = getConnected(hash);if (seed == null) seed = getDisconnected(hash);if (seed == null) seed = getPotential(hash);return seed;}-+public void update(final String hash, final yacySeed seed) {if (this.mySeed == null) initMySeed();- if (hash.equals(mySeed.hash)) {- mySeed = seed;+ if (hash.equals(this.mySeed.hash)) {+ this.mySeed = seed;return;}- byte[] hashb = ASCII.getBytes(hash);- yacySeed s = get(hash, seedActiveDB);- if (s != null) try { seedActiveDB.insert(hashb, seed.getMap()); return;} catch (final Exception e) {Log.logException(e);}-- s = get(hash, seedPassiveDB);- if (s != null) try { seedPassiveDB.insert(hashb, seed.getMap()); return;} catch (final Exception e) {Log.logException(e);}-- s = get(hash, seedPotentialDB);- if (s != null) try { seedPotentialDB.insert(hashb, seed.getMap()); return;} catch (final Exception e) {Log.logException(e);}+ final byte[] hashb = ASCII.getBytes(hash);+ yacySeed s = get(hash, this.seedActiveDB);+ if (s != null) try { this.seedActiveDB.insert(hashb, seed.getMap()); return;} catch (final Exception e) {Log.logException(e);}++ s = get(hash, this.seedPassiveDB);+ if (s != null) try { this.seedPassiveDB.insert(hashb, seed.getMap()); return;} catch (final Exception e) {Log.logException(e);}++ s = get(hash, this.seedPotentialDB);+ if (s != null) try { this.seedPotentialDB.insert(hashb, seed.getMap()); return;} catch (final Exception e) {Log.logException(e);}}-+public yacySeed lookupByName(String peerName) {// reads a seed by searching by nameif (peerName.endsWith(".yacy")) peerName = peerName.substring(0, peerName.length() - 5);@@ -636,17 +634,17 @@ public final class yacySeedDB implements AlternativeDomainNames {// local peer?if (peerName.equals("localpeer")) {if (this.mySeed == null) initMySeed();- return mySeed;+ return this.mySeed;}-+// then try to use the cache- String seedhash = nameLookupCache.get(peerName);+ final String seedhash = this.nameLookupCache.get(peerName);yacySeed seed;if (seedhash != null) {seed = this.get(seedhash);if (seed != null) return seed;}-+// enumerate the cache and simultanous insert valuesString name;for (int table = 0; table < 2; table++) {@@ -655,48 +653,48 @@ public final class yacySeedDB implements AlternativeDomainNames {seed = e.next();if (seed != null) {name = seed.getName().toLowerCase();- if (seed.isProper(false) == null) nameLookupCache.put(name, seed.hash);+ if (seed.isProper(false) == null) this.nameLookupCache.put(name, seed.hash);if (name.equals(peerName)) return seed;}}}// check local seedif (this.mySeed == null) initMySeed();- name = mySeed.getName().toLowerCase();- if (mySeed.isProper(false) == null) nameLookupCache.put(name, mySeed.hash);- if (name.equals(peerName)) return mySeed;+ name = this.mySeed.getName().toLowerCase();+ if (this.mySeed.isProper(false) == null) this.nameLookupCache.put(name, this.mySeed.hash);+ if (name.equals(peerName)) return this.mySeed;// nothing foundreturn null;}-+public yacySeed lookupByIP(- final InetAddress peerIP,- final boolean lookupConnected,+ final InetAddress peerIP,+ final boolean lookupConnected,final boolean lookupDisconnected,final boolean lookupPotential) {-+if (peerIP == null) return null;- yacySeed seed = null;-+ yacySeed seed = null;+// local peer?if (Domains.isThisHostIP(peerIP)) {if (this.mySeed == null) initMySeed();- return mySeed;+ return this.mySeed;}-+// then try to use the cache- final SoftReference<yacySeed> ref = ipLookupCache.get(peerIP);- if (ref != null) {+ final SoftReference<yacySeed> ref = this.ipLookupCache.get(peerIP);+ if (ref != null) {seed = ref.get();if (seed != null) return seed;}int pos = -1;String addressStr = null;- InetAddress seedIPAddress = null;+ InetAddress seedIPAddress = null;final HandleSet badPeerHashes = new HandleSet(12, Base64Order.enhancedCoder, 0);-+if (lookupConnected) {// enumerate the cache and simultanous insert valuesfinal Iterator<yacySeed> e = seedsConnected(true, false, null, (float) 0.0);@@ -708,27 +706,27 @@ public final class yacySeedDB implements AlternativeDomainNames {Log.logWarning("YACY","lookupByIP/Connected: address of seed " + seed.getName() + "/" + seed.hash + " is null.");try {badPeerHashes.put(ASCII.getBytes(seed.hash));- } catch (RowSpaceExceededException e1) {+ } catch (final RowSpaceExceededException e1) {Log.logException(e1);break;}- continue;+ continue;}if ((pos = addressStr.indexOf(':'))!= -1) {addressStr = addressStr.substring(0,pos);}seedIPAddress = Domains.dnsResolve(addressStr);if (seedIPAddress == null) continue;- if (seed.isProper(false) == null) ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(seed));+ if (seed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(seed));if (seedIPAddress.equals(peerIP)) return seed;}}// delete bad peersfinal Iterator<byte[]> i = badPeerHashes.iterator();- while (i.hasNext()) try {seedActiveDB.delete(i.next());} catch (final IOException e1) {Log.logException(e1);}+ while (i.hasNext()) try {this.seedActiveDB.delete(i.next());} catch (final IOException e1) {Log.logException(e1);}badPeerHashes.clear();}-+if (lookupDisconnected) {// enumerate the cache and simultanous insert valuesfinal Iterator<yacySeed>e = seedsDisconnected(true, false, null, (float) 0.0);@@ -741,7 +739,7 @@ public final class yacySeedDB implements AlternativeDomainNames {Log.logWarning("YACY","lookupByIPDisconnected: address of seed " + seed.getName() + "/" + seed.hash + " is null.");try {badPeerHashes.put(UTF8.getBytes(seed.hash));- } catch (RowSpaceExceededException e1) {+ } catch (final RowSpaceExceededException e1) {Log.logException(e1);break;}@@ -752,16 +750,16 @@ public final class yacySeedDB implements AlternativeDomainNames {}seedIPAddress = Domains.dnsResolve(addressStr);if (seedIPAddress == null) continue;- if (seed.isProper(false) == null) ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(seed));+ if (seed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(seed));if (seedIPAddress.equals(peerIP)) return seed;}}// delete bad peersfinal Iterator<byte[]> i = badPeerHashes.iterator();- while (i.hasNext()) try {seedActiveDB.delete(i.next());} catch (final IOException e1) {Log.logException(e1);}+ while (i.hasNext()) try {this.seedActiveDB.delete(i.next());} catch (final IOException e1) {Log.logException(e1);}badPeerHashes.clear();}-+if (lookupPotential) {// enumerate the cache and simultanous insert valuesfinal Iterator<yacySeed> e = seedsPotential(true, false, null, (float) 0.0);@@ -774,43 +772,43 @@ public final class yacySeedDB implements AlternativeDomainNames {}seedIPAddress = Domains.dnsResolve(addressStr);if (seedIPAddress == null) continue;- if (seed.isProper(false) == null) ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(seed));+ if (seed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(seed));if (seedIPAddress.equals(peerIP)) return seed;}}}-+// check local seedif (this.mySeed == null) return null;- addressStr = mySeed.getPublicAddress();+ addressStr = this.mySeed.getPublicAddress();if (addressStr == null) return null;if ((pos = addressStr.indexOf(':'))!= -1) {addressStr = addressStr.substring(0,pos);}seedIPAddress = Domains.dnsResolve(addressStr);if (seedIPAddress == null) return null;- if (mySeed.isProper(false) == null) ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(mySeed));- if (seedIPAddress.equals(peerIP)) return mySeed;+ if (this.mySeed.isProper(false) == null) this.ipLookupCache.put(seedIPAddress, new SoftReference<yacySeed>(this.mySeed));+ if (seedIPAddress.equals(peerIP)) return this.mySeed;// nothing foundreturn null;}private ArrayList<String> storeSeedList(final File seedFile, final boolean addMySeed) throws IOException {PrintWriter pw = null;- final ArrayList<String> v = new ArrayList<String>(seedActiveDB.size() + 1);+ final ArrayList<String> v = new ArrayList<String>(this.seedActiveDB.size() + 1);try {-+pw = new PrintWriter(new BufferedWriter(new FileWriter(seedFile)));-+// store own peer seedString line;if (this.mySeed == null) initMySeed();if (addMySeed) {- line = mySeed.genSeedStr(null);+ line = this.mySeed.genSeedStr(null);v.add(line);pw.print(line + serverCore.CRLF_STRING);}-+// store active peer seedsyacySeed ys;Iterator<yacySeed> se = seedsConnected(true, false, null, (float) 0.0);@@ -822,14 +820,14 @@ public final class yacySeedDB implements AlternativeDomainNames {pw.print(line + serverCore.CRLF_STRING);}}-+// store some of the not-so-old passive peer seeds (limit: 1 day)se = seedsDisconnected(true, false, null, (float) 0.0);- long timeout = System.currentTimeMillis() - (1000L * 60L * 60L * 24L);+ final long timeout = System.currentTimeMillis() - (1000L * 60L * 60L * 24L);while (se.hasNext()) {ys = se.next();if (ys != null) {- if (ys.getLastSeenUTC() < timeout) continue;+ if (ys.getLastSeenUTC() < timeout) continue;line = ys.genSeedStr(null);v.add(line);pw.print(line + serverCore.CRLF_STRING);@@ -842,31 +840,31 @@ public final class yacySeedDB implements AlternativeDomainNames {return v;}- protected String uploadSeedList(final yacySeedUploader uploader,+ protected String uploadSeedList(final yacySeedUploader uploader,final serverSwitch sb,final yacySeedDB seedDB,final DigestURI seedURL) throws Exception {-+// upload a seed file, if possibleif (seedURL == null) throw new NullPointerException("UPLOAD - Error: URL not given");-- String log = null;++ String log = null;File seedFile = null;- try {- // create a seed file which for uploading ...+ try {+ // create a seed file which for uploading ...seedFile = File.createTempFile("seedFile",".txt", seedDB.myOwnSeedFile.getParentFile());seedFile.deleteOnExit();if (Log.isFine("YACY")) Log.logFine("YACY", "SaveSeedList: Storing seedlist into tempfile " + seedFile.toString());- final ArrayList<String> uv = storeSeedList(seedFile, true);-+ final ArrayList<String> uv = storeSeedList(seedFile, true);+// uploading the seed fileif (Log.isFine("YACY")) Log.logFine("YACY", "SaveSeedList: Trying to upload seed-file, " + seedFile.length() + " bytes, " + uv.size() + " entries.");log = uploader.uploadSeedFile(sb, seedFile);-+// test downloadif (Log.isFine("YACY")) Log.logFine("YACY", "SaveSeedList: Trying to download seed-file '" + seedURL + "'.");final Iterator<String> check = downloadSeedFile(seedURL);-+// Comparing if local copy and uploaded copy are equalfinal String errorMsg = checkCache(uv, check);if (errorMsg == null)@@ -882,17 +880,17 @@ public final class yacySeedDB implements AlternativeDomainNames {/* ignore this */}}-+return log;}-+private Iterator<String> downloadSeedFile(final DigestURI seedURL) throws IOException {// Configure http headersfinal RequestHeader reqHeader = new RequestHeader();reqHeader.put(HeaderFramework.PRAGMA, "no-cache");reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache"); // httpc uses HTTP/1.0 is this necessary?reqHeader.put(HeaderFramework.USER_AGENT, ClientIdentification.getUserAgent());-+final HTTPClient client = new HTTPClient();client.setHeader(reqHeader.entrySet());byte[] content = null;@@ -902,12 +900,12 @@ public final class yacySeedDB implements AlternativeDomainNames {} catch (final Exception e) {throw new IOException("Unable to download seed file '" + seedURL + "'. " + e.getMessage());}-+// check response codeif (client.getHttpResponse().getStatusLine().getStatusCode() != 200) {throw new IOException("Server returned status: " + client.getHttpResponse().getStatusLine());}-+try {// uncompress it if it is gzippedcontent = FileUtils.uncompressGZipArray(content);@@ -919,19 +917,19 @@ public final class yacySeedDB implements AlternativeDomainNames {}}- private String checkCache(final ArrayList<String> uv, final Iterator<String> check) {+ private String checkCache(final ArrayList<String> uv, final Iterator<String> check) {if ((check == null) || (uv == null)) {if (Log.isFine("YACY")) Log.logFine("YACY", "SaveSeedList: Local and uploades seed-list are different");return "Entry count is different: uv.size() = " + ((uv == null) ? "null" : Integer.toString(uv.size()));}-+if (Log.isFine("YACY")) Log.logFine("YACY", "SaveSeedList: Comparing local and uploades seed-list entries ...");int i = 0;while (check.hasNext() && i < uv.size()) {if (!((uv.get(i)).equals(check.next()))) return "Element at position " + i + " is different.";i++;}-+// no difference foundreturn null;}@@ -962,8 +960,8 @@ public final class yacySeedDB implements AlternativeDomainNames {// check local seedif (seed == null) {if (this.mySeed == null) initMySeed();- if (hash.equals(mySeed.hash))- seed = mySeed;+ if (hash.equals(this.mySeed.hash))+ seed = this.mySeed;else return null;}return seed.getPublicAddress() + ((subdom == null) ? "" : ("/" + subdom));@@ -979,7 +977,7 @@ public final class yacySeedDB implements AlternativeDomainNames {seed = lookupByName(domain);if (seed == null) return null;if (this.mySeed == null) initMySeed();- if ((seed == mySeed) && (!(seed.isOnline()))) {+ if ((seed == this.mySeed) && (!(seed.isOnline()))) {// take local ip instead of externalreturn Switchboard.getSwitchboard().myPublicIP() + ":" + Switchboard.getSwitchboard().getConfig("port", "8090") + ((subdom == null) ? "" : ("/" + subdom));}@@ -990,81 +988,81 @@ public final class yacySeedDB implements AlternativeDomainNames {}public String targetAddress(final String targetHash) {- // find target address+ // find target addressString address;- if (targetHash.equals(this.mySeed().hash)) {- address = this.mySeed().getClusterAddress();+ if (targetHash.equals(mySeed().hash)) {+ address = mySeed().getClusterAddress();} else {- final yacySeed targetSeed = this.getConnected(targetHash);+ final yacySeed targetSeed = getConnected(targetHash);if (targetSeed == null) { return null; }address = targetSeed.getClusterAddress();}if (address == null) address = "localhost:8090";return address;}-+private class seedEnum implements Iterator<yacySeed> {-+private MapDataMining.mapIterator it;private yacySeed nextSeed;- private MapDataMining database;+ private final MapDataMining database;private float minVersion;-+private seedEnum(final boolean up, final boolean rot, final byte[] firstKey, final byte[] secondKey, final MapDataMining database, final float minVersion) {this.database = database;this.minVersion = minVersion;try {- it = (firstKey == null) ? database.maps(up, rot) : database.maps(up, rot, firstKey, secondKey);+ this.it = (firstKey == null) ? database.maps(up, rot) : database.maps(up, rot, firstKey, secondKey);float version;while (true) {- nextSeed = internalNext();- if (nextSeed == null) break;- version = nextSeed.getVersion();+ this.nextSeed = internalNext();+ if (this.nextSeed == null) break;+ version = this.nextSeed.getVersion();if (version >= this.minVersion || version == 0.0) break; // include 0.0 to access always developer peers}} catch (final IOException e) {Log.logException(e);yacyCore.log.logSevere("ERROR seedLinEnum: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- if (database == seedActiveDB) seedActiveDB = resetSeedTable(seedActiveDB, seedActiveDBFile);- if (database == seedPassiveDB) seedPassiveDB = resetSeedTable(seedPassiveDB, seedPassiveDBFile);- it = null;+ if (database == yacySeedDB.this.seedActiveDB) yacySeedDB.this.seedActiveDB = resetSeedTable(yacySeedDB.this.seedActiveDB, yacySeedDB.this.seedActiveDBFile);+ if (database == yacySeedDB.this.seedPassiveDB) yacySeedDB.this.seedPassiveDB = resetSeedTable(yacySeedDB.this.seedPassiveDB, yacySeedDB.this.seedPassiveDBFile);+ this.it = null;} catch (final kelondroException e) {Log.logException(e);yacyCore.log.logSevere("ERROR seedLinEnum: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- if (database == seedActiveDB) seedActiveDB = resetSeedTable(seedActiveDB, seedActiveDBFile);- if (database == seedPassiveDB) seedPassiveDB = resetSeedTable(seedPassiveDB, seedPassiveDBFile);- it = null;+ if (database == yacySeedDB.this.seedActiveDB) yacySeedDB.this.seedActiveDB = resetSeedTable(yacySeedDB.this.seedActiveDB, yacySeedDB.this.seedActiveDBFile);+ if (database == yacySeedDB.this.seedPassiveDB) yacySeedDB.this.seedPassiveDB = resetSeedTable(yacySeedDB.this.seedPassiveDB, yacySeedDB.this.seedPassiveDBFile);+ this.it = null;}}-+private seedEnum(final boolean up, final String field, final MapDataMining database) {this.database = database;try {- it = database.maps(up, field);- nextSeed = internalNext();+ this.it = database.maps(up, field);+ this.nextSeed = internalNext();} catch (final kelondroException e) {Log.logException(e);yacyCore.log.logSevere("ERROR seedLinEnum: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- if (database == seedActiveDB) seedActiveDB = resetSeedTable(seedActiveDB, seedActiveDBFile);- if (database == seedPassiveDB) seedPassiveDB = resetSeedTable(seedPassiveDB, seedPassiveDBFile);- if (database == seedPotentialDB) seedPotentialDB = resetSeedTable(seedPotentialDB, seedPotentialDBFile);- it = null;+ if (database == yacySeedDB.this.seedActiveDB) yacySeedDB.this.seedActiveDB = resetSeedTable(yacySeedDB.this.seedActiveDB, yacySeedDB.this.seedActiveDBFile);+ if (database == yacySeedDB.this.seedPassiveDB) yacySeedDB.this.seedPassiveDB = resetSeedTable(yacySeedDB.this.seedPassiveDB, yacySeedDB.this.seedPassiveDBFile);+ if (database == yacySeedDB.this.seedPotentialDB) yacySeedDB.this.seedPotentialDB = resetSeedTable(yacySeedDB.this.seedPotentialDB, yacySeedDB.this.seedPotentialDBFile);+ this.it = null;}}-+public boolean hasNext() {- return (nextSeed != null);+ return (this.nextSeed != null);}-+private yacySeed internalNext() {- if (it == null || !(it.hasNext())) return null;+ if (this.it == null || !(this.it.hasNext())) return null;try {Map<String, String> dna0;ConcurrentHashMap<String, String> dna;- while (it.hasNext()) {+ while (this.it.hasNext()) {try {- dna0 = it.next();- } catch (OutOfMemoryError e) {+ dna0 = this.it.next();+ } catch (final OutOfMemoryError e) {Log.logException(e);dna0 = null;}@@ -1085,27 +1083,27 @@ public final class yacySeedDB implements AlternativeDomainNames {} catch (final Exception e) {Log.logException(e);yacyCore.log.logSevere("ERROR internalNext: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);- if (database == seedActiveDB) seedActiveDB = resetSeedTable(seedActiveDB, seedActiveDBFile);- if (database == seedPassiveDB) seedPassiveDB = resetSeedTable(seedPassiveDB, seedPassiveDBFile);- if (database == seedPotentialDB) seedPotentialDB = resetSeedTable(seedPotentialDB, seedPotentialDBFile);+ if (this.database == yacySeedDB.this.seedActiveDB) yacySeedDB.this.seedActiveDB = resetSeedTable(yacySeedDB.this.seedActiveDB, yacySeedDB.this.seedActiveDBFile);+ if (this.database == yacySeedDB.this.seedPassiveDB) yacySeedDB.this.seedPassiveDB = resetSeedTable(yacySeedDB.this.seedPassiveDB, yacySeedDB.this.seedPassiveDBFile);+ if (this.database == yacySeedDB.this.seedPotentialDB) yacySeedDB.this.seedPotentialDB = resetSeedTable(yacySeedDB.this.seedPotentialDB, yacySeedDB.this.seedPotentialDBFile);return null;}}-+public yacySeed next() {- final yacySeed seed = nextSeed;+ final yacySeed seed = this.nextSeed;float version;try {while (true) {- nextSeed = internalNext();- if (nextSeed == null) break;- version = nextSeed.getVersion();+ this.nextSeed = internalNext();+ if (this.nextSeed == null) break;+ version = this.nextSeed.getVersion();if (version >= this.minVersion || version == 0.0) break; // include 0.0 to access always developer peers}} catch (final kelondroException e) {Log.logException(e);// emergency resetyacyCore.log.logSevere("seed-db emergency reset", e);- database.clear();- nextSeed = null;+ this.database.clear();+ this.nextSeed = null;return null;}return seed;@@ -1114,7 +1112,7 @@ public final class yacySeedDB implements AlternativeDomainNames {public void remove() {throw new UnsupportedOperationException();}-+}}diff --git a/source/net/yacy/cora/date/GenericFormatter.java b/source/net/yacy/cora/date/GenericFormatter.javaindex e2ce661a0..d79a10337 100644--- a/source/net/yacy/cora/date/GenericFormatter.java+++ b/source/net/yacy/cora/date/GenericFormatter.java@@ -95,15 +95,15 @@ public class GenericFormatter extends AbstractFormatter implements DateFormatterpublic String format() {if (Math.abs(System.currentTimeMillis() - this.last_time) < this.maxCacheDiff) return this.last_format;+ // threads that had been waiting here may use the cache now instead of calculating the date again+ final long time = System.currentTimeMillis();++ // if the cache is not fresh, calculate the datesynchronized (this.dateFormat) {- // threads that had been waiting here may use the cache now instead of calculating the date again- final long time = System.currentTimeMillis();if (Math.abs(time - this.last_time) < this.maxCacheDiff) return this.last_format;-- // if the cache is not fresh, calculate the datethis.last_format = this.dateFormat.format(new Date(time));- this.last_time = time;}+ this.last_time = time;return this.last_format;}