cleaned, finals, Properties

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@884 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 20 years ago
parent 45f55a6fad
commit 4180c422e8

@ -1,9 +1,12 @@
// yacyCore.java
// yacyCore.java
// -------------------------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last major change: 03.12.2004
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -63,11 +66,11 @@ import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
import de.anomic.http.httpc;
import de.anomic.net.natLib;
import de.anomic.plasma.plasmaSwitchboard;
@ -75,9 +78,10 @@ import de.anomic.server.serverSemaphore;
import de.anomic.server.serverSwitch;
import de.anomic.server.serverDate;
import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacySeed;
public class yacyCore {
// statics
public static ThreadGroup publishThreadGroup = new ThreadGroup("publishThreadGroup");
public static long startupTime = System.currentTimeMillis();
@ -91,44 +95,42 @@ public class yacyCore {
public static float latestVersion = (float) 0.1;
public static long speedKey = 0;
public static File yacyDBPath;
//public static yacyShare shareManager = null;
//public static boolean terminate = false;
// public static yacyShare shareManager = null;
// public static boolean terminate = false;
// class variables
private int lastSeedUpload_seedDBSize = 0;
private int lastSeedUpload_seedDBSize = 0;
public long lastSeedUpload_timeStamp = System.currentTimeMillis();
private String lastSeedUpload_myPeerType = "";
private String lastSeedUpload_myPeerType = "";
private String lastSeedUpload_myIP = "";
private int onlineMode = 1;
private plasmaSwitchboard switchboard;
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("America/Los_Angeles");
public static String universalDateShortPattern = "yyyyMMddHHmmss";
public static SimpleDateFormat shortFormatter = new SimpleDateFormat(universalDateShortPattern);
/*
public static long universalTime() {
return universalDate().getTime();
return universalDate().getTime();
}
public static Date universalDate() {
return new GregorianCalendar(GMTTimeZone).getTime();
return new GregorianCalendar(GMTTimeZone).getTime();
}
public static String universalDateShortString() {
return universalDateShortString(universalDate());
return universalDateShortString(universalDate());
}
*/
public static String universalDateShortString(Date date) {
return shortFormatter.format(date);
return shortFormatter.format(date);
}
public static Date parseUniversalDate(String remoteTimeString, String remoteUTCOffset) {
if ((remoteTimeString == null) || (remoteTimeString.length() == 0)) return new Date();
if ((remoteUTCOffset == null) || (remoteUTCOffset.length() == 0)) return new Date();
if (remoteTimeString == null || remoteTimeString.length() == 0) { return new Date(); }
if (remoteUTCOffset == null || remoteUTCOffset.length() == 0) { return new Date(); }
try {
return new Date(yacyCore.shortFormatter.parse(remoteTimeString).getTime() - serverDate.UTCDiff() + serverDate.UTCDiff(remoteUTCOffset));
} catch (java.text.ParseException e) {
@ -139,42 +141,42 @@ public class yacyCore {
return new Date();
}
}
public static int yacyTime() {
// the time since startup of yacy in seconds
return (int) ((System.currentTimeMillis() - startupTime) / 1000);
}
public yacyCore(plasmaSwitchboard sb) throws IOException {
long time = System.currentTimeMillis();
this.switchboard = sb;
switchboard.setConfig("yacyStatus","");
switchboard.setConfig("yacyStatus", "");
// set log level
log = new serverLog("YACY");
// create a yacy db
yacyDBPath = new File(sb.getRootPath(), sb.getConfig("yacyDB", "DATA/YACYDB"));
if (!(yacyDBPath.exists())) yacyDBPath.mkdir();
if (!yacyDBPath.exists()) { yacyDBPath.mkdir(); }
// create or init seed cache
int memDHT = Integer.parseInt(switchboard.getConfig("ramCacheDHT", "1024")) / 1024;
log.logConfig("DHT Cache memory = " + memDHT + " KB");
seedDB = new yacySeedDB(
sb,
sb,
new File(yacyDBPath, "seed.new.db"),
new File(yacyDBPath, "seed.old.db"),
new File(yacyDBPath, "seed.pot.db"),
memDHT);
// create or init news database
int memNews = Integer.parseInt(switchboard.getConfig("ramCacheNews", "1024")) / 1024;
log.logConfig("News Cache memory = " + memNews + " KB");
newsPool = new yacyNewsPool(yacyDBPath, memNews);
loadSeedUploadMethods();
// deploy peer actions
peerActions = new yacyPeerActions(seedDB, switchboard,
new File(sb.getRootPath(), sb.getConfig("superseedFile", "superseed.txt")),
@ -182,27 +184,27 @@ public class yacyCore {
dhtAgent = new yacyDHTAction(seedDB);
peerActions.deploy(dhtAgent);
peerActions.deploy(new yacyNewsAction(newsPool));
// create or init index sharing
//shareManager = new yacyShare(switchboard);
// shareManager = new yacyShare(switchboard);
lastSeedUpload_seedDBSize = seedDB.sizeConnected();
log.logConfig("CORE INITIALIZED");
// ATTENTION, VERY IMPORTANT: before starting the thread, the httpd yacy server must be running!
speedKey = System.currentTimeMillis() - time;
// start with a seedList update to propagate out peer, if possible
onlineMode = Integer.parseInt(switchboard.getConfig("onlineMode", "1"));
//lastSeedUpdate = universalTime();
lastOnlineTime = 0;
// cycle
// within cycle: update seed file, strengthen network, pass news (new, old seed's)
if (online())
if (online()) {
log.logConfig("you are in online mode");
else {
} else {
log.logConfig("YOU ARE OFFLINE! ---");
log.logConfig("--- TO START BOOTSTRAPING, YOU MUST USE THE PROXY,");
log.logConfig("--- OR HIT THE BUTTON 'go online'");
@ -210,26 +212,24 @@ public class yacyCore {
}
}
synchronized static public void triggerOnlineAction() {
lastOnlineTime = System.currentTimeMillis();
}
public boolean online() {
this.onlineMode = Integer.parseInt(switchboard.getConfig("onlineMode", "1"));
this.onlineMode = Integer.parseInt(switchboard.getConfig("onlineMode", "1"));
return ((onlineMode == 2) || ((System.currentTimeMillis() - lastOnlineTime) < 10000));
}
public void loadSeeds() {
//new Thread(new vprobe()).start();
//new Thread(new vprobe()).start();
peerActions.loadSeedLists(); // start to bootstrap the network here
publishSeedList();
}
public void publishSeedList() {
log.logFine("yacyCore.publishSeedList: Triggered Seed Publish");
/*
if (oldIPStamp.equals((String) seedDB.mySeed.get("IP", "127.0.0.1")))
yacyCore.log.logDebug("***DEBUG publishSeedList: oldIP is equal");
@ -238,7 +238,7 @@ public class yacyCore {
if (canReachMyself())
yacyCore.log.logDebug("***DEBUG publishSeedList: I can reach myself");
*/
if (
(this.lastSeedUpload_myIP.equals(seedDB.mySeed.get("IP", "127.0.0.1"))) &&
(this.lastSeedUpload_seedDBSize == seedDB.sizeConnected()) &&
@ -249,97 +249,92 @@ public class yacyCore {
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 ...
String seedUploadMethod = this.switchboard.getConfig("seedUploadMethod","");
final String seedUploadMethod = this.switchboard.getConfig("seedUploadMethod", "");
if (
(!seedUploadMethod.equalsIgnoreCase("none")) ||
((seedUploadMethod.equals("")) && (this.switchboard.getConfig("seedFTPPassword","").length() > 0)) ||
(!seedUploadMethod.equalsIgnoreCase("none")) ||
((seedUploadMethod.equals("")) && (this.switchboard.getConfig("seedFTPPassword", "").length() > 0)) ||
((seedUploadMethod.equals("")) && (this.switchboard.getConfig("seedFilePath", "").length() > 0))
) {
if (seedUploadMethod.equals("")) {
if (this.switchboard.getConfig("seedFTPPassword","").length() > 0)
if (this.switchboard.getConfig("seedFTPPassword", "").length() > 0)
this.switchboard.setConfig("seedUploadMethod","Ftp");
if (this.switchboard.getConfig("seedFilePath","").length() > 0)
this.switchboard.setConfig("seedUploadMethod","File");
if (this.switchboard.getConfig("seedFilePath", "").length() > 0)
this.switchboard.setConfig("seedUploadMethod","File");
}
// we want to be a principal...
saveSeedList();
saveSeedList();
} else {
if (seedUploadMethod.equals("")) this.switchboard.setConfig("seedUploadMethod","none");
log.logFine("yacyCore.publishSeedList: No uploading method configured");
return;
}
}
public void peerPing() {
if (!(online())) return;
if (!online()) return;
// before publishing, update some seed data
peerActions.updateMySeed();
// publish own seed to other peer, this can every peer, but makes only sense for senior peers
int oldSize = seedDB.sizeConnected();
final int oldSize = seedDB.sizeConnected();
if (oldSize == 0) {
// reload the seed lists
peerActions.loadSeedLists();
log.logInfo("re-initialized seed list. received " + seedDB.sizeConnected() + " new peer(s)");
}
int newSeeds = publishMySeed(false);
final int newSeeds = publishMySeed(false);
if (newSeeds > 0) log.logInfo("received " + newSeeds + " new peer(s), know a total of " +
seedDB.sizeConnected() + " different peers");
seedDB.sizeConnected() + " different peers");
}
private boolean canReachMyself() {
// 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
int urlc = yacyClient.queryUrlCount(seedDB.mySeed);
final int urlc = yacyClient.queryUrlCount(seedDB.mySeed);
if (urlc >= 0) {
seedDB.mySeed.put("LastSeen", universalDateShortString(new Date()));
return true;
}
log.logInfo("re-connect own seed");
String oldAddress = seedDB.mySeed.getAddress();
int newSeeds = publishMySeed(true);
return ((oldAddress != null) && (oldAddress.equals(seedDB.mySeed.getAddress())));
final String oldAddress = seedDB.mySeed.getAddress();
final int newSeeds = publishMySeed(true);
return (oldAddress != null && oldAddress.equals(seedDB.mySeed.getAddress()));
}
protected class publishThread extends Thread {
protected class publishThread extends Thread {
public int added;
public yacySeed seed;
public Exception error;
private final serverSemaphore sync;
private final List syncList;
public publishThread(ThreadGroup tg, yacySeed seed, serverSemaphore sync, List syncList) throws InterruptedException {
super(tg, "PublishSeed_" + seed.getName());
this.sync = sync;
this.sync.P();
this.sync.P();
this.syncList = syncList;
this.seed = seed;
this.added = 0;
this.error = null;
}
public void run() {
try {
try {
this.added = yacyClient.publishMySeed(seed.getAddress(), seed.hash);
if (this.added < 0) {
// no or wrong response, delete that address
log.logInfo("publish: disconnected " + this.seed.get("PeerType", "senior") + " peer '" + this.seed.getName() + "' from " + this.seed.getAddress());
log.logInfo("publish: disconnected " + this.seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) + " peer '" + this.seed.getName() + "' from " + this.seed.getAddress());
peerActions.peerDeparture(this.seed);
} 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("PeerType", "senior") + " peer '" + this.seed.getName() + "' at " + this.seed.getAddress());
log.logInfo("publish: handshaked " + this.seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) + " peer '" + this.seed.getName() + "' at " + this.seed.getAddress());
}
} catch (Exception e) {
log.logSevere("publishThread: error with target seed " + seed.toString() + ": " + e.getMessage(), e);
@ -349,13 +344,12 @@ public class yacyCore {
this.sync.V();
}
}
}
private int publishMySeed(boolean force) {
try {
// call this after the httpd was started up
// we need to find out our own ip
// This is not always easy, since the application may
// live behind a firewall or nat.
@ -369,43 +363,44 @@ public class yacyCore {
// only supported for address retrieval
// 3. ask ip respond services in the internet. There are several, and they are all
// probed until we get a valid response.
// init yacyHello-process
yacySeed[] seeds;
int attempts = seedDB.sizeConnected();
if (attempts > 10) attempts = 10;
int attempts = seedDB.sizeConnected();
if (attempts > 10) { attempts = 10; }
// getting a list of peers to contact
if (seedDB.mySeed.get("PeerType", "virgin").equals("virgin")) {
if (seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN).equals(yacySeed.PEERTYPE_VIRGIN)) {
seeds = seedDB.seedsByAge(true, attempts); // best for fast connection
} else {
seeds = seedDB.seedsByAge(false, attempts); // best for seed list maintenance/cleaning
}
if (seeds == null) return 0;
if (seeds == null) { return 0; }
// include a YaCyNews record to my seed
try {
yacyNewsRecord record = newsPool.myPublication();
if (record == null)
final yacyNewsRecord record = newsPool.myPublication();
if (record == null) {
seedDB.mySeed.put("news", "");
else
} else {
seedDB.mySeed.put("news", de.anomic.tools.crypt.simpleEncode(record.toString()));
}
} catch (IOException e) {
log.logSevere("publishMySeed: problem with news encoding", e);
}
// holding a reference to all started threads
int contactedSeedCount = 0;
List syncList = Collections.synchronizedList(new LinkedList()); // memory for threads
serverSemaphore sync = new serverSemaphore(attempts);
final List syncList = Collections.synchronizedList(new LinkedList()); // memory for threads
final serverSemaphore sync = new serverSemaphore(attempts);
// going through the peer list and starting a new publisher thread for each peer
for (int i = 0; i < seeds.length; i++) {
if (seeds[i] == null) continue;
String address = seeds[i].getAddress();
log.logFine("HELLO #" + i + " to peer '" + seeds[i].get("Name", "") + "' at " + address); // debug
final String address = seeds[i].getAddress();
log.logFine("HELLO #" + i + " to peer '" + seeds[i].get("Name", "") + "' at " + address); // debug
if ((address == null) || (seeds[i].isProper() != null)) {
// we don't like that address, delete it
peerActions.peerDeparture(seeds[i]);
@ -416,41 +411,44 @@ public class yacyCore {
(new publishThread(yacyCore.publishThreadGroup,seeds[i],sync,syncList)).start();
}
}
// receiving the result of all started publisher threads
int newSeeds = -1;
for (int j=0; j < contactedSeedCount; j++) {
// waiting for the next thread to finish
sync.P();
sync.P();
// if this is true something is wrong ...
if (syncList.isEmpty()) return 0;
// getting a reference to the finished thread
publishThread t = (publishThread) syncList.remove(0);
final publishThread t = (publishThread) syncList.remove(0);
// getting the amount of new reported seeds
if (t.added >= 0) {
if (newSeeds==-1) newSeeds = t.added;
else newSeeds += t.added;
}
if (newSeeds==-1) {
newSeeds = t.added;
} else {
newSeeds += t.added;
}
}
}
if (newSeeds >= 0) {
// success! we have published our peer to a senior peer
// update latest news from the other peer
//log.logInfo("publish: handshaked " + t.seed.get("PeerType", "senior") + " peer '" + t.seed.getName() + "' at " + t.seed.getAddress());
// log.logInfo("publish: handshaked " + t.seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) + " peer '" + t.seed.getName() + "' at " + t.seed.getAddress());
peerActions.saveMySeed();
return newSeeds;
}
}
// // wait
// try {
// if (i == 0) Thread.currentThread().sleep(2000); // after the first time wait some seconds
// Thread.currentThread().sleep(1000 + 500 * v.size()); // wait a while
// } catch (InterruptedException e) {}
//
//
// // check all threads
// for (int j = 0; j < v.size(); j++) {
// t = (publishThread) v.elementAt(j);
@ -460,27 +458,27 @@ public class yacyCore {
// if (added >= 0) {
// // success! we have published our peer to a senior peer
// // update latest news from the other peer
// //log.logInfo("publish: handshaked " + t.seed.get("PeerType", "senior") + " peer '" + t.seed.getName() + "' at " + t.seed.getAddress());
// //log.logInfo("publish: handshaked " + t.seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) + " peer '" + t.seed.getName() + "' at " + t.seed.getAddress());
// peerActions.saveMySeed();
// return added;
// }
// }
// }
// if we have an address, we do nothing
if ((seedDB.mySeed.isProper() == null) && (!(force))) return 0;
if (seedDB.mySeed.isProper() == null && !force) { return 0; }
// still no success: ask own NAT or internet responder
boolean DI604use = switchboard.getConfig("DI604use", "false").equals("true");
String DI604pw = switchboard.getConfig("DI604pw", "");
final boolean DI604use = switchboard.getConfig("DI604use", "false").equals("true");
final String DI604pw = switchboard.getConfig("DI604pw", "");
String ip = switchboard.getConfig("staticIP", "");
if(ip.equals("")){
if (ip.equals("")) {
ip = natLib.retrieveIP(DI604use, DI604pw);
}
//yacyCore.log.logDebug("DEBUG: new IP=" + ip);
// yacyCore.log.logDebug("DEBUG: new IP=" + ip);
seedDB.mySeed.put("IP", ip);
if (seedDB.mySeed.get("PeerType", "junior").equals("junior")) // ???????????????
seedDB.mySeed.put("PeerType", "senior"); // to start bootstraping, we need to be recognised as "senior" peer
if (seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR).equals(yacySeed.PEERTYPE_JUNIOR)) // ???????????????
seedDB.mySeed.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR); // to start bootstraping, we need to be recognised as PEERTYPE_SENIOR peer
log.logInfo("publish: no recipient found, asked NAT or responder; our address is " +
((seedDB.mySeed.getAddress() == null) ? "unknown" : seedDB.mySeed.getAddress()));
peerActions.saveMySeed();
@ -488,121 +486,121 @@ public class yacyCore {
} catch (InterruptedException e) {
try {
log.logInfo("publish: Interruption detected while publishing my seed.");
// consuming the theads interrupted signal
Thread.interrupted();
// interrupt all already started publishThreads
log.logInfo("publish: Signaling shutdown to " + yacyCore.publishThreadGroup.activeCount() + " remaining publishing threads ...");
yacyCore.publishThreadGroup.interrupt();
// waiting some time for the publishThreads to finish execution
try { Thread.sleep(500); } catch (InterruptedException ex) {}
// getting the amount of remaining publishing threads
int threadCount = yacyCore.publishThreadGroup.activeCount();
Thread[] threadList = new Thread[threadCount];
int threadCount = yacyCore.publishThreadGroup.activeCount();
final Thread[] threadList = new Thread[threadCount];
threadCount = yacyCore.publishThreadGroup.enumerate(threadList);
// we need to use a timeout here because of missing interruptable session threads ...
log.logFine("publish: Trying to abort " + yacyCore.publishThreadGroup.activeCount() + " remaining publishing threads ...");
for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) {
log.logFine("publish: Closing socket of publishing thread '" + currentThread.getName() + "' [" + currentThreadIdx + "].");
httpc.closeOpenSockets(currentThread);
}
}
// we need to use a timeout here because of missing interruptable session threads ...
log.logFine("publish: Waiting for " + yacyCore.publishThreadGroup.activeCount() + " remaining publishing threads to finish shutdown ...");
for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {
Thread currentThread = threadList[currentThreadIdx];
final Thread currentThread = threadList[currentThreadIdx];
if (currentThread.isAlive()) {
log.logFine("publish: Waiting for remaining publishing thread '" + currentThread.getName() + "' to finish shutdown");
try { currentThread.join(500); }catch (InterruptedException ex) {}
}
}
}
log.logInfo("publish: Shutdown off all remaining publishing thread finished.");
}
catch (Exception ee) {
log.logWarning("publish: Unexpected error while trying to shutdown all remaining publishing threads.",e);
log.logWarning("publish: Unexpected error while trying to shutdown all remaining publishing threads.",e);
}
return 0;
}
}
public static HashMap getSeedUploadMethods() {
synchronized (yacyCore.seedUploadMethods) {
return (HashMap) yacyCore.seedUploadMethods.clone();
}
}
}
public static yacySeedUploader getSeedUploader(String methodname) {
String className = null;
synchronized (yacyCore.seedUploadMethods) {
if (yacyCore.seedUploadMethods.containsKey(methodname)) {
className = (String) yacyCore.seedUploadMethods.get(methodname);
}
}
if (className == null) return null;
}
if (className == null) { return null; }
try {
Class uploaderClass = Class.forName(className);
Object uploader = uploaderClass.newInstance();
final Class uploaderClass = Class.forName(className);
final Object uploader = uploaderClass.newInstance();
return (yacySeedUploader) uploader;
} catch (Exception e) {
return null;
}
}
public static void loadSeedUploadMethods() {
HashMap availableUploaders = new HashMap();
final HashMap availableUploaders = new HashMap();
try {
String uploadersPkgName = yacyCore.class.getPackage().getName() + ".seedUpload";
String packageURI = yacyCore.class.getResource("/"+uploadersPkgName.replace('.','/')).toString();
final String uploadersPkgName = yacyCore.class.getPackage().getName() + ".seedUpload";
final String packageURI = yacyCore.class.getResource("/"+uploadersPkgName.replace('.','/')).toString();
// open the parser directory
File uploadersDir = new File(new URI(packageURI));
final File uploadersDir = new File(new URI(packageURI));
if ((uploadersDir == null) || (!uploadersDir.exists()) || (!uploadersDir.isDirectory())) {
yacyCore.seedUploadMethods.clear();
yacyCore.seedUploadMethods.clear();
changeSeedUploadMethod("none");
}
String[] uploaderClasses = uploadersDir.list(new FilenameFilter() {
final String[] uploaderClasses = uploadersDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("yacySeedUpload") && name.endsWith(".class");
}});
String javaClassPath = System.getProperty("java.class.path");
if (uploaderClasses == null) return;
final String javaClassPath = System.getProperty("java.class.path");
if (uploaderClasses == null) { return; }
for (int uploaderNr=0; uploaderNr<uploaderClasses.length; uploaderNr++) {
String className = uploaderClasses[uploaderNr].substring(0,uploaderClasses[uploaderNr].indexOf(".class"));
String fullClassName = uploadersPkgName + "." + className;
final String className = uploaderClasses[uploaderNr].substring(0,uploaderClasses[uploaderNr].indexOf(".class"));
final String fullClassName = uploadersPkgName + "." + className;
try {
Class uploaderClass = Class.forName(fullClassName);
Object theUploader = uploaderClass.newInstance();
if (!(theUploader instanceof yacySeedUploader)) continue;
String[] neededLibx = ((yacySeedUploader)theUploader).getLibxDependences();
final Class uploaderClass = Class.forName(fullClassName);
final Object theUploader = uploaderClass.newInstance();
if (!(theUploader instanceof yacySeedUploader)) { continue; }
final String[] neededLibx = ((yacySeedUploader)theUploader).getLibxDependences();
if (neededLibx != null) {
for (int libxId=0; libxId < neededLibx.length; libxId++) {
if (javaClassPath.indexOf(neededLibx[libxId]) == -1)
if (javaClassPath.indexOf(neededLibx[libxId]) == -1) {
throw new Exception("Missing dependency");
}
}
}
availableUploaders.put(className.substring("yacySeedUpload".length()),fullClassName);
} catch (Exception e) { /* we can ignore this for the moment */
} catch (Exception e) { /* we can ignore this for the moment */
} catch (Error e) { /* we can ignore this for the moment */ }
}
} catch (Exception e) {
} finally {
synchronized (yacyCore.seedUploadMethods) {
yacyCore.seedUploadMethods.clear();
@ -612,114 +610,110 @@ public class yacyCore {
}
public static boolean changeSeedUploadMethod(String method) {
if ((method == null)||(method.length() == 0)) return false;
if (method == null || method.length() == 0) return false;
if (method.equalsIgnoreCase("none")) return true;
synchronized (yacyCore.seedUploadMethods) {
return yacyCore.seedUploadMethods.containsKey(method);
}
}
}
public String saveSeedList() {
// return an error if this is not successful, and NULL if everything is fine
return saveSeedList(this.switchboard);
}
public String saveSeedList(serverSwitch sb) {
try {
// return an error if this is not successful, and NULL if everything is fine
String logt;
// be shure that we have something to say
if (seedDB.mySeed.getAddress() == null) {
String errorMsg = "We have no valid IP address until now";
final String errorMsg = "We have no valid IP address until now";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// getting the configured seed uploader
String seedUploadMethod = sb.getConfig("seedUploadMethod","");
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);
sb.setConfig("seedUploadMethod",seedUploadMethod);
}
// determine the seed uploader that should be used ...
if (seedUploadMethod.equalsIgnoreCase("none")) return "no uploader specified";
// determine the seed uploader that should be used ...
if (seedUploadMethod.equalsIgnoreCase("none")) { return "no uploader specified"; }
yacySeedUploader uploader = getSeedUploader(seedUploadMethod);
if (uploader == null) {
String errorMsg = "Unable to get the proper uploader-class for seed uploading method '" + seedUploadMethod + "'.";
final String errorMsg = "Unable to get the proper uploader-class for seed uploading method '" + seedUploadMethod + "'.";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
return errorMsg;
}
// ensure that the seed file url is configured properly
URL seedURL;
try{
String seedURLStr = sb.getConfig("seedURL","");
if (seedURLStr.length() == 0) throw new MalformedURLException("The seed-file url must not be empty.");
if (!seedURLStr.toLowerCase().startsWith("http://")) throw new MalformedURLException("Unsupported protocol.");
final String seedURLStr = sb.getConfig("seedURL", "");
if (seedURLStr.length() == 0) { throw new MalformedURLException("The seed-file url must not be empty."); }
if (!seedURLStr.toLowerCase().startsWith("http://")) { throw new MalformedURLException("Unsupported protocol."); }
seedURL = new URL(seedURLStr);
}catch(MalformedURLException e){
String errorMsg = "Malformed seed file URL '" + sb.getConfig("seedURL","") + "'. " + e.getMessage();
log.logWarning("SaveSeedList: " + errorMsg);
} catch(MalformedURLException e) {
final String errorMsg = "Malformed seed file URL '" + sb.getConfig("seedURL", "") + "'. " + e.getMessage();
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
}
// upload the seed-list using the configured uploader class
String prevStatus = seedDB.mySeed.get("PeerType", "junior");
if (prevStatus.equals("principal")) prevStatus = "senior";
String prevStatus = seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR);
if (prevStatus.equals(yacySeed.PEERTYPE_PRINCIPAL)) { prevStatus = yacySeed.PEERTYPE_SENIOR; }
try {
seedDB.mySeed.put("PeerType", "principal"); // this information shall also be uploaded
seedDB.mySeed.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_PRINCIPAL); // this information shall also be uploaded
log.logFine("SaveSeedList: Using seed uploading method '" + seedUploadMethod + "' for seed-list uploading." +
"\n\tPrevious peerType is '" + seedDB.mySeed.get("PeerType", "junior") + "'.");
//logt = seedDB.uploadCache(seedFTPServer, seedFTPAccount, seedFTPPassword, seedFTPPath, seedURL);
"\n\tPrevious peerType is '" + seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR) + "'.");
// logt = seedDB.uploadCache(seedFTPServer, seedFTPAccount, seedFTPPassword, seedFTPPath, seedURL);
logt = seedDB.uploadCache(uploader,sb, seedDB, seedURL);
if (logt != null) {
if (logt.indexOf("Error") >= 0) {
seedDB.mySeed.put("PeerType", prevStatus);
String errorMsg = "SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error") + 6);
seedDB.mySeed.put(yacySeed.PEERTYPE, prevStatus);
final String errorMsg = "SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error") + 6);
log.logSevere(errorMsg);
return errorMsg;
}
log.logInfo(logt);
}
// finally, set the principal status
sb.setConfig("yacyStatus","principal");
sb.setConfig("yacyStatus", yacySeed.PEERTYPE_PRINCIPAL);
return null;
} catch (Exception e) {
seedDB.mySeed.put("PeerType", prevStatus);
seedDB.mySeed.put(yacySeed.PEERTYPE, prevStatus);
sb.setConfig("yacyStatus", prevStatus);
String errorMsg = "SaveSeedList: Seed upload failed (IO error): " + e.getMessage();
final String errorMsg = "SaveSeedList: Seed upload failed (IO error): " + e.getMessage();
log.logInfo(errorMsg,e);
return errorMsg;
}
} finally {
this.lastSeedUpload_seedDBSize = seedDB.sizeConnected();
this.lastSeedUpload_timeStamp = System.currentTimeMillis();
this.lastSeedUpload_myIP = seedDB.mySeed.get("IP", "127.0.0.1");
this.lastSeedUpload_myPeerType = seedDB.mySeed.get("PeerType", yacySeed.PEERTYPE_JUNIOR);
this.lastSeedUpload_myIP = seedDB.mySeed.get("IP", "127.0.0.1");
this.lastSeedUpload_myPeerType = seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR);
}
}
}
}
Loading…
Cancel
Save