From f763923e0a6cf8f9fd65e77b22adbf87f4ab9229 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 11 Nov 2005 08:02:46 +0000 Subject: [PATCH] added missing files for last commit git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1057 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/yacy/transfer.html | 12 ++ htroot/yacy/transfer.java | 161 ++++++++++++++++++ .../de/anomic/plasma/plasmaSwitchboard.java | 5 +- 3 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 htroot/yacy/transfer.html create mode 100644 htroot/yacy/transfer.java diff --git a/htroot/yacy/transfer.html b/htroot/yacy/transfer.html new file mode 100644 index 000000000..e7b0e7a96 --- /dev/null +++ b/htroot/yacy/transfer.html @@ -0,0 +1,12 @@ +version=#[version]# +uptime=#[uptime]# +response=#[response]# +#(process)# +access=#[access]# +address=#[address]# +protocol=#[protocol]# +path=#[path]# +maxsize=#[maxsize]# +:: +tt=#[tt]# +#(/process)# \ No newline at end of file diff --git a/htroot/yacy/transfer.java b/htroot/yacy/transfer.java new file mode 100644 index 000000000..1680897fb --- /dev/null +++ b/htroot/yacy/transfer.java @@ -0,0 +1,161 @@ +// transfer.java +// ----------------------- +// part of YaCy caching proxy +// (C) by Michael Peter Christen; mc@anomic.de +// first published on http://www.anomic.de +// Frankfurt, Germany, 2004 +// created 07.11.2005 +// +// $LastChangedDate: 2005-10-17 17:46:12 +0200 (Mon, 17 Oct 2005) $ +// $LastChangedRevision: 947 $ +// $LastChangedBy: borg-0300 $ +// +// 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Using this software in any meaning (reading, learning, copying, compiling, +// running) means that you agree that the Author(s) is (are) not responsible +// for cost, loss of data or any harm that may be caused directly or indirectly +// by usage of this softare or this documentation. The usage of this software +// is on your own risk. The installation and usage (starting/running) of this +// software may allow other people or application to access your computer and +// any attached devices and is highly dependent on the configuration of the +// software which must be done by the user of the software; the author(s) is +// (are) also not responsible for proper configuration and usage of the +// software, even if provoked by documentation provided together with +// the software. +// +// Any changes to this file according to the GPL as documented in the file +// gpl.txt aside this file in the shipment you received can be done to the +// lines that follows this copyright notice here, but changes must not be +// done inside the copyright notive above. A re-distribution must contain +// the intact and unchanged copyright notice. +// Contributions and changes to the program code must be marked as such. + +import java.io.File; +import java.io.IOException; + +import de.anomic.http.httpHeader; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.plasma.plasmaRankingDistribution; +import de.anomic.server.serverFileUtils; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; +import de.anomic.server.serverCodings; +import de.anomic.yacy.yacyCore; +import de.anomic.yacy.yacySeed; +import de.anomic.yacy.yacySeedDB; + +public final class transfer { + + public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { + if (post == null || env == null) return null; + plasmaSwitchboard sb = (plasmaSwitchboard) env; + serverObjects prop = new serverObjects(); + + + String process = (String) post.get("process", ""); // permission or store + String key = (String) post.get("key", ""); // a transmission key from the client + String otherpeer = (String) post.get("iam", ""); // identification of the client (a peer-hash) + String purpose = (String) post.get("purpose", ""); // declares how the file shall be treated + String filename = (String) post.get("filename", ""); // a name of a file without path + long filesize = Long.parseLong((String) post.get("filesize", "")); // the size of the file + + yacySeed otherseed = yacyCore.seedDB.get(otherpeer); + if (otherseed == null) { + // reject unknown peers + // this does not appear fair, but anonymous senders are dangerous + prop.put("process", 0); + prop.put("response", "denied"); + prop.put("process_access", ""); + prop.put("process_address", ""); + prop.put("process_protocol", ""); + prop.put("process_path", ""); + prop.put("process_maxsize", "0"); + sb.getLog().logFine("RankingTransmission: rejected unknown peer '" + otherpeer + "'"); + return prop; + } + + String otherpeerName = otherseed.hash + ":" + otherseed.getName(); + + if (process.equals("permission")) { + prop.put("process", 0); + if (purpose.equals("crcon")) { + // consolidation of cr files + //System.out.println("yacy/transfer:post=" + post.toString()); + String cansendprotocol = (String) post.get("can-send-protocol", "http"); + String access = serverCodings.enhancedCoder.encodeMD5B64(otherpeer + ":" + filename, true) + ":" + serverCodings.enhancedCoder.encodeMD5B64("" + System.currentTimeMillis(), true); + prop.put("response", "ok"); + prop.put("process_access", access); + prop.put("process_address", yacyCore.seedDB.mySeed.getAddress()); + prop.put("process_protocol", "http"); + prop.put("process_path", ""); // currently empty; the store process will find a path + prop.put("process_maxsize", "-1"); // if response is too big we return the size of the file + sb.rankingPermissions.put(serverCodings.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(access)), filename); + sb.getLog().logFine("RankingTransmission: granted peer " + otherpeerName + " to send CR file " + filename); + } + return prop; + } + + if (process.equals("store")) { + prop.put("process", 1); + if (purpose.equals("crcon")) { + byte[] filebytes = (byte[]) post.get("filename$file"); + String accesscode = (String) post.get("access", ""); // one-time authentication + String md5 = (String) post.get("md5", ""); // one-time authentication + java.util.HashMap perm = sb.rankingPermissions; + //System.out.println("PERMISSIONDEBUG: accesscode=" + accesscode + ", permissions=" + perm.toString()); + String grantedFile = (String) sb.rankingPermissions.get(accesscode); + prop.put("process_tt", ""); + if ((grantedFile == null) || (!(grantedFile.equals(filename)))) { + // fraud-access of this interface + prop.put("response", "denied"); + sb.getLog().logFine("RankingTransmission: denied " + otherpeerName + " to send CR file " + filename + ": wrong access code"); + } else { + sb.rankingPermissions.remove(accesscode); // not needed any more + File path = new File(sb.rankingPath, plasmaRankingDistribution.CR_OTHER); + path.mkdirs(); + File file = new File(path, filename); + try { + serverFileUtils.write(filebytes, file); + String md5t = serverCodings.encodeMD5Hex(file); + if (md5t.equals(md5)) { + prop.put("response", "ok"); + sb.getLog().logFine("RankingTransmission: received from peer " + otherpeerName + " CR file " + filename); + } else { + prop.put("response", "transfer failure"); + sb.getLog().logFine("RankingTransmission: transfer failunre from peer " + otherpeerName + " for CR file " + filename); + } + } catch (IOException e) { + prop.put("response", "io error"); + } + } + } + return prop; + } + + // wrong access + prop.put("process", 0); + prop.put("response", "denied"); + prop.put("process_access", ""); + prop.put("process_address", ""); + prop.put("process_protocol", ""); + prop.put("process_path", ""); + prop.put("process_maxsize", "0"); + sb.getLog().logFine("RankingTransmission: rejected unknown process " + process + ":" + purpose + " from peer " + otherpeerName); + return prop; + } + + +} diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index 9c2b55dbd..20a7d6af6 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -117,7 +117,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.logging.Level; -import java.util.WeakHashMap; import de.anomic.data.messageBoard; import de.anomic.data.wikiBoard; import de.anomic.data.userDB; @@ -165,7 +164,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser public File listsPath; public File htDocsPath; public File rankingPath; - public WeakHashMap rankingPermissions; + public HashMap rankingPermissions; public plasmaURLPool urlPool; public plasmaWordIndex wordIndex; public plasmaHTCache cacheManager; @@ -233,7 +232,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser this.log.logConfig("HTDOCS Path: " + this.htDocsPath.toString()); this.rankingPath = new File(rootPath, getConfig("rankingPath", "DATA/RANKING")); this.log.logConfig("Ranking Path: " + this.rankingPath.toString()); - this.rankingPermissions = new WeakHashMap(); // mapping of permission - to filename. + this.rankingPermissions = new HashMap(); // mapping of permission - to filename. /* ============================================================================ * Remote Proxy configuration