From 9b941fb77341bfbb95085bb915787ca43e0ffde1 Mon Sep 17 00:00:00 2001 From: theli Date: Fri, 17 Feb 2006 10:53:20 +0000 Subject: [PATCH] *) bugfix for usage of yacy with extended port binding (e.g. #eth0:8080, 192.168.0.1:8080, etc.) - port was reported incorrectly to other peers git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1678 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/DetailedSearch.java | 3 ++- htroot/Status.java | 11 ++++++++- htroot/Status_p.inc | 2 +- htroot/htdocsdefault/dir.java | 4 ++-- htroot/htdocsdefault/welcome.java | 4 ++-- htroot/index.java | 2 +- source/de/anomic/http/httpd.java | 8 +++---- source/de/anomic/server/serverCore.java | 26 ++++++++++++++------- source/de/anomic/soap/httpdSoapHandler.java | 3 ++- source/de/anomic/yacy/yacyCore.java | 3 ++- source/de/anomic/yacy/yacyPeerActions.java | 2 +- source/de/anomic/yacy/yacySeed.java | 2 +- source/de/anomic/yacy/yacySeedDB.java | 4 ++-- source/yacy.java | 4 ++-- 14 files changed, 49 insertions(+), 29 deletions(-) diff --git a/htroot/DetailedSearch.java b/htroot/DetailedSearch.java index 66c7a85ea..cd90d365d 100644 --- a/htroot/DetailedSearch.java +++ b/htroot/DetailedSearch.java @@ -55,6 +55,7 @@ import de.anomic.plasma.plasmaSearchRankingProfile; import de.anomic.plasma.plasmaSearchTimingProfile; import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSearchQuery; +import de.anomic.server.serverCore; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; import de.anomic.yacy.yacyCore; @@ -209,7 +210,7 @@ public class DetailedSearch { // adding some additional properties needed for the rss feed String hostName = (String) header.get("Host","localhost"); - if (hostName.indexOf(":") == -1) hostName += ":" + env.getConfig("port","8080"); + if (hostName.indexOf(":") == -1) hostName += ":" + serverCore.getPortNr(env.getConfig("port","8080")); prop.put("rssYacyImageURL","http://" + hostName + "/env/grafics/yacy.gif"); return prop; diff --git a/htroot/Status.java b/htroot/Status.java index ac84322a8..4e8366c48 100644 --- a/htroot/Status.java +++ b/htroot/Status.java @@ -126,8 +126,17 @@ public class Status { } prop.put("versioncomment_latestVersion", Float.toString(yacyCore.latestVersion)); + // hostname and port + String extendedPortString = env.getConfig("port", "8080"); + int pos = extendedPortString.indexOf(":"); + prop.put("port",serverCore.getPortNr(extendedPortString)); + if (pos!=-1) { + prop.put("extPortFormat",1); + prop.put("extPortFormat_extPort",extendedPortString); + } else { + prop.put("extPortFormat",0); + } prop.put("host", serverCore.publicLocalIP()); - prop.put("port", env.getConfig("port", "")); // port forwarding: hostname and port if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) { diff --git a/htroot/Status_p.inc b/htroot/Status_p.inc index 2260f2811..19e60cc03 100644 --- a/htroot/Status_p.inc +++ b/htroot/Status_p.inc @@ -20,7 +20,7 @@ Peer host - #[host]#:#[port]# + #[host]#:#[port]# #(extPortFormat)#::(Binding to interface: #[extPort]#)#(/extPortFormat)#   diff --git a/htroot/htdocsdefault/dir.java b/htroot/htdocsdefault/dir.java index 7bbee28dd..5ce7bba72 100644 --- a/htroot/htdocsdefault/dir.java +++ b/htroot/htdocsdefault/dir.java @@ -106,8 +106,8 @@ public class dir { prop.put("hostip", InetAddress.getByName(serverCore.publicIP()).getHostAddress()); }catch(UnknownHostException e){ prop.put("hostip", "Unknown Host Exception"); - } - prop.put("port", env.getConfig("port", "8080")); + } + prop.put("port", serverCore.getPortNr(env.getConfig("port","8080"))); // generate upload/download authorizations final String adminAccountBase64MD5 = switchboard.getConfig("adminAccountBase64MD5", ""); diff --git a/htroot/htdocsdefault/welcome.java b/htroot/htdocsdefault/welcome.java index e81967b65..2aa7fe1ba 100644 --- a/htroot/htdocsdefault/welcome.java +++ b/htroot/htdocsdefault/welcome.java @@ -72,8 +72,8 @@ public class welcome { prop.put("hostip", InetAddress.getByName(serverCore.publicIP()).getHostAddress()); }catch(UnknownHostException e){ prop.put("hostip", "Unknown Host Exception"); - } - prop.put("port", env.getConfig("port", "8080")); + } + prop.put("port", serverCore.getPortNr(env.getConfig("port","8080"))); prop.put("clientip", header.get("CLIENTIP", "")); final String peertype = (yacyCore.seedDB.mySeed == null) ? yacySeed.PEERTYPE_JUNIOR : yacyCore.seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN); diff --git a/htroot/index.java b/htroot/index.java index fa665eb2a..88036be04 100644 --- a/htroot/index.java +++ b/htroot/index.java @@ -306,7 +306,7 @@ public class index { // adding some additional properties needed for the rss feed String hostName = (String) header.get("Host","localhost"); - if (hostName.indexOf(":") == -1) hostName += ":" + env.getConfig("port","8080"); + if (hostName.indexOf(":") == -1) hostName += ":" + serverCore.getPortNr(env.getConfig("port","8080")); prop.put("rssYacyImageURL","http://" + hostName + "/env/grafics/yacy.gif"); return prop; diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java index d9da7db9a..e44fe6de1 100644 --- a/source/de/anomic/http/httpd.java +++ b/source/de/anomic/http/httpd.java @@ -1065,15 +1065,15 @@ public final class httpd implements serverHandler { InetAddress hostAddress = httpc.dnsResolve(clientIP); if (hostAddress == null) { tp.put("host", serverCore.publicLocalIP().getHostAddress()); - tp.put("port", switchboard.getConfig("port", "8080")); + tp.put("port", serverCore.getPortNr(switchboard.getConfig("port", "8080"))); } else if (hostAddress.isSiteLocalAddress() || hostAddress.isLoopbackAddress()) { tp.put("host", serverCore.publicLocalIP().getHostAddress()); - tp.put("port", switchboard.getConfig("port", "8080")); + tp.put("port", serverCore.getPortNr(switchboard.getConfig("port", "8080"))); } else { tp.put("host", serverCore.publicIP()); tp.put("port", (serverCore.portForwardingEnabled && (serverCore.portForwarding != null)) ? Integer.toString(serverCore.portForwarding.getPort()) - : switchboard.getConfig("port", "8080")); + : Integer.toString(serverCore.getPortNr(switchboard.getConfig("port", "8080")))); } tp.put("peerName", yacyCore.seedDB.mySeed.getName()); @@ -1448,7 +1448,7 @@ public final class httpd implements serverHandler { * If the port number is equal to the yacy port and the IP address is an address of this host ... * Please note that yacy is listening to all interfaces of this host */ - } else if (dstPort.equals(Integer.valueOf(switchboard.getConfig("port", "8080"))) && + } else if (dstPort.equals(Integer.valueOf(serverCore.getPortNr(switchboard.getConfig("port", "8080")))) && isThisHostIP(dstHost)) { return true; } else if ((serverCore.portForwardingEnabled) && diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index e73624b72..a3bf4f688 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -90,7 +90,7 @@ public final class serverCore extends serverAbstractThread implements serverThre public static Hashtable bfHost = new Hashtable(); // for brute-force prevention // class variables - private String port; // the listening port + private String extendedPort; // the listening port public boolean forceRestart = false; // specifies if the server should try to do a restart public static boolean portForwardingEnabled = false; @@ -193,11 +193,11 @@ public final class serverCore extends serverAbstractThread implements serverThre this.log.logInfo("Initializing serverCore ..."); // read some config values - this.port = this.switchboard.getConfig("port", "8080").trim(); + this.extendedPort = this.switchboard.getConfig("port", "8080").trim(); // Open a new server-socket channel try { - this.initPort(this.port); + this.initPort(this.extendedPort); } catch (Exception e) { String errorMsg = "FATAL ERROR: " + e.getMessage() + " - probably root access rights needed. check port number"; this.log.logSevere(errorMsg); @@ -260,16 +260,24 @@ public final class serverCore extends serverAbstractThread implements serverThre yacyCore.seedDB.mySeed.put(yacySeed.PORT,Integer.toString(bindAddress.getPort())); } - public InetSocketAddress generateSocketAddress(String thePort) throws SocketException { + public static int getPortNr(String extendedPortString) { + int pos = -1; + if ((pos = extendedPortString.indexOf(":"))!= -1) { + extendedPortString = extendedPortString.substring(pos+1); + } + return Integer.parseInt(extendedPortString); + } + + public InetSocketAddress generateSocketAddress(String extendedPortString) throws SocketException { // parsing the port configuration String bindIP = null; int bindPort; int pos = -1; - if ((pos = thePort.indexOf(":"))!= -1) { - bindIP = thePort.substring(0,pos).trim(); - thePort = thePort.substring(pos+1); + if ((pos = extendedPortString.indexOf(":"))!= -1) { + bindIP = extendedPortString.substring(0,pos).trim(); + extendedPortString = extendedPortString.substring(pos+1); if (bindIP.startsWith("#")) { String interfaceName = bindIP.substring(1); @@ -303,7 +311,7 @@ public final class serverCore extends serverAbstractThread implements serverThre } } } - bindPort = Integer.parseInt(thePort); + bindPort = Integer.parseInt(extendedPortString); return (bindIP == null) ? new InetSocketAddress(bindPort) @@ -448,7 +456,7 @@ public final class serverCore extends serverAbstractThread implements serverThre } public void open() { - this.log.logConfig("* server started on " + publicLocalIP() + ":" + this.port); + this.log.logConfig("* server started on " + publicLocalIP() + ":" + this.extendedPort); } // class body diff --git a/source/de/anomic/soap/httpdSoapHandler.java b/source/de/anomic/soap/httpdSoapHandler.java index eba277248..8f12182bc 100644 --- a/source/de/anomic/soap/httpdSoapHandler.java +++ b/source/de/anomic/soap/httpdSoapHandler.java @@ -30,6 +30,7 @@ import de.anomic.http.httpc; import de.anomic.http.httpdAbstractHandler; import de.anomic.http.httpdHandler; import de.anomic.server.serverClassLoader; +import de.anomic.server.serverCore; import de.anomic.server.serverFileUtils; import de.anomic.server.serverSwitch; @@ -431,7 +432,7 @@ public final class httpdSoapHandler extends httpdAbstractHandler implements http msgContext.setProperty(Constants.MC_RELATIVE_PATH, path.toString()); msgContext.setProperty(Constants.MC_JWS_CLASSDIR, "jwsClasses"); msgContext.setProperty(Constants.MC_HOME_DIR, "."); - msgContext.setProperty(MessageContext.TRANS_URL, "http://" + requestHeader.get("Host") + ((((String)requestHeader.get("Host")).indexOf(":") > -1)?"":this.switchboard.getConfig("port","8080")) + "/soap/index"); + msgContext.setProperty(MessageContext.TRANS_URL, "http://" + requestHeader.get("Host") + ((((String)requestHeader.get("Host")).indexOf(":") > -1)?"":Integer.toString(serverCore.getPortNr(this.switchboard.getConfig("port","8080")))) + "/soap/index"); msgContext.setProperty(MESSAGE_CONTEXT_HTTP_ROOT_PATH ,this.htRootPath.toString()); msgContext.setProperty(MESSAGE_CONTEXT_SERVER_SWITCH,this.switchboard); diff --git a/source/de/anomic/yacy/yacyCore.java b/source/de/anomic/yacy/yacyCore.java index 12017f6b4..d22cec758 100644 --- a/source/de/anomic/yacy/yacyCore.java +++ b/source/de/anomic/yacy/yacyCore.java @@ -76,6 +76,7 @@ import java.util.TimeZone; import de.anomic.http.httpc; import de.anomic.net.natLib; import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverCore; import de.anomic.server.serverSemaphore; import de.anomic.server.serverSwitch; import de.anomic.server.serverDate; @@ -218,7 +219,7 @@ public class yacyCore { log.logConfig("YOU ARE OFFLINE! ---"); log.logConfig("--- TO START BOOTSTRAPING, YOU MUST USE THE PROXY,"); log.logConfig("--- OR HIT THE BUTTON 'go online'"); - log.logConfig("--- ON THE STATUS PAGE http://localhost:" + switchboard.getConfig("port", "8080") + "/Status.html"); + log.logConfig("--- ON THE STATUS PAGE http://localhost:" + serverCore.getPortNr(switchboard.getConfig("port", "8080")) + "/Status.html"); } } diff --git a/source/de/anomic/yacy/yacyPeerActions.java b/source/de/anomic/yacy/yacyPeerActions.java index 870f436c3..4c79f703f 100644 --- a/source/de/anomic/yacy/yacyPeerActions.java +++ b/source/de/anomic/yacy/yacyPeerActions.java @@ -106,7 +106,7 @@ public class yacyPeerActions { if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) { seedDB.mySeed.put(yacySeed.PORT, Integer.toString(serverCore.portForwarding.getPort())); } else { - seedDB.mySeed.put(yacySeed.PORT, sb.getConfig("port", "8080")); + seedDB.mySeed.put(yacySeed.PORT, Integer.toString(serverCore.getPortNr(sb.getConfig("port", "8080")))); } long uptime = ((System.currentTimeMillis() - Long.parseLong(sb.getConfig("startupTime", "0"))) / 1000) / 60; long uptimediff = uptime - Long.parseLong(sb.getConfig("lastseedcheckUptime", "0")); //TODO: Do not use the switchboard? diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index 6f994527c..f4a17fd4d 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -540,7 +540,7 @@ public class yacySeed { if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) { newSeed.dna.put(PORT,Integer.toString(serverCore.portForwarding.getPort())); } else { - newSeed.dna.put(PORT, sb.getConfig("port", "8080")); + newSeed.dna.put(PORT,Integer.toString(serverCore.getPortNr(sb.getConfig("port", "8080")))); } newSeed.dna.put(BDATE, yacyCore.universalDateShortString(new Date())); newSeed.dna.put(LASTSEEN, newSeed.dna.get(BDATE)); // just as initial setting diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.java index 1d405e4b8..38db2705c 100644 --- a/source/de/anomic/yacy/yacySeedDB.java +++ b/source/de/anomic/yacy/yacySeedDB.java @@ -144,7 +144,7 @@ public final class yacySeedDB { mySeed.put(yacySeed.IP, sb.getConfig("portForwardingHost","localhost")); } else { mySeed.put(yacySeed.IP, ""); // we delete the old information to see what we have now - mySeed.put(yacySeed.PORT, sb.getConfig("port", "8080")); // set my seed's correct port number + mySeed.put(yacySeed.PORT, Integer.toString(serverCore.getPortNr(sb.getConfig("port", "8080")))); // set my seed's correct port number } mySeed.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN); // markup startup condition @@ -761,7 +761,7 @@ public final class yacySeedDB { if (seed == null) return null; if ((seed == mySeed) && (!(seed.isOnline()))) { // take local ip instead of external - return serverCore.publicIP() + ":" + sb.getConfig("port", "8080") + ((subdom == null) ? "" : ("/" + subdom)); + return serverCore.publicIP() + ":" + serverCore.getPortNr(sb.getConfig("port", "8080")) + ((subdom == null) ? "" : ("/" + subdom)); } return seed.getAddress() + ((subdom == null) ? "" : ("/" + subdom)); } else { diff --git a/source/yacy.java b/source/yacy.java index f63aec73c..47fc1ba4e 100644 --- a/source/yacy.java +++ b/source/yacy.java @@ -382,7 +382,7 @@ public final class yacy { if (browserPopUpTrigger) { final String browserPopUpPage = sb.getConfig("browserPopUpPage", "Status.html"); final String browserPopUpApplication = sb.getConfig("browserPopUpApplication", "netscape"); - serverSystem.openBrowser("http://localhost:" + port + "/" + browserPopUpPage, browserPopUpApplication); + serverSystem.openBrowser("http://localhost:" + server.getPortNr(port) + "/" + browserPopUpPage, browserPopUpApplication); } //Copy the shipped locales into DATA @@ -457,7 +457,7 @@ public final class yacy { server.terminate(false); server.interrupt(); if (server.isAlive()) try { - httpc.wget(new URL("http://localhost:" + port), 1000, null, null, null); // kick server + httpc.wget(new URL("http://localhost:" + serverCore.getPortNr(port)), 1000, null, null, null); // kick server serverLog.logConfig("SHUTDOWN", "sent termination signal to server socket"); } catch (IOException ee) { serverLog.logConfig("SHUTDOWN", "termination signal to server socket missed (server shutdown, ok)");