Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) Network.html/Network.java: - Adding function to manually force peer ping to remote yacy peer See:Network.html?page=4 - for debugging purpose only!
theli0e2c33ee55ca
diff --git a/htroot/Network.html b/htroot/Network.htmlindex c2cc72be1..75c1bb988 100644--- a/htroot/Network.html+++ b/htroot/Network.html@@ -28,6 +28,8 @@<h2>Passive Peers</h2>::<h2>Potential Peers</h2>+::+<h2>Manually contacting Peer</h2>#(/page)#<p>#(table)#@@ -173,6 +175,28 @@ To do this, press this button:</form>#(/comment)#</p></font>+::+<p>+#(comment)#+::+<font color="red"><code>#[status]#</code></font>+::+<font color="green"><code>#[status]#</code></font>+</p>+<p>+<font color="green"><code><small>#[details]#</small></code></font>+</p>+#(/comment)#+</p>+<form action="Network.html" method="get">+<input name="page" type="hidden" value="4">+<table>+<tr><td>Peer Hash</td><td><input name="peerHash" type="text" size="32" maxlength="128" value="#[peerHash]#"></td></tr>+<tr><td>Peer IP</td><td><input name="peerIP" type="text" size="32" maxlength="128" value="#[peerIP]#"></td></tr>+<tr><td>Peer Port</td><td><input name="peerPort" type="text" size="32" maxlength="128" value="#[peerPort]#"></td></tr>+<tr><td> </td><td><input type="submit" name="addPeer" value="add Peer"></td></tr>+</table>+</form>#(/table)##[footer]#</body>diff --git a/htroot/Network.java b/htroot/Network.javaindex b95364419..331530dd2 100644--- a/htroot/Network.java+++ b/htroot/Network.java@@ -44,11 +44,13 @@// if the shell's current path is HTROOTimport java.util.Enumeration;+import java.util.HashMap;import de.anomic.http.httpHeader;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.server.serverDate;+import de.anomic.yacy.yacyClient;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacySeed;@@ -141,7 +143,47 @@ public class Network {}prop.put("table", 2); // triggers overviewprop.put("page", 0);- } else {+ } else if (Integer.parseInt(post.get("page", "1")) == 4) {+ prop.put("table", 4); // triggers overview+ prop.put("page", 4);++ if (post.containsKey("addPeer")) {++ // AUTHENTICATE+ if (!header.containsKey(httpHeader.AUTHORIZATION)) {+ prop.put("AUTHENTICATE","log-in");+ return prop;+ }+++ HashMap map = new HashMap();+ map.put("IP",(String) post.get("peerIP"));+ map.put("Port",(String) post.get("peerPort"));+ yacySeed peer = new yacySeed((String) post.get("peerHash"),map);++ int added = yacyClient.publishMySeed(peer.getAddress(), peer.hash);++ if (added < 0) {+ prop.put("table_comment",1);+ prop.put("table_comment_status","publish: disconnected peer '" + peer.getName() + "/" + post.get("peerHash") + "' from " + peer.getAddress());+ } else {+ peer = yacyCore.seedDB.getConnected(peer.hash);+ prop.put("table_comment",2);+ prop.put("table_comment_status","publish: handshaked " + peer.get("PeerType", "senior") + " peer '" + peer.getName() + "' at " + peer.getAddress());+ prop.put("table_comment_details",peer.toString());+ }++ prop.put("table_peerHash",(String) post.get("peerHash"));+ prop.put("table_peerIP",(String)post.get("peerIP"));+ prop.put("table_peerPort",(String) post.get("peerPort"));+ } else {+ prop.put("table_peerHash","");+ prop.put("table_peerIP","");+ prop.put("table_peerPort","");++ prop.put("table_comment",0);+ }+ }else {// generate tableint page = Integer.parseInt(post.get("page", "1"));int conCount = 0;diff --git a/htroot/SettingsAck_p.html b/htroot/SettingsAck_p.htmlindex 2a747f607..5d3d9fa47 100644--- a/htroot/SettingsAck_p.html+++ b/htroot/SettingsAck_p.html@@ -31,16 +31,14 @@ Your new administration account name is #[user]#. The password has been accepted<b>Your proxy access setting has been changed.<br>Your proxy account check has been disabled, since you did not supply a password.</b><p>The new proxy IP filter is set to #[filter]#<br>-The proxy port is: <font color="#556699">#[port]#</font><br>-Port Forwarding is: <font color="#556699">#[portForwardingEnabled]#</font><p>+The proxy port is: <font color="#556699">#[port]#</font><p><u>if you changed the Port or Port Forwarding Settings, you need to restart YaCy.</u>::<!-- 7 --><b>Your proxy access setting has been changed.</b><br>Your new proxy account name is #[user]#. The password has been accepted.<br>If you open any public web page through the proxy, you must log-in then.<p>The new proxy IP filter is set to #[filter]#.<br>-The proxy port is: <font color="#556699">#[port]#</font><br>-Port Forwarding is: <font color="#556699">#[portForwardingEnabled]#</font><p>+The proxy port is: <font color="#556699">#[port]#</font><p><u>if you changed the Port or Port Forwarding Settings, you need to restart YaCy.</u>::<!-- 8 --><b>Your server access filter is now set to #[filter]#</b><br>@@ -116,6 +114,31 @@ Seed Upload method was changed successfully.<td><font color="#556699"><b>#[msgForwardingTo]#</b></font></td></tr></table>+::<!-- 22 -->+<p><b>Your port forwarding settings have been changed.</b></p>+<table>+<tr>+ <td>Port Forwarding Support is:</td>+ <td><font color="#556699"><b>#[portForwardingEnabled]#</b></font></td>+</tr>+<tr>+ <td>Port Forwarding Port:</td>+ <td><font color="#556699"><b>#[portForwardingPort]#</b></font></td>+</tr>+<tr>+ <td>Port Forwarding Host:</td>+ <td><font color="#556699"><b>#[portForwardingHostUser]#@#[portForwardingHost]#:#[portForwardingHostPort]#</b></font></td>+</tr>+<tr>+ <td>Port Forwarding uses proxy:</td>+ <td><font color="#556699"><b>#[portForwardingUseProxy]#</b></font></td>+</tr>+</table>+::<!-- 23 : Port forwarding - error -->+<p><b>Port Forwarding Settings changed, but something is wrong.</b></p>+<p><font color="red">#[errormsg]#</font></p>+Port Forwarding was deactivated automatically.<br>+Please return to the settings page and modify the data.<br>#(/info)#</p><p>You can now go back to the <a href="Settings_p.html">Settings</a> page if you want to make more changes.</p>diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.javaindex 62aa87a5b..171b67fdf 100644--- a/htroot/SettingsAck_p.java+++ b/htroot/SettingsAck_p.java@@ -53,13 +53,17 @@ import java.util.HashMap;import java.util.Iterator;import java.util.List;+import org.apache.commons.pool.impl.GenericObjectPool;+import de.anomic.http.httpHeader;import de.anomic.http.httpd;import de.anomic.http.httpdProxyHandler;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCodings;+import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;+import de.anomic.server.serverThread;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacySeed;import de.anomic.yacy.yacySeedUploader;@@ -131,14 +135,6 @@ public class SettingsAck_p {env.setConfig("port", port);prop.put("info_port", port);- // port forwarding configuration- env.setConfig("portForwardingEnabled", post.containsKey("portForwardingEnabled")?"true":"false");- env.setConfig("portForwardingHost", (String)post.get("portForwardingHost"));- env.setConfig("portForwardingPort", (String)post.get("portForwardingPort"));- env.setConfig("portForwardingUser", (String)post.get("portForwardingUser"));- env.setConfig("portForwardingPwd", (String)post.get("portForwardingPwd"));- prop.put("info_portForwardingEnabled",post.containsKey("portForwardingEnabled")?"on":"off");-// read and process dataString filter = (String) post.get("proxyfilter");String user = (String) post.get("proxyuser");@@ -194,6 +190,48 @@ public class SettingsAck_p {return prop;}+ // port forwarding configuration+ if (post.containsKey("portForwarding")) {+ env.setConfig("portForwardingEnabled", post.containsKey("portForwardingEnabled")?"true":"false");+ env.setConfig("portForwardingUseProxy",post.containsKey("portForwardingUseProxy")?"true":"false");+ env.setConfig("portForwardingPort", (String)post.get("portForwardingPort"));++ env.setConfig("portForwardingHost", (String)post.get("portForwardingHost"));+ env.setConfig("portForwardingHostPort",(String)post.get("portForwardingHostPort"));+ env.setConfig("portForwardingHostUser",(String)post.get("portForwardingHostUser"));+ env.setConfig("portForwardingHostPwd", (String)post.get("portForwardingHostPwd"));++ // trying to reconnect the port forwarding channel+ try {+ serverCore httpd = (serverCore) env.getThread("10_httpd");+ if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) {+ // trying to shutdown the current port forwarding channel+ serverCore.portForwarding.disconnect();+ }+ // trying to reinitialize the port forwarding+ httpd.initPortForwarding();++ // notifying publishSeed Thread+ serverThread peerPing = env.getThread("30_peerping");+ peerPing.notifyThread();+ } catch (Exception e) {+ prop.put("info", 23);+ prop.put("info_errormsg",(e.getMessage() == null) ? "unknown" : e.getMessage().replaceAll("\n","<br>"));+ return prop;+ }++ prop.put("info", 22);+ prop.put("info_portForwardingEnabled", post.containsKey("portForwardingEnabled")?"on":"off");+ prop.put("info_portForwardingUseProxy",post.containsKey("portForwardingUseProxy")?"on":"off");+ prop.put("info_portForwardingPort", (String)post.get("portForwardingPort"));+ prop.put("info_portForwardingHost", (String)post.get("portForwardingHost"));+ prop.put("info_portForwardingHostPort",(String)post.get("portForwardingHostPort"));+ prop.put("info_portForwardingHostUser",(String)post.get("portForwardingHostUser"));+ prop.put("info_portForwardingHostPwd", (String)post.get("portForwardingHostPwd"));+ return prop;+ }++// server passwordif (post.containsKey("serveraccount")) {// read and process datadiff --git a/htroot/Settings_p.html b/htroot/Settings_p.htmlindex 7462df4db..12ee04ed8 100644--- a/htroot/Settings_p.html+++ b/htroot/Settings_p.html@@ -30,12 +30,16 @@ delete the file 'DATA/SETTINGS/httpProxy.conf' in the YaCy application root fold</tr><tr><td><img src="env/grafics/down.gif" alt="down"><a href="#http">HTTP Networking</a></td>- <td><img src="env/grafics/down.gif" alt="down"><a href="#messageForwarding">Message Forwarding</a></td>+ <td><img src="env/grafics/down.gif" alt="down"><a href="#messageForwarding">Message Forwarding (optional)</a></td></tr><tr><td><img src="env/grafics/down.gif" alt="down"><a href="#proxy">Remote Proxy (optional)</a></td><td><img src="env/grafics/down.gif" alt="down"><a href="#parser">Content Parser Settings</a></td></tr>+<tr>+ <td><img src="env/grafics/down.gif" alt="down"><a href="#portForwarding">Port Forwarding (optional)</a></td>+ <td> </td>+</tr></table></p>@@ -64,7 +68,7 @@ delete the file 'DATA/SETTINGS/httpProxy.conf' in the YaCy application root fold<p><table border="0" cellspacing="5"><tr valign="top">- <td>Peer Name:</td>+ <td>Peer Name:</td><td><input name="peername" type="text" size="32" maxlength="80" value="#[peerName]#"></td><td><b>Your peer name defines also a new '.yacy' - domain, which can be accessed from every peer running this proxy.Using your 'Home Page' and 'File Share' - zones you also have a platform to provide content to your new domain.</b><br>@@ -97,40 +101,6 @@ All traffic is routed throug one single port, for both proxy and server.<br></tr></table>--<p><b>Port Forwarding</b><br><br>-You can use a remote server running a ssh demon to forward your server/proxy port.-This is useful if you want to tunnel throug a NAT/router.-Alternatively, you can simply set a virtual server port on your NAT/Server to enable connections from outside.-<table border="0" cellspacing="5">- <tr valign="top">- <td>Enable port forwarding:</td>- <td><input type="checkbox" name="portForwardingEnabled" align="top" #(portForwardingEnabled)#::checked#(/portForwardingEnabled)# DISABLED></td>- <td><i>Feature currently not available. </i></td>- </tr>- <tr valign="top">- <td>Forwarding host:</td>- <td><input name="portForwardingHost" type="text" size="32" maxlength="128" value="#[portForwardingHost]#"></td>- <td> </td>- </tr>- <tr valign="top">- <td>Forwarding port:</td>- <td><input name="portForwardingPort" type="text" size="5" maxlength="5" value="#[portForwardingPort]#"></td>- <td> </td>- </tr>- <tr valign="top">- <td>Remote host user:</td>- <td><input name="portForwardingUser" type="text" size="32" maxlength="128" value="#[portForwardingUser]#"></td>- <td> </td>- </tr>- <tr valign="top">- <td>Remote host password:</td>- <td><input name="portForwardingPwd" type="password" size="32" maxlength="128" value="#[portForwardingPwd]#"></td>- <td> </td>- </tr>-</table>-</p>-<p><b>Server Access Restrictions</b><br><br>You can restrict the access to this proxy/server using a two-stage security barrier:<ul><li>define an <i>access domain</i> with a list of granted client IP-numbers or with wildcards</li>@@ -194,12 +164,63 @@ Alternatively, you can simply set a virtual server port on your NAT/Server to en</tr><tr valign="top"><td></td>- <td><input type="submit" name="proxysettings" value="submit"></td>+ <td><input type="submit" name="proxysettings" value="submit"> <i>Changes will take effect immediately.</i></td>+ </tr>+</table>+</fieldset>+</form><br>++<p><form action="SettingsAck_p.html" method="post" enctype="multipart/form-data">+<fieldset><legend id="portForwarding">Port Forwarding (optional)</legend>+<p>You can use a remote server running a ssh demon to forward your server/proxy port.+This is useful if you want to tunnel throug a NAT/router.+Alternatively, you can simply set a virtual server port on your NAT/Server to enable connections from outside.</p>+<table border="0" cellspacing="5">+ <tr valign="top">+ <td>Enable port forwarding:</td>+ <td><input type="checkbox" name="portForwardingEnabled" align="top" #(portForwardingEnabled)#::checked#(/portForwardingEnabled)#></td>+ <td>Enabling disabling port forwarding via secure channel.</td></tr>+ <tr valign="top">+ <td>Forwarding via proxy:</td>+ <td><input type="checkbox" name="portForwardingUseProxy" align="top" #(portForwardingUseProxy)#::checked#(/portForwardingUseProxy)# DISABLED></td>+ <td><!-- Specifies if the connection should be established through the <a href="#proxy">remote proxy</a>.-->+ <i>Function not available at the moment.</i></td>+ </tr>+ <tr valign="top">+ <td>Forwarding port:</td>+ <td><input name="portForwardingPort" type="text" size="5" maxlength="5" value="#[portForwardingPort]#"></td>+ <td>The port on the remote server that should be forwarded via the secure channel to the local host.</td>+ </tr>+ <tr valign="top">+ <td>Forwarding host:</td>+ <td><input name="portForwardingHost" type="text" size="32" maxlength="128" value="#[portForwardingHost]#"></td>+ <td> </td>+ </tr>+ <tr valign="top">+ <td>Forwarding host port:</td>+ <td><input name="portForwardingHostPort" type="text" size="5" maxlength="5" value="#[portForwardingHostPort]#"></td>+ <td> </td>+ </tr>+ <tr valign="top">+ <td>Forwarding host user:</td>+ <td><input name="portForwardingHostUser" type="text" size="32" maxlength="128" value="#[portForwardingHostUser]#"></td>+ <td> </td>+ </tr>+ <tr valign="top">+ <td>Forwarding host password:</td>+ <td><input name="portForwardingHostPwd" type="password" size="32" maxlength="128" value="#[portForwardingHostPwd]#"></td>+ <td> </td>+ </tr>+ <tr valign="top">+ <td> </td>+ <td colspan="2"><input type="submit" name="portForwarding" value="Submit"> <i>Changes will take effect immediately.</i></td>+ </tr></table></fieldset></form><br>+<p><form action="SettingsAck_p.html" method="post" enctype="multipart/form-data"><fieldset><legend id="ServerAccess">Server Access Settings</legend><p>Here you can restrict access to the server. By default, the access is not limited, because this function is needed to spawn the p2p index-sharing function. If you block access to your server (setting anything else than '*'), then you will also be blocked from using other peers' indexes for search service. However, blocking access may be correct in enterprise environments where you only want to index your company's own web pages.</p>@@ -277,7 +298,7 @@ but only if there had been changes to the seed-list.</tr><tr valign="top"><td>Forwarding Command:</td>- <td><input name="msgForwardingCmd" type="text" size="32" maxlength="512" value="#[msgForwardingCmd]#"></td>+ <td><input name="msgForwardingCmd" type="text" size="32" value="#[msgForwardingCmd]#"></td><td><i>The command-line program that should be used to forward the message.<br>e.g.:</i> <code>/usr/sbin/sendmail -t</code></td></tr><tr valign="top">diff --git a/htroot/Settings_p.java b/htroot/Settings_p.javaindex 935ce565b..ce6d7e9ac 100644--- a/htroot/Settings_p.java+++ b/htroot/Settings_p.java@@ -79,10 +79,13 @@ public final class Settings_p {// remote port forwarding settingsprop.put("portForwardingEnabled",env.getConfig("portForwardingEnabled","false").equals("true")? 1 : 0);- prop.put("portForwardingHost",env.getConfig("portForwardingHost", ""));+ prop.put("portForwardingUseProxy",env.getConfig("portForwardingUseProxy", "false").equals("true")? 1 : 0);prop.put("portForwardingPort",env.getConfig("portForwardingPort", ""));- prop.put("portForwardingUser",env.getConfig("portForwardingUser", ""));- prop.put("portForwardingPwd",env.getConfig("portForwardingPwd", ""));++ prop.put("portForwardingHost",env.getConfig("portForwardingHost", ""));+ prop.put("portForwardingHostPort",env.getConfig("portForwardingHostPort", ""));+ prop.put("portForwardingHostUser",env.getConfig("portForwardingHostUser", ""));+ prop.put("portForwardingHostPwd",env.getConfig("portForwardingHostPwd", ""));// set valuesString s;diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex 9d7d8f639..4da85e1ef 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -43,9 +43,11 @@//javac -classpath .:../../Classes hello.java//if the shell's current path is HTROOT+import java.net.InetAddress;import java.util.Date;import de.anomic.http.httpHeader;+import de.anomic.http.httpd;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;@@ -84,6 +86,9 @@ public class hello {float clientversion = remoteSeed.getVersion();int urls = -1;+ // if the remote client has reported its own IP address and the client supports+ // the port forwarding feature (if client version >= 0.383) then we try to+ // connect to the reported IP address firstif ((reportedip.length() > 0) && (!(clientip.equals(reportedip))) && (clientversion >= (float)0.383)) {// try first the reportedip, since this may be a connect from a port-forwarding hostprop.put("yourip", reportedip);@@ -91,11 +96,29 @@ public class hello {urls = yacyClient.queryUrlCount(remoteSeed);}- if (urls < 0) {- // if the previous attempt was not successful, try the ip where the request came from- prop.put("yourip", clientip);- remoteSeed.put("IP", clientip);- urls = yacyClient.queryUrlCount(remoteSeed);+ // if the previous attempt (using the reported ip address) was not successful, try the ip where+ // the request came from+ if (urls < 0) {+ boolean isLocalIP = false;+ if (serverCore.portForwardingEnabled) {+ try {+ InetAddress clientAddress = InetAddress.getByName(clientip);+ InetAddress[] localAddress = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());+ for (int i=0; i<localAddress.length; i++) {+ if (localAddress[i].equals(clientAddress)) {+ isLocalIP = true;+ break;+ }+ }+ } catch (Exception e) {}+ }++ // we are only allowed to connect to the client IP address if it's not our own address+ if (!isLocalIP) {+ prop.put("yourip", clientip);+ remoteSeed.put("IP", clientip);+ urls = yacyClient.queryUrlCount(remoteSeed);+ }}//System.out.println("YACYHELLO: YOUR IP=" + clientip);@@ -123,7 +146,7 @@ public class hello {if ((remoteSeed.hash != null) && (remoteSeed.isProper())) yacyCore.peerActions.peerPing(remoteSeed);}if (!((String)prop.get("yourtype")).equals(reportedPeerType)) {- yacyCore.log.logInfo("hello: changing remote peer '" + remoteSeed.getName() + "' [" + reportedip + "] peerType to '" + prop.get("yourtype") + "'.");+ yacyCore.log.logInfo("hello: changing remote peer '" + remoteSeed.getName() + "' [" + reportedip + "] peerType from '" + reportedPeerType + "' to '" + prop.get("yourtype") + "'.");}String seeds = "";diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.javaindex c410083f9..5967e3ff6 100644--- a/source/de/anomic/http/httpc.java+++ b/source/de/anomic/http/httpc.java@@ -125,6 +125,7 @@ public final class httpc {private boolean remoteProxyUse = false;private String savedRemoteHost = null;private String requestPath = null;+ private boolean allowContentEncoding = true;static {// set time-out of InetAddress.getByName cache ttl@@ -223,6 +224,10 @@ public final class httpc {}}+ public void setAllowContentEncoding(boolean status) {+ this.allowContentEncoding = status;+ }+public boolean isClosed() {if (this.socket == null) return true;else return (!this.socket.isConnected()) || (this.socket.isClosed());@@ -349,6 +354,7 @@ public final class httpc {this.savedRemoteHost = null;this.requestPath = null;+ this.allowContentEncoding = true;// shrink readlinebuffer if it is to largethis.readLineBuffer.reset(80);@@ -659,7 +665,7 @@ public final class httpc {public response GET(String path, httpHeader requestHeader) throws IOException {//serverLog.logDebug("HTTPC", handle + " requested GET '" + path + "', time = " + (System.currentTimeMillis() - handle));try {- boolean zipped = httpd.shallTransportZipped(path);+ boolean zipped = (this.allowContentEncoding) ? true : httpd.shallTransportZipped(path);send(httpHeader.METHOD_GET, path, requestHeader, zipped);response r = new response(zipped);//serverLog.logDebug("HTTPC", handle + " returned GET '" + path + "', time = " + (System.currentTimeMillis() - handle));diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.javaindex 747bc0882..c13f879f7 100644--- a/source/de/anomic/http/httpdFileHandler.java+++ b/source/de/anomic/http/httpdFileHandler.java@@ -478,9 +478,11 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httphttpd.sendRespondError(conProp,out,3,404,"File not Found",null,null);//textMessage(out, 404, "404 File not Found\r\n"); // would be a possible vuln to return original the original path}- } catch (Exception e) {+ } catch (Exception e) {if (e instanceof InterruptedException) {- this.theLogger.logInfo("Interruption detected while processing query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'");+ this.theLogger.logInfo("Interruption detected while processing query: " + path ++ "\nClient: " + conProp.getProperty(httpd.CONNECTION_PROP_CLIENTIP,"unknown") ++ "\nReason: " + e.toString());if (!conProp.containsKey(httpd.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {httpd.sendRespondError(conProp,out, 4, 503, null, "Exception with query: " + path + "; Service unavailable because of server shutdown.",e);} else {@@ -490,10 +492,14 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httpString errorMsg = e.getMessage();if ((errorMsg != null) && (errorMsg.startsWith("Broken pipe") || errorMsg.startsWith("Connection reset"))) {// client closed the connection, so we just end silently- this.theLogger.logInfo("Client unexpectedly closed connection while processing query: " + path + "; '" + e.toString() + ":" + errorMsg + "'");+ this.theLogger.logInfo("Client unexpectedly closed connection while processing query " + path ++ "\nClient: " + conProp.getProperty(httpd.CONNECTION_PROP_CLIENTIP,"unknown")++ "\nReason: " + e.toString());conProp.put(httpd.CONNECTION_PROP_PERSISTENT,"close");} else {- this.theLogger.logError("ERROR: Exception with query: " + path + "; '" + e.toString() + ":" + ((errorMsg ==null)?"":e.getMessage()) + "'");+ this.theLogger.logError("ERROR: Exception with query: " + path ++ "\nClient: " + conProp.getProperty(httpd.CONNECTION_PROP_CLIENTIP,"unknown") ++ "\nReason: " + e.toString());if (!conProp.containsKey(httpd.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {httpd.sendRespondError(conProp,out, 4, 503, null, "Exception with query: " + path + "; '" + e.toString() + ":" + ((errorMsg ==null)?"":e.getMessage()) + "'",e);} else {@@ -505,7 +511,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httptry {out.flush();}catch (Exception e) {}if (!(requestHeader.get(httpHeader.CONNECTION, "close").equals("keep-alive"))) {// wait a little time until everything closes so that clients can read from the streams/sockets- try {Thread.currentThread().sleep(1000);} catch (InterruptedException e) {}+ try {Thread.sleep(1000);} catch (InterruptedException e) {}}}}diff --git a/source/de/anomic/plasma/plasmaCrawlWorker.java b/source/de/anomic/plasma/plasmaCrawlWorker.javaindex 6b1edcf59..baa7228b2 100644--- a/source/de/anomic/plasma/plasmaCrawlWorker.java+++ b/source/de/anomic/plasma/plasmaCrawlWorker.java@@ -151,7 +151,7 @@ public final class plasmaCrawlWorker extends Thread {this.depth = 0;this.startdate = 0;this.profile = null;- //this.error = null;+ //this.error = null;}public void run() {@@ -243,11 +243,12 @@ public final class plasmaCrawlWorker extends Thread {remoteProxyUse,cacheManager,log,- 0+ 0,+ true);}- public static void load(+ private static void load(URL url,String referer,String initiator,@@ -259,7 +260,8 @@ public final class plasmaCrawlWorker extends Thread {boolean remoteProxyUse,plasmaHTCache cacheManager,serverLog log,- int redirectionCount+ int redirectionCount,+ boolean useContentEncodingGzip) throws IOException {if (url == null) return;Date requestDate = new Date(); // remember the time...@@ -285,10 +287,11 @@ public final class plasmaCrawlWorker extends Thread {//System.out.println("CRAWLER_REQUEST_HEADER=" + requestHeader.toString()); // DEBUG// open the connection- if (remoteProxyUse)- remote = httpc.getInstance(host, port, socketTimeout, ssl, remoteProxyHost, remoteProxyPort);- else- remote = httpc.getInstance(host, port, socketTimeout, ssl);+ remote = (remoteProxyUse) ? httpc.getInstance(host, port, socketTimeout, ssl, remoteProxyHost, remoteProxyPort)+ : httpc.getInstance(host, port, socketTimeout, ssl);++ // specifying if content encoding is allowed+ remote.setAllowContentEncoding(useContentEncodingGzip);// send requesthttpc.response res = remote.GET(path, requestHeader);@@ -369,7 +372,8 @@ public final class plasmaCrawlWorker extends Thread {remoteProxyUse,cacheManager,log,- ++redirectionCount+ ++redirectionCount,+ useContentEncodingGzip);}} else {@@ -382,9 +386,28 @@ public final class plasmaCrawlWorker extends Thread {}if (remote != null) remote.close();} catch (Exception e) {- // this may happen if the targeted host does not exist or anything with the- // remote server was wrong.- log.logError("CRAWLER LOADER ERROR2 with url=" + url.toString() + ": " + e.toString(),e);+ if ((e.getMessage() != null) && (e.getMessage().indexOf("Corrupt GZIP trailer") >= 0)) {+ log.logWarning("Problems detected while receiving gzip encoded content from '" + url.toString() ++ "'. Retrying request without using gzip content encoding.");+ load(url,+ referer,+ initiator,+ depth,+ profile,+ socketTimeout,+ remoteProxyHost,+ remoteProxyPort,+ remoteProxyUse,+ cacheManager,+ log,+ 0,+ false+ );+ } else {+ // this may happen if the targeted host does not exist or anything with the+ // remote server was wrong.+ log.logError("CRAWLER LOADER ERROR2 with url=" + url.toString() + ": " + e.toString(),e);+ }} finally {if (remote != null) httpc.returnInstance(remote);}diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex dca95ecbd..d44ddcea1 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -356,8 +356,10 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements sernew serverInstantThread(this, "coreCrawlJob", "coreCrawlJobSize"), 10000);deployThread("40_peerseedcycle", "Seed-List Upload", "task that a principal peer performes to generate and upload a seed-list to a ftp account",new serverInstantThread(yc, "publishSeedList", null), 180000);+ serverInstantThread peerPing = null;deployThread("30_peerping", "YaCy Core", "this is the p2p-control and peer-ping task",- new serverInstantThread(yc, "peerPing", null), 2000);+ peerPing = new serverInstantThread(yc, "peerPing", null), 2000);+ peerPing.setSyncObject(new Object());indexDistribution = new distributeIndex(100 /*indexCount*/, 8000, 1 /*peerCount*/);deployThread("20_dhtdistribution", "DHT Distribution (currently by juniors only)", "selection, transfer and deletion of index entries that are not searched on your peer, but on others",new serverInstantThread(indexDistribution, "job", null), 120000);diff --git a/source/de/anomic/server/serverAbstractThread.java b/source/de/anomic/server/serverAbstractThread.javaindex c553312e9..b4ab87af3 100644--- a/source/de/anomic/server/serverAbstractThread.java+++ b/source/de/anomic/server/serverAbstractThread.java@@ -61,6 +61,7 @@ public abstract class serverAbstractThread extends Thread implements serverThreaprivate String shortDescr = "", longDescr = "";private long threadBlockTimestamp = System.currentTimeMillis();private long idleCycles = 0, busyCycles = 0, outofmemoryCycles = 0;+ private Object syncObject = null;protected final void announceThreadBlockApply() {// shall only be used, if a thread blocks for an important reason@@ -261,12 +262,35 @@ public abstract class serverAbstractThread extends Thread implements serverThrea// try {this.sleep(millis);} catch (InterruptedException e) {}// }try {- Thread.sleep(millis);+ if (this.syncObject != null) {+ synchronized(this.syncObject) {+ this.syncObject.wait(millis);+ }+ } else {+ Thread.sleep(millis);+ }} catch (InterruptedException e) {- if (this.log != null) log.logSystem(this.getName() + " interrupted because of shutdown.");+ if (this.log != null) this.log.logSystem("thread '" + this.getName() + "' interrupted because of shutdown.");}}public void open() {} // dummy definition; should be overridenpublic void close() {} // dummy definition; should be overriden++ public void setSyncObject(Object sync) {+ this.syncObject = sync;+ }++ public Object getSyncObject() {+ return this.syncObject;+ }++ public void notifyThread() {+ if (this.syncObject != null) {+ synchronized(this.syncObject) {+ if (this.log != null) this.log.logDebug("thread '" + this.getName() + "' has received a notification from thead '" + Thread.currentThread().getName() + "'.");+ this.syncObject.notifyAll();+ }+ }+ }}\ No newline at end of filediff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex b7b681204..7a57b3885 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -208,46 +208,7 @@ public final class serverCore extends serverAbstractThread implements serverThre} catch (java.net.BindException e) {System.out.println("FATAL ERROR: " + e.getMessage() + " - probably root access rights needed. check port number"); System.exit(0);}-- // doing the port forwarding stuff- if (switchboard.getConfig("portForwardingEnabled","false").equalsIgnoreCase("true")) {- try {- String portFwHost = switchboard.getConfig("portForwardingHost","localhost");- Integer portFwPort = Integer.valueOf(switchboard.getConfig("portForwardingPort","8080"));- String portFwUser = switchboard.getConfig("portForwardingUser","xxx");-- String localHost = this.socket.getInetAddress().getHostName();- Integer localPort = new Integer(this.socket.getLocalPort());-- this.log.logInfo("Trying to connect to remote port forwarding host " + portFwUser + "@" + portFwHost + ":" + portFwPort);- Class forwarderClass = Class.forName("de.anomic.server.serverPortForwardingSch");- serverCore.portForwarding = (serverPortForwarding) forwarderClass.newInstance();-- serverCore.portForwarding.init(- portFwHost,- portFwPort.intValue(),- portFwUser,- switchboard.getConfig("portForwardingPwd","xxx"),- localHost,- localPort.intValue());-- serverCore.portForwarding.connect();-- serverCore.portForwardingEnabled = true;- yacyCore.seedDB.mySeed.put("IP",publicIP().getHostAddress());- yacyCore.seedDB.mySeed.put("Port",Integer.toString(serverCore.portForwarding.getPort()));-- this.log.logInfo("Remote port forwarding connection established: " + portFwHost+":"+portFwPort+" -> "+localHost+":"+localPort);- } catch (Exception e) {- this.log.logError("Unable to initialize server port forwarding.",e);- switchboard.setConfig("portForwardingEnabled","false");- } catch (Error e) {- this.log.logError("Unable to initialize server port forwarding.",e);- switchboard.setConfig("portForwardingEnabled","false");- }- }-try {this.handlerPrototype = handlerPrototype;this.switchboard = switchboard;@@ -259,6 +220,17 @@ public final class serverCore extends serverAbstractThread implements serverThre} catch (java.lang.ClassNotFoundException e) {System.out.println("FATAL ERROR: " + e.getMessage() + " - Class Not Found"); System.exit(0);}++ // init port forwarding+ try {+ this.initPortForwarding();+ } catch (Exception e) {+ this.log.logError("Unable to initialize server port forwarding.",e);+ this.switchboard.setConfig("portForwardingEnabled","false");+ } catch (Error e) {+ this.log.logError("Unable to initialize server port forwarding.",e);+ this.switchboard.setConfig("portForwardingEnabled","false");+ }// implementation of session thread poolthis.cralwerPoolConfig = new GenericObjectPool.Config();@@ -285,6 +257,43 @@ public final class serverCore extends serverAbstractThread implements serverThre}+ public void initPortForwarding() throws Exception {+ // doing the port forwarding stuff+ if (this.switchboard.getConfig("portForwardingEnabled","false").equalsIgnoreCase("true")) {+ try {+ String localHost = this.socket.getInetAddress().getHostName();+ Integer localPort = new Integer(this.socket.getLocalPort());++ this.log.logInfo("Trying to load port forwarding class");++ // loading port forwarding class+ Class forwarderClass = Class.forName("de.anomic.server.serverPortForwardingSch");+ serverCore.portForwarding = (serverPortForwarding) forwarderClass.newInstance();++ // initializing port forwarding+ serverCore.portForwarding.init(+ this.switchboard,+ localHost,+ localPort.intValue());++ // connection to port forwarding host+ serverCore.portForwarding.connect();++ serverCore.portForwardingEnabled = true;+ yacyCore.seedDB.mySeed.put("IP",publicIP().getHostAddress());+ yacyCore.seedDB.mySeed.put("Port",Integer.toString(serverCore.portForwarding.getPort()));+ } catch (Exception e) {+ serverCore.portForwardingEnabled = false;+ this.switchboard.setConfig("portForwardingEnabled", "false");+ throw e;+ } catch (Error e) {+ serverCore.portForwardingEnabled = false;+ this.switchboard.setConfig("portForwardingEnabled", "false");+ throw e;+ }+ }+ }+public GenericObjectPool.Config getPoolConfig() {return this.cralwerPoolConfig ;}@@ -372,7 +381,7 @@ public final class serverCore extends serverAbstractThread implements serverThre}public void open() {- log.logSystem("* server started on " + publicIP() + ":" + port);+ this.log.logSystem("* server started on " + publicLocalIP() + ":" + this.port);}// class body@@ -502,7 +511,7 @@ public final class serverCore extends serverAbstractThread implements serverThretry {// trying to gracefull stop all still running sessions ...- serverCore.this.log.logInfo("Trying to shutdown " + threadCount + " remaining session threads ...");+ serverCore.this.log.logInfo("Signaling shutdown to " + threadCount + " remaining session threads ...");for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {((Session)threadList[currentThreadIdx]).setStopped(true);}@@ -514,10 +523,12 @@ public final class serverCore extends serverAbstractThread implements serverThrefor ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {Session currentSession = (Session)threadList[currentThreadIdx];if (currentSession.isAlive()) {- if ((currentSession.controlSocket != null)&&(currentSession.controlSocket.isConnected())) {- currentSession.controlSocket.close();- serverCore.this.log.logInfo("Closing socket of thread '" + currentSession.getName() + "'");- }+ try {+ if ((currentSession.controlSocket != null)&&(currentSession.controlSocket.isConnected())) {+ currentSession.controlSocket.close();+ serverCore.this.log.logInfo("Closing socket of thread '" + currentSession.getName() + "'");+ }+ } catch (IOException e) {}}}@@ -525,9 +536,10 @@ public final class serverCore extends serverAbstractThread implements serverThrefor ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {if (threadList[currentThreadIdx].isAlive()) threadList[currentThreadIdx].join(500);}- }- catch (InterruptedException e) {+ } catch (InterruptedException e) {serverCore.this.log.logWarning("Interruption while trying to shutdown all remaining session threads.");+ } catch (Exception e) {+ serverCore.this.log.logError("Unexpected error while trying to shutdown all remaining session threads.",e);}this.isClosed = true;@@ -885,7 +897,7 @@ public final class serverCore extends serverAbstractThread implements serverThre} else if (result instanceof Boolean) {if (((Boolean) result).equals(TERMINATE_CONNECTION)) break;// deactivating timeout. this is needed because of persistent connections- this.controlSocket.setSoTimeout(0);+ if (!this.controlSocket.isClosed()) this.controlSocket.setSoTimeout(0);} else if (result instanceof String) {if (((String) result).startsWith("!")) {result = ((String) result).substring(1);diff --git a/source/de/anomic/server/serverPortForwarding.java b/source/de/anomic/server/serverPortForwarding.javaindex eff324647..05ba4728c 100644--- a/source/de/anomic/server/serverPortForwarding.java+++ b/source/de/anomic/server/serverPortForwarding.java@@ -3,20 +3,13 @@ package de.anomic.server;import java.io.IOException;public interface serverPortForwarding {- public void init(- String remoteHost,- int remotePort,- String remoteUser,- String remotePwd,- String localHost,- int localPort- );+ public void init(serverSwitch switchboard, String localHost, int localPort) throws Exception;public String getHost();public int getPort();- public String getUser();public void connect() throws IOException;public void disconnect() throws IOException;+ public boolean reconnect() throws IOException;public boolean isConnected();}diff --git a/source/de/anomic/server/serverPortForwardingSch.java b/source/de/anomic/server/serverPortForwardingSch.javaindex f14f37638..6bc747d2f 100644--- a/source/de/anomic/server/serverPortForwardingSch.java+++ b/source/de/anomic/server/serverPortForwardingSch.java@@ -1,69 +1,116 @@package de.anomic.server;import java.io.IOException;-import com.jcraft.jsch.JSch;+import com.jcraft.jsch.ProxyHTTP;import com.jcraft.jsch.Session;import com.jcraft.jsch.UIKeyboardInteractive;import com.jcraft.jsch.UserInfo;+import de.anomic.server.logging.serverLog;+public class serverPortForwardingSch implements serverPortForwarding{- String rHost;- int rPort;- String rUser;- String rPwd;+ /* ========================================================================+ * Constants needed to read properties from the configuration file+ * ======================================================================== */+ public static final String FORWARDING_HOST = "portForwardingHost";+ public static final String FORWARDING_HOST_PORT = "portForwardingHostPort";+ public static final String FORWARDING_HOST_USER = "portForwardingHostUser";+ public static final String FORWARDING_HOST_PWD = "portForwardingHostPwd";++ public static final String FORWARDING_PORT = "portForwardingPort";+ public static final String FORWARDING_USE_PROXY = "portForwardingUseProxy";+++ /* ========================================================================+ * Other object fields+ * ======================================================================== */+ private serverSwitch switchboard;++ private String forwardingHost;+ private int forwardingHostPort;+ private String forwardingHostUser;+ private String forwardingHostPwd;++ private int forwardingPort;+ private boolean useProxy;++ private String remoteProxyHost;+ private int remoteProxyPort;++ private String localHost;+ private int localHostPort;- String lHost;- int lPort;+ private static Session session;+ private static serverInstantThread sessionWatcher;- Session session;+ private serverLog log;public serverPortForwardingSch() {super();+ this.log = new serverLog("PORT_FORWARDING_SCH");}public void init(- String remoteHost,- int remotePort,- String remoteUser,- String remotePwd,+ serverSwitch switchboard,String localHost,int localPort- ) {- this.rHost = remoteHost;- this.rPort = remotePort;- this.rUser = remoteUser;- this.rPwd = remotePwd;-- this.lHost = localHost;- this.lPort = localPort;-- // checking if all needed libs are availalbe- String javaClassPath = System.getProperty("java.class.path");- if (javaClassPath.indexOf("jsch") == -1) {- throw new IllegalStateException("Missing library.");+ ) throws Exception {+ try {+ this.log.logDebug("Initializing port forwarding via sch ...");++ this.switchboard = switchboard;++ this.forwardingHost = switchboard.getConfig(FORWARDING_HOST,"localhost");+ this.forwardingHostPort = Integer.valueOf(switchboard.getConfig(FORWARDING_HOST_PORT,"8080")).intValue();+ this.forwardingHostUser = switchboard.getConfig(FORWARDING_HOST_USER,"xxx");+ this.forwardingHostPwd = switchboard.getConfig(FORWARDING_HOST_PWD,"xxx");++ this.forwardingPort = Integer.valueOf(switchboard.getConfig(FORWARDING_PORT,"8080")).intValue();+ this.useProxy = Boolean.valueOf(switchboard.getConfig(FORWARDING_USE_PROXY,"false")).booleanValue();++ this.localHost = localHost;+ this.localHostPort = localPort;++ // load remote proxy data+ this.remoteProxyHost = switchboard.getConfig("remoteProxyHost","");+ try {+ this.remoteProxyPort = Integer.parseInt(switchboard.getConfig("remoteProxyPort","3128"));+ } catch (NumberFormatException e) {+ remoteProxyPort = 3128;+ }++ // checking if all needed libs are availalbe+ String javaClassPath = System.getProperty("java.class.path");+ if (javaClassPath.indexOf("jsch") == -1) {+ throw new IllegalStateException("Missing library.");+ }+ } catch (Exception e) {+ this.log.logFailure("Unable to initialize port forwarding.",e);+ throw e;}}public String getHost() {- return this.rHost;+ return this.forwardingHost;}public int getPort() {- return this.rPort;- }-- public String getUser() {- return this.rUser;+ return this.forwardingPort;}+- public void connect() throws IOException {-+ public synchronized void connect() throws IOException {try{+ if ((session != null) && (session.isConnected()))+ throw new IOException("Session already connected");++ this.log.logInfo("Trying to connect to remote port forwarding host " + this.forwardingHostUser + "@" + this.forwardingHost + ":" + this.forwardingHostPort);+JSch jsch=new JSch();- this.session=jsch.getSession(this.rUser, this.rHost, 22);- this.session.setPassword(this.rPwd);+ session=jsch.getSession(this.forwardingHostUser, this.forwardingHost, this.forwardingHostPort);+ session.setPassword(this.forwardingHostPwd);/** Setting the StrictHostKeyChecking to ignore unknown@@ -71,38 +118,70 @@ public class serverPortForwardingSch implements serverPortForwarding{*/java.util.Properties config = new java.util.Properties();config.put("StrictHostKeyChecking","no");- this.session.setConfig(config);+ session.setConfig(config);++ // setting the proxy that should be used+ if (this.useProxy) {+ session.setProxy(new ProxyHTTP(this.remoteProxyHost, this.remoteProxyPort));+ }// username and password will be given via UserInfo interface.- UserInfo ui= new MyUserInfo(this.rPwd);- this.session.setUserInfo(ui);+ UserInfo ui= new MyUserInfo(this.forwardingHostPwd);+ session.setUserInfo(ui);// trying to connect ...- this.session.connect();+ session.connect();++ // activating remote port forwarding+ session.setPortForwardingR(this.forwardingPort, this.localHost, this.localHostPort);- // Channel channel=session.openChannel("shell");- // channel.connect();+ // using a timer task to control if the session remains open+ if (sessionWatcher == null) {+ this.log.logDebug("Deploying port forwarding session watcher thread.");+ this.switchboard.deployThread("portForwardingWatcher", "Remote Port Forwarding Watcher", "this thread is used to detect broken connections and to re-establish it if necessary.",+ sessionWatcher = new serverInstantThread(this, "reconnect", null), 30000,30000,30000,1000);+ }- this.session.setPortForwardingR(this.rPort, this.lHost, this.lPort);+ this.log.logInfo("Remote port forwarding connection established: " ++ this.forwardingHost+ ":" + this.forwardingPort + " -> " ++ this.localHost + ":" + this.localHostPort);}catch(Exception e){+ this.log.logError("Unable to connect to remote port forwarding host.",e);throw new IOException(e.getMessage());}}- public void disconnect() throws IOException {- if (this.session == null) throw new IllegalStateException("No connection established.");+ public synchronized boolean reconnect() throws IOException {+ if ((!this.isConnected()) && (!Thread.currentThread().isInterrupted())) {+ this.log.logDebug("Trying to reconnect to port forwarding host.");+ this.connect();+ return this.isConnected();+ }+ return false;+ }++ public synchronized void disconnect() throws IOException {+ if (session == null) throw new IOException("No connection established.");++ // terminating port watcher thread+ this.log.logDebug("Terminating port forwarding session watcher thread.");+ this.switchboard.terminateThread("portForwardingWatcher",true);+ sessionWatcher = null;+ // disconnection the sessiontry {- this.session.disconnect();+ session.disconnect();+ this.log.logDebug("Successfully disconnected from port forwarding host.");} catch (Exception e) {+ this.log.logError("Error while trying to disconnect from port forwarding host.",e);throw new IOException(e.getMessage());}}- public boolean isConnected() {- if (this.session == null) return false;- return this.session.isConnected();+ public synchronized boolean isConnected() {+ if (session == null) return false;+ return session.isConnected();}class MyUserInfodiff --git a/source/de/anomic/server/serverThread.java b/source/de/anomic/server/serverThread.javaindex 91c4126c9..dd5921426 100644--- a/source/de/anomic/server/serverThread.java+++ b/source/de/anomic/server/serverThread.java@@ -122,4 +122,9 @@ public interface serverThread {// jobs that need to be done after termination// terminate must be called before++ public void setSyncObject(Object sync);+ public Object getSyncObject();+ public void notifyThread();+}diff --git a/source/de/anomic/soap/httpdSoapService.java b/source/de/anomic/soap/httpdSoapService.javaindex 0037443e5..bc1987c8b 100644--- a/source/de/anomic/soap/httpdSoapService.java+++ b/source/de/anomic/soap/httpdSoapService.java@@ -71,8 +71,7 @@ public class httpdSoapService/*** Constructor of this class*/- public httpdSoapService()- {+ public httpdSoapService() {super();// nothing special todo here at the moment@@ -94,10 +93,8 @@ public class httpdSoapServiceint maxSearchTime,String urlMaskFilter)- throws AxisFault- {- try- {+ throws AxisFault {+ try {// extracting the message contextextractMessageContext();@@ -123,9 +120,7 @@ public class httpdSoapService// sending back the result to the clientreturn this.convertContentToXML(result);- }- catch (Exception e)- {+ } catch (Exception e) {throw new AxisFault(e.getMessage());}}@@ -134,10 +129,8 @@ public class httpdSoapService* Service used to query the network properties* @throws AxisFault if the service could not be executed propery.*/- public String network() throws AxisFault- {- try- {+ public String network() throws AxisFault {+ try {// extracting the message contextextractMessageContext();@@ -146,9 +139,7 @@ public class httpdSoapService// sending back the result to the clientreturn result;- }- catch (Exception e)- {+ } catch (Exception e) {throw new AxisFault(e.getMessage());}}@@ -161,10 +152,8 @@ public class httpdSoapService** @throws AxisFault if the service could not be executed propery.*/- public String crawling(String crawlingURL) throws AxisFault- {- try- {+ public String crawling(String crawlingURL) throws AxisFault {+ try {// extracting the message contextextractMessageContext();@@ -185,9 +174,7 @@ public class httpdSoapService// sending back the crawling status page to the userreturn result;- }- catch (Exception e)- {+ } catch (Exception e) {throw new AxisFault(e.getMessage());}}@@ -196,8 +183,7 @@ public class httpdSoapService* This function is called by the available service functions to* extract all needed informations from the SOAP message context.*/- private void extractMessageContext()- {+ private void extractMessageContext() {this.messageContext = MessageContext.getCurrentContext();this.rootPath = (String) this.messageContext.getProperty(httpdSoapHandler.MESSAGE_CONTEXT_HTTP_ROOT_PATH);@@ -218,16 +204,13 @@ public class httpdSoapService* @throws AxisFault*/private String writeTemplate(String templateName, serverObjects args)- throws AxisFault- {- try- {+ throws AxisFault {+ try {// determining the proper class that should be invokedFile file = new File(this.rootPath, templateName);File rc = rewriteClassFile(file);- if (SERVICE_NEEDS_AUTHENTICATION.contains(templateName))- {+ if (SERVICE_NEEDS_AUTHENTICATION.contains(templateName)) {this.doAuthentication();}@@ -250,9 +233,7 @@ public class httpdSoapService// convert it into a byte array and send it back as resultbyte[] result = o.toByteArray();return new String(result);- }- catch (Exception e)- {+ } catch (Exception e) {throw new AxisFault(e.getMessage());}}@@ -268,8 +249,7 @@ public class httpdSoapServicethrows AxisFault{// check if the servlets requests authentification- if (tp.containsKey("AUTHENTICATE"))- {+ if (tp.containsKey("AUTHENTICATE")) {throw new AxisFault("log-in required");}}@@ -281,8 +261,7 @@ public class httpdSoapService* @throws AxisFault if the authentication could not be done successfully*/private void doAuthentication()- throws AxisFault- {+ throws AxisFault {// accessing the SOAP request messageMessage message = this.messageContext.getRequestMessage();@@ -291,18 +270,14 @@ public class httpdSoapService// getting the proper soap header containing the authorization fieldSOAPHeaderElement authElement = envelope.getHeaderByName(httpdSoapHandler.serviceHeaderNamespace, "Authorization");- if (authElement != null)- {+ if (authElement != null) {// the base64 encoded and md5 hashed authentication stringString authString = authElement.getValue();String adminAccountBase64MD5 = this.switchboard.getConfig("adminAccountBase64MD5","");- if (adminAccountBase64MD5.length() == 0)- {+ if (adminAccountBase64MD5.length() == 0) {throw new AxisFault("log-in required");- }- else if (!(adminAccountBase64MD5.equals(authString)))- {+ } else if (!(adminAccountBase64MD5.equals(authString))) {throw new AxisFault("log-in required");}}@@ -358,16 +333,13 @@ public class httpdSoapServicethrows Exception{Document doc = null;- try- {+ try {DocumentBuilderFactory newDocBuilderFactory = DocumentBuilderFactory.newInstance();DocumentBuilder newDocBuilder = newDocBuilderFactory.newDocumentBuilder();InputSource is = new InputSource(new StringReader(contentString));doc = newDocBuilder.parse(is);- }- catch (Exception e)- {+ } catch (Exception e) {String errorMessage = "Unable to parse the search result XML data. " + e.getClass().getName() + ". " + e.getMessage();throw new Exception(errorMessage);}diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex fe098a4fb..b14725fc0 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -63,7 +63,7 @@ import de.anomic.tools.crypt;import de.anomic.tools.nxTools;public class yacyClient {-+public static int publishMySeed(String address, String otherHash) {// this is called to enrich the seed information by// - own address (if peer is behind a nat/router)@@ -127,7 +127,7 @@ public class yacyClient {if ((otherHash != null ) && (otherHash.length() > 0)) {otherPeer = yacySeed.genRemoteSeed((String) result.get("seed0"), key, remoteTime);if ((otherPeer == null) || (!(otherPeer.hash.equals(otherHash)))) {- yacyCore.log.logDebug("yacyClient.publishMySeed consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");+ yacyCore.log.logDebug("yacyClient.publishMySeed: consistency error: other peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' wrong");return -1; // no success}otherPeerVersion = otherPeer.getVersion();@@ -152,13 +152,36 @@ public class yacyClient {*/if ((!serverCore.portForwardingEnabled) || (otherPeerVersion >= (float)0.383)) {String mytype = (String) result.get("yourtype");- if (mytype == null) mytype = "junior";- if ((yacyCore.seedDB.mySeed.get("PeerType", "junior").equals("principal")) && (mytype.equals("senior"))) mytype = "principal";+ if (mytype == null) mytype = yacySeed.PEERTYPE_JUNIOR;+ if (+ (yacyCore.seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_JUNIOR).equals(yacySeed.PEERTYPE_PRINCIPAL)) &&+ (mytype.equals(yacySeed.PEERTYPE_SENIOR))+ ) {+ mytype = yacySeed.PEERTYPE_PRINCIPAL;+ }- if (mytype.equalsIgnoreCase("junior")) {+ /*+ * If we were reported as junior we have to check if your port forwarding channel is broken+ * If this is true we try to reconnect the sch channel to the remote server now.+ */+ if (mytype.equalsIgnoreCase(yacySeed.PEERTYPE_JUNIOR)) {yacyCore.log.logInfo("yacyClient.publishMySeed: Peer '" + ((otherPeer==null)?"unknown":otherPeer.getName()) + "' reported us as junior.");+ if (serverCore.portForwardingEnabled) {+ if (+ (!Thread.currentThread().isInterrupted()) &&+ (serverCore.portForwarding != null) &&+ (!serverCore.portForwarding.isConnected())+ ) {+ yacyCore.log.logWarning("yacyClient.publishMySeed: Broken portForwarding channel detected. Trying to reconnect ...");+ try {+ serverCore.portForwarding.reconnect();+ } catch (IOException e) {+ yacyCore.log.logWarning("yacyClient.publishMySeed: Unable to reconnect to port forwarding host.");+ }+ }+ }}- yacyCore.seedDB.mySeed.put("PeerType", mytype);+ yacyCore.seedDB.mySeed.put(yacySeed.PEERTYPE, mytype);}if (!(yacyCore.seedDB.mySeed.isProper())) {diff --git a/yacy.init b/yacy.initindex c0b620b21..81b6af2a5 100644--- a/yacy.init+++ b/yacy.init@@ -484,10 +484,15 @@ connectionKeepAliveSupport=false# Configuration options needed to configure server port forwardingportForwardingEnabled=false-portForwardingHost=+portForwardingUseProxy=falseportForwardingPort=-portForwardingUser=-portForwardingPwd=++portForwardingHost=+portForwardingHostPort=22+portForwardingHostUser=+portForwardingHostPwd=++# Specifies if yacy should forward received messages via# email to the configured email address