diff --git a/htroot/IndexControl_p.html b/htroot/IndexControl_p.html index c9247daa3..06a935d42 100644 --- a/htroot/IndexControl_p.html +++ b/htroot/IndexControl_p.html @@ -99,6 +99,14 @@ If checked, your peer silently ignores transmitted URLs that match your blacklist + + Peer Tags: + + If your peer runs in 'Robinson Mode' (Distribution and Receive off), you probably run YaCy as a search engine + for your own search portal. Please describe your search portal with some keywords (comma-separated). + This will help to use your peer as search target even if you do not distribute your web index by + DHT distribution. + diff --git a/htroot/IndexControl_p.java b/htroot/IndexControl_p.java index ee1dc139b..113231e1f 100644 --- a/htroot/IndexControl_p.java +++ b/htroot/IndexControl_p.java @@ -65,6 +65,7 @@ import de.anomic.plasma.plasmaCrawlLURL; import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaWordIndex; import de.anomic.plasma.urlPattern.plasmaURLPattern; +import de.anomic.server.serverCodings; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; import de.anomic.yacy.yacyClient; @@ -92,6 +93,7 @@ public class IndexControl_p { prop.put("indexDistributeWhileCrawling", (switchboard.getConfig("allowDistributeIndexWhileCrawling", "true").equals("true")) ? "checked" : ""); prop.put("indexReceiveChecked", (switchboard.getConfig("allowReceiveIndex", "true").equals("true")) ? "checked" : ""); prop.put("indexReceiveBlockBlacklistChecked", (switchboard.getConfig("indexReceiveBlockBlacklist", "true").equals("true")) ? "checked" : ""); + prop.put("peertags", serverCodings.set2string(yacyCore.seedDB.mySeed.getPeerTags(), ",", false)); return prop; // be save } @@ -143,6 +145,10 @@ public class IndexControl_p { } else { switchboard.setConfig("indexReceiveBlockBlacklist", "false"); } + + if (post.containsKey("peertags")) { + yacyCore.seedDB.mySeed.setPeerTags(serverCodings.string2set((String) post.get("peertags"), ",")); + } } // delete word @@ -392,6 +398,7 @@ public class IndexControl_p { prop.put("indexDistributeWhileCrawling", (switchboard.getConfig("allowDistributeIndexWhileCrawling", "true").equals("true")) ? "checked" : ""); prop.put("indexReceiveChecked", (switchboard.getConfig("allowReceiveIndex", "true").equals("true")) ? "checked" : ""); prop.put("indexReceiveBlockBlacklistChecked", (switchboard.getConfig("indexReceiveBlockBlacklist", "true").equals("true")) ? "checked" : ""); + prop.put("peertags", serverCodings.set2string(yacyCore.seedDB.mySeed.getPeerTags(), ",", false)); // return rewrite properties return prop; } diff --git a/htroot/Network.html b/htroot/Network.html index 1249ef3b0..5eab96963 100644 --- a/htroot/Network.html +++ b/htroot/Network.html @@ -70,7 +70,7 @@ #(isCrawling)#::Crawl#(/isCrawling)# #[shortname]# - #(type)##(direct)#Junior passive::Junior direct::Junior offline#(/direct)#::#(direct)#senior passive::Senior direct::Senior offline#(/direct)#::#(direct)#Principal passive::Principal active::Principal offline#(/direct)##(/type)##(acceptcrawl)#no crawl::crawl possible::crawl possible#(/acceptcrawl)##(dhtreceive)#no DHT receive::DHT receive enabled::DHT receive enabled#(/dhtreceive)##(rankingreceive)#no ranking receive::Ranking receive enabled::ranking collects#(/rankingreceive)# + #(type)##(direct)#Junior passive::Junior direct::Junior offline#(/direct)#::#(direct)#senior passive::Senior direct::Senior offline#(/direct)#::#(direct)#Principal passive::Principal active::Principal offline#(/direct)##(/type)##(acceptcrawl)#no crawl::crawl possible::crawl possible#(/acceptcrawl)##(dhtreceive)#no DHT receive::DHT receive enabled::DHT receive enabled#(/dhtreceive)##(rankingreceive)#no ranking receive::Ranking receive enabled::ranking collects#(/rankingreceive)# #[version]# #[ppm]# #[lastSeen]# diff --git a/htroot/Network.java b/htroot/Network.java index 6df0e0dc0..0957c1e24 100644 --- a/htroot/Network.java +++ b/htroot/Network.java @@ -54,6 +54,7 @@ import java.util.Map; import de.anomic.http.httpHeader; import de.anomic.http.httpc; +import de.anomic.server.serverCodings; import de.anomic.server.serverDate; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; @@ -409,6 +410,7 @@ public class Network { } else { prop.put(STR_TABLE_LIST + conCount + "_dhtreceive", 0); // red/red; offline was off } + if (seed.getVersion() >= yacyVersion.YACY_ACCEPTS_RANKING_TRANSMISSION && seed.getFlagAcceptCitationReference()) { prop.put(STR_TABLE_LIST + conCount + "_rankingreceive", 1); @@ -416,6 +418,12 @@ public class Network { prop.put(STR_TABLE_LIST + conCount + "_rankingreceive", 0); } } + if (seed.getFlagAcceptRemoteIndex()) { + prop.put(STR_TABLE_LIST + conCount + "_dhtreceive_peertags", ""); + } else { + String peertags = serverCodings.set2string(seed.getPeerTags(), ",", false); + prop.put(STR_TABLE_LIST + conCount + "_dhtreceive_peertags", ((peertags == null) || (peertags.length() == 0)) ? "no tags given" : ("tags = " + peertags)); + } prop.put(STR_TABLE_LIST + conCount + "_version", yacy.combinedVersionString2PrettyString(seed.get(yacySeed.VERSION, "0.1"))); prop.put(STR_TABLE_LIST + conCount + "_lastSeen", lastseen); prop.put(STR_TABLE_LIST + conCount + "_utc", seed.get(yacySeed.UTC, "-")); diff --git a/source/de/anomic/server/serverCodings.java b/source/de/anomic/server/serverCodings.java index 4381930a5..43cc7bd92 100644 --- a/source/de/anomic/server/serverCodings.java +++ b/source/de/anomic/server/serverCodings.java @@ -47,8 +47,13 @@ import java.io.FileInputStream; import java.io.InputStream; import java.security.MessageDigest; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.StringTokenizer; +import java.util.Map.Entry; public final class serverCodings { @@ -154,21 +159,69 @@ public final class serverCodings { return p; } - public static HashMap string2map(String string) { + public static HashMap string2map(String string, String separator) { // this can be used to parse a Map.toString() into a Map again - if (string == null) return null; - HashMap map = new HashMap(); - int pos; - pos = string.indexOf("{"); if (pos >= 0) string = string.substring(pos + 1).trim(); - pos = string.lastIndexOf("}"); if (pos >= 0) string = string.substring(0, pos).trim(); - StringTokenizer st = new StringTokenizer(string, ","); - String token; - while (st.hasMoreTokens()) { - token = st.nextToken().trim(); - pos = token.indexOf("="); - if (pos > 0) map.put(token.substring(0, pos).trim(), token.substring(pos + 1).trim()); - } - return map; + if (string == null) return null; + HashMap map = new HashMap(); + int pos; + if ((pos = string.indexOf("{")) >= 0) string = string.substring(pos + 1).trim(); + if ((pos = string.lastIndexOf("}")) >= 0) string = string.substring(0, pos).trim(); + StringTokenizer st = new StringTokenizer(string, separator); + String token; + while (st.hasMoreTokens()) { + token = st.nextToken().trim(); + pos = token.indexOf("="); + if (pos > 0) map.put(token.substring(0, pos).trim(), token.substring(pos + 1).trim()); + } + return map; + } + + public static String map2string(Map m, String separator, boolean braces) { + StringBuffer buf = new StringBuffer(); + if (braces) buf.append("{"); + Iterator i = m.entrySet().iterator(); + boolean hasNext = i.hasNext(); + while (hasNext) { + Entry e = (Entry) (i.next()); + Object key = e.getKey(); + Object value = e.getValue(); + buf.append(key.toString()); + buf.append('='); + buf.append(value.toString()); + + hasNext = i.hasNext(); + if (hasNext) buf.append(separator); + } + if (braces) buf.append("}"); + return buf.toString(); + } + + public static Set string2set(String string, String separator) { + // this can be used to parse a Map.toString() into a Map again + if (string == null) return null; + HashSet set = new HashSet(); + int pos; + if ((pos = string.indexOf("{")) >= 0) string = string.substring(pos + 1).trim(); + if ((pos = string.lastIndexOf("}")) >= 0) string = string.substring(0, pos).trim(); + StringTokenizer st = new StringTokenizer(string, separator); + while (st.hasMoreTokens()) { + set.add(st.nextToken().trim()); + } + return set; + } + + public static String set2string(Set s, String separator, boolean braces) { + StringBuffer buf = new StringBuffer(); + if (braces) buf.append("{"); + Iterator i = s.iterator(); + boolean hasNext = i.hasNext(); + while (hasNext) { + buf.append(i.next().toString()); + hasNext = i.hasNext(); + if (hasNext) buf.append(separator); + } + if (braces) buf.append("}"); + return buf.toString(); } public static void main(String[] s) { @@ -179,7 +232,7 @@ public final class serverCodings { if (s[0].equals("-s2m")) { // generate a b64 decoding from a given string - System.out.println(string2map(s[1]).toString()); + System.out.println(string2map(s[1], ",").toString()); } } diff --git a/source/de/anomic/yacy/yacyNewsAction.java b/source/de/anomic/yacy/yacyNewsAction.java index ad7b0a5d8..3bdbe877f 100644 --- a/source/de/anomic/yacy/yacyNewsAction.java +++ b/source/de/anomic/yacy/yacyNewsAction.java @@ -64,8 +64,8 @@ public class yacyNewsAction implements yacyPeerAction { String decodedString = de.anomic.tools.crypt.simpleDecode(recordString, ""); yacyNewsRecord record = new yacyNewsRecord(decodedString); //System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString()); - String cre1 = (String) serverCodings.string2map(decodedString).get("cre"); - String cre2 = (String) serverCodings.string2map(record.toString()).get("cre"); + String cre1 = (String) serverCodings.string2map(decodedString, ",").get("cre"); + String cre2 = (String) serverCodings.string2map(record.toString(), ",").get("cre"); if ((cre1 == null) || (cre2 == null) || (!(cre1.equals(cre2)))) { System.out.println("### ERROR - cre are not equal: cre1=" + cre1 + ", cre2=" + cre2); return; diff --git a/source/de/anomic/yacy/yacyNewsDB.java b/source/de/anomic/yacy/yacyNewsDB.java index 0f9c24a31..c8ab83fd0 100644 --- a/source/de/anomic/yacy/yacyNewsDB.java +++ b/source/de/anomic/yacy/yacyNewsDB.java @@ -160,7 +160,7 @@ public class yacyNewsDB { b.getColString(1, "UTF-8"), (b.empty(2)) ? null : yacyCore.parseUniversalDate(b.getColString(2, null), serverDate.UTCDiffString()), (int) b.getColLong(3), - serverCodings.string2map(b.getColString(4, "UTF-8")) + serverCodings.string2map(b.getColString(4, "UTF-8"), ",") ); } diff --git a/source/de/anomic/yacy/yacyNewsRecord.java b/source/de/anomic/yacy/yacyNewsRecord.java index afd23a7e9..efeab6609 100644 --- a/source/de/anomic/yacy/yacyNewsRecord.java +++ b/source/de/anomic/yacy/yacyNewsRecord.java @@ -79,7 +79,7 @@ public class yacyNewsRecord { ); public yacyNewsRecord(String newsString) { - this.attributes = serverCodings.string2map(newsString); + this.attributes = serverCodings.string2map(newsString, ","); this.received = (attributes.containsKey("rec")) ? yacyCore.parseUniversalDate((String) attributes.get("rec"), serverDate.UTCDiffString()) : new Date(); this.created = (attributes.containsKey("cre")) ? yacyCore.parseUniversalDate((String) attributes.get("cre"), serverDate.UTCDiffString()) : new Date(); this.category = (attributes.containsKey("cat")) ? (String) attributes.get("cat") : null; diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index 7eb2ef2dd..a1e5fa1c0 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -67,6 +67,7 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.Set; import de.anomic.kelondro.kelondroBase64Order; import de.anomic.net.natLib; @@ -128,6 +129,7 @@ public class yacySeed { public static final String NAME = "Name"; public static final String BDATE = "BDate"; public static final String UTC = "UTC"; + public static final String PEERTAGS = "Tags"; public static final String ISPEED = "ISpeed"; public static final String UPTIME = "Uptime"; @@ -392,6 +394,14 @@ public class yacySeed { put(LASTSEEN, yacyCore.shortFormatter.format(new Date(System.currentTimeMillis() - serverDate.UTCDiff() + getUTCDiff()))); } + public void setPeerTags(Set keys) { + put(PEERTAGS, serverCodings.set2string(keys, "|", false)); + } + + public Set getPeerTags() { + return serverCodings.string2set(get(PEERTAGS, ""), "|"); + } + public int getPPM() { try { return Integer.parseInt(get(ISPEED, "0")); @@ -609,7 +619,7 @@ public class yacySeed { if (seedStr == null) { return null; } final String seed = crypt.simpleDecode(seedStr, key); if (seed == null) { return null; } - final HashMap dna = serverCodings.string2map(seed); + final HashMap dna = serverCodings.string2map(seed, ","); final String hash = (String) dna.remove("Hash"); yacySeed resultSeed = new yacySeed(hash, dna); if (properTest) { @@ -624,9 +634,9 @@ public class yacySeed { public String toString() { synchronized (this.dna) { - this.dna.put("Hash", this.hash); // set hash into seed code structure - final String s = this.dna.toString(); // generate string representation - this.dna.remove("Hash"); // reconstruct original: hash is stored external + this.dna.put("Hash", this.hash); // set hash into seed code structure + final String s = serverCodings.map2string(this.dna, ",", true); // generate string representation + this.dna.remove("Hash"); // reconstruct original: hash is stored external return s; } }