cleaned, finals, Properties

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

@ -61,26 +61,26 @@ import de.anomic.yacy.yacyVersion;
public final class hello {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
final serverObjects prop = new serverObjects(); // return variable that accumulates replacements
if ((post == null) ||
(env == null) ||
(yacyCore.seedDB == null) ||
(yacyCore.seedDB.mySeed == null)) { return new serverObjects(); }
// final String iam = (String) post.get("iam", ""); // complete seed of the requesting peer
// final String pattern = (String) post.get("pattern", ""); //
// final String mytime = (String) post.get(STR_MYTIME, ""); //
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {
if (post == null || ss == null || yacyCore.seedDB == null || yacyCore.seedDB.mySeed == null) { return new serverObjects(); }
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
if (prop == null) { return new serverObjects(); }
// final String iam = (String) post.get("iam", ""); // complete seed of the requesting peer
// final String pattern = (String) post.get("pattern", ""); //
// final String mytime = (String) post.get(STR_MYTIME, ""); //
final String key = (String) post.get("key", ""); // transmission key for response
final String seed = (String) post.get(yacySeed.STR_SEED, ""); //
final String countStr = (String) post.get("count", "0"); //
int i;
int count = 0;
try {count = (countStr == null) ? 0 : Integer.parseInt(countStr);} catch (NumberFormatException e) {count = 0;}
//final Date remoteTime = yacyCore.parseUniversalDate((String) post.get(STR_MYTIME)); // read remote time
// final Date remoteTime = yacyCore.parseUniversalDate((String) post.get(STR_MYTIME)); // read remote time
final yacySeed remoteSeed = yacySeed.genRemoteSeed(seed, key);
//System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString()));
// System.out.println("YACYHELLO: REMOTESEED=" + ((remoteSeed == null) ? "NULL" : remoteSeed.toString()));
if (remoteSeed == null) { return new serverObjects(); }
// we easily know the caller's IP:
@ -190,4 +190,3 @@ public final class hello {
}
}

@ -1,55 +1,56 @@
//message.java
//-----------------------
//part of the AnomicHTTPD caching proxy
//(C) by Michael Peter Christen; mc@anomic.de
//first published on http://www.anomic.de
//Frankfurt, Germany, 2004
//last major change: 29.06.2003
// message.java
// -----------------------
// part of the AnomicHTTPD caching proxy
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
//
//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.
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
//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.
// 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.
//
//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
// 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.
//
//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.
// 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
//
//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.
// 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.
//You must compile this file with
//javac -classpath .:../../Classes message.java
//if the shell's current path is HTROOT/yacy
// You must compile this file with
// javac -classpath .:../../classes message.java
// if the shell's current path is HTROOT/yacy
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import de.anomic.data.messageBoard;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
@ -59,7 +60,6 @@ import de.anomic.server.serverSwitch;
import de.anomic.tools.crypt;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacySeedDB;
public final class message {
@ -68,15 +68,15 @@ public final class message {
return SimpleFormatter.format(date);
}
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {
if (post == null || ss == null) { return new serverObjects(); }
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
// return variable that accumulates replacements
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
plasmaSwitchboard sb = (plasmaSwitchboard) ss;
serverObjects prop = new serverObjects();
if (prop == null || sb == null) { return new serverObjects(); }
//System.out.println("yacy/message:post=" + post.toString());
if ((post == null) || (env == null)) return new serverObjects();
// System.out.println("yacy/message:post=" + post.toString());
String process = (String) post.get("process", "permission");
String key = (String) post.get("key", "");
@ -87,13 +87,13 @@ public final class message {
prop.put("messagesize", "0");
prop.put("attachmentsize", "0");
//System.out.println("DEBUG yacy/message: message post values = " + post.toString());
// System.out.println("DEBUG yacy/message: message post values = " + post.toString());
String youare = (String) post.get("youare", ""); // seed hash of the target peer, needed for network stability
// check if we are the right target and requester has correct information about this peer
if ((yacyCore.seedDB.mySeed == null) || (!(yacyCore.seedDB.mySeed.hash.equals(youare)))) {
// this request has a wrong target
//System.out.println("DEBUG yacy/message: authenticate failed");
// System.out.println("DEBUG yacy/message: authenticate failed");
prop.put("response", "-1"); // request rejected
return prop;
}
@ -103,7 +103,7 @@ public final class message {
if (process.equals("permission")) {
// permission: respond with accceptabeale message and attachment size
String iam = (String) post.get("iam", ""); // seed hash of requester
// String iam = (String) post.get("iam", ""); // seed hash of requester
prop.put("response", "Welcome to my peer!");
// that's it!
}
@ -125,30 +125,29 @@ public final class message {
// save message
messageBoard.entry msgEntry = null;
switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry(
sb.messageDB.write(msgEntry = sb.messageDB.newEntry(
"remote",
otherSeed.get("Name", "anonymous"), otherSeed.hash,
yacyCore.seedDB.mySeed.getName(), yacyCore.seedDB.mySeed.hash,
subject, message.getBytes()));
messageForwardingViaEmail(env,msgEntry);
messageForwardingViaEmail(ss, msgEntry);
// finally write notification
File notifierSource = new File(switchboard.getRootPath(), switchboard.getConfig("htRootPath","htroot") + "/env/grafics/message.gif");
File notifierDest = new File(switchboard.getRootPath(), switchboard.getConfig("htRootPath","htroot") + "/env/grafics/notifier.gif");
File notifierSource = new File(sb.getRootPath(), sb.getConfig("htRootPath","htroot") + "/env/grafics/message.gif");
File notifierDest = new File(sb.getRootPath(), sb.getConfig("htRootPath","htroot") + "/env/grafics/notifier.gif");
try {
serverFileUtils.copy(notifierSource, notifierDest);
} catch (IOException e) {
System.out.println("NEW MESSAGE ARRIVED! (error: " + e.getMessage() + ")");
};
}
//System.out.println("respond = " + prop.toString());
// System.out.println("respond = " + prop.toString());
// return rewrite properties
return prop;
}
/*
* To: #[to]#
From: #[from]#
@ -203,7 +202,6 @@ public final class message {
}
/*
on 83
DEBUG: message post values = {youare=Ty2F86ekSWM5, key=pPQSZaXD, iam=WSjicAx1hRio, process=permission}

@ -6,7 +6,10 @@
// Frankfurt, Germany, 2004, 2005
//
// This file ist contributed by Alexander Schier
// last major change: 27.02.2005
//
// $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
@ -58,24 +61,27 @@ import de.anomic.server.serverSwitch;
public final class profile {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
serverObjects prop = new serverObjects(); // return variable that accumulates replacements
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {
// return variable that accumulates replacements
serverObjects prop = new serverObjects();
if (prop == null) { return new serverObjects(); }
Properties profile = new Properties();
int count=0;
String key="";
String value="";
FileInputStream fileIn = null;
try{
try {
fileIn = new FileInputStream(new File("DATA/SETTINGS/profile.txt"));
profile.load(fileIn);
}catch(IOException e){}
finally {
if (fileIn!=null) try{fileIn.close(); fileIn=null;}catch(Exception e) {}
} catch(IOException e) {
} finally {
if (fileIn != null) try { fileIn.close(); fileIn = null; } catch (Exception e) {}
}
Iterator it = ((Map)profile).keySet().iterator();
while(it.hasNext()){
while (it.hasNext()) {
key=(String)it.next();
value=profile.getProperty(key, "").replaceAll("\r","").replaceAll("\n","\\\\n");
if( !(key.equals("")) && !(value.equals("")) ){
@ -86,7 +92,6 @@ public final class profile {
}
prop.put("list", count);
// return rewrite properties
return prop;
}

@ -4,7 +4,10 @@
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last change: 15.05.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
@ -40,12 +43,11 @@
// Contributions and changes to the program code must be marked as such.
// You must compile this file with
// javac -classpath .:../../Classes query.java
// javac -classpath .:../../classes query.java
// if the shell's current path is HTROOT
import java.util.Date;
import java.io.IOException;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects;
@ -54,38 +56,38 @@ import de.anomic.yacy.yacyCore;
public final class query {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch sb) {
// return variable that accumulates replacements
serverObjects prop = new serverObjects();
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {
if (post == null || ss == null) { return new serverObjects(); }
plasmaSwitchboard switchboard = (plasmaSwitchboard) sb;
// System.out.println("YACYQUERY: RECEIVED POST = " + ((post == null) ? "NULL" : post.toString()));
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
final plasmaSwitchboard sb = (plasmaSwitchboard) ss;
if (prop == null || sb == null) { return new serverObjects(); }
if ((post == null) || (switchboard == null)) return new serverObjects();
// System.out.println("YACYQUERY: RECEIVED POST = " + ((post == null) ? "NULL" : post.toString()));
String iam = (String) post.get("iam", ""); // complete seed of the requesting peer
String youare = (String) post.get("youare", ""); // seed hash of the target peer, used for testing network stability
String key = (String) post.get("key", ""); // transmission key for response
String obj = (String) post.get("object", ""); // keyword for query subject
String env = (String) post.get("env", ""); // argument to query
// final String iam = (String) post.get("iam", ""); // complete seed of the requesting peer
final String youare = (String) post.get("youare", ""); // seed hash of the target peer, used for testing network stability
// final String key = (String) post.get("key", ""); // transmission key for response
final String obj = (String) post.get("object", ""); // keyword for query subject
final String env = (String) post.get("env", ""); // argument to query
prop.put("mytime", yacyCore.universalDateShortString(new Date()));
// check if we are the right target and requester has correct information about this peer
if ((yacyCore.seedDB.mySeed == null) || (!(yacyCore.seedDB.mySeed.hash.equals(youare)))) {
if (yacyCore.seedDB.mySeed == null || !yacyCore.seedDB.mySeed.hash.equals(youare)) {
// this request has a wrong target
prop.put("response", "-1"); // request rejected
return prop;
}
// requests about environment
if (obj.equals("rwiurlcount")) {
// the total number of different urls in the rwi is returned
// <env> shall contain a word hash, the number of assigned lurls to this hash is returned
de.anomic.plasma.plasmaWordIndexEntity entity = null;
try {
entity = switchboard.wordIndex.getEntity(env, true);
entity = sb.wordIndex.getEntity(env, true);
prop.put("response", entity.size());
entity.close();
} catch (IOException e) {
@ -98,13 +100,13 @@ public final class query {
if (obj.equals("rwicount")) {
// return the total number of available word indexes
prop.put("response", switchboard.wordIndex.size());
prop.put("response", sb.wordIndex.size());
return prop;
}
if (obj.equals("lurlcount")) {
// return the number of all available l-url's
prop.put("response", switchboard.urlPool.loadedURL.size());
prop.put("response", sb.urlPool.loadedURL.size());
return prop;
}
@ -138,7 +140,6 @@ public final class query {
return prop;
}
// return rewrite properties
return prop;
}

@ -4,7 +4,10 @@
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004, 2005
// last change: 24.01.2005
//
// $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
@ -42,7 +45,6 @@
// You must compile this file with
// javac -classpath .:../classes transferRWI.java
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaCrawlLURL;
@ -53,33 +55,33 @@ import de.anomic.yacy.yacySeed;
public final class transferURL {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch ss) {
if (post == null || ss == null) { return new serverObjects(); }
long start = System.currentTimeMillis();
// return variable that accumulates replacements
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects();
if ((post == null) || (env == null)) return prop;
final plasmaSwitchboard sb = (plasmaSwitchboard) ss;
final serverObjects prop = new serverObjects();
if (prop == null || sb == null) { return new serverObjects(); }
// request values
String iam = (String) post.get("iam", ""); // seed hash of requester
String youare = (String) post.get("youare", ""); // seed hash of the target peer, needed for network stability
String key = (String) post.get("key", ""); // transmission key
int urlc = Integer.parseInt((String) post.get("urlc", "")); // number of transported urls
boolean granted = switchboard.getConfig("allowReceiveIndex", "false").equals("true");
boolean blockBlacklist = switchboard.getConfig("indexReceiveBlockBlacklist", "false").equals("true");
final String iam = (String) post.get("iam", ""); // seed hash of requester
// final String youare = (String) post.get("youare", ""); // seed hash of the target peer, needed for network stability
// final String key = (String) post.get("key", ""); // transmission key
final int urlc = Integer.parseInt((String) post.get("urlc", "")); // number of transported urls
final boolean granted = sb.getConfig("allowReceiveIndex", "false").equals("true");
final boolean blockBlacklist = sb.getConfig("indexReceiveBlockBlacklist", "false").equals("true");
// response values
String result = "";
String doublevalues = "0";
yacySeed otherPeer = yacyCore.seedDB.get(iam);
String otherPeerName = iam + ":" + ((otherPeer == null) ? "NULL" : (otherPeer.getName() + "/" + otherPeer.getVersion()));
final yacySeed otherPeer = yacyCore.seedDB.get(iam);
final String otherPeerName = iam + ":" + ((otherPeer == null) ? "NULL" : (otherPeer.getName() + "/" + otherPeer.getVersion()));
if (granted) {
int received = 0;
int sizeBefore = switchboard.urlPool.loadedURL.size();
final int sizeBefore = sb.urlPool.loadedURL.size();
// read the urls from the other properties and store
String urls;
plasmaCrawlLURL.Entry lEntry;
@ -88,15 +90,14 @@ public final class transferURL {
if (urls == null) {
yacyCore.log.logFine("transferURL: got null URL-string from peer " + otherPeerName);
} else {
lEntry = switchboard.urlPool.loadedURL.newEntry(urls, true);
if ((lEntry != null) && (blockBlacklist)) {
if (plasmaSwitchboard.urlBlacklist.isListed(lEntry.url().getHost().toLowerCase(), lEntry.url().getPath())) {
lEntry = sb.urlPool.loadedURL.newEntry(urls, true);
if (lEntry != null && blockBlacklist &&
sb.urlBlacklist.isListed(lEntry.url().getHost().toLowerCase(), lEntry.url().getPath())) {
yacyCore.log.logFine("transferURL: blocked blacklisted URL '" + lEntry.url() + "' from peer " + otherPeerName);
lEntry = null;
}
}
if (lEntry != null) {
switchboard.urlPool.loadedURL.addEntry(lEntry, iam, iam, 3);
sb.urlPool.loadedURL.addEntry(lEntry, iam, iam, 3);
yacyCore.log.logFine("transferURL: received URL '" + lEntry.url() + "' from peer " + otherPeerName);
received++;
}
@ -106,14 +107,13 @@ public final class transferURL {
yacyCore.seedDB.mySeed.incRU(received);
// return rewrite properties
int more = switchboard.urlPool.loadedURL.size() - sizeBefore;
final int more = sb.urlPool.loadedURL.size() - sizeBefore;
doublevalues = Integer.toString(received - more);
switchboard.getLog().logInfo("Received " + received + " URLs from peer " + otherPeerName +
" in " + (System.currentTimeMillis() - start) + " ms.");
if ((received - more) > 0) switchboard.getLog().logSevere("Received " + doublevalues + " double URLs from peer " + otherPeerName);
sb.getLog().logInfo("Received " + received + " URLs from peer " + otherPeerName + " in " + (System.currentTimeMillis() - start) + " ms.");
if ((received - more) > 0) sb.getLog().logSevere("Received " + doublevalues + " double URLs from peer " + otherPeerName);
result = "ok";
} else {
switchboard.getLog().logInfo("Rejecting URLs from peer " + otherPeerName + ". Not granted.");
sb.getLog().logInfo("Rejecting URLs from peer " + otherPeerName + ". Not granted.");
result = "error_not_granted";
}

Loading…
Cancel
Save