*) 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
pull/1/head
theli 19 years ago
parent 26d7e8dd0d
commit 9b941fb773

@ -55,6 +55,7 @@ import de.anomic.plasma.plasmaSearchRankingProfile;
import de.anomic.plasma.plasmaSearchTimingProfile; import de.anomic.plasma.plasmaSearchTimingProfile;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaSearchQuery; import de.anomic.plasma.plasmaSearchQuery;
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
@ -209,7 +210,7 @@ public class DetailedSearch {
// adding some additional properties needed for the rss feed // adding some additional properties needed for the rss feed
String hostName = (String) header.get("Host","localhost"); 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"); prop.put("rssYacyImageURL","http://" + hostName + "/env/grafics/yacy.gif");
return prop; return prop;

@ -126,8 +126,17 @@ public class Status {
} }
prop.put("versioncomment_latestVersion", Float.toString(yacyCore.latestVersion)); 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("host", serverCore.publicLocalIP());
prop.put("port", env.getConfig("port", "<unknown>"));
// port forwarding: hostname and port // port forwarding: hostname and port
if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) { if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) {

@ -20,7 +20,7 @@
</tr> </tr>
<tr class="TableCellLight"> <tr class="TableCellLight">
<td>Peer host</td> <td>Peer host</td>
<td>#[host]#:#[port]#</td> <td>#[host]#:#[port]# #(extPortFormat)#::(Binding to interface: #[extPort]#)#(/extPortFormat)#</td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<tr class="TableCellDark"> <tr class="TableCellDark">

@ -106,8 +106,8 @@ public class dir {
prop.put("hostip", InetAddress.getByName(serverCore.publicIP()).getHostAddress()); prop.put("hostip", InetAddress.getByName(serverCore.publicIP()).getHostAddress());
}catch(UnknownHostException e){ }catch(UnknownHostException e){
prop.put("hostip", "Unknown Host Exception"); 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 // generate upload/download authorizations
final String adminAccountBase64MD5 = switchboard.getConfig("adminAccountBase64MD5", ""); final String adminAccountBase64MD5 = switchboard.getConfig("adminAccountBase64MD5", "");

@ -72,8 +72,8 @@ public class welcome {
prop.put("hostip", InetAddress.getByName(serverCore.publicIP()).getHostAddress()); prop.put("hostip", InetAddress.getByName(serverCore.publicIP()).getHostAddress());
}catch(UnknownHostException e){ }catch(UnknownHostException e){
prop.put("hostip", "Unknown Host Exception"); 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", "")); 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); final String peertype = (yacyCore.seedDB.mySeed == null) ? yacySeed.PEERTYPE_JUNIOR : yacyCore.seedDB.mySeed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);

@ -306,7 +306,7 @@ public class index {
// adding some additional properties needed for the rss feed // adding some additional properties needed for the rss feed
String hostName = (String) header.get("Host","localhost"); 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"); prop.put("rssYacyImageURL","http://" + hostName + "/env/grafics/yacy.gif");
return prop; return prop;

@ -1065,15 +1065,15 @@ public final class httpd implements serverHandler {
InetAddress hostAddress = httpc.dnsResolve(clientIP); InetAddress hostAddress = httpc.dnsResolve(clientIP);
if (hostAddress == null) { if (hostAddress == null) {
tp.put("host", serverCore.publicLocalIP().getHostAddress()); 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()) { } else if (hostAddress.isSiteLocalAddress() || hostAddress.isLoopbackAddress()) {
tp.put("host", serverCore.publicLocalIP().getHostAddress()); tp.put("host", serverCore.publicLocalIP().getHostAddress());
tp.put("port", switchboard.getConfig("port", "8080")); tp.put("port", serverCore.getPortNr(switchboard.getConfig("port", "8080")));
} else { } else {
tp.put("host", serverCore.publicIP()); tp.put("host", serverCore.publicIP());
tp.put("port", (serverCore.portForwardingEnabled && (serverCore.portForwarding != null)) tp.put("port", (serverCore.portForwardingEnabled && (serverCore.portForwarding != null))
? Integer.toString(serverCore.portForwarding.getPort()) ? Integer.toString(serverCore.portForwarding.getPort())
: switchboard.getConfig("port", "8080")); : Integer.toString(serverCore.getPortNr(switchboard.getConfig("port", "8080"))));
} }
tp.put("peerName", yacyCore.seedDB.mySeed.getName()); 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 ... * 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 * 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)) { isThisHostIP(dstHost)) {
return true; return true;
} else if ((serverCore.portForwardingEnabled) && } else if ((serverCore.portForwardingEnabled) &&

@ -90,7 +90,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
public static Hashtable bfHost = new Hashtable(); // for brute-force prevention public static Hashtable bfHost = new Hashtable(); // for brute-force prevention
// class variables // 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 boolean forceRestart = false; // specifies if the server should try to do a restart
public static boolean portForwardingEnabled = false; public static boolean portForwardingEnabled = false;
@ -193,11 +193,11 @@ public final class serverCore extends serverAbstractThread implements serverThre
this.log.logInfo("Initializing serverCore ..."); this.log.logInfo("Initializing serverCore ...");
// read some config values // 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 // Open a new server-socket channel
try { try {
this.initPort(this.port); this.initPort(this.extendedPort);
} catch (Exception e) { } catch (Exception e) {
String errorMsg = "FATAL ERROR: " + e.getMessage() + " - probably root access rights needed. check port number"; String errorMsg = "FATAL ERROR: " + e.getMessage() + " - probably root access rights needed. check port number";
this.log.logSevere(errorMsg); 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())); 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 // parsing the port configuration
String bindIP = null; String bindIP = null;
int bindPort; int bindPort;
int pos = -1; int pos = -1;
if ((pos = thePort.indexOf(":"))!= -1) { if ((pos = extendedPortString.indexOf(":"))!= -1) {
bindIP = thePort.substring(0,pos).trim(); bindIP = extendedPortString.substring(0,pos).trim();
thePort = thePort.substring(pos+1); extendedPortString = extendedPortString.substring(pos+1);
if (bindIP.startsWith("#")) { if (bindIP.startsWith("#")) {
String interfaceName = bindIP.substring(1); 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) return (bindIP == null)
? new InetSocketAddress(bindPort) ? new InetSocketAddress(bindPort)
@ -448,7 +456,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
} }
public void open() { public void open() {
this.log.logConfig("* server started on " + publicLocalIP() + ":" + this.port); this.log.logConfig("* server started on " + publicLocalIP() + ":" + this.extendedPort);
} }
// class body // class body

@ -30,6 +30,7 @@ import de.anomic.http.httpc;
import de.anomic.http.httpdAbstractHandler; import de.anomic.http.httpdAbstractHandler;
import de.anomic.http.httpdHandler; import de.anomic.http.httpdHandler;
import de.anomic.server.serverClassLoader; import de.anomic.server.serverClassLoader;
import de.anomic.server.serverCore;
import de.anomic.server.serverFileUtils; import de.anomic.server.serverFileUtils;
import de.anomic.server.serverSwitch; 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_RELATIVE_PATH, path.toString());
msgContext.setProperty(Constants.MC_JWS_CLASSDIR, "jwsClasses"); msgContext.setProperty(Constants.MC_JWS_CLASSDIR, "jwsClasses");
msgContext.setProperty(Constants.MC_HOME_DIR, "."); 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_HTTP_ROOT_PATH ,this.htRootPath.toString());
msgContext.setProperty(MESSAGE_CONTEXT_SERVER_SWITCH,this.switchboard); msgContext.setProperty(MESSAGE_CONTEXT_SERVER_SWITCH,this.switchboard);

@ -76,6 +76,7 @@ import java.util.TimeZone;
import de.anomic.http.httpc; import de.anomic.http.httpc;
import de.anomic.net.natLib; import de.anomic.net.natLib;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCore;
import de.anomic.server.serverSemaphore; import de.anomic.server.serverSemaphore;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.server.serverDate; import de.anomic.server.serverDate;
@ -218,7 +219,7 @@ public class yacyCore {
log.logConfig("YOU ARE OFFLINE! ---"); log.logConfig("YOU ARE OFFLINE! ---");
log.logConfig("--- TO START BOOTSTRAPING, YOU MUST USE THE PROXY,"); log.logConfig("--- TO START BOOTSTRAPING, YOU MUST USE THE PROXY,");
log.logConfig("--- OR HIT THE BUTTON 'go online'"); 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");
} }
} }

