Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- refactoring of seedURL handling - additional check for seedURL pointing to localhost: deny such peers
orbiter11e00a0849c5
diff --git a/build.properties b/build.propertiesindex a0344e219..07b026de0 100644--- a/build.properties+++ b/build.properties@@ -3,7 +3,7 @@ javacSource=1.5javacTarget=1.5# Release Configuration-releaseVersion=0.586+releaseVersion=0.587stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gzembReleaseFile=yacy_emb_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gzproReleaseFile=yacy_pro_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gzdiff --git a/defaults/yacy.init b/defaults/yacy.initindex ce9705462..a6b05ff1d 100644--- a/defaults/yacy.init+++ b/defaults/yacy.init@@ -381,9 +381,6 @@ adminAccountForLocalhost=true#seedUploadMethod=none-# The URL to the seed list file-seedURL=-# This is the most common method to upload the seed-list## This is an ftp account with all relevant information.diff --git a/htroot/Network.java b/htroot/Network.javaindex c7bcd5ebb..07b6f1f4d 100644--- a/htroot/Network.java+++ b/htroot/Network.java@@ -161,7 +161,7 @@ public class Network {prop.putNum("table_my-totalqph", Math.round(6000d * sb.totalQPM) / 100d);prop.putNum("table_my-seeds", Long.parseLong(seed.get(yacySeed.SCOUNT, "0")));prop.putNum("table_my-connects", Double.parseDouble(seed.get(yacySeed.CCOUNT, "0")));- prop.put("table_my-url", seed.get("seedURL", ""));+ prop.put("table_my-url", seed.get(yacySeed.SEEDLIST, ""));// generating the location stringprop.putHTML("table_my-location", HttpClient.generateLocation());@@ -406,7 +406,7 @@ public class Network {} else if(seed.isPrincipal()) {prop.put(STR_TABLE_LIST + conCount + "_type", 2);}- prop.putHTML(STR_TABLE_LIST + conCount + "_type_url", seed.get("seedURL", "http://nowhere/"));+ prop.putHTML(STR_TABLE_LIST + conCount + "_type_url", seed.get(yacySeed.SEEDLIST, "http://nowhere/"));final long lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60);if (page == 2 || lastseen > 1440) { // Passive Peers should be passive, also Peers without contact greater than an daydiff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.javaindex 3ef200291..2b714db66 100644--- a/htroot/SettingsAck_p.java+++ b/htroot/SettingsAck_p.java@@ -407,8 +407,8 @@ public class SettingsAck_p {// getting the currently used uploading methodString oldSeedUploadMethod = env.getConfig("seedUploadMethod","none");String newSeedUploadMethod = (String)post.get("seedUploadMethod");- String oldSeedURLStr = env.getConfig("seedURL","");- String newSeedURLStr = (String)post.get("seedURL");+ String oldSeedURLStr = sb.webIndex.seedDB.mySeed().get(yacySeed.SEEDLIST, "");+ String newSeedURLStr = (String) post.get("seedURL");boolean seedUrlChanged = !oldSeedURLStr.equals(newSeedURLStr);boolean uploadMethodChanged = !oldSeedUploadMethod.equals(newSeedUploadMethod);@@ -418,7 +418,7 @@ public class SettingsAck_p {if (seedUrlChanged || uploadMethodChanged) {env.setConfig("seedUploadMethod", newSeedUploadMethod);- env.setConfig("seedURL", newSeedURLStr);+ sb.webIndex.seedDB.mySeed().put(yacySeed.SEEDLIST, newSeedURLStr);// try an uploadString error;diff --git a/htroot/Settings_p.java b/htroot/Settings_p.javaindex f805e3d55..3ea319391 100644--- a/htroot/Settings_p.java+++ b/htroot/Settings_p.java@@ -56,6 +56,7 @@ import de.anomic.plasma.parser.ParserInfo;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.yacy.yacyCore;+import de.anomic.yacy.yacySeed;import de.anomic.yacy.yacySeedUploader;public final class Settings_p {@@ -63,6 +64,7 @@ public final class Settings_p {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch<?> env) {// return variable that accumulates replacementsserverObjects prop = new serverObjects();+ plasmaSwitchboard sb = (plasmaSwitchboard) env;//if (post == null) System.out.println("POST: NULL"); else System.out.println("POST: " + post.toString());@@ -222,7 +224,7 @@ public final class Settings_p {}// general settings- prop.put("seedURL", env.getConfig("seedURL", ""));+ prop.put("seedURL", sb.webIndex.seedDB.mySeed().get(yacySeed.SEEDLIST, ""));/** Message forwarding configuration@@ -234,7 +236,6 @@ public final class Settings_p {/** Parser Configuration*/- plasmaSwitchboard sb = (plasmaSwitchboard)env;HashMap<String, plasmaParserConfig> configList = plasmaParser.getParserConfigList();plasmaParserConfig[] configArray = (plasmaParserConfig[]) configList.values().toArray(new plasmaParserConfig[configList.size()]);diff --git a/htroot/Status.java b/htroot/Status.javaindex 982d59686..14f2a90bf 100644--- a/htroot/Status.java+++ b/htroot/Status.java@@ -223,7 +223,7 @@ public class Status {} else if (peerStatus.equals(yacySeed.PEERTYPE_PRINCIPAL)) {prop.put(PEERSTATUS, "3");prop.put("hintStatusPrincipal", "1");- prop.put("hintStatusPrincipal_seedURL", sb.webIndex.seedDB.mySeed().get("seedURL", "?"));+ prop.put("hintStatusPrincipal_seedURL", sb.webIndex.seedDB.mySeed().get(yacySeed.SEEDLIST, "?"));}prop.putHTML("peerName", thisName);prop.put("hash", thisHash);diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex 23fa37a0b..97d48ff47 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -91,7 +91,7 @@ public final class hello {prop.put("message", "your seed is too long (" + seed.length() + ")");return prop;}- final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key, false);+ final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key);// System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString()));if ((remoteSeed == null) || (remoteSeed.hash == null)) {diff --git a/htroot/yacy/message.java b/htroot/yacy/message.javaindex bd6b18157..4d6ca3eb3 100644--- a/htroot/yacy/message.java+++ b/htroot/yacy/message.java@@ -124,7 +124,7 @@ public final class message {return prop;}//Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time- yacySeed otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, true);+ yacySeed otherSeed = yacySeed.genRemoteSeed(otherSeedString, key);String subject = crypt.simpleDecode(post.get("subject", ""), key); // message's subjectString message = crypt.simpleDecode(post.get("message", ""), key); // message bodydiff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex bd40b0e7b..74c8c9f4b 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -150,7 +150,7 @@ public final class search {TreeSet<String> abstractSet = ((abstracts.length() == 0) || (abstracts.equals("auto"))) ? null : plasmaSearchQuery.hashes2Set(abstracts);// store accessing peer- yacySeed remoteSeed = yacySeed.genRemoteSeed(oseed, key, true);+ yacySeed remoteSeed = yacySeed.genRemoteSeed(oseed, key);if (sb.webIndex.seedDB == null) {yacyCore.log.logSevere("yacy.search: seed cache not initialized");} else {diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.javaindex 718c92d0d..54f423a1b 100644--- a/source/de/anomic/http/httpd.java+++ b/source/de/anomic/http/httpd.java@@ -197,7 +197,7 @@ public final class httpd implements serverHandler {this.userAddress = session.userAddress; // client InetAddressthis.clientIP = this.userAddress.getHostAddress();if (this.userAddress.isAnyLocalAddress()) this.clientIP = "localhost";- if (this.clientIP.equals("0:0:0:0:0:0:0:1")) this.clientIP = "localhost";+ if (this.clientIP.startsWith("0:0:0:0:0:0:0:1")) this.clientIP = "localhost";if (this.clientIP.equals("127.0.0.1")) this.clientIP = "localhost";final String proxyClient = switchboard.getConfig("proxyClient", "*");final String serverClient = switchboard.getConfig("serverClient", "*");diff --git a/source/de/anomic/icap/icapd.java b/source/de/anomic/icap/icapd.javaindex b2c80bd8a..9c1f7f808 100644--- a/source/de/anomic/icap/icapd.java+++ b/source/de/anomic/icap/icapd.java@@ -114,7 +114,7 @@ public class icapd implements serverHandler {this.userAddress = session.userAddress; // client InetAddressthis.clientIP = this.userAddress.getHostAddress();if (this.userAddress.isAnyLocalAddress()) this.clientIP = "localhost";- if (this.clientIP.equals("0:0:0:0:0:0:0:1")) this.clientIP = "localhost";+ if (this.clientIP.startsWith("0:0:0:0:0:0:0:1")) this.clientIP = "localhost";if (this.clientIP.equals("127.0.0.1")) this.clientIP = "localhost";}diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex b1807d253..697da408b 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -148,7 +148,7 @@ public final class yacyClient {if (seed.length() > yacySeed.maxsize) {yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");} else {- otherPeer = yacySeed.genRemoteSeed(seed, salt, true);+ otherPeer = yacySeed.genRemoteSeed(seed, salt);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@@ -214,7 +214,7 @@ public final class yacyClient {if (seedStr.length() > yacySeed.maxsize) {yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")");} else {- if (yacyCore.peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, salt, true), (i == 1))) count++;+ if (yacyCore.peerActions.peerArrival(yacySeed.genRemoteSeed(seedStr, salt), (i == 1))) count++;}}return count;@@ -323,7 +323,7 @@ public final class yacyClient {if (result == null || result.size() == 0) { return null; }//final Date remoteTime = yacyCore.parseUniversalDate((String) result.get(yacySeed.MYTIME)); // read remote time- return yacySeed.genRemoteSeed((String) result.get("response"), salt, true);+ return yacySeed.genRemoteSeed((String) result.get("response"), salt);} catch (Exception e) {yacyCore.log.logSevere("yacyClient.querySeed error:" + e.getMessage());return null;diff --git a/source/de/anomic/yacy/yacyCore.java b/source/de/anomic/yacy/yacyCore.javaindex 3509da8e7..ff59ba4df 100644--- a/source/de/anomic/yacy/yacyCore.java+++ b/source/de/anomic/yacy/yacyCore.java@@ -695,7 +695,7 @@ public class yacyCore {// ensure that the seed file url is configured properlyyacyURL seedURL;try {- final String seedURLStr = sb.getConfig("seedURL", "");+ final String seedURLStr = sb.webIndex.seedDB.mySeed().get(yacySeed.SEEDLIST, "");if (seedURLStr.length() == 0) { throw new MalformedURLException("The seed-file url must not be empty."); }if (!(seedURLStr.toLowerCase().startsWith("http://") ||@@ -705,7 +705,7 @@ public class yacyCore {}seedURL = new yacyURL(seedURLStr, null);} catch (MalformedURLException e) {- final String errorMsg = "Malformed seed file URL '" + sb.getConfig("seedURL", "") + "'. " + e.getMessage();+ final String errorMsg = "Malformed seed file URL '" + sb.webIndex.seedDB.mySeed().get(yacySeed.SEEDLIST, "") + "'. " + e.getMessage();log.logWarning("SaveSeedList: " + errorMsg);return errorMsg;}diff --git a/source/de/anomic/yacy/yacyPeerActions.java b/source/de/anomic/yacy/yacyPeerActions.javaindex 506e1837e..c5c668d4b 100644--- a/source/de/anomic/yacy/yacyPeerActions.java+++ b/source/de/anomic/yacy/yacyPeerActions.java@@ -116,10 +116,6 @@ public class yacyPeerActions {seedDB.mySeed().put(yacySeed.SCOUNT, Integer.toString(seedDB.sizeConnected())); // the number of seeds that the peer has storedseedDB.mySeed().put(yacySeed.CCOUNT, Double.toString(((int) ((seedDB.sizeConnected() + seedDB.sizeDisconnected() + seedDB.sizePotential()) * 60.0 / (uptime + 1.01)) * 100) / 100.0)); // the number of clients that the peer connects (as connects/hour)seedDB.mySeed().put(yacySeed.VERSION, sb.getConfig("version", ""));- if (seedDB.mySeed().get(yacySeed.PEERTYPE,"").equals(yacySeed.PEERTYPE_PRINCIPAL)) {- // attach information about seed location- seedDB.mySeed().put("seedURL", sb.getConfig("seedURL", ""));- }seedDB.mySeed().setFlagDirectConnect(true);seedDB.mySeed().setLastSeenUTC();seedDB.mySeed().put(yacySeed.UTC, serverDate.UTCDiffString());@@ -180,7 +176,7 @@ public class yacyPeerActions {enu = seedList.iterator();lc = 0;while (enu.hasNext()) {- ys = yacySeed.genRemoteSeed((String) enu.next(), null, true);+ ys = yacySeed.genRemoteSeed((String) enu.next(), null);if ((ys != null) && (ys.isProper() == null) &&((!seedDB.mySeedIsDefined()) || (seedDB.mySeed().hash != ys.hash))) {if (connectPeer(ys, false)) lc++;diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.javaindex 1351f6aa5..4a3bf2101 100644--- a/source/de/anomic/yacy/yacySeed.java+++ b/source/de/anomic/yacy/yacySeed.java@@ -64,6 +64,8 @@ import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.net.InetAddress;+import java.net.MalformedURLException;+import java.net.URL;import java.util.Date;import java.util.HashMap;import java.util.Iterator;@@ -166,6 +168,7 @@ public class yacySeed {public static final String CRTCNT = "CRTCnt";public static final String IP = "IP";public static final String PORT = "Port";+ public static final String SEEDLIST = "seedURL";/** zero-value */public static final String ZERO = "0";@@ -815,28 +818,64 @@ public class yacySeed {return hash;}- public static yacySeed genRemoteSeed(String seedStr, String key, boolean properTest) {+ public static yacySeed genRemoteSeed(String seedStr, String key) {// this method is used to convert the external representation of a seed into a seed object-// yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key);+ // yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key);++ // check protocol and syntax of seedif (seedStr == null) { return null; }final String seed = crypt.simpleDecode(seedStr, key);if (seed == null) { return null; }++ // extract hashfinal HashMap<String, String> dna = serverCodings.string2map(seed, ",");- String peerName = dna.get(yacySeed.NAME);- if (peerName == null) return null;- dna.put(yacySeed.NAME, checkPeerName(peerName));- final String hash = (String) dna.remove(yacySeed.HASH);+ final String hash = dna.remove(yacySeed.HASH);final yacySeed resultSeed = new yacySeed(hash, dna);- if (properTest) {- final String testResult = resultSeed.isProper();- if (testResult != null) {- yacyCore.log.logFinest("seed is not proper (" + testResult + "): " + resultSeed);- return null;- }++ // check semantics of content+ final String testResult = resultSeed.isProper();+ if (testResult != null) {+ yacyCore.log.logFinest("seed is not proper (" + testResult + "): " + resultSeed);+ return null;}++ // seed okreturn resultSeed;}+ public final String isProper() {+ // checks if everything is ok with that seed++ // check hash+ if (this.hash == null) return "hash is null";+ if (this.hash.length() != yacySeedDB.commonHashLength) return "wrong hash length (" + this.hash.length() + ")";++ // name+ String peerName = this.dna.get(yacySeed.NAME);+ if (peerName == null) return "no peer name given";+ dna.put(yacySeed.NAME, checkPeerName(peerName));++ // check IP+ final String ip = (String) this.dna.get(yacySeed.IP);+ if (ip == null) return "IP is null";+ if (ip.length() < 8) return "IP is too short: " + ip;+ if (!natLib.isProper(ip)) return "IP is not proper: " + ip; //this does not work with staticIP++ // seedURL+ final String seedURL = this.dna.get(SEEDLIST);+ if (seedURL != null && seedURL.length() > 0) {+ if (!seedURL.startsWith("http://") && !seedURL.startsWith("http://")) return "wrong protocol for seedURL";+ try {+ URL url = new URL(seedURL);+ String host = url.getHost();+ if (host.equals("localhost") || host.equals("127.0.0.1") || (host.startsWith("0:0:0:0:0:0:0:1"))) return "seedURL in localhost rejected";+ } catch (MalformedURLException e) {+ return "seedURL malformed";+ }+ }+ return null;+ }+public final String toString() {synchronized (this.dna) {this.dna.put(yacySeed.HASH, this.hash); // set hash into seed code structure@@ -859,21 +898,6 @@ public class yacySeed {return crypt.simpleEncode(this.toString(), key, method);}- public final boolean isPeerOK() {- return this.hash != null && this.isProper() == null;- }-- public final String isProper() {- // checks if everything is ok with that seed- if (this.hash == null) { return "hash is null"; }- if (this.hash.length() != yacySeedDB.commonHashLength) { return "wrong hash length (" + this.hash.length() + ")"; }- final String ip = (String) this.dna.get(yacySeed.IP);- if (ip == null) { return "IP is null"; }- if (ip.length() < 8) { return "IP is too short: " + ip; }- if (!natLib.isProper(ip)) { return "IP is not proper: " + ip; } //this does not work with staticIP- return null;- }-public final void save(File f) throws IOException {final String out = this.genSeedStr('p', null);final FileWriter fw = new FileWriter(f);@@ -886,7 +910,7 @@ public class yacySeed {final char[] b = new char[(int) f.length()];fr.read(b, 0, b.length);fr.close();- return genRemoteSeed(new String(b), null, false);+ return genRemoteSeed(new String(b), null);}@SuppressWarnings("unchecked")diff --git a/source/de/anomic/yacy/yacyURL.java b/source/de/anomic/yacy/yacyURL.javaindex 919fc7e07..f754a5a87 100644--- a/source/de/anomic/yacy/yacyURL.java+++ b/source/de/anomic/yacy/yacyURL.java@@ -762,7 +762,7 @@ public class yacyURL implements Serializable {// checks for local/global IP range and local IPpublic boolean isLocal() {if (this.hash == null) {- if (this.host.startsWith("0:0:0:0:0:0:0:1") || this.host.equals("127.0.0.1")) return true;+ if (this.host.startsWith("0:0:0:0:0:0:0:1") || this.host.equals("127.0.0.1") || this.host.equals("localhost")) return true;synchronized (this) {this.hash = urlHashComputation();}