use staticIP more often

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@592 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 20 years ago
parent 2a081c9ee5
commit 66ebce1109

@ -1125,7 +1125,7 @@ public final class httpd implements serverHandler {
// tp.put("host", serverCore.publicIP().getHostAddress());
// tp.put("port", switchboard.getConfig("port", "8080"));
tp.put("peerName", yacyCore.seedDB.mySeed.getName());
tp.put("host", serverCore.publicIP().getHostAddress());
tp.put("host", serverCore.publicIP());
tp.put("port", (serverCore.portForwardingEnabled && (serverCore.portForwarding != null))
? Integer.toString(serverCore.portForwarding.getPort())
: switchboard.getConfig("port", "8080"));

@ -1549,11 +1549,12 @@ cd ..
int DataPort = DataSocketActive.getLocalPort();
// client ip
InetAddress LocalIp = serverCore.publicIP();
//InetAddress LocalIp = serverCore.publicIP();
// InetAddress LocalIp = DataSocketActive.getInetAddress().getLocalHost();
// save ip address in high byte order
byte[] Bytes = LocalIp.getAddress();
//byte[] Bytes = LocalIp.getAddress();
byte[] Bytes = serverCore.publicIP().getBytes();
// bytes greater than 127 should not be printed as negative
short Shorts[] = new short[4];

@ -157,11 +157,13 @@ public class natLib {
}
// maybe this is a dial-up connection (or LAN and DebugMode) and we can get it from java variables
InetAddress ia = serverCore.publicIP();
/*InetAddress ia = serverCore.publicIP();
if (ia != null) {
ip = ia.getHostAddress();
if (isProper(ip)) return ip;
}
}*/
ip = serverCore.publicIP();
if (isProper(ip)) return ip;
// now go the uneasy way and ask some web responder
disorderHeap random = new disorderHeap(retrieveOptions());

@ -80,6 +80,7 @@ import de.anomic.http.httpc;
import de.anomic.http.httpd;
import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacyCore;
import de.anomic.plasma.plasmaSwitchboard;
public final class serverCore extends serverAbstractThread implements serverThread {
@ -275,7 +276,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
serverCore.portForwarding.connect();
serverCore.portForwardingEnabled = true;
yacyCore.seedDB.mySeed.put("IP",publicIP().getHostAddress());
yacyCore.seedDB.mySeed.put("IP",publicIP());
yacyCore.seedDB.mySeed.put("Port",Integer.toString(serverCore.portForwarding.getPort()));
} catch (Exception e) {
serverCore.portForwardingEnabled = false;
@ -310,14 +311,22 @@ public final class serverCore extends serverAbstractThread implements serverThre
return true;
}
public static InetAddress publicIP() {
public static String publicIP() {
try {
// If port forwarding was enabled we need to return the remote IP Address
plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard();
if(sb != null){
String staticIP=sb.getConfig("staticIP", "");
if( (!staticIP.equals("")) && sb.getConfig("yacyDebugMode", "false").equals("true") ){
return staticIP;
}
}
if ((serverCore.portForwardingEnabled)&&(serverCore.portForwarding != null)) {
return InetAddress.getByName(serverCore.portForwarding.getHost());
//does not return serverCore.portForwarding.getHost(), because hostnames are not valid, except in DebugMode
return InetAddress.getByName(serverCore.portForwarding.getHost()).getHostAddress();
} else {
return publicLocalIP();
return publicLocalIP().getHostAddress();
}
} catch (java.net.UnknownHostException e) {
System.err.println("ERROR: (internal) " + e.getMessage());

@ -145,7 +145,7 @@ public class yacyClient {
if (!serverCore.portForwardingEnabled) {
yacyCore.seedDB.mySeed.put("IP", (String) result.get("yourip"));
} else {
yacyCore.seedDB.mySeed.put("IP", serverCore.publicIP().getHostAddress());
yacyCore.seedDB.mySeed.put("IP", serverCore.publicIP());
}
/* If we have port forwarding enabled but the other peer uses a too old yacy version

@ -94,7 +94,7 @@ public class yacyPeerActions {
public void updateMySeed() {
if (sb.getConfig("peerName", "nameless").equals("nameless")) {
// generate new peer name
String newPeerName = serverCore.publicIP().getHostName() + yacyCore.speedKey + serverSystem.infoKey() + (System.currentTimeMillis() & 99);
String newPeerName = serverCore.publicIP() + yacyCore.speedKey + serverSystem.infoKey() + (System.currentTimeMillis() & 99);
newPeerName = newPeerName.replace('.', '-');
newPeerName = newPeerName.replace('_', '-');
sb.setConfig("peerName", newPeerName);

@ -632,7 +632,7 @@ public class yacySeedDB {
if (seed == null) return null;
if ((seed == mySeed) && (!(seed.isOnline()))) {
// take local ip instead of external
return serverCore.publicIP().getHostAddress() + ":" + sb.getConfig("port", "8080") + ((subdom == null) ? "" : ("/" + subdom));
return serverCore.publicIP() + ":" + sb.getConfig("port", "8080") + ((subdom == null) ? "" : ("/" + subdom));
}
return seed.getAddress() + ((subdom == null) ? "" : ("/" + subdom));
} else {

Loading…
Cancel
Save