@ -106,7 +106,7 @@ public class yacyPeerActions {
if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) { if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) {
seedDB.mySeed.put(yacySeed.PORT, Integer.toString(serverCore.portForwarding.getPort())); seedDB.mySeed.put(yacySeed.PORT, Integer.toString(serverCore.portForwarding.getPort()));
} else { } 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 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? long uptimediff = uptime - Long.parseLong(sb.getConfig("lastseedcheckUptime", "0")); //TODO: Do not use the switchboard?

@ -540,7 +540,7 @@ public class yacySeed {
if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) { if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) {
newSeed.dna.put(PORT,Integer.toString(serverCore.portForwarding.getPort())); newSeed.dna.put(PORT,Integer.toString(serverCore.portForwarding.getPort()));
} else { } 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(BDATE, yacyCore.universalDateShortString(new Date()));
newSeed.dna.put(LASTSEEN, newSeed.dna.get(BDATE)); // just as initial setting newSeed.dna.put(LASTSEEN, newSeed.dna.get(BDATE)); // just as initial setting

@ -144,7 +144,7 @@ public final class yacySeedDB {
mySeed.put(yacySeed.IP, sb.getConfig("portForwardingHost","localhost")); mySeed.put(yacySeed.IP, sb.getConfig("portForwardingHost","localhost"));
} else { } else {
mySeed.put(yacySeed.IP, ""); // we delete the old information to see what we have now 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 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 == null) return null;
if ((seed == mySeed) && (!(seed.isOnline()))) { if ((seed == mySeed) && (!(seed.isOnline()))) {
// take local ip instead of external // 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)); return seed.getAddress() + ((subdom == null) ? "" : ("/" + subdom));
} else { } else {

@ -382,7 +382,7 @@ public final class yacy {
if (browserPopUpTrigger) { if (browserPopUpTrigger) {
final String browserPopUpPage = sb.getConfig("browserPopUpPage", "Status.html"); final String browserPopUpPage = sb.getConfig("browserPopUpPage", "Status.html");
final String browserPopUpApplication = sb.getConfig("browserPopUpApplication", "netscape"); 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 //Copy the shipped locales into DATA
@ -457,7 +457,7 @@ public final class yacy {
server.terminate(false); server.terminate(false);
server.interrupt(); server.interrupt();
if (server.isAlive()) try { 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"); serverLog.logConfig("SHUTDOWN", "sent termination signal to server socket");
} catch (IOException ee) { } catch (IOException ee) {
serverLog.logConfig("SHUTDOWN", "termination signal to server socket missed (server shutdown, ok)"); serverLog.logConfig("SHUTDOWN", "termination signal to server socket missed (server shutdown, ok)");

Loading…
Cancel
Save