- redesign of a part of the remote search client to make it possible to have a test environment for remote search performance tests

- added a remote search test main methods in yacyClient

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7146 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 2e75879504
commit 7ebef56add

@ -672,6 +672,7 @@ public final class Switchboard extends serverSwitch {
this.trail = new ArrayList<String>(); this.trail = new ArrayList<String>();
log.logConfig("Finished Switchboard Initialization"); log.logConfig("Finished Switchboard Initialization");
sb = this;
} }
private void setDefaultSegments() { private void setDefaultSegments() {

@ -47,11 +47,11 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
//import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
//import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -84,12 +84,13 @@ import org.apache.http.entity.mime.content.StringBody;
import de.anomic.crawler.ResultURLs; import de.anomic.crawler.ResultURLs;
import de.anomic.crawler.retrieval.EventOrigin; import de.anomic.crawler.retrieval.EventOrigin;
import de.anomic.crawler.retrieval.HTTPLoader; import de.anomic.crawler.retrieval.HTTPLoader;
import de.anomic.search.ContentDomain;
import de.anomic.search.QueryParams;
import de.anomic.search.RankingProfile; import de.anomic.search.RankingProfile;
import de.anomic.search.RankingProcess; import de.anomic.search.RankingProcess;
import de.anomic.search.SearchEvent; import de.anomic.search.SearchEvent;
import de.anomic.search.Segment; import de.anomic.search.Segment;
import de.anomic.search.Switchboard; import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
import de.anomic.search.TextSnippet; import de.anomic.search.TextSnippet;
import de.anomic.server.serverCore; import de.anomic.server.serverCore;
import de.anomic.tools.crypt; import de.anomic.tools.crypt;
@ -397,82 +398,23 @@ public final class yacyClient {
// partitions : number of remote peers that are asked (for evaluation of QPM) // partitions : number of remote peers that are asked (for evaluation of QPM)
// duetime : maximum time that a peer should spent to create a result // duetime : maximum time that a peer should spent to create a result
// prepare request
final String salt = crypt.randomSalt();
final long timestamp = System.currentTimeMillis(); final long timestamp = System.currentTimeMillis();
boolean thisIsASecondarySearch = urlhashes.length() > 0; SearchResult result;
assert !thisIsASecondarySearch || secondarySearchSuperviser == null;
// send request
Map<String, String> result = null;
try { try {
// result = FileUtils.table(HttpConnector.wput("http://" + target.getClusterAddress() + "/yacy/search.html", target.getHexHash() + ".yacyh", post, 60000)); result = searchClient(
final LinkedHashMap<String,ContentBody> parts = yacyNetwork.basicRequestParts(Switchboard.getSwitchboard(), target.hash, salt); yacyNetwork.basicRequestParts(Switchboard.getSwitchboard(), target.hash, crypt.randomSalt()),
parts.put("myseed", new StringBody(mySeed.genSeedStr(salt))); mySeed, wordhashes, excludehashes, urlhashes, prefer, filter, language,
parts.put("count", new StringBody(Integer.toString(Math.max(10, count)))); sitehash, authorhash, count, maxDistance, global, partitions, target.getHexHash() + ".yacyh", target.getClusterAddress(),
parts.put("resource", new StringBody(((global) ? "global" : "local"))); secondarySearchSuperviser, rankingProfile, constraint);
parts.put("partitions", new StringBody(Integer.toString(partitions)));
parts.put("query", new StringBody(wordhashes));
parts.put("exclude", new StringBody(excludehashes));
parts.put("duetime", new StringBody("1000"));
parts.put("urls", new StringBody(urlhashes));
parts.put("prefer", new StringBody(prefer.toString()));
parts.put("filter", new StringBody(filter.toString()));
parts.put("language", new StringBody(language));
parts.put("sitehash", new StringBody(sitehash));
parts.put("authorhash", new StringBody(authorhash));
parts.put("ttl", new StringBody("0"));
parts.put("maxdist", new StringBody(Integer.toString(maxDistance)));
parts.put("profile", new StringBody(crypt.simpleEncode(rankingProfile.toExternalString())));
parts.put("constraint", new StringBody((constraint == null) ? "" : constraint.exportB64()));
if (secondarySearchSuperviser != null)
parts.put("abstracts", new StringBody("auto"));
result = FileUtils.table(HTTPConnector.getConnector(HTTPLoader.crawlerUserAgent).post(new MultiProtocolURI("http://" + target.getClusterAddress() + "/yacy/search.html"), 60000, target.getHexHash() + ".yacyh", parts));
} catch (final IOException e) { } catch (final IOException e) {
yacyCore.log.logInfo("SEARCH failed, Peer: " + target.hash + ":" + target.getName() + " (" + e.getMessage() + "), score=" + target.selectscore); yacyCore.log.logInfo("SEARCH failed, Peer: " + target.hash + ":" + target.getName() + " (" + e.getMessage() + "), score=" + target.selectscore);
//yacyCore.peerActions.peerDeparture(target, "search request to peer created io exception: " + e.getMessage()); //yacyCore.peerActions.peerDeparture(target, "search request to peer created io exception: " + e.getMessage());
return -1; return -1;
} }
if (result == null) return -1;
if (result == null || result.isEmpty()) { // computation time
if (yacyCore.log.isFine()) yacyCore.log.logFine("SEARCH failed FROM "
+ target.hash
+ ":"
+ target.getName()
+ " (zero response), score="
+ target.selectscore);
return -1;
}
// compute all computation times
final long totalrequesttime = System.currentTimeMillis() - timestamp; final long totalrequesttime = System.currentTimeMillis() - timestamp;
// OUTPUT:
// version : application version of responder
// uptime : uptime in seconds of responder
// total : number of total available LURL's for this search
// count : number of returned LURL's for this search
// resource<n> : LURL of search
// fwhop : hops (depth) of forwards that had been performed to construct this result
// fwsrc : peers that helped to construct this result
// fwrec : peers that would have helped to construct this result (recommendations)
// searchtime : time that the peer actually spent to create the result
// references : references (search hints) that was calculated during search
// now create a plasmaIndex out of this result
// System.out.println("yacyClient: " + ((urlhashes.length() == 0) ? "primary" : "secondary")+ " search result = " + result.toString()); // debug
int urlcount = 0, joincount = 0;
try {
joincount = Integer.parseInt(result.get("joincount")); // the complete number of hits at remote site
urlcount = Integer.parseInt(result.get("count")); // the number of hits that are returned in the result list
} catch (final NumberFormatException e) {
yacyCore.log.logInfo("SEARCH failed FROM " + target.hash + ":" + target.getName() + ", wrong output format: " + e.getMessage());
//yacyCore.peerActions.peerDeparture(target, "search request to peer created number format exception");
return -1;
}
// System.out.println("***result count " + results);
// create containers // create containers
final int words = wordhashes.length() / Word.commonHashLength; final int words = wordhashes.length() / Word.commonHashLength;
assert words > 0 : "wordhashes = " + wordhashes; assert words > 0 : "wordhashes = " + wordhashes;
@ -487,10 +429,8 @@ public final class yacyClient {
} }
// insert results to containers // insert results to containers
URIMetadataRow urlEntry; for (URIMetadataRow urlEntry: result.links) {
for (int n = 0; n < urlcount; n++) {
// get one single search result // get one single search result
urlEntry = URIMetadataRow.importEntry(result.get("resource" + n));
if (urlEntry == null) continue; if (urlEntry == null) continue;
assert (urlEntry.hash().length == 12) : "urlEntry.hash() = " + new String(urlEntry.hash()); assert (urlEntry.hash().length == 12) : "urlEntry.hash() = " + new String(urlEntry.hash());
if (urlEntry.hash().length != 12) continue; // bad url hash if (urlEntry.hash().length != 12) continue; // bad url hash
@ -551,7 +491,7 @@ public final class yacyClient {
// store remote result to local result container // store remote result to local result container
// insert one container into the search result buffer // insert one container into the search result buffer
// one is enough, only the references are used, not the word // one is enough, only the references are used, not the word
containerCache.add(container[0], false, target.getName() + "/" + target.hash, joincount); containerCache.add(container[0], false, target.getName() + "/" + target.hash, result.joincount);
// insert the containers to the index // insert the containers to the index
for (ReferenceContainer<WordReference> c: container) try { for (ReferenceContainer<WordReference> c: container) try {
@ -559,45 +499,39 @@ public final class yacyClient {
} catch (Exception e) { } catch (Exception e) {
Log.logException(e); Log.logException(e);
} }
yacyCore.log.logInfo("remote search: peer " + target.getName() + " sent " + container[0].size() + "/" + joincount + " references for " + (thisIsASecondarySearch ? "a secondary search" : "joined word queries")); boolean thisIsASecondarySearch = urlhashes.length() > 0;
assert !thisIsASecondarySearch || secondarySearchSuperviser == null;
yacyCore.log.logInfo("remote search: peer " + target.getName() + " sent " + container[0].size() + "/" + result.joincount + " references for " + (thisIsASecondarySearch ? "a secondary search" : "joined word queries"));
// integrate remote top-words/topics // integrate remote top-words/topics
final String references = result.get("references"); if (result.references != null && result.references.length > 0) {
if (references != null && references.length() > 0) { yacyCore.log.logInfo("remote search: peer " + target.getName() + " sent " + result.references.length + " topics");
yacyCore.log.logInfo("remote search: peer " + target.getName() + " sent topics: " + references);
// add references twice, so they can be counted (must have at least 2 entries) // add references twice, so they can be counted (must have at least 2 entries)
String[] rs = references.split(",");
synchronized (containerCache) { synchronized (containerCache) {
containerCache.addTopic(rs); containerCache.addTopic(result.references);
containerCache.addTopic(rs); containerCache.addTopic(result.references);
} }
} }
// read index abstract // read index abstract
if (secondarySearchSuperviser != null) { if (secondarySearchSuperviser != null) {
final Iterator<Map.Entry<String, String>> i = result.entrySet().iterator();
Map.Entry<String, String> entry;
String wordhash; String wordhash;
String whacc = ""; String whacc = "";
ByteBuffer ci; ByteBuffer ci;
int ac = 0; int ac = 0;
abstractparser: while (i.hasNext()) { for (Map.Entry<byte[], String> abstractEntry: result.indexabstract.entrySet()) {
entry = i.next(); wordhash = new String(abstractEntry.getKey());
if (entry.getKey().startsWith("indexabstract.")) {
wordhash = entry.getKey().substring(14);
if (wordhash.charAt(0) == '[') break abstractparser;
whacc += wordhash; whacc += wordhash;
try { try {
ci = new ByteBuffer(entry.getValue().getBytes("UTF-8")); ci = new ByteBuffer(abstractEntry.getValue().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Log.logException(e); Log.logException(e);
return -1; return -1;
} }
//System.out.println("DEBUG-ABSTRACTFETCH: for word hash " + wordhash + " received " + ci.toString());
secondarySearchSuperviser.addAbstract(wordhash, ReferenceContainer.decompressIndex(ci, target.hash)); secondarySearchSuperviser.addAbstract(wordhash, ReferenceContainer.decompressIndex(ci, target.hash));
ac++; ac++;
} }
}
if (ac > 0) { if (ac > 0) {
secondarySearchSuperviser.commitAbstract(); secondarySearchSuperviser.commitAbstract();
yacyCore.log.logInfo("remote search: peer " + target.getName() + " sent " + ac + " index abstracts for words "+ whacc); yacyCore.log.logInfo("remote search: peer " + target.getName() + " sent " + ac + " index abstracts for words "+ whacc);
@ -605,24 +539,139 @@ public final class yacyClient {
} }
// generate statistics // generate statistics
long searchtime;
try {
searchtime = Integer.parseInt(result.get("searchtime"));
} catch (final NumberFormatException e) {
searchtime = totalrequesttime;
}
if (yacyCore.log.isFine()) yacyCore.log.logFine("SEARCH " if (yacyCore.log.isFine()) yacyCore.log.logFine("SEARCH "
+ urlcount + result.urlcount
+ " URLS FROM " + " URLS FROM "
+ target.hash + target.hash
+ ":" + ":"
+ target.getName() + target.getName()
+ ", score=" + ", score="
+ target.selectscore + target.selectscore
+ ", searchtime=" + searchtime + ", netdelay=" + ", searchtime=" + result.searchtime + ", netdelay="
+ (totalrequesttime - searchtime) + ", references=" + (totalrequesttime - result.searchtime) + ", references="
+ result.get("references")); + result.references);
return urlcount; return result.urlcount;
}
public static SearchResult searchClient(
LinkedHashMap<String,ContentBody> parts,
final yacySeed mySeed,
final String wordhashes,
final String excludehashes,
final String urlhashes,
final Pattern prefer,
final Pattern filter,
final String language,
final String sitehash,
final String authorhash,
final int count,
final int maxDistance,
final boolean global,
final int partitions,
String hostname,
String hostaddress,
final SearchEvent.SecondarySearchSuperviser secondarySearchSuperviser,
final RankingProfile rankingProfile,
final Bitfield constraint
) throws IOException {
// send a search request to peer with remote Hash
// INPUT:
// iam : complete seed of the requesting peer
// youare : seed hash of the target peer, used for testing network stability
// key : transmission key for response
// search : a list of search words
// hsearch : a string of word hashes
// fwdep : forward depth. if "0" then peer may NOT ask another peer for more results
// fwden : forward deny, a list of seed hashes. They may NOT be target of forward hopping
// count : maximum number of wanted results
// global : if "true", then result may consist of answers from other peers
// partitions : number of remote peers that are asked (for evaluation of QPM)
// duetime : maximum time that a peer should spent to create a result
// send request
Map<String, String> resultMap = null;
parts.put("myseed", new StringBody((mySeed == null) ? "" : mySeed.genSeedStr(parts.get("key").toString())));
parts.put("count", new StringBody(Integer.toString(Math.max(10, count))));
parts.put("resource", new StringBody(((global) ? "global" : "local")));
parts.put("partitions", new StringBody(Integer.toString(partitions)));
parts.put("query", new StringBody(wordhashes));
parts.put("exclude", new StringBody(excludehashes));
parts.put("duetime", new StringBody("1000"));
parts.put("urls", new StringBody(urlhashes));
parts.put("prefer", new StringBody(prefer.toString()));
parts.put("filter", new StringBody(filter.toString()));
parts.put("language", new StringBody(language));
parts.put("sitehash", new StringBody(sitehash));
parts.put("authorhash", new StringBody(authorhash));
parts.put("ttl", new StringBody("0"));
parts.put("maxdist", new StringBody(Integer.toString(maxDistance)));
parts.put("profile", new StringBody(crypt.simpleEncode(rankingProfile.toExternalString())));
parts.put("constraint", new StringBody((constraint == null) ? "" : constraint.exportB64()));
if (secondarySearchSuperviser != null) parts.put("abstracts", new StringBody("auto"));
resultMap = FileUtils.table(HTTPConnector.getConnector(HTTPLoader.crawlerUserAgent).post(new MultiProtocolURI("http://" + hostaddress + "/yacy/search.html"), 60000, hostname, parts));
//resultMap = FileUtils.table(HTTPConnector.getConnector(HTTPLoader.crawlerUserAgent).post(new MultiProtocolURI("http://" + target.getClusterAddress() + "/yacy/search.html"), 60000, target.getHexHash() + ".yacyh", parts));
if (resultMap == null || resultMap.isEmpty()) throw new IOException("resultMap is NULL");
return new SearchResult(resultMap);
}
public static class SearchResult {
public String version; // version : application version of responder
public String uptime; // uptime : uptime in seconds of responder
public String fwhop; // hops (depth) of forwards that had been performed to construct this result
public String fwsrc; // peers that helped to construct this result
public String fwrec; // peers that would have helped to construct this result (recommendations)
public int urlcount; // number of returned LURL's for this search
public int joincount; //
public Map<byte[], Integer> indexcount; //
public long searchtime; // time that the peer actually spent to create the result
public String[] references; // search hints, the top-words
public List<URIMetadataRow> links; // LURLs of search
public Map<byte[], String> indexabstract; // index abstracts, a collection of url-hashes per word
public SearchResult(Map<String, String> resultMap) throws IOException {
try {
this.searchtime = Integer.parseInt(resultMap.get("searchtime"));
} catch (final NumberFormatException e) {
throw new IOException("wrong output format for searchtime: " + e.getMessage());
}
try {
this.joincount = Integer.parseInt(resultMap.get("joincount")); // the complete number of hits at remote site
} catch (final NumberFormatException e) {
throw new IOException("wrong output format for joincount: " + e.getMessage());
}
try {
this.urlcount = Integer.parseInt(resultMap.get("count")); // the number of hits that are returned in the result list
} catch (final NumberFormatException e) {
throw new IOException("wrong output format for count: " + e.getMessage());
}
this.fwhop = resultMap.get("fwhop");
this.fwsrc = resultMap.get("fwsrc");
this.fwrec = resultMap.get("fwrec");
// scan the result map for entries with special prefix
indexcount = new TreeMap<byte[], Integer>(Base64Order.enhancedCoder);
indexabstract = new TreeMap<byte[], String>(Base64Order.enhancedCoder);
for (Map.Entry<String, String> entry: resultMap.entrySet()) {
if (entry.getKey().startsWith("indexcount.")) {
indexcount.put(entry.getKey().substring(11).getBytes(), Integer.parseInt(entry.getValue()));
}
if (entry.getKey().startsWith("indexabstract.")) {
indexabstract.put(entry.getKey().substring(14).getBytes(), entry.getValue());
}
}
references = resultMap.get("references").split(",");
this.links = new ArrayList<URIMetadataRow>(this.urlcount);
for (int n = 0; n < this.urlcount; n++) {
// get one single search result
String resultLine = resultMap.get("resource" + n);
if (resultLine == null) continue;
URIMetadataRow urlEntry = URIMetadataRow.importEntry(resultLine);
if (urlEntry == null) continue;
this.links.add(urlEntry);
}
}
} }
public static Map<String, String> permissionMessage(final yacySeedDB seedDB, final String targetHash) { public static Map<String, String> permissionMessage(final yacySeedDB seedDB, final String targetHash) {
@ -1029,30 +1078,64 @@ public final class yacyClient {
} }
} }
public static void main(final String[] args) { public static void main(final String[] args) {
if(args.length > 1) { if(args.length > 2) {
// search a remote peer. arguments:
// first arg: path to application home
// second arg: address of target peer
// third arg: search word or file name with list of search words
System.out.println("yacyClient Test"); System.out.println("yacyClient Test");
File searchwordfile = new File(args[2]);
List<String> searchlines = new ArrayList<String>();
if (searchwordfile.exists()) {
Iterator<String> i;
try { try {
final Switchboard sb = new Switchboard(new File(args[0]), new File(args[0]), "httpProxy.init", "DATA/SETTINGS/yacy.conf"); i = FileUtils.strings(FileUtils.read(searchwordfile));
/*final yacyCore core =*/ new yacyCore(sb); while (i.hasNext()) searchlines.add(i.next());
sb.loadSeedLists(); } catch (IOException e) {
final yacySeed target = sb.peers.getConnected(args[1]); e.printStackTrace();
final byte[] wordhashe = Word.word2hash("test"); System.exit(-1);
//System.out.println("permission=" + permissionMessage(args[1])); }
} else {
final byte[] content = new MultiProtocolURI("http://" + target.getPublicAddress() + "/yacy/search.html" + searchlines.add(args[2]);
"?myseed=" + sb.peers.mySeed().genSeedStr(null) + }
"&youare=" + target.hash + "&key=" + for (String line: searchlines) {
"&myseed=" + sb.peers.mySeed() .genSeedStr(null) + final byte[] wordhashe = QueryParams.hashSet2hashString(Word.words2hashesHandles(QueryParams.cleanQuery(line)[0])).getBytes();
"&count=10" + long time = System.currentTimeMillis();
"&resource=global" + SearchResult result;
"&query=" + new String(wordhashe) + try {
"&network.unit.name=" + Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, yacySeed.DFLT_NETWORK_UNIT)).get(HTTPLoader.crawlerUserAgent, 10000); result = searchClient(
final Map<String, String> result = FileUtils.table(content); yacyNetwork.basicRequestParts((String) null, (String) null, "freeworld"),
System.out.println("Result=" + result.toString()); null, // sb.peers.mySeed(),
} catch (final Exception e) { new String(wordhashe),
Log.logException(e); "", // excludehashes,
"", // urlhashes,
Pattern.compile(""), // prefer,
Pattern.compile(".*"), // filter,
"", // language,
"", // sitehash,
"", // authorhash,
10, // count,
1000, // maxDistance,
true, //global,
16, // partitions,
"", args[1],
null, //secondarySearchSuperviser,
new RankingProfile(ContentDomain.TEXT), // rankingProfile,
null // constraint);
);
if (result == null) {
System.out.println("no response");
} else {
for (URIMetadataRow link: result.links) {
System.out.println(link.metadata().url().toNormalform(true, false));
System.out.println(link.snippet());
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Search Time: " + (System.currentTimeMillis() - time));
} }
System.exit(0); System.exit(0);
} else if(args.length == 1) { } else if(args.length == 1) {
@ -1064,7 +1147,7 @@ public final class yacyClient {
} catch (final MalformedURLException e) { } catch (final MalformedURLException e) {
Log.logException(e); Log.logException(e);
} }
if(url == null) { if (url == null) {
System.exit(1); System.exit(1);
return; return;
} }

@ -77,54 +77,13 @@ public class yacyNetwork {
return false; return false;
} }
// public static final List<Part> basicRequestPost(final Switchboard sb, final String targetHash, final String salt) { public static final LinkedHashMap<String,ContentBody> basicRequestParts(final Switchboard sb, final String targetHash, final String salt) {
// // put in all the essentials for routing and network authentication
// // generate a session key
// final ArrayList<Part> post = new ArrayList<Part>();
// post.add(new DefaultCharsetStringPart("key", salt));
//
// // just standard identification essentials
// post.add(new DefaultCharsetStringPart("iam", sb.peers.mySeed().hash));
// if (targetHash != null) post.add(new DefaultCharsetStringPart("youare", targetHash));
//
// // time information for synchronization
// post.add(new DefaultCharsetStringPart("mytime", DateFormatter.formatShortSecond(new Date())));
// post.add(new DefaultCharsetStringPart("myUTC", Long.toString(System.currentTimeMillis())));
//
// // network identification
// post.add(new DefaultCharsetStringPart(SwitchboardConstants.NETWORK_NAME, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, yacySeed.DFLT_NETWORK_UNIT)));
//
// // authentication essentials
// final String authenticationControl = sb.getConfig("network.unit.protocol.control", "uncontrolled");
// final String authenticationMethod = sb.getConfig("network.unit.protocol.request.authentication.method", "");
// if ((authenticationControl.equals("controlled")) && (authenticationMethod.length() > 0)) {
// if (authenticationMethod.equals("salted-magic-sim")) {
// // generate an authentication essential using the salt, the iam-hash and the network magic
// final String magic = sb.getConfig("network.unit.protocol.request.authentication.essentials", "");
// final String md5 = Digest.encodeMD5Hex(salt + sb.peers.mySeed().hash + magic);
// post.add(new DefaultCharsetStringPart("magicmd5", md5));
// }
// }
//
// return post;
// }
public static final LinkedHashMap<String,ContentBody> basicRequestParts(final Switchboard sb, final String targetHash, final String salt) throws UnsupportedEncodingException {
// put in all the essentials for routing and network authentication // put in all the essentials for routing and network authentication
// generate a session key // generate a session key
final LinkedHashMap<String,ContentBody> parts = new LinkedHashMap<String,ContentBody>(); final LinkedHashMap<String,ContentBody> parts = basicRequestParts(sb.peers.mySeed().hash, targetHash, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, yacySeed.DFLT_NETWORK_UNIT));
try {
parts.put("key", new StringBody(salt)); parts.put("key", new StringBody(salt));
} catch (UnsupportedEncodingException e) {}
// just standard identification essentials
parts.put("iam", new StringBody(sb.peers.mySeed().hash));
if (targetHash != null) parts.put("youare", new StringBody(targetHash));
// time information for synchronization
parts.put("mytime", new StringBody(DateFormatter.formatShortSecond(new Date())));
parts.put("myUTC", new StringBody(Long.toString(System.currentTimeMillis())));
// network identification
parts.put(SwitchboardConstants.NETWORK_NAME, new StringBody(Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, yacySeed.DFLT_NETWORK_UNIT)));
// authentication essentials // authentication essentials
final String authenticationControl = sb.getConfig("network.unit.protocol.control", "uncontrolled"); final String authenticationControl = sb.getConfig("network.unit.protocol.control", "uncontrolled");
@ -134,11 +93,35 @@ public class yacyNetwork {
// generate an authentication essential using the salt, the iam-hash and the network magic // generate an authentication essential using the salt, the iam-hash and the network magic
final String magic = sb.getConfig("network.unit.protocol.request.authentication.essentials", ""); final String magic = sb.getConfig("network.unit.protocol.request.authentication.essentials", "");
final String md5 = Digest.encodeMD5Hex(salt + sb.peers.mySeed().hash + magic); final String md5 = Digest.encodeMD5Hex(salt + sb.peers.mySeed().hash + magic);
try {
parts.put("magicmd5", new StringBody(md5)); parts.put("magicmd5", new StringBody(md5));
} catch (UnsupportedEncodingException e) {}
} }
} }
return parts; return parts;
} }
public static final LinkedHashMap<String,ContentBody> basicRequestParts(String myHash, String targetHash, String networkName) {
// put in all the essentials for routing and network authentication
// generate a session key
final LinkedHashMap<String,ContentBody> parts = new LinkedHashMap<String,ContentBody>();
// just standard identification essentials
if (myHash != null)
try {
parts.put("iam", new StringBody(myHash));
if (targetHash != null) parts.put("youare", new StringBody(targetHash));
// time information for synchronization
parts.put("mytime", new StringBody(DateFormatter.formatShortSecond(new Date())));
parts.put("myUTC", new StringBody(Long.toString(System.currentTimeMillis())));
// network identification
parts.put(SwitchboardConstants.NETWORK_NAME, new StringBody(networkName));
} catch (UnsupportedEncodingException e) {}
return parts;
}
} }

@ -752,9 +752,9 @@ public class yacySeed implements Cloneable {
// yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key); // yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key);
// check protocol and syntax of seed // check protocol and syntax of seed
if (seedStr == null) { return null; } if (seedStr == null || seedStr.length() == 0) return null;
final String seed = crypt.simpleDecode(seedStr, key); final String seed = crypt.simpleDecode(seedStr, key);
if (seed == null) { return null; } if (seed == null || seed.length() == 0) return null;
// extract hash // extract hash
final ConcurrentHashMap<String, String> dna = MapTools.string2map(seed, ","); final ConcurrentHashMap<String, String> dna = MapTools.string2map(seed, ",");

Loading…
Cancel
Save