enhancements for staticIP and ipv6 handling

pull/1/head
Michael Peter Christen 11 years ago
parent a71718a459
commit d2b8f2b477

@ -208,14 +208,17 @@ public class SettingsAck_p {
} else if (staticIP.startsWith("https://")) { } else if (staticIP.startsWith("https://")) {
if (staticIP.length() > 8) { staticIP = staticIP.substring(8); } else { staticIP = ""; } if (staticIP.length() > 8) { staticIP = staticIP.substring(8); } else { staticIP = ""; }
} }
if (staticIP.isEmpty()) { String error = Seed.isProperIP(staticIP);
serverCore.useStaticIP = false; if (error == null) {
} else {
serverCore.useStaticIP = true; serverCore.useStaticIP = true;
sb.peers.mySeed().setIP(staticIP);
env.setConfig("staticIP", staticIP);
} else {
serverCore.useStaticIP = false;
sb.peers.mySeed().setIP("");
env.setConfig("staticIP", "");
} }
if (Seed.isProperIP(staticIP) == null) sb.peers.mySeed().setIP(staticIP);
env.setConfig("staticIP", staticIP);
// server access data // server access data
String filter = (post.get("serverfilter")).trim(); String filter = (post.get("serverfilter")).trim();
/*String user = (String) post.get("serveruser"); /*String user = (String) post.get("serveruser");

@ -121,13 +121,18 @@ public final class hello {
prop.put("message", "I am I"); prop.put("message", "I am I");
return prop; return prop;
} }
if (remoteSeed.hash.equals(sb.peers.mySeed().hash)) {
// reject a ping with my own hash
prop.put("message", "You are using my peer hash");
return prop;
}
/*
if (remoteSeed.getName().equals(sb.peers.mySeed().getName())) { if (remoteSeed.getName().equals(sb.peers.mySeed().getName())) {
// reject a ping with my name // reject a ping with my name
prop.put("message", "You are using my name"); prop.put("message", "You are using my name");
return prop; return prop;
} }
*/
if (sb.isRobinsonMode() && !sb.isPublicRobinson()) { if (sb.isRobinsonMode() && !sb.isPublicRobinson()) {
// if we are a robinson cluster, answer only if this client is known by our network definition // if we are a robinson cluster, answer only if this client is known by our network definition
prop.put("message", "I am robinson, I do not answer"); prop.put("message", "I am robinson, I do not answer");

@ -56,6 +56,7 @@ import net.yacy.cora.storage.ConcurrentARC;
import net.yacy.cora.storage.KeyList; import net.yacy.cora.storage.KeyList;
import net.yacy.cora.util.CommonPattern; import net.yacy.cora.util.CommonPattern;
import net.yacy.cora.util.ConcurrentLog; import net.yacy.cora.util.ConcurrentLog;
import net.yacy.kelondro.util.MemoryControl;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.SimpleTimeLimiter; import com.google.common.util.concurrent.SimpleTimeLimiter;
@ -705,12 +706,15 @@ public class Domains {
if (host0 == null || host0.isEmpty()) return null; if (host0 == null || host0.isEmpty()) return null;
final String host = host0.toLowerCase().trim(); final String host = host0.toLowerCase().trim();
/*
if (MemoryControl.shortStatus()) { if (MemoryControl.shortStatus()) {
NAME_CACHE_HIT.clear(); NAME_CACHE_HIT.clear();
NAME_CACHE_MISS.clear(); NAME_CACHE_MISS.clear();
} }
*/
if (host0.endsWith(".yacyh")) {
// that should not happen here
return null;
}
// try to resolve host by doing a name cache lookup // try to resolve host by doing a name cache lookup
InetAddress ip = NAME_CACHE_HIT.get(host); InetAddress ip = NAME_CACHE_HIT.get(host);

@ -286,13 +286,14 @@ public final class Protocol {
} else { } else {
final String myIP = result.get("yourip"); final String myIP = result.get("yourip");
final String properIP = Seed.isProperIP(myIP); final String properIP = Seed.isProperIP(myIP);
mySeed.setFlagRootNode((mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL)) && responseTime < 1000 && Domains.isThisHostIP(myIP) && if ( properIP == null ) mySeed.setIP(myIP);
Switchboard.getSwitchboard().index.fulltext().connectedLocalSolr()); // RootNode may receive direct Solr queries, set flag only if available
if ( properIP == null ) {
mySeed.setIP(myIP);
}
} }
mySeed.setFlagRootNode(
(mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL)) &&
responseTime < 1000 && Domains.isThisHostIP(mySeed.getIP()) &&
Switchboard.getSwitchboard().index.fulltext().connectedLocalSolr()
); // RootNode may receive direct Solr queries, set flag only if available
// change our seed-type // change our seed-type
final Accessible accessible = new Accessible(); final Accessible accessible = new Accessible();
if ( mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL) ) { if ( mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL) ) {

@ -582,6 +582,9 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
String ip = getIP(); String ip = getIP();
if (ip == null) ip = Domains.LOCALHOST; // that should not happen if (ip == null) ip = Domains.LOCALHOST; // that should not happen
int p = ip.lastIndexOf(':');
if (p > 0 && (ip.indexOf(':') == p || "]:".equals(ip.substring(p - 1, p + 1)))) return ip; // includes already the port
final String port = this.dna.get(Seed.PORT); final String port = this.dna.get(Seed.PORT);
if ( port == null || port.length() < 2 || port.length() > 5 ) { if ( port == null || port.length() < 2 || port.length() > 5 ) {
return null; return null;
@ -590,9 +593,9 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
final StringBuilder sb = new StringBuilder(ip.length() + port.length() + 3); final StringBuilder sb = new StringBuilder(ip.length() + port.length() + 3);
if (ip.indexOf(':') >= 0) { if (ip.indexOf(':') >= 0) {
// IPv6 Address!, see: http://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_network_resource_identifiers // IPv6 Address!, see: http://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_network_resource_identifiers
sb.append('['); if (!ip.startsWith("[")) sb.append('[');
sb.append(ip); sb.append(ip);
sb.append(']'); if (!ip.endsWith("]")) sb.append(']');
sb.append(':'); sb.append(':');
sb.append(port); sb.append(port);
} else { } else {
@ -1128,7 +1131,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
if ( ipString == null ) { if ( ipString == null ) {
return ipString + " -> IP is null"; return ipString + " -> IP is null";
} }
if ( !ipString.isEmpty() && ipString.length() < 8 ) { if ( ipString.length() < 8 ) {
return ipString + " -> IP is too short: "; return ipString + " -> IP is too short: ";
} }
if ( Switchboard.getSwitchboard().isAllIPMode() ) { if ( Switchboard.getSwitchboard().isAllIPMode() ) {

@ -682,7 +682,7 @@ public final class SeedDB implements AlternativeDomainNames {
// local peer? // local peer?
if (Domains.isThisHostIP(peerIP)) { if (Domains.isThisHostIP(peerIP)) {
if (this.mySeed == null) initMySeed(); if (this.mySeed == null) initMySeed();
return this.mySeed; if (port > 0 && this.mySeed.getPort() == port) return this.mySeed;
} }
// then try to use the cache // then try to use the cache
@ -695,7 +695,7 @@ public final class SeedDB implements AlternativeDomainNames {
for (byte[] pk: idx) { for (byte[] pk: idx) {
seed = this.getConnected(pk); seed = this.getConnected(pk);
if (seed == null) continue; if (seed == null) continue;
if ((port >= 0) && (seed.getPort() != port)) continue; if (port > 0 && seed.getPort() != port) continue;
//System.out.println("*** found lookupByIP in connected: " + peerIP.toString() + " -> " + seed.getName()); //System.out.println("*** found lookupByIP in connected: " + peerIP.toString() + " -> " + seed.getName());
return seed; return seed;
} }
@ -710,7 +710,7 @@ public final class SeedDB implements AlternativeDomainNames {
for (byte[] pk: idx) { for (byte[] pk: idx) {
seed = this.getDisconnected(pk); seed = this.getDisconnected(pk);
if (seed == null) continue; if (seed == null) continue;
if ((port >= 0) && (seed.getPort() != port)) continue; if (port > 0 && seed.getPort() != port) continue;
//System.out.println("*** found lookupByIP in disconnected: " + peerIP.toString() + " -> " + seed.getName()); //System.out.println("*** found lookupByIP in disconnected: " + peerIP.toString() + " -> " + seed.getName());
return seed; return seed;
} }
@ -725,7 +725,7 @@ public final class SeedDB implements AlternativeDomainNames {
for (byte[] pk: idx) { for (byte[] pk: idx) {
seed = this.getPotential(pk); seed = this.getPotential(pk);
if (seed == null) continue; if (seed == null) continue;
if ((port >= 0) && (seed.getPort() != port)) continue; if (port > 0 && seed.getPort() != port) continue;
//System.out.println("*** found lookupByIP in potential: " + peerIP.toString() + " -> " + seed.getName()); //System.out.println("*** found lookupByIP in potential: " + peerIP.toString() + " -> " + seed.getName());
return seed; return seed;
} }
@ -739,7 +739,7 @@ public final class SeedDB implements AlternativeDomainNames {
String s = this.mySeed.getIP(); String s = this.mySeed.getIP();
if (s == null || !ipString.equals(s)) return null; if (s == null || !ipString.equals(s)) return null;
int p = this.mySeed.getPort(); int p = this.mySeed.getPort();
if ((port >= 0) && (p != port)) return null; if (port > 0 && p != port) return null;
//System.out.println("*** found lookupByIP as my seed: " + peerIP.toString() + " -> " + this.mySeed.getName()); //System.out.println("*** found lookupByIP as my seed: " + peerIP.toString() + " -> " + this.mySeed.getName());
return this.mySeed; return this.mySeed;
} }

@ -148,7 +148,7 @@ public class serverSwitch
public String myPublicIP() { public String myPublicIP() {
// if a static IP was configured, we have to return it here ... // if a static IP was configured, we have to return it here ...
final String staticIP = getConfig("staticIP", ""); final String staticIP = getConfig("staticIP", "");
if ( !"".equals(staticIP) ) return staticIP; if ( staticIP.length() > 0 ) return staticIP;
// otherwise we return the real IP address of this host // otherwise we return the real IP address of this host
final InetAddress pLIP = Domains.myPublicLocalIP(); final InetAddress pLIP = Domains.myPublicLocalIP();

Loading…
Cancel
Save