cleaned;
Properties;

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

@ -3,7 +3,10 @@
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last major change: 02.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
@ -45,10 +48,7 @@ import java.net.URL;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;
import de.anomic.http.httpc;
import de.anomic.plasma.plasmaCrawlLURL;
import de.anomic.plasma.plasmaSearch;
@ -62,6 +62,7 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.tools.crypt;
import de.anomic.tools.nxTools;
import de.anomic.yacy.yacySeed;
public class yacyClient {
@ -84,7 +85,7 @@ public class yacyClient {
// but they appear to be another peer by comparisment of the other peer's hash
// this works of course only if we know the other peer's hash.
String key = crypt.randomSalt();
final String key = crypt.randomSalt();
HashMap result = null;
try {
/*
@ -97,8 +98,8 @@ public class yacyClient {
10000, null, null, yacyCore.seedCache.sb.remoteProxyHost, yacyCore.seedCache.sb.remoteProxyPort));
*/
URL url = new URL("http://" + address + "/yacy/hello.html");
serverObjects obj = new serverObjects();
final URL url = new URL("http://" + address + "/yacy/hello.html");
final serverObjects obj = new serverObjects();
obj.put("iam", yacyCore.seedDB.mySeed.hash);
obj.put("pattern", "");
obj.put("count", "20");
@ -118,20 +119,20 @@ public class yacyClient {
}
return -1;
}
if ((result == null) || (result.size() < 3)) {
if (result == null || result.size() < 3) {
yacyCore.log.logFine("yacyClient.publishMySeed result error: " +
((result == null) ? "result null" : ("result=" + result.toString())));
return -1;
}
Date remoteTime = yacyCore.parseUniversalDate((String) result.get("mytime")); // read remote time
final Date remoteTime = yacyCore.parseUniversalDate((String) result.get("mytime")); // read remote time
// check consistency with expectation
yacySeed otherPeer = null;
float otherPeerVersion = 0;
if ((otherHash != null ) && (otherHash.length() > 0)) {
if (otherHash != null && otherHash.length() > 0) {
otherPeer = yacySeed.genRemoteSeed((String) result.get("seed0"), key, remoteTime);
if ((otherPeer == null) || (!(otherPeer.hash.equals(otherHash)))) {
if (otherPeer == null || !otherPeer.hash.equals(otherHash)) {
yacyCore.log.logFine("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");
return -1; // no success
}
@ -139,13 +140,13 @@ public class yacyClient {
}
// set my own seed according to new information
yacySeed mySeedBkp = (yacySeed) yacyCore.seedDB.mySeed.clone();
final yacySeed mySeedBkp = (yacySeed) yacyCore.seedDB.mySeed.clone();
// we overwrite our own IP number only, if we do not portForwarding
if (!serverCore.portForwardingEnabled) {
yacyCore.seedDB.mySeed.put("IP", (String) result.get("yourip"));
} else {
if (serverCore.portForwardingEnabled) {
yacyCore.seedDB.mySeed.put("IP", serverCore.publicIP());
} else {
yacyCore.seedDB.mySeed.put("IP", (String) result.get("yourip"));
}
/* If we have port forwarding enabled but the other peer uses a too old yacy version
@ -155,9 +156,9 @@ public class yacyClient {
*
* @see serverCore#portForwardingEnabled
*/
if ((!serverCore.portForwardingEnabled) || (otherPeerVersion >= (float)0.383)) {
if (!serverCore.portForwardingEnabled || otherPeerVersion >= (float)0.383) {
String mytype = (String) result.get("yourtype");
if (mytype == null) mytype = yacySeed.PEERTYPE_JUNIOR;
if (mytype == null) { mytype = yacySeed.PEERTYPE_JUNIOR; }
if (
(yacyCore.seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR).equals(yacySeed.PEERTYPE_PRINCIPAL)) &&
(mytype.equals(yacySeed.PEERTYPE_SENIOR))
@ -172,10 +173,9 @@ public class yacyClient {
if (mytype.equalsIgnoreCase(yacySeed.PEERTYPE_JUNIOR)) {
yacyCore.log.logInfo("yacyClient.publishMySeed: Peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' reported us as junior.");
if (serverCore.portForwardingEnabled) {
if (
(!Thread.currentThread().isInterrupted()) &&
(serverCore.portForwarding != null) &&
(!serverCore.portForwarding.isConnected())
if (!Thread.currentThread().isInterrupted() &&
serverCore.portForwarding != null &&
!serverCore.portForwarding.isConnected()
) {
yacyCore.log.logWarning("yacyClient.publishMySeed: Broken portForwarding channel detected. Trying to reconnect ...");
try {
@ -191,8 +191,8 @@ public class yacyClient {
yacyCore.seedDB.mySeed.put(yacySeed.PEERTYPE, mytype);
}
String error;
if ((error = yacyCore.seedDB.mySeed.isProper()) != null) {
final String error = yacyCore.seedDB.mySeed.isProper();
if (error != null) {
yacyCore.seedDB.mySeed = mySeedBkp;
yacyCore.log.logFine("yacyClient.publishMySeed mySeed error - not proper: " + error);
return -1;
@ -200,8 +200,8 @@ public class yacyClient {
// read the seeds that the peer returned and integrate them into own database
int i = 0;
String seedStr;
int count = 0;
String seedStr;
while ((seedStr = (String) result.get("seed" + i++)) != null) {
// integrate new seed into own database
// the first seed, "seed0" is the seed of the responding peer
@ -210,18 +210,17 @@ public class yacyClient {
return count;
}
public static yacySeed querySeed(yacySeed target, String seedHash) {
String key = crypt.randomSalt();
final String key = crypt.randomSalt();
try {
HashMap result = nxTools.table(httpc.wget(
final HashMap result = nxTools.table(httpc.wget(
new URL("http://" + target.getAddress() +
"/yacy/query.html?iam=" + yacyCore.seedDB.mySeed.hash +
"&youare=" + target.hash + "&key=" + key +
"&object=seed&env=" + seedHash),
10000, null, null, yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort));
if ((result == null) || (result.size() == 0)) return null;
Date remoteTime = yacyCore.parseUniversalDate((String) result.get("mytime")); // read remote time
if (result == null || result.size() == 0) { return null; }
final Date remoteTime = yacyCore.parseUniversalDate((String) result.get("mytime")); // read remote time
return yacySeed.genRemoteSeed((String) result.get("response"), key, remoteTime);
} catch (Exception e) {
yacyCore.log.logSevere("yacyClient.querySeed error:" + e.getMessage());
@ -231,14 +230,14 @@ public class yacyClient {
public static int queryRWICount(yacySeed target, String wordHash) {
try {
HashMap result = nxTools.table(httpc.wget(
final HashMap result = nxTools.table(httpc.wget(
new URL("http://" + target.getAddress() +
"/yacy/query.html?iam=" + yacyCore.seedDB.mySeed.hash +
"&youare=" + target.hash + "&key=" +
"&object=rwicount&env=" + wordHash +
"&ttl=0"),
10000, null, null, yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort));
if ((result == null) || (result.size() == 0)) return -1;
if (result == null || result.size() == 0) { return -1; }
return Integer.parseInt((String) result.get("response"));
} catch (Exception e) {
yacyCore.log.logSevere("yacyClient.queryRWICount error:" + e.getMessage());
@ -247,22 +246,22 @@ public class yacyClient {
}
public static int queryUrlCount(yacySeed target) {
if (target == null) return -1;
if (target == null) { return -1; }
if (yacyCore.seedDB.mySeed == null) return -1;
String querystr =
final String querystr =
"http://" + target.getAddress() +
"/yacy/query.html?iam=" + yacyCore.seedDB.mySeed.hash +
"&youare=" + target.hash +
"&key=" +
"&object=lurlcount&env=&ttl=0";
try {
HashMap result = nxTools.table(httpc.wget(
final HashMap result = nxTools.table(httpc.wget(
new URL(querystr), 6000, null, null,
yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort));
//yacyCore.log("DEBUG QUERY: query=" + querystr + "; result = " + result.toString());
// yacyCore.log("DEBUG QUERY: query=" + querystr + "; result = " + result.toString());
if ((result == null) || (result.size() == 0)) return -1;
String resp = (String) result.get("response");
if (resp == null) return -1; else return Integer.parseInt(resp);
final String resp = (String) result.get("response");
if (resp == null) { return -1; } else { return Integer.parseInt(resp); }
} catch (Exception e) {
yacyCore.log.logSevere("yacyClient.queryUrlCount error asking peer '" + target.getName() + "':" + e.toString());
return -1;
@ -290,9 +289,9 @@ public class yacyClient {
// duetime : maximum time that a peer should spent to create a result
// request result
String key = crypt.randomSalt();
final String key = crypt.randomSalt();
try {
String url = "http://" + targetPeer.getAddress() + "/yacy/search.html";
final String url = "http://" + targetPeer.getAddress() + "/yacy/search.html";
/*
String url = "http://" + targetPeer.getAddress() +
"/yacy/search.html?myseed=" + yacyCore.seedCache.mySeed.genSeedStr(key) +
@ -301,7 +300,7 @@ public class yacyClient {
"&count=" + count + "&resource=" + ((global) ? "global" : "local") +
"&query=" + wordhashes;
*/
serverObjects obj = new serverObjects();
final serverObjects obj = new serverObjects();
obj.put("myseed", yacyCore.seedDB.mySeed.genSeedStr(key));
obj.put("youare", targetPeer.hash);
obj.put("key", key);
@ -312,13 +311,13 @@ public class yacyClient {
obj.put("duetime", Long.toString(duetime));
obj.put("mytime", yacyCore.universalDateShortString());
//yacyCore.log.logDebug("yacyClient.search url=" + url);
long timestamp = System.currentTimeMillis();
HashMap result = nxTools.table(httpc.wput(new URL(url),
final long timestamp = System.currentTimeMillis();
final HashMap result = nxTools.table(httpc.wput(new URL(url),
300000, null, null,
yacyCore.seedDB.sb.remoteProxyHost,
yacyCore.seedDB.sb.remoteProxyPort,
obj));
long totalrequesttime = System.currentTimeMillis() - timestamp;
final long totalrequesttime = System.currentTimeMillis() - timestamp;
/*
HashMap result = nxTools.table(httpc.wget(new URL(url),
@ -338,12 +337,12 @@ public class yacyClient {
// now create a plasmaIndex out of this result
//System.out.println("yacyClient: search result = " + result.toString()); // debug
int results = Integer.parseInt((String) result.get("count"));
final int results = Integer.parseInt((String) result.get("count"));
//System.out.println("***result count " + results);
plasmaCrawlLURL.Entry link;
// create containers
int words = wordhashes.length() / plasmaWordIndexEntry.wordHashLength;
final int words = wordhashes.length() / plasmaWordIndexEntry.wordHashLength;
plasmaWordIndexEntryContainer[] container = new plasmaWordIndexEntryContainer[words];
for (int i = 0; i < words; i++) {
container[i] = new plasmaWordIndexEntryContainer(wordhashes.substring(i * plasmaWordIndexEntry.wordHashLength, (i + 1) * plasmaWordIndexEntry.wordHashLength));
@ -354,10 +353,10 @@ public class yacyClient {
for (int n = 0; n < results; n++) {
// get one single search result
lEntry = urlManager.newEntry((String) result.get("resource" + n), true);
if ((lEntry != null) && (blacklist.isListed(lEntry.url().getHost().toLowerCase(), lEntry.url().getPath()))) continue; // block with backlist
if (lEntry != null && blacklist.isListed(lEntry.url().getHost().toLowerCase(), lEntry.url().getPath())) { continue; } // block with backlist
link = urlManager.addEntry(lEntry, yacyCore.seedDB.mySeed.hash, targetPeer.hash, 2);
// save the url entry
plasmaWordIndexEntry entry = new plasmaWordIndexEntry(link.hash(), link.wordCount(), 0, 0, 0,
final plasmaWordIndexEntry entry = new plasmaWordIndexEntry(link.hash(), link.wordCount(), 0, 0, 0,
plasmaSearch.calcVirtualAge(link.moddate()), link.quality(),
link.language(), link.doctype(), false);
if (link.snippet() != null) {
@ -373,7 +372,7 @@ public class yacyClient {
}
// finally insert the containers to the index
for (int m = 0; m < words; m++) searchManager.addWords(container[m]);
for (int m = 0; m < words; m++) { searchManager.addWords(container[m]); }
// generate statistics
long searchtime;
@ -394,9 +393,9 @@ public class yacyClient {
public static HashMap permissionMessage(String targetHash) {
// ask for allowed message size and attachement size
// if this replies null, the peer does not answer
if ((yacyCore.seedDB == null) || (yacyCore.seedDB.mySeed == null)) return null;
serverObjects post = new serverObjects();
String key = crypt.randomSalt();
if (yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return null; }
final serverObjects post = new serverObjects();
final String key = crypt.randomSalt();
post.put("key", key);
post.put("process", "permission");
post.put("iam", yacyCore.seedDB.mySeed.hash);
@ -407,12 +406,12 @@ public class yacyClient {
address = yacyCore.seedDB.mySeed.getAddress();
//System.out.println("local address: " + address);
} else {
yacySeed targetSeed = yacyCore.seedDB.getConnected(targetHash);
if (targetSeed == null) return null;
final yacySeed targetSeed = yacyCore.seedDB.getConnected(targetHash);
if (targetSeed == null) { return null; }
address = targetSeed.getAddress();
//System.out.println("remote address: " + address);
}
if (address == null) address = "localhost:8080";
if (address == null) { address = "localhost:8080"; }
try {
return nxTools.table(httpc.wput(
new URL("http://" + address + "/yacy/message.html"),
@ -426,8 +425,8 @@ public class yacyClient {
public static HashMap postMessage(String targetHash, String subject, byte[] message) {
// this post a message to the remote message board
serverObjects post = new serverObjects();
String key = crypt.randomSalt();
final serverObjects post = new serverObjects();
final String key = crypt.randomSalt();
post.put("key", key);
post.put("process", "post");
post.put("myseed", yacyCore.seedDB.mySeed.genSeedStr(key));
@ -436,14 +435,15 @@ public class yacyClient {
post.put("mytime", yacyCore.universalDateShortString());
post.put("message", new String(message));
String address;
if (targetHash.equals(yacyCore.seedDB.mySeed.hash))
if (targetHash.equals(yacyCore.seedDB.mySeed.hash)) {
address = yacyCore.seedDB.mySeed.getAddress();
else
} else {
address = yacyCore.seedDB.getConnected(targetHash).getAddress();
if (address == null) address = "localhost:8080";
}
if (address == null) { address = "localhost:8080"; }
//System.out.println("DEBUG POST " + address + "/yacy/message.html" + post.toString());
try {
Vector v = httpc.wput(new URL("http://" + address + "/yacy/message.html"), 20000, null, null,
final Vector v = httpc.wput(new URL("http://" + address + "/yacy/message.html"), 20000, null, null,
yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort, post);
//System.out.println("V=" + v.toString());
return nxTools.table(v);
@ -455,13 +455,13 @@ public class yacyClient {
public static HashMap crawlOrder(yacySeed targetSeed, URL url, URL referrer) {
// this post a message to the remote message board
if (targetSeed == null) return null;
if (yacyCore.seedDB.mySeed == null) return null;
if (yacyCore.seedDB.mySeed == targetSeed) return null;
if (targetSeed == null) { return null; }
if (yacyCore.seedDB.mySeed == null) { return null; }
if (yacyCore.seedDB.mySeed == targetSeed) { return null; }
// construct request
serverObjects post = new serverObjects();
String key = crypt.randomSalt();
final serverObjects post = new serverObjects();
final String key = crypt.randomSalt();
post.put("key", key);
post.put("process", "crawl");
post.put("iam", yacyCore.seedDB.mySeed.hash);
@ -472,8 +472,8 @@ public class yacyClient {
post.put("depth", "0");
post.put("ttl", "0");
String address = targetSeed.getAddress();
if (address == null) return null;
final String address = targetSeed.getAddress();
if (address == null) { return null; }
try {
return nxTools.table(httpc.wput(
new URL("http://" + address + "/yacy/crawlOrder.html"),
@ -493,9 +493,9 @@ public class yacyClient {
*/
public static HashMap crawlReceipt(yacySeed targetSeed, String process, String result, String reason, plasmaCrawlLURL.Entry entry, String wordhashes) {
if (targetSeed == null) return null;
if (yacyCore.seedDB.mySeed == null) return null;
if (yacyCore.seedDB.mySeed == targetSeed) return null;
if (targetSeed == null) { return null; }
if (yacyCore.seedDB.mySeed == null) { return null; }
if (yacyCore.seedDB.mySeed == targetSeed) { return null; }
/*
the result can have one of the following values:
@ -518,10 +518,10 @@ public class yacyClient {
*/
// construct request
String key = crypt.randomSalt();
final String key = crypt.randomSalt();
String address = targetSeed.getAddress();
if (address == null) return null;
if (address == null) { return null; }
try {
return nxTools.table(httpc.wget(
new URL("http://" + address + "/yacy/crawlReceipt.html?" +
@ -550,17 +550,17 @@ public class yacyClient {
public static String transferIndex(yacySeed targetSeed, plasmaWordIndexEntity[] indexes, HashMap urlCache) {
HashMap in = transferRWI(targetSeed, indexes);
if (in == null) return "no_connection_1";
if (in == null) { return "no_connection_1"; }
String result = (String) in.get("result");
if (result == null) return "no_result_1";
if (result == null) { return "no_result_1"; }
if (!(result.equals("ok"))) return result;
// in now contains a list of unknown hashes
String uhss = (String) in.get("unknownURL");
if (uhss == null) return "no_unknownURL_tag_in_response";
if (uhss.length() == 0) return null; // all url's known, we are ready here
String[] uhs = uhss.split(",");
//System.out.println("DEBUG yacyClient.transferIndex: " + uhs.length + " urls unknown");
if (uhs.length == 0) return null; // all url's known
final String uhss = (String) in.get("unknownURL");
if (uhss == null) { return "no_unknownURL_tag_in_response"; }
if (uhss.length() == 0) { return null; } // all url's known, we are ready here
final String[] uhs = uhss.split(",");
// System.out.println("DEBUG yacyClient.transferIndex: " + uhs.length + " urls unknown");
if (uhs.length == 0) { return null; } // all url's known
// extract the urlCache from the result
plasmaCrawlLURL.Entry[] urls = new plasmaCrawlLURL.Entry[uhs.length];
for (int i = 0; i < uhs.length; i++) {
@ -568,27 +568,27 @@ public class yacyClient {
if (urls[i] == null) System.out.println("DEBUG transferIndex: error with requested url hash '" + uhs[i] + "', unknownURL='" + uhss + "'");
}
in = transferURL(targetSeed, urls);
if (in == null) return "no_connection_2";
if (in == null) { return "no_connection_2"; }
result = (String) in.get("result");
if (result == null) return "no_result_2";
if (!(result.equals("ok"))) return result;
int doubleentries = Integer.parseInt((String) in.get("double"));
//System.out.println("DEBUG tansferIndex: transferred " + uhs.length + " URL's, double=" + doubleentries);
if (result == null) { return "no_result_2"; }
if (!(result.equals("ok"))) { return result; }
// int doubleentries = Integer.parseInt((String) in.get("double"));
// System.out.println("DEBUG tansferIndex: transferred " + uhs.length + " URL's, double=" + doubleentries);
return null;
}
private static HashMap transferRWI(yacySeed targetSeed, plasmaWordIndexEntity[] indexes) {
String address = targetSeed.getAddress();
if (address == null) return null;
final String address = targetSeed.getAddress();
if (address == null) { return null; }
// prepare post values
serverObjects post = new serverObjects();
String key = crypt.randomSalt();
final serverObjects post = new serverObjects();
final String key = crypt.randomSalt();
post.put("key", key);
post.put("iam", yacyCore.seedDB.mySeed.hash);
post.put("youare", targetSeed.hash);
post.put("wordc", Integer.toString(indexes.length));
int indexcount = 0;
StringBuffer entrypost = new StringBuffer(indexes.length*73);
final StringBuffer entrypost = new StringBuffer(indexes.length*73);
Enumeration eenum;
plasmaWordIndexEntry entry;
for (int i = 0; i < indexes.length; i++) {
@ -604,7 +604,7 @@ public class yacyClient {
if (indexcount == 0) {
// nothing to do but everything ok
HashMap result = new HashMap();
final HashMap result = new HashMap();
result.put("result", "ok");
result.put("unknownURL", "");
return result;
@ -613,14 +613,14 @@ public class yacyClient {
post.put("entryc", Integer.toString(indexcount));
post.put("indexes", entrypost.toString());
try {
Vector v = httpc.wput(new URL("http://" + address + "/yacy/transferRWI.html"), 60000, null, null,
final Vector v = httpc.wput(new URL("http://" + address + "/yacy/transferRWI.html"), 60000, null, null,
yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort, post);
// this should return a list of urlhashes that are unknwon
if (v != null) {
yacyCore.seedDB.mySeed.incSI(indexcount);
}
HashMap result = nxTools.table(v);
final HashMap result = nxTools.table(v);
return result;
} catch (Exception e) {
yacyCore.log.logSevere("yacyClient.transferRWI error:" + e.getMessage());
@ -630,11 +630,11 @@ public class yacyClient {
private static HashMap transferURL(yacySeed targetSeed, plasmaCrawlLURL.Entry[] urls) {
// this post a message to the remote message board
String address = targetSeed.getAddress();
if (address == null) return null;
final String address = targetSeed.getAddress();
if (address == null) { return null; }
// prepare post values
serverObjects post = new serverObjects();
String key = crypt.randomSalt();
final serverObjects post = new serverObjects();
final String key = crypt.randomSalt();
post.put("key", key);
post.put("iam", yacyCore.seedDB.mySeed.hash);
post.put("youare", targetSeed.hash);
@ -651,7 +651,7 @@ public class yacyClient {
}
post.put("urlc", Integer.toString(urlc));
try {
Vector v = httpc.wput(new URL("http://" + address + "/yacy/transferURL.html"), 60000, null, null,
final Vector v = httpc.wput(new URL("http://" + address + "/yacy/transferURL.html"), 60000, null, null,
yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort, post);
if (v != null) {
yacyCore.seedDB.mySeed.incSU(urlc);
@ -665,13 +665,13 @@ public class yacyClient {
public static HashMap getProfile(yacySeed targetSeed) {
// this post a message to the remote message board
serverObjects post = new serverObjects();
final serverObjects post = new serverObjects();
post.put("iam", yacyCore.seedDB.mySeed.hash);
post.put("youare", targetSeed.hash);
String address = targetSeed.getAddress();
if (address == null) address = "localhost:8080";
if (address == null) { address = "localhost:8080"; }
try {
Vector v = httpc.wput(new URL("http://" + address + "/yacy/profile.html"), 20000, null, null,
final Vector v = httpc.wput(new URL("http://" + address + "/yacy/profile.html"), 20000, null, null,
yacyCore.seedDB.sb.remoteProxyHost, yacyCore.seedDB.sb.remoteProxyPort, post);
return nxTools.table(v);
} catch (Exception e) {
@ -683,14 +683,14 @@ public class yacyClient {
public static void main(String[] args) {
System.out.println("yacyClient Test");
try {
plasmaSwitchboard sb = new plasmaSwitchboard(args[0], "httpProxy.init", "DATA/SETTINGS/httpProxy.conf");
yacyCore core = new yacyCore(sb);
final plasmaSwitchboard sb = new plasmaSwitchboard(args[0], "httpProxy.init", "DATA/SETTINGS/httpProxy.conf");
final yacyCore core = new yacyCore(sb);
core.peerActions.loadSeedLists();
yacySeed target = core.seedDB.getConnected(args[1]);
String wordhashe = plasmaWordIndexEntry.word2hash("test");
final yacySeed target = core.seedDB.getConnected(args[1]);
final String wordhashe = plasmaWordIndexEntry.word2hash("test");
//System.out.println("permission=" + permissionMessage(args[1]));
HashMap result = nxTools.table(httpc.wget(
final HashMap result = nxTools.table(httpc.wget(
new URL("http://" + target.getAddress() +
"/yacy/search.html?myseed=" + core.seedDB.mySeed.genSeedStr(null) +
"&youare=" + target.hash + "&key=" +
@ -704,4 +704,5 @@ public class yacyClient {
}
System.exit(0);
}
}

@ -3,7 +3,10 @@
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last major change: 11.07.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
@ -56,7 +59,6 @@
*/
package de.anomic.yacy;
import java.io.File;
@ -67,8 +69,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import de.anomic.net.natLib;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCodings;
@ -78,6 +78,11 @@ import de.anomic.tools.crypt;
public class yacySeed {
public static final String INDEX_OUT = "sI";
public static final String INDEX_IN = "rI";
public static final String URL_OUT = "sU";
public static final String URL_IN = "rU";
public static final String PEERTYPE_VIRGIN = "virgin";
public static final String PEERTYPE_JUNIOR = "junior";
public static final String PEERTYPE_SENIOR = "senior";
@ -118,7 +123,7 @@ public class yacySeed {
// settings that is created during the 'hello' phase - in first contact
dna.put("IP", ""); // 123.234.345.456
dna.put("Port", "&empty;"); //
dna.put("PeerType", "virgin"); // virgin/junior/senior/principal
dna.put(PEERTYPE, PEERTYPE_VIRGIN); // virgin/junior/senior/principal
dna.put("IPType", "&empty;"); // static/dynamic (if the ip changes often for any reason)
// settings that can only be computed by visiting peer
@ -132,15 +137,14 @@ public class yacySeed {
setFlagAcceptRemoteIndex(true);
// index transfer
dna.put("sI", "0"); // send index
dna.put("rI", "0"); // received Index
dna.put("sU", "0"); // send url
dna.put("rU", "0"); // received URL
dna.put(INDEX_OUT, "0"); // send index
dna.put(INDEX_IN, "0"); // received Index
dna.put(URL_OUT, "0"); // send url
dna.put(URL_IN, "0"); // received URL
available = 0;
}
public String get(String key, String dflt) {
Object o = dna.get(key);
if (o == null) return dflt; else return (String) o;
@ -163,20 +167,23 @@ public class yacySeed {
}
public void incSI(int count) {
String v = (String) dna.get("sI"); if (v == null) v = "0";
dna.put("sI", Integer.toString(Integer.parseInt(v) + count));
String v = (String) dna.get(INDEX_OUT); if (v == null) v = "0";
dna.put(INDEX_OUT, Integer.toString(Integer.parseInt(v) + count));
}
public void incRI(int count) {
String v = (String) dna.get("rI"); if (v == null) v = "0";
dna.put("rI", Integer.toString(Integer.parseInt(v) + count));
String v = (String) dna.get(INDEX_IN); if (v == null) v = "0";
dna.put(INDEX_IN, Integer.toString(Integer.parseInt(v) + count));
}
public void incSU(int count) {
String v = (String) dna.get("sU"); if (v == null) v = "0";
dna.put("sU", Integer.toString(Integer.parseInt(v) + count));
String v = (String) dna.get(URL_OUT); if (v == null) v = "0";
dna.put(URL_OUT, Integer.toString(Integer.parseInt(v) + count));
}
public void incRU(int count) {
String v = (String) dna.get("rU"); if (v == null) v = "0";
dna.put("rU", Integer.toString(Integer.parseInt(v) + count));
String v = (String) dna.get(URL_IN); if (v == null) v = "0";
dna.put(URL_IN, Integer.toString(Integer.parseInt(v) + count));
}
// 12 * 6 bit = 72 bit = 9 byte
@ -200,7 +207,7 @@ public class yacySeed {
public String getAddress() {
String ip = (String) dna.get("IP");
String port = (String) dna.get("Port");
if ((ip != null) && (ip.length() >= 8) && (port != null) && (port.length() >= 2)) return ip + ":" + port; else return null;
if (ip != null && ip.length() >= 8 && port != null && port.length() >= 2) return ip + ":" + port; else return null;
}
public int getPPM() {
@ -210,6 +217,7 @@ public class yacySeed {
return 0;
}
}
private boolean getFlag(int flag) {
String flags = get("Flags", "0000");
return (new bitfield(flags.getBytes())).get(flag);
@ -237,19 +245,19 @@ public class yacySeed {
}
public boolean isVirgin() {
return get("PeerType", "").equals("virgin");
return get(PEERTYPE, "").equals(PEERTYPE_VIRGIN);
}
public boolean isJunior() {
return get("PeerType", "").equals("junior");
return get(PEERTYPE, "").equals(PEERTYPE_JUNIOR);
}
public boolean isSenior() {
return get("PeerType", "").equals("senior");
return get(PEERTYPE, "").equals(PEERTYPE_SENIOR);
}
public boolean isPrincipal() {
return get("PeerType", "").equals("principal");
return get(PEERTYPE, "").equals(PEERTYPE_PRINCIPAL);
}
public boolean isOnline() {
return (isSenior()) || (isPrincipal());
return (isSenior() || isPrincipal());
}
public String encodeLex(long c, int length) {
@ -260,7 +268,7 @@ public class yacySeed {
s = ((char) (32 + (c % 96))) + s;
c = c / 96;
}
if ((length != 0) && (s.length() > length))
if (length != 0 && s.length() > length)
throw new RuntimeException("encodeLex result '" + s + "' exceeds demanded length of " + length + " digits");
if (length == 0) length = 1; // rare exception for the case that c == 0
while (s.length() < length) s = '-' + s;
@ -300,22 +308,22 @@ public class yacySeed {
// variables and can even then be reconstructed if the local seed has disappeared
Properties sp = System.getProperties();
String slow =
sp.getProperty("file.encoding","") +
sp.getProperty("file.separator","") +
sp.getProperty("java.class.path","") +
sp.getProperty("java.vendor","") +
sp.getProperty("os.arch","") +
sp.getProperty("os.name","") +
sp.getProperty("path.separator","") +
sp.getProperty("user.dir","") +
sp.getProperty("user.home","") +
sp.getProperty("user.language","") +
sp.getProperty("user.name","") +
sp.getProperty("file.encoding", "") +
sp.getProperty("file.separator", "") +
sp.getProperty("java.class.path", "") +
sp.getProperty("java.vendor", "") +
sp.getProperty("os.arch", "") +
sp.getProperty("os.name", "") +
sp.getProperty("path.separator", "") +
sp.getProperty("user.dir", "") +
sp.getProperty("user.home", "") +
sp.getProperty("user.language", "") +
sp.getProperty("user.name", "") +
sp.getProperty("user.timezone", "");
String medium =
sp.getProperty("java.class.version","") +
sp.getProperty("java.version","") +
sp.getProperty("os.version","") +
sp.getProperty("java.class.version", "") +
sp.getProperty("java.version", "") +
sp.getProperty("os.version", "") +
sb.getConfig("peerName", "noname");
String fast = Long.toString(System.currentTimeMillis());
// the resultinh hash does not have any information than can be used to reconstruct the
@ -346,7 +354,7 @@ public class yacySeed {
}
newSeed.dna.put("BDate", yacyCore.universalDateShortString());
newSeed.dna.put("LastSeen", newSeed.dna.get("BDate")); // just as initial setting
newSeed.dna.put("PeerType", "virgin");
newSeed.dna.put(PEERTYPE, PEERTYPE_VIRGIN);
return newSeed;
}

Loading…
Cancel
Save