Removed some remaining uses of deprecated Seed.getIP()

pull/137/head
luccioman 7 years ago
parent c35d0568b6
commit addd18c993

@ -85,11 +85,11 @@
<li>Insert the following code:
<pre>
&lt;p&gt;Search with YaCy in this Wiki:&lt;/p&gt;
&lt;script src="http://#[address]#/yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="#[address]#/yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function() {
yconf = {
url : 'http://#[address]#/',
url : '#[address]#/',
theme : 'smoothness',
title : 'YaCy Wiki Search',
urlmaskfilter : '.*',
@ -100,7 +100,7 @@
});
&lt;/script&gt;
&lt;div id="yacylivesearch"&gt;
&lt;form id="ysearch" method="get" accept-charset="UTF-8" action="http://#[address]#/yacysearch.html"&gt;
&lt;form id="ysearch" method="get" accept-charset="UTF-8" action="#[address]#/yacysearch.html"&gt;
&lt;input name="search" id="yquery" type="text" size="15" maxlength="80" value=""/&gt;
&lt;input type="hidden" name="verify" value="false" /&gt;
&lt;input type="hidden" name="maximumRecords" value="10" /&gt;

@ -24,6 +24,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.util.Set;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
@ -32,20 +34,21 @@ import net.yacy.server.serverSwitch;
public class Load_MediawikiWiki {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, @SuppressWarnings("unused") final serverObjects post, final serverSwitch env) {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
// define visible variables
String a;
if (sb.peers.myIPs().isEmpty()) {
a = "localhost:" + sb.getLocalPort();
String myUrl;
final Set<String> myIps = sb.peers.mySeed().getIPs();
if (myIps.isEmpty()) {
myUrl = "http://localhost:" + sb.getLocalPort();
} else {
a = sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP());
myUrl = sb.peers.mySeed().getPublicURL(myIps.iterator().next(), true);
}
prop.put("starturl", "http://");
prop.put("address", a);
prop.put("address", myUrl);
// hidden form param : clean up search events cache ?
if (post != null && post.containsKey("cleanSearchCache")) {

@ -77,11 +77,11 @@
<li>find the line where the default search window is displayed, thats right behind the <pre>&lt;div id="search-box"&gt;</pre> statement</li>
<li>Insert the following code right behind the div tag:
<pre>
&lt;script src="http://#[address]#/yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="#[address]#/yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function() {
yconf = {
url : 'http://#[address]#/',
url : '#[address]#/',
title : 'YaCy Forum Search',
width : 500,
height : 600,
@ -91,7 +91,7 @@
});
&lt;/script&gt;
&lt;div id="yacylivesearch"&gt;
&lt;form id="ysearch" method="get" accept-charset="UTF-8" action="http://#[address]#/yacysearch.html"&gt;
&lt;form id="ysearch" method="get" accept-charset="UTF-8" action="#[address]#/yacysearch.html"&gt;
&lt;input name="search" id="yquery" type="text" size="16" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search" value=""/&gt;
&lt;input type="hidden" name="verify" value="cacheonly" /&gt;
&lt;input type="hidden" name="maximumRecords" value="10" /&gt;

@ -24,6 +24,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.util.Set;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
@ -32,18 +34,22 @@ import net.yacy.server.serverSwitch;
public class Load_PHPBB3 {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, @SuppressWarnings("unused") final serverObjects post, final serverSwitch env) {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
// define visible variables
String a = sb.peers.mySeed().getIP() == null ? null : sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP());
if (a == null) a = "localhost:" + sb.getLocalPort();
String myUrl;
final Set<String> myIps = sb.peers.mySeed().getIPs();
if (myIps.isEmpty()) {
myUrl = "http://localhost:" + sb.getLocalPort();
} else {
myUrl = sb.peers.mySeed().getPublicURL(myIps.iterator().next(), true);
}
final boolean intranet = sb.getConfig(SwitchboardConstants.NETWORK_NAME, "").equals("intranet");
final String repository = "http://" + a + "/";
prop.put("starturl", (intranet) ? repository : "http://");
prop.put("address", a);
prop.put("starturl", (intranet) ? myUrl : "http://");
prop.put("address", myUrl);
// hidden form param : clean up search events cache ?
if (post != null && post.containsKey("cleanSearchCache")) {

@ -374,11 +374,15 @@ public class Network {
}
if (abort) continue;
}
final Set<String> ips = seed.getIPs();
if(ips.isEmpty()) {
continue;
}
prop.put(STR_TABLE_LIST + conCount + "_updatedProfile", 0);
prop.put(STR_TABLE_LIST + conCount + "_updatedWikiPage", 0);
prop.put(STR_TABLE_LIST + conCount + "_updatedBlog", 0);
prop.put(STR_TABLE_LIST + conCount + "_isCrawling", 0);
String ip = seed.getIP();
final String ip = ips.iterator().next();
if (conCount >= maxCount) { break; }
if (sb.peers != null && sb.peers.mySeed() != null && seed.hash != null && seed.hash.equals(sb.peers.mySeed().hash)) {
prop.put(STR_TABLE_LIST + conCount + "_dark", 2);
@ -419,7 +423,7 @@ public class Network {
prop.putHTML(STR_TABLE_LIST + conCount + "_fullname", seed.get(Seed.NAME, "deadlink"));
prop.put(STR_TABLE_LIST + conCount + "_special", (seed.getFlagRootNode() && !seed.getFlagAcceptRemoteIndex()) ? 1 : 0);
prop.put(STR_TABLE_LIST + conCount + "_ssl", (seed.getFlagSSLAvailable()) ? 1 : 0);
prop.put(STR_TABLE_LIST + conCount + "_ssl_ip", seed.getIP());
prop.put(STR_TABLE_LIST + conCount + "_ssl_ip", ip);
prop.put(STR_TABLE_LIST + conCount + "_ssl_portssl", seed.get(Seed.PORTSSL,"8443"));
userAgent = null;
if (seed.hash != null && seed.hash.equals(sb.peers.mySeed().hash)) {
@ -436,9 +440,8 @@ public class Network {
}
prop.putHTML(STR_TABLE_LIST + conCount + "_location", location);
String port = seed.get(Seed.PORT, "-");
Set<String> ips = seed.getIPs();
int ipsc = 0;
for (String s: ips) {
for (final String s: ips) {
prop.put(STR_TABLE_LIST + conCount + "_ips_" + ipsc + "_nodestate", seed.getFlagRootNode() ? 1 : 0);
prop.put(STR_TABLE_LIST + conCount + "_ips_" + ipsc + "_c", c ? 1 : 0);
prop.putHTML(STR_TABLE_LIST + conCount + "_ips_" + ipsc + "_c_hash", seed.hash);

@ -226,12 +226,13 @@ public class Status
prop.put("peerStatistics", "1");
prop.put("peerStatistics_uptime", PeerActions.formatInterval(uptime));
thisHash = sb.peers.mySeed().hash;
if ( sb.peers.mySeed().getIPs().size() == 0 ) {
final Set<String> myIps = sb.peers.mySeed().getIPs();
if ( myIps.size() == 0 ) {
prop.put("peerAddress", "0"); // not assigned + instructions
prop.put("warningGoOnline", "1");
} else {
prop.put("peerAddress", "1"); // Address
prop.put("peerAddress_address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()));
prop.put("peerAddress_address", sb.peers.mySeed().getPublicAddress(myIps.iterator().next()));
prop.putXML("peerAddress_peername", sb.peers.mySeed().getName().toLowerCase());
}
}

@ -29,6 +29,7 @@ import java.net.MalformedURLException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.encoding.UTF8;
@ -278,14 +279,17 @@ public class Surftips {
Seed seed = sb.peers.getConnected(record.originator());
if (seed == null) seed = sb.peers.getDisconnected(record.originator());
if (seed != null) {
url = "http://" + seed.getPublicAddress(seed.getIP()) + "/Wiki.html?page=" + record.attribute("page", "");
entry = rowdef.newEntry(new byte[][]{
UTF8.getBytes(url),
UTF8.getBytes(record.attribute("author", "Anonymous") + ": " + record.attribute("page", "")),
UTF8.getBytes("Wiki Update: " + record.attribute("description", "")),
UTF8.getBytes(record.id())
});
score = 4 + timeFactor(record.created());
final Set<String> ips = seed.getIPs();
if(!ips.isEmpty()) {
url = seed.getPublicURL(ips.iterator().next(), false) + "/Wiki.html?page=" + record.attribute("page", "");
entry = rowdef.newEntry(new byte[][]{
UTF8.getBytes(url),
UTF8.getBytes(record.attribute("author", "Anonymous") + ": " + record.attribute("page", "")),
UTF8.getBytes("Wiki Update: " + record.attribute("description", "")),
UTF8.getBytes(record.id())
});
score = 4 + timeFactor(record.created());
}
}
}
@ -293,14 +297,17 @@ public class Surftips {
Seed seed = sb.peers.getConnected(record.originator());
if (seed == null) seed = sb.peers.getDisconnected(record.originator());
if (seed != null) {
url = "http://" + seed.getPublicAddress(seed.getIP()) + "/Blog.html?page=" + record.attribute("page", "");
entry = rowdef.newEntry(new byte[][]{
UTF8.getBytes(url),
UTF8.getBytes(record.attribute("author", "Anonymous") + ": " + record.attribute("page", "")),
UTF8.getBytes("Blog Entry: " + record.attribute("subject", "")),
UTF8.getBytes(record.id())
});
score = 4 + timeFactor(record.created());
final Set<String> ips = seed.getIPs();
if(!ips.isEmpty()) {
url = seed.getPublicURL(ips.iterator().next(), false) + "/Blog.html?page=" + record.attribute("page", "");
entry = rowdef.newEntry(new byte[][]{
UTF8.getBytes(url),
UTF8.getBytes(record.attribute("author", "Anonymous") + ": " + record.attribute("page", "")),
UTF8.getBytes("Blog Entry: " + record.attribute("subject", "")),
UTF8.getBytes(record.id())
});
score = 4 + timeFactor(record.created());
}
}
}

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Scanner;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.http.servlets.YaCyDefaultServlet;
import net.yacy.search.Switchboard;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
@ -30,9 +31,9 @@ public class ynetSearch {
InputStream is = null;
try {
String searchaddress = post.get("url");
if (!searchaddress.startsWith("http://")) {
if (!searchaddress.startsWith("http://") && !searchaddress.startsWith("https://")) {
// a relative path .. this addresses the local peer
searchaddress = "http://" + sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()) + ((searchaddress.length() > 0 && searchaddress.charAt(0) == '/') ? "" : "/") + searchaddress;
searchaddress = YaCyDefaultServlet.getContext(header, sb) + ((searchaddress.length() > 0 && searchaddress.charAt(0) == '/') ? "" : "/") + searchaddress;
}
post.remove("url");
post.remove("login");

@ -26,6 +26,8 @@
// javac -classpath .:../Classes goto_p.java
// if the shell's current path is HTROOT
import java.util.Set;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.peers.Seed;
import net.yacy.search.Switchboard;
@ -56,11 +58,19 @@ public class goto_p {
Seed seed = sb.peers.getConnected(hash);
if (seed != null) {
String peersUrl = seed.getPublicAddress(seed.getIP());
final Set<String> ips = seed.getIPs();
String peersUrl = null;
if(!ips.isEmpty()) {
peersUrl = seed.getPublicURL(ips.iterator().next(), false);
}
if (peersUrl != null) {
String path = post.get("path", "/");
if (!path.startsWith("/")) path = "/" + path;
prop.put(serverObjects.ACTION_LOCATION, "http://" + peersUrl + path); // redirect command
if (!path.startsWith("/")) {
path = "/" + path;
}
prop.put(serverObjects.ACTION_LOCATION, peersUrl + path); // redirect command
} else {
prop.put("msg", "peer not available");
}
} else {
prop.put("msg", "peer not available");

@ -918,7 +918,13 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
final Seed seed = peers.getConnected(hash);
final String path = this.url().getFile();
String address = null;
if ((seed == null) || ((address = seed.getPublicAddress(seed.getIP())) == null)) {
if(seed != null) {
final Set<String> ips = seed.getIPs();
if(!ips.isEmpty()) {
address = seed.getPublicAddress(ips.iterator().next());
}
}
if (address == null) {
// seed is not known from here
try {
if (indexSegment.termIndex() != null) indexSegment.termIndex().remove(

@ -372,18 +372,24 @@ public class Network
}
i++;
String ip = seed.getIP();
final String address = seed.getPublicAddress(ip);
if ( log.isFine() ) log.fine("HELLO #" + i + " to peer '" + seed.get(Seed.NAME, "") + "' at " + address); // debug
final String seederror = seed.isProper(false);
if ( (address == null) || (seederror != null) ) {
// we don't like that address, delete it
this.sb.peers.peerActions.interfaceDeparture(seed, ip);
final Set<String> ips = seed.getIPs();
if(ips.isEmpty()) {
/* This should not happen : seeds db maintains only seeds with at least one IP */
log.warn("Peer " + seed.getName() + "has no known IP address");
} else {
// starting a new publisher thread
publishThread t = new publishThread(Network.publishThreadGroup, seed);
t.start();
syncList.add(t);
String ip = ips.iterator().next();
final String address = seed.getPublicAddress(ip);
if ( log.isFine() ) log.fine("HELLO #" + i + " to peer '" + seed.getName() + "' at " + address); // debug
final String seederror = seed.isProper(false);
if ( (address == null) || (seederror != null) ) {
// we don't like that address, delete it
this.sb.peers.peerActions.interfaceDeparture(seed, ip);
} else {
// starting a new publisher thread
publishThread t = new publishThread(Network.publishThreadGroup, seed);
t.start();
syncList.add(t);
}
}
}

@ -58,6 +58,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@ -1216,7 +1217,6 @@ public final class Protocol {
Map<String, LinkedHashSet<String>> snippets = new HashMap<String, LinkedHashSet<String>>(); // this will be a list of urlhash-snippet entries
final QueryResponse[] rsp = new QueryResponse[]{null};
final SolrDocumentList[] docList = new SolrDocumentList[]{null};
String ip = target.getIP();
{// encapsulate expensive solr QueryResponse object
if (localsearch && !Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.DEBUG_SEARCH_REMOTE_SOLR_TESTLOCAL, false)) {
// search the local index
@ -1231,12 +1231,21 @@ public final class Protocol {
return -1;
}
} else {
String targetBaseURL = null;
try {
final boolean myseed = target == event.peers.mySeed();
final String targetBaseURL;
if(myseed) {
targetBaseURL = "http://localhost:" + target.getPort();
} else {
final Set<String> ips = target.getIPs();
if(ips.isEmpty()) {
/* This should not happen : seeds db maintains only seeds with at least one IP */
Network.log.info("SEARCH failed (solr), remote Peer: " + target.getName() + " has no known IP address");
target.setFlagSolrAvailable(false);
return -1;
}
final String ip = ips.iterator().next();
targetBaseURL = target.getPublicURL(ip,
Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.REMOTESEARCH_HTTPS_PREFERRED,
SwitchboardConstants.REMOTESEARCH_HTTPS_PREFERRED_DEFAULT));
@ -1279,7 +1288,9 @@ public final class Protocol {
* we must not in that case mark the target as not available but rather transmit the exception to the caller (likely RemoteSearch.solrRemoteSearch) */
throw e;
} catch (final Throwable e) {
Network.log.info("SEARCH failed (solr), remote Peer: " + target.getName() + "/" + target.getPublicAddress(ip) + " (" + e.getMessage() + ")");
if(Network.log.isInfo()) {
Network.log.info("SEARCH failed (solr), remote Peer: " + target.getName() + (targetBaseURL != null ? "/" + targetBaseURL : "") + " (" + e.getMessage() + ")");
}
target.setFlagSolrAvailable(false || localsearch);
return -1;
}
@ -2035,7 +2046,12 @@ public final class Protocol {
final Map<String, ContentBody> parts =
basicRequestParts(Switchboard.getSwitchboard(), target.hash, salt);
parts.put("object", UTF8.StringBody("host"));
final String remoteBaseURL = target.getPublicURL(target.getIP(),
final Set<String> targetIps = target.getIPs();
if(targetIps.isEmpty()) {
Network.log.warn("yacyClient.loadIDXHosts error: no known address on target peer.");
return null;
}
final String remoteBaseURL = target.getPublicURL(targetIps.iterator().next(),
Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.NETWORK_PROTOCOL_HTTPS_PREFERRED,
SwitchboardConstants.NETWORK_PROTOCOL_HTTPS_PREFERRED_DEFAULT));
final Post post = new Post(new MultiProtocolURL(remoteBaseURL), target.hash, "/yacy/idx.json", parts, 30000);

@ -1303,8 +1303,16 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
// check IP
if ( !checkOwnIP ) {
// checking of IP is omitted if we read the own seed file
final String ip = getIP();
if (!isProperIP(ip)) return "not a proper IP " + ip;
final Set<String> ips = getIPs();
if(ips.isEmpty()) {
return "no IP at all";
}
for(final String ip: ips) {
if (!isProperIP(ip)) {
Network.log.severe("not a proper IP " + ip + " peer : " + this.getName() + "ips " + ips);
return "not a proper IP " + ip;
}
}
}
// seedURL

@ -974,7 +974,11 @@ public final class SeedDB implements AlternativeDomainNames {
seed = this.mySeed;
else return null;
}
return seed.getPublicAddress(seed.getIP()) + ((subdom == null) ? "" : ("/" + subdom));
final Set<String> ips = seed.getIPs();
if(ips.isEmpty()) {
return null;
}
return seed.getPublicAddress(ips.iterator().next()) + ((subdom == null) ? "" : ("/" + subdom));
} else if (host.endsWith(".yacy")) {
// identify subdomain
p = host.indexOf('.');
@ -989,9 +993,17 @@ public final class SeedDB implements AlternativeDomainNames {
if (this.mySeed == null) initMySeed();
if (seed == this.mySeed && !(seed.isOnline())) {
// take local ip instead of external
return Switchboard.getSwitchboard().myPublicIP() + ":" + Switchboard.getSwitchboard().getLocalPort() + ((subdom == null) ? "" : ("/" + subdom));
final Set<String> ips = Switchboard.getSwitchboard().myPublicIPs();
if(ips.isEmpty()) {
return null;
}
return ips.iterator().next() + ":" + Switchboard.getSwitchboard().getLocalPort() + ((subdom == null) ? "" : ("/" + subdom));
}
final Set<String> ips = seed.getIPs();
if(ips.isEmpty()) {
return null;
}
return seed.getPublicAddress(seed.getIP()) + ((subdom == null) ? "" : ("/" + subdom));
return seed.getPublicAddress(ips.iterator().next()) + ((subdom == null) ? "" : ("/" + subdom));
} else {
return null;
}

Loading…
Cancel
Save