Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
enhancements for staticIP and ipv6 handling
Michael Peter Christend2b8f2b477e7
diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.javaindex edc8821e5..ea9147349 100644--- a/htroot/SettingsAck_p.java+++ b/htroot/SettingsAck_p.java@@ -208,14 +208,17 @@ public class SettingsAck_p {} else if (staticIP.startsWith("https://")) {if (staticIP.length() > 8) { staticIP = staticIP.substring(8); } else { staticIP = ""; }}- if (staticIP.isEmpty()) {- serverCore.useStaticIP = false;- } else {+ String error = Seed.isProperIP(staticIP);+ if (error == null) {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 dataString filter = (post.get("serverfilter")).trim();/*String user = (String) post.get("serveruser");diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex 6a499572a..7dadac23f 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -121,13 +121,18 @@ public final class hello {prop.put("message", "I am I");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())) {- // reject a ping with my name+ // reject a ping with my nameprop.put("message", "You are using my name");return prop;}-+ */if (sb.isRobinsonMode() && !sb.isPublicRobinson()) {// if we are a robinson cluster, answer only if this client is known by our network definitionprop.put("message", "I am robinson, I do not answer");diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.javaindex 69c448ccf..f476a0522 100644--- a/source/net/yacy/cora/protocol/Domains.java+++ b/source/net/yacy/cora/protocol/Domains.java@@ -56,6 +56,7 @@ import net.yacy.cora.storage.ConcurrentARC;import net.yacy.cora.storage.KeyList;import net.yacy.cora.util.CommonPattern;import net.yacy.cora.util.ConcurrentLog;+import net.yacy.kelondro.util.MemoryControl;import com.google.common.net.InetAddresses;import com.google.common.util.concurrent.SimpleTimeLimiter;@@ -705,12 +706,15 @@ public class Domains {if (host0 == null || host0.isEmpty()) return null;final String host = host0.toLowerCase().trim();- /*if (MemoryControl.shortStatus()) {NAME_CACHE_HIT.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 lookupInetAddress ip = NAME_CACHE_HIT.get(host);diff --git a/source/net/yacy/peers/Protocol.java b/source/net/yacy/peers/Protocol.javaindex 2ada4430c..215b56042 100644--- a/source/net/yacy/peers/Protocol.java+++ b/source/net/yacy/peers/Protocol.java@@ -286,13 +286,14 @@ public final class Protocol {} else {final String myIP = result.get("yourip");final String properIP = Seed.isProperIP(myIP);- mySeed.setFlagRootNode((mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL)) && responseTime < 1000 && Domains.isThisHostIP(myIP) &&- Switchboard.getSwitchboard().index.fulltext().connectedLocalSolr()); // RootNode may receive direct Solr queries, set flag only if available- if ( properIP == null ) {- mySeed.setIP(myIP);- }+ 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-typefinal Accessible accessible = new Accessible();if ( mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL) ) {diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.javaindex 68e255ab6..44f43b4f7 100644--- a/source/net/yacy/peers/Seed.java+++ b/source/net/yacy/peers/Seed.java@@ -582,6 +582,9 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>String ip = getIP();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);if ( port == null || port.length() < 2 || port.length() > 5 ) {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);if (ip.indexOf(':') >= 0) {// 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(']');+ if (!ip.endsWith("]")) sb.append(']');sb.append(':');sb.append(port);} else {@@ -1128,7 +1131,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>if ( ipString == null ) {return ipString + " -> IP is null";}- if ( !ipString.isEmpty() && ipString.length() < 8 ) {+ if ( ipString.length() < 8 ) {return ipString + " -> IP is too short: ";}if ( Switchboard.getSwitchboard().isAllIPMode() ) {diff --git a/source/net/yacy/peers/SeedDB.java b/source/net/yacy/peers/SeedDB.javaindex a7554ed1a..a2cf0c785 100644--- a/source/net/yacy/peers/SeedDB.java+++ b/source/net/yacy/peers/SeedDB.java@@ -682,7 +682,7 @@ public final class SeedDB implements AlternativeDomainNames {// local peer?if (Domains.isThisHostIP(peerIP)) {if (this.mySeed == null) initMySeed();- return this.mySeed;+ if (port > 0 && this.mySeed.getPort() == port) return this.mySeed;}// then try to use the cache@@ -695,7 +695,7 @@ public final class SeedDB implements AlternativeDomainNames {for (byte[] pk: idx) {seed = this.getConnected(pk);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());return seed;}@@ -710,7 +710,7 @@ public final class SeedDB implements AlternativeDomainNames {for (byte[] pk: idx) {seed = this.getDisconnected(pk);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());return seed;}@@ -725,7 +725,7 @@ public final class SeedDB implements AlternativeDomainNames {for (byte[] pk: idx) {seed = this.getPotential(pk);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());return seed;}@@ -739,7 +739,7 @@ public final class SeedDB implements AlternativeDomainNames {String s = this.mySeed.getIP();if (s == null || !ipString.equals(s)) return null;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());return this.mySeed;}diff --git a/source/net/yacy/server/serverSwitch.java b/source/net/yacy/server/serverSwitch.javaindex 10ca7e007..56b95d362 100644--- a/source/net/yacy/server/serverSwitch.java+++ b/source/net/yacy/server/serverSwitch.java@@ -148,7 +148,7 @@ public class serverSwitchpublic String myPublicIP() {// if a static IP was configured, we have to return it here ...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 hostfinal InetAddress pLIP = Domains.myPublicLocalIP();