Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

redesign of remote proxy settings

orbiter3f93a0cc8f4f
diff --git a/htroot/CrawlResults.java b/htroot/CrawlResults.java
index bbe60a8a7..9b340ca0d 100644
--- a/htroot/CrawlResults.java
+++ b/htroot/CrawlResults.java
@@ -197,8 +197,8 @@ public class CrawlResults {
urlstr = metadata.url().toNormalform(false, true);
urltxt = nxTools.shortenURLString(urlstr, 72); // shorten the string text like a URL
}
- initiatorSeed = sb.peers.getConnected(new String(entry.getValue().initiatorHash));
- executorSeed = sb.peers.getConnected(new String(entry.getValue().executorHash));
+ initiatorSeed = entry.getValue() == null ? null : sb.peers.getConnected(new String(entry.getValue().initiatorHash));
+ executorSeed = entry.getValue() == null ? null : sb.peers.getConnected(new String(entry.getValue().executorHash));
prop.put("table_indexed_" + cnt + "_dark", (dark) ? "1" : "0");
prop.put("table_indexed_" + cnt + "_feedbackpage", "CrawlResults.html");
diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.java
index 0c3fe9214..5c1cb1da6 100644
--- a/htroot/SettingsAck_p.java
+++ b/htroot/SettingsAck_p.java
@@ -41,7 +41,6 @@ import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.Formatter;
-import de.anomic.http.client.RemoteProxyConfig;
import de.anomic.http.server.HTTPDemon;
import de.anomic.http.server.HTTPDProxyHandler;
import de.anomic.http.server.RequestHeader;
@@ -323,7 +322,7 @@ public class SettingsAck_p {
/* ====================================================================
* Enabling settings
* ==================================================================== */
- RemoteProxyConfig.init(sb);
+ sb.initRemoteProxy();
prop.put("info", "15"); // The remote-proxy setting has been changed
return prop;
diff --git a/htroot/api/util/getpageinfo_p.java b/htroot/api/util/getpageinfo_p.java
index 580c52cd3..7bd69c4a0 100755
--- a/htroot/api/util/getpageinfo_p.java
+++ b/htroot/api/util/getpageinfo_p.java
@@ -3,6 +3,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Set;
+import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.parser.html.ContentScraper;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.repository.LoaderDispatcher;
@@ -96,8 +97,8 @@ public class getpageinfo_p {
prop.put("robots-allowed", sb.robots.isDisallowed(theURL) ? "0" : "1");
// get the sitemap URL of the domain
- final DigestURI sitemapURL = sb.robots.getSitemapURL(theURL);
- prop.putXML("sitemap", (sitemapURL==null)?"":sitemapURL.toString());
+ final MultiProtocolURI sitemapURL = sb.robots.getSitemapURL(theURL);
+ prop.putXML("sitemap", (sitemapURL==null) ? "" : sitemapURL.toString());
} catch (final MalformedURLException e) {}
}
diff --git a/source/de/anomic/crawler/Balancer.java b/source/de/anomic/crawler/Balancer.java
index 6bf011408..e67b37351 100644
--- a/source/de/anomic/crawler/Balancer.java
+++ b/source/de/anomic/crawler/Balancer.java
@@ -52,7 +52,7 @@ public class Balancer {
private static final int objectIndexBufferSize = 1000;
// class variables
- private final ConcurrentHashMap<String, LinkedList<byte[]>> domainStacks; // a map from domain name part to Lists with url hashs
+ private final ConcurrentHashMap<String, LinkedList<byte[]>> domainStacks; // a map from domain name hash part to Lists with url hashs
private final ConcurrentLinkedQueue<byte[]> top;
private final TreeMap<Long, byte[]> delayed;
private BufferedObjectIndex urlFileIndex;
@@ -433,7 +433,7 @@ public class Balancer {
try {synchronized(this) { this.wait(3000); }} catch (final InterruptedException e) {}
}
}
- Latency.update(new String(crawlEntry.url().hash()).substring(6), crawlEntry.url().getHost());
+ Latency.update(crawlEntry.url());
return crawlEntry;
}
@@ -452,7 +452,7 @@ public class Balancer {
// iterate over the domain stacks
final Iterator<Map.Entry<String, LinkedList<byte[]>>> i = this.domainStacks.entrySet().iterator();
Map.Entry<String, LinkedList<byte[]>> entry;
- long smallestWaiting = Long.MAX_VALUE;
+ //long smallestWaiting = Long.MAX_VALUE;
byte[] besthash = null;
while (i.hasNext()) {
entry = i.next();
@@ -465,6 +465,7 @@ public class Balancer {
byte[] n = entry.getValue().getFirst();
if (n == null) continue;
+ /*
if (delay) {
final long w = Latency.waitingRemainingGuessed(n, minimumLocalDelta, minimumGlobalDelta);
if (w > maximumwaiting) {
@@ -476,6 +477,7 @@ public class Balancer {
}
//System.out.println("*** accepting " + n + " : " + w);
}
+ */
n = entry.getValue().removeFirst();
this.top.add(n);
if (entry.getValue().isEmpty()) i.remove();
diff --git a/source/de/anomic/crawler/Latency.java b/source/de/anomic/crawler/Latency.java
index 9af61d32b..1d4123d2b 100644
--- a/source/de/anomic/crawler/Latency.java
+++ b/source/de/anomic/crawler/Latency.java
@@ -27,55 +27,51 @@ import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import net.yacy.kelondro.data.meta.DigestURI;
+import net.yacy.cora.document.MultiProtocolURI;
import de.anomic.search.Switchboard;
public class Latency {
+ // the map is a mapping from host names to host configurations
private static final ConcurrentHashMap<String, Host> map = new ConcurrentHashMap<String, Host>();
- public static void update(String hosthash, String host, long time) {
- assert hosthash.length() == 6;
- Host h = map.get(hosthash);
+ public static void update(MultiProtocolURI url, long time) {
+ Host h = map.get(url.getHost());
if (h == null) {
- h = new Host(host, time);
- map.put(hosthash, h);
+ h = new Host(url.getHost(), time);
+ map.put(url.getHost(), h);
} else {
h.update(time);
}
}
- public static void update(String hosthash, String host) {
- assert hosthash.length() == 6;
- Host h = map.get(hosthash);
+ public static void update(MultiProtocolURI url) {
+ Host h = map.get(url.getHost());
if (h == null) {
- h = new Host(host, 3000);
- map.put(hosthash, h);
+ h = new Host(url.getHost(), 3000);
+ map.put(url.getHost(), h);
} else {
h.update();
}
}
- public static void slowdown(String hosthash, String host) {
- assert hosthash.length() == 6;
- Host h = map.get(hosthash);
+ public static void slowdown(MultiProtocolURI url) {
+ Host h = map.get(url.getHost());
if (h == null) {
- h = new Host(host, 3000);
- map.put(hosthash, h);
+ h = new Host(url.getHost(), 3000);
+ map.put(url.getHost(), h);
} else {
h.slowdown();
}
}
- public static Host host(String hosthash) {
- assert hosthash.length() == 6;
- return map.get(hosthash);
+ public static Host host(MultiProtocolURI url) {
+ return map.get(url.getHost());
}
- public static int average(String hosthash) {
- assert hosthash.length() == 6;
- Host h = map.get(hosthash);
+ public static int average(MultiProtocolURI url) {
+ Host h = map.get(url.getHost());
if (h == null) return 1000;
return h.average();
}
@@ -90,9 +86,8 @@ public class Latency {
* @param urlhash
* @return a time in milliseconds since last access of the domain or Long.MAX_VALUE if the domain was not accessed before
*/
- public static long lastAccessDelta(final String urlhash) {
- assert urlhash.length() == 12 || urlhash.length() == 6;
- final Latency.Host host = Latency.host((urlhash.length() == 6) ? urlhash : urlhash.substring(6));
+ public static long lastAccessDelta(MultiProtocolURI url) {
+ final Latency.Host host = Latency.host(url);
if (host == null) return Long.MAX_VALUE; // never accessed
return System.currentTimeMillis() - host.lastacc();
}
@@ -109,16 +104,15 @@ public class Latency {
* @return the remaining waiting time in milliseconds. The return value may be negative
* which expresses how long the time is over the minimum waiting time.
*/
- public static long waitingRemainingGuessed(byte[] hosthash, final long minimumLocalDelta, final long minimumGlobalDelta) {
- assert hosthash.length == 12 || hosthash.length == 6;
- Host host = Latency.host((hosthash.length == 6) ? new String(hosthash) : new String(hosthash).substring(6));
+ public static long waitingRemainingGuessed(String hostname, final long minimumLocalDelta, final long minimumGlobalDelta) {
+ Host host = map.get(hostname);
if (host == null) return Long.MIN_VALUE;
// the time since last access to the domain is the basis of the remaining calculation
final long timeSinceLastAccess = System.currentTimeMillis() - host.lastacc();
// find the minimum waiting time based on the network domain (local or global)
- final boolean local = DigestURI.isLocal(hosthash);
+ final boolean local = MultiProtocolURI.isLocal(hostname);
long waiting = (local) ? minimumLocalDelta : minimumGlobalDelta;
// if we have accessed the domain many times, get slower (the flux factor)
@@ -149,11 +143,10 @@ public class Latency {
* @param minimumGlobalDelta
* @return the remaining waiting time in milliseconds
*/
- public static long waitingRemaining(DigestURI url, final long minimumLocalDelta, final long minimumGlobalDelta) {
+ public static long waitingRemaining(MultiProtocolURI url, final long minimumLocalDelta, final long minimumGlobalDelta) {
// first check if the domain was _ever_ accessed before
- String hosthash = new String(url.hash()).substring(6);
- Host host = host(hosthash);
+ Host host = host(url);
if (host == null) return Long.MIN_VALUE; // no delay if host is new
// find the minimum waiting time based on the network domain (local or global)
@@ -190,12 +183,11 @@ public class Latency {
}
- public static String waitingRemainingExplain(DigestURI url, final long minimumLocalDelta, final long minimumGlobalDelta) {
+ public static String waitingRemainingExplain(MultiProtocolURI url, final long minimumLocalDelta, final long minimumGlobalDelta) {
// first check if the domain was _ever_ accessed before
- String hosthash = new String(url.hash()).substring(6);
- Host host = host(hosthash);
- if (host == null) return "host " + hosthash + "/" + url.getHost() + " never accessed before -> 0"; // no delay if host is new
+ Host host = host(url);
+ if (host == null) return "host " + url.getHost() + " never accessed before -> 0"; // no delay if host is new
StringBuilder s = new StringBuilder(50);
diff --git a/source/de/anomic/crawler/RobotsEntry.java b/source/de/anomic/crawler/RobotsEntry.java
index b4291afa9..cfec8c15b 100644
--- a/source/de/anomic/crawler/RobotsEntry.java
+++ b/source/de/anomic/crawler/RobotsEntry.java
@@ -35,7 +35,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import net.yacy.kelondro.data.meta.DigestURI;
+import net.yacy.cora.document.MultiProtocolURI;
+
public class RobotsEntry {
@@ -86,7 +87,7 @@ public class RobotsEntry {
}
public RobotsEntry(
- final DigestURI theURL,
+ final MultiProtocolURI theURL,
final List<String> allowPathList,
final List<String> disallowPathList,
final Date loadedDate,
diff --git a/source/de/anomic/crawler/RobotsTxt.java b/source/de/anomic/crawler/RobotsTxt.java
index c6569a9f8..cefac4f5a 100644
--- a/source/de/anomic/crawler/RobotsTxt.java
+++ b/source/de/anomic/crawler/RobotsTxt.java
@@ -37,7 +37,6 @@ import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.kelondro.blob.BEncodedHeap;
-import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.ByteBuffer;
import net.yacy.kelondro.util.DateFormatter;
@@ -79,7 +78,7 @@ public class RobotsTxt {
return this.robotsTable.size();
}
- private RobotsEntry getEntry(final DigestURI theURL, final boolean fetchOnlineIfNotAvailableOrNotFresh) throws IOException {
+ private RobotsEntry getEntry(final MultiProtocolURI theURL, final boolean fetchOnlineIfNotAvailableOrNotFresh) throws IOException {
// this method will always return a non-null value
String urlHostPort = getHostPort(theURL);
RobotsEntry robotsTxt4Host = null;
@@ -115,9 +114,9 @@ public class RobotsTxt {
}
// generating the proper url to download the robots txt
- DigestURI robotsURL = null;
+ MultiProtocolURI robotsURL = null;
try {
- robotsURL = new DigestURI("http://" + urlHostPort + "/robots.txt", null);
+ robotsURL = new MultiProtocolURI("http://" + urlHostPort + "/robots.txt");
} catch (final MalformedURLException e) {
log.logSevere("Unable to generate robots.txt URL for host:port '" + urlHostPort + "'.");
robotsURL = null;
@@ -191,7 +190,7 @@ public class RobotsTxt {
}
private RobotsEntry addEntry(
- final DigestURI theURL,
+ final MultiProtocolURI theURL,
final ArrayList<String> allowPathList,
final ArrayList<String> denyPathList,
final Date loadedDate,
@@ -226,7 +225,7 @@ public class RobotsTxt {
public static final int DOWNLOAD_ETAG = 2;
public static final int DOWNLOAD_MODDATE = 3;
- static final String getHostPort(final DigestURI theURL) {
+ static final String getHostPort(final MultiProtocolURI theURL) {
String urlHostPort = null;
final int port = getPort(theURL);
urlHostPort = theURL.getHost() + ":" + port;
@@ -235,7 +234,7 @@ public class RobotsTxt {
return urlHostPort;
}
- private static final int getPort(final DigestURI theURL) {
+ private static final int getPort(final MultiProtocolURI theURL) {
int port = theURL.getPort();
if (port == -1) {
if (theURL.getProtocol().equalsIgnoreCase("http")) {
@@ -248,10 +247,10 @@ public class RobotsTxt {
return port;
}
- public DigestURI getSitemapURL(final DigestURI theURL) {
+ public MultiProtocolURI getSitemapURL(final MultiProtocolURI theURL) {
if (theURL == null) throw new IllegalArgumentException();
if (!theURL.getProtocol().startsWith("http")) return null;
- DigestURI sitemapURL = null;
+ MultiProtocolURI sitemapURL = null;
// generating the hostname:poart string needed to do a DB lookup
RobotsEntry robotsTxt4Host;
@@ -263,13 +262,13 @@ public class RobotsTxt {
try {
final String sitemapUrlStr = robotsTxt4Host.getSitemap();
- if (sitemapUrlStr != null) sitemapURL = new DigestURI(sitemapUrlStr, null);
+ if (sitemapUrlStr != null) sitemapURL = new MultiProtocolURI(sitemapUrlStr);
} catch (final MalformedURLException e) {/* ignore this */}
return sitemapURL;
}
- public long getCrawlDelayMillis(final DigestURI theURL) {
+ public long getCrawlDelayMillis(final MultiProtocolURI theURL) {
if (theURL == null) throw new IllegalArgumentException();
if (!theURL.getProtocol().startsWith("http")) return 0;
@@ -283,7 +282,7 @@ public class RobotsTxt {
return robotsEntry.getCrawlDelayMillis();
}
- public boolean isDisallowed(final DigestURI nexturl) {
+ public boolean isDisallowed(final MultiProtocolURI nexturl) {
if (nexturl == null) throw new IllegalArgumentException();
if (!nexturl.getProtocol().startsWith("http")) return false;
@@ -298,7 +297,7 @@ public class RobotsTxt {
return robotsTxt4Host.isDisallowed(nexturl.getFile());
}
- private static Object[] downloadRobotsTxt(final DigestURI robotsURL, int redirectionCount, final RobotsEntry entry) throws Exception {
+ private static Object[] downloadRobotsTxt(final MultiProtocolURI robotsURL, int redirectionCount, final RobotsEntry entry) throws Exception {
if (robotsURL == null || !robotsURL.getProtocol().startsWith("http")) return null;
if (redirectionCount < 0) return new Object[]{Boolean.FALSE,null,null};
@@ -381,7 +380,7 @@ public class RobotsTxt {
redirectionUrlString = redirectionUrlString.trim();
// generating the new URL object
- final DigestURI redirectionUrl = new DigestURI(MultiProtocolURI.newURL(robotsURL, redirectionUrlString));
+ final MultiProtocolURI redirectionUrl = MultiProtocolURI.newURL(robotsURL, redirectionUrlString);
// following the redirection
if (log.isFinest()) log.logFinest("Redirection detected for robots.txt with URL '" + robotsURL + "'." +
diff --git a/source/de/anomic/crawler/retrieval/FTPLoader.java b/source/de/anomic/crawler/retrieval/FTPLoader.java
index 4c9967b9d..58a496d8a 100644
--- a/source/de/anomic/crawler/retrieval/FTPLoader.java
+++ b/source/de/anomic/crawler/retrieval/FTPLoader.java
@@ -155,7 +155,7 @@ public class FTPLoader {
throw new IOException("FTPLoader: Unable to download URL " + request.url().toString() + detail);
}
- Latency.update(new String(request.url().hash()).substring(6), request.url().getHost(), System.currentTimeMillis() - start);
+ Latency.update(request.url(), System.currentTimeMillis() - start);
return response;
}
diff --git a/source/de/anomic/crawler/retrieval/HTTPLoader.java b/source/de/anomic/crawler/retrieval/HTTPLoader.java
index bbb3f41c6..5d2917e0e 100644
--- a/source/de/anomic/crawler/retrieval/HTTPLoader.java
+++ b/source/de/anomic/crawler/retrieval/HTTPLoader.java
@@ -78,7 +78,7 @@ public final class HTTPLoader {
public Response load(final Request entry, final boolean acceptOnlyParseable, long maxFileSize) throws IOException {
long start = System.currentTimeMillis();
Response doc = load(entry, acceptOnlyParseable, DEFAULT_CRAWLING_RETRY_COUNT, maxFileSize);
- Latency.update(new String(entry.url().hash()).substring(6), entry.url().getHost(), System.currentTimeMillis() - start);
+ Latency.update(entry.url(), System.currentTimeMillis() - start);
return doc;
}
diff --git a/source/de/anomic/http/client/Client.java b/source/de/anomic/http/client/Client.java
index 303e200c6..cdb07b844 100644
--- a/source/de/anomic/http/client/Client.java
+++ b/source/de/anomic/http/client/Client.java
@@ -30,13 +30,12 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPOutputStream;
-import net.yacy.kelondro.data.meta.DigestURI;
-import net.yacy.kelondro.logging.Log;
+import net.yacy.cora.document.MultiProtocolURI;
+import net.yacy.cora.protocol.ProxySettings;
import net.yacy.kelondro.order.Base64Order;
import org.apache.commons.httpclient.ConnectMethod;
@@ -165,8 +164,6 @@ public class Client {
private static long lastCleanup = 0;
private Header[] headers = new Header[0];
- private RemoteProxyConfig proxyConfig = null;
- private boolean useGlobalProxyConfig = true;
private boolean followRedirects = true;
//private boolean ignoreCookies = true;
@@ -191,33 +188,6 @@ public class Client {
setHeader(header);
}
- /**
- * creates a new JakartaCommonsHttpClient with given timeout and requestHeader using given remoteProxyConfig
- *
- * if proxyConfig is null, then no proxy is used
- *
- * @param timeout in milliseconds
- * @param header header options to send
- * @param proxyConfig
- */
- public Client(final int timeout, final RequestHeader header, final RemoteProxyConfig proxyConfig) {
- super();
- setTimeout(timeout);
- setHeader(header);
- setProxy(proxyConfig);
- }
-
- /*
- * (non-Javadoc)
- * @see de.anomic.http.HttpClient#setProxy(de.anomic.http.httpRemoteProxyConfig)
- */
- public void setProxy(final RemoteProxyConfig proxyConfig) {
- if (proxyConfig != null) {
- this.useGlobalProxyConfig = false;
- this.proxyConfig = proxyConfig;
- }
- }
-
/*
* (non-Javadoc)
* @see de.anomic.http.HttpClient#setHeader(de.anomic.http.httpHeader)
@@ -457,16 +427,13 @@ public class Client {
assert method != null : "precondition violated: method != null";
setHeader(method);
- final RemoteProxyConfig hostProxyConfig = setProxy(method);
- final HostConfiguration hostConfig = getProxyHostConfig(hostProxyConfig);
+ setProxy(method);
+ final HostConfiguration hostConfig = ProxySettings.getProxyHostConfig(apacheHttpClient);
// statistics
ConnectionInfo.addConnection(generateConInfo(method));
// execute (send request)
- if (Log.isFine("HTTPC")) Log.logFine("HTTPC", "executing " + method.hashCode() + " " + method.getName() + " " + method.getURI());
- if (Log.isFinest("HTTPC")) Log.logFinest("HTTPC", "->" + method.hashCode() + " request headers " +
- Arrays.toString(method.getRequestHeaders()));
try {
if (hostConfig == null) {
apacheHttpClient.executeMethod(method);
@@ -475,28 +442,26 @@ public class Client {
}
} catch (final IllegalThreadStateException e) {
// cleanUp statistics
- DigestURI url = new DigestURI(method.getURI().toString(), null);
- if (url.hash() != null) Latency.slowdown(new String(url.hash()).substring(6), url.getHost());
+ MultiProtocolURI url = new MultiProtocolURI(method.getURI().toString());
+ Latency.slowdown(url);
ConnectionInfo.removeConnection(generateConInfo(method));
throw new IOException(e.getMessage());
} catch (final IOException e) {
// cleanUp statistics
- DigestURI url = new DigestURI(method.getURI().toString(), null);
- if (url.hash() != null) Latency.slowdown(new String(url.hash()).substring(6), url.getHost());
+ MultiProtocolURI url = new MultiProtocolURI(method.getURI().toString());
+ Latency.slowdown(url);
ConnectionInfo.removeConnection(generateConInfo(method));
throw e;
} catch (final IllegalStateException e) {
// cleanUp statistics
- DigestURI url = new DigestURI(method.getURI().toString(), null);
- if (url.hash() != null) Latency.slowdown(new String(url.hash()).substring(6), url.getHost());
+ MultiProtocolURI url = new MultiProtocolURI(method.getURI().toString());
+ Latency.slowdown(url);
ConnectionInfo.removeConnection(generateConInfo(method));
throw new IOException(e.getMessage());
} finally {
// cleanUp statistics
ConnectionInfo.removeConnection(generateConInfo(method));
}
- if (Log.isFinest("HTTPC")) Log.logFinest("HTTPC", "<-" + method.hashCode() + " response headers " +
- Arrays.toString(method.getResponseHeaders()));
// return response
return new ResponseContainer(method);
@@ -507,25 +472,18 @@ public class Client {
* @return
* @throws URIException
*/
- private RemoteProxyConfig setProxy(final HttpMethod method) throws URIException {
+ private void setProxy(final HttpMethod method) throws URIException {
String host = null;
// set proxy
- try {
- host = method.getURI().getHost();
- } catch (final URIException e) {
- Log.logWarning("HTTPC", "could not extract host of uri: "+ e.getMessage());
- throw e;
- }
- final RemoteProxyConfig hostProxyConfig = getProxyConfig(host);
- if(hostProxyConfig != null) {
+ host = method.getURI().getHost();
+ if (ProxySettings.useForHost(host)) {
final String scheme = method.getURI().getScheme();
- if(scheme != null && scheme.toLowerCase().startsWith("https") && !hostProxyConfig.useProxy4SSL()) {
+ if(scheme != null && scheme.toLowerCase().startsWith("https") && !ProxySettings.use4ssl) {
// do not use proxy for HTTPS
- return null;
+ return;
}
- addProxyAuth(method, hostProxyConfig);
+ addProxyAuth(method);
}
- return hostProxyConfig;
}
/**
@@ -564,59 +522,18 @@ public class Client {
* @param method
* @param hostProxyConfig
*/
- private void addProxyAuth(final HttpMethod method, final RemoteProxyConfig hostProxyConfig) {
- if (hostProxyConfig != null && hostProxyConfig.useProxy()) {
- final String remoteProxyUser = hostProxyConfig.getProxyUser();
+ private void addProxyAuth(final HttpMethod method) {
+ if (ProxySettings.use) {
+ final String remoteProxyUser = ProxySettings.user;
if (remoteProxyUser != null && remoteProxyUser.length() > 0) {
- if (remoteProxyUser.contains(":")) {
- Log.logWarning("HTTPC", "Proxy authentication contains invalid characters, trying anyway");
- }
- final String remoteProxyPwd = hostProxyConfig.getProxyPwd();
- final String credentials = Base64Order.standardCoder.encodeString(
- remoteProxyUser.replace(":", "") + ":" + remoteProxyPwd);
+ assert !remoteProxyUser.contains(":"): "Proxy authentication contains invalid characters: " + remoteProxyUser;
+ final String remoteProxyPwd = ProxySettings.password;
+ final String credentials = Base64Order.standardCoder.encodeString(remoteProxyUser.replace(":", "") + ":" + remoteProxyPwd);
method.setRequestHeader(RequestHeader.PROXY_AUTHORIZATION, "Basic " + credentials);
}
}
}
- /**
- *
- * @param hostname
- * @return null if no proxy should be used
- */
- private RemoteProxyConfig getProxyConfig(final String hostname) {
- final RemoteProxyConfig hostProxyConfig;
- if (useGlobalProxyConfig) {
- // default settings
- hostProxyConfig = RemoteProxyConfig.getProxyConfigForHost(hostname);
- } else {
- // client specific
- if (proxyConfig == null) {
- hostProxyConfig = null;
- } else {
- hostProxyConfig = proxyConfig.useForHost(hostname) ? proxyConfig : null;
- }
- }
- return hostProxyConfig;
- }
-
- /**
- * @param hostProxyConfig
- * @return current host-config with additional proxy set or null if no proxy should be used
- */
- private HostConfiguration getProxyHostConfig(final RemoteProxyConfig hostProxyConfig) {
- final HostConfiguration hostConfig;
- // generate http-configuration
- if (hostProxyConfig != null && hostProxyConfig.useProxy()) {
- // new config based on client (default)
- hostConfig = new HostConfiguration(apacheHttpClient.getHostConfiguration());
- // add proxy
- hostConfig.setProxy(hostProxyConfig.getProxyHost(), hostProxyConfig.getProxyPort());
- } else {
- hostConfig = null;
- }
- return hostConfig;
- }
/**
* close all connections
@@ -673,7 +590,7 @@ public class Client {
System.out.println(new String(wget(url, null, 10000)));
}
} catch (final IOException e) {
- Log.logException(e);
+ e.printStackTrace();
} finally {
if (resp != null) {
// release connection
@@ -758,34 +675,26 @@ public class Client {
* @param vhost
* @param timeout in milliseconds
* @return
+ * @throws IOException
*/
- public static byte[] wget(final String uri) {
+ public static byte[] wget(final String uri) throws IOException {
return wget(uri, new RequestHeader(), 10000, null);
}
- public static byte[] wget(final String uri, final RequestHeader header, final int timeout) {
+ public static byte[] wget(final String uri, final RequestHeader header, final int timeout) throws IOException {
return wget(uri, header, timeout, null);
}
- public static byte[] wget(final String uri, final RequestHeader header, final int timeout, final String vhost) {
+ public static byte[] wget(final String uri, final RequestHeader header, final int timeout, final String vhost) throws IOException {
assert uri != null : "precondition violated: uri != null";
addHostHeader(header, vhost);
final Client client = new Client(timeout, header);
// do the request
- ResponseContainer response = null;
- try {
- response = client.GET(uri);
- return response.getData();
- } catch (final IOException e) {
- Log.logWarning("HTTPC", "wget(" + uri + ") failed: " + e.getMessage());
- } finally {
- // release connection
- if (response != null) {
- response.closeStream();
- }
- }
- return null;
+ ResponseContainer response = client.GET(uri);
+ byte[] data = response.getData();
+ response.closeStream();
+ return data;
}
/**
@@ -810,8 +719,9 @@ public class Client {
*
* @param uri
* @return
+ * @throws IOException
*/
- public static ResponseHeader whead(final String uri) {
+ public static ResponseHeader whead(final String uri) throws IOException {
return whead(uri, null);
}
@@ -822,19 +732,11 @@ public class Client {
* @param header request header
* @return null on error
*/
- public static ResponseHeader whead(final String uri, final RequestHeader header) {
+ public static ResponseHeader whead(final String uri, final RequestHeader header) throws IOException {
final Client client = new Client(10000, header);
- ResponseContainer response = null;
- try {
- response = client.HEAD(uri);
- return response.getResponseHeader();
- } catch (final IOException e) {
- Log.logWarning("HTTPC", "whead(" + uri + ") failed: " + e.getMessage());
- return null;
- } finally {
- if (response != null) {
- response.closeStream();
- }
- }
+ ResponseContainer response = client.HEAD(uri);
+ ResponseHeader rh = response.getResponseHeader();
+ response.closeStream();
+ return rh;
}
}
\ No newline at end of file
diff --git a/source/de/anomic/http/client/RemoteProxyConfig.java b/source/de/anomic/http/client/RemoteProxyConfig.java
deleted file mode 100644
index 888f4f72b..000000000
--- a/source/de/anomic/http/client/RemoteProxyConfig.java
+++ /dev/null
@@ -1,317 +0,0 @@
-//httpRemoteProxyConfig.java
-//-----------------------
-//part of the AnomicHTTPD caching proxy
-//(C) by Michael Peter Christen; [email protected]
-//first published on http://www.anomic.de
-//Frankfurt, Germany, 2004
-//
-//this file was contributed by Martin Thelian
-//$LastChangedDate$
-//$LastChangedBy$
-//$LastChangedRevision$
-//
-//This program is free software; you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation; either version 2 of the License, or
-//(at your option) any later version.
-//
-//This program is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-//GNU General Public License for more details.
-//
-//You should have received a copy of the GNU General Public License
-//along with this program; if not, write to the Free Software
-//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-//You must compile this file with
-//javac -classpath .:../Classes Settings_p.java
-//if the shell's current path is HTROOT
-
-package de.anomic.http.client;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import de.anomic.search.Switchboard;
-
-public final class RemoteProxyConfig {
-
- /*
- * Remote Proxy configuration
- */
- private boolean remoteProxyUse;
- private boolean remoteProxyUse4Yacy;
- private boolean remoteProxyUse4SSL;
-
- private String remoteProxyHost;
- private int remoteProxyPort;
- private String remoteProxyUser;
- private String remoteProxyPwd;
-
- private String[] remoteProxyNoProxyPatterns = null;
-
- private final Set<String> remoteProxyAllowProxySet = new HashSet<String>();
- private final Set<String> remoteProxyDisallowProxySet = new HashSet<String>();
-
- /**
- * *The* remote Proxy configuration
- */
- private static RemoteProxyConfig remoteProxyConfig = null;
-
- /**
- * @param remoteProxyConfig the remoteProxyConfig to set
- */
- public static synchronized void setRemoteProxyConfig(final RemoteProxyConfig newConfig) {
- remoteProxyConfig = newConfig;
- }
-
- /**
- * @return the remoteProxyConfig
- */
- public static synchronized RemoteProxyConfig getRemoteProxyConfig() {
- return remoteProxyConfig;
- }
-
- /**
- * creates a new remoteProxyConfig for given proxy
- *
- * @param proxyHostName
- * @param proxyHostPort
- * @return
- */
- public static RemoteProxyConfig createRemoteProxyConfig(
- final String proxyHostName,
- final int proxyHostPort
- ) {
- final RemoteProxyConfig newConfig = new RemoteProxyConfig();
-
- newConfig.remoteProxyUse = true;
- newConfig.remoteProxyUse4SSL = true;
- newConfig.remoteProxyUse4Yacy = true;
- newConfig.remoteProxyPort = proxyHostPort;
- newConfig.remoteProxyHost = proxyHostName;
- if ((newConfig.remoteProxyHost == null) || (newConfig.remoteProxyHost.length() == 0)) {
- newConfig.remoteProxyUse = false;
- }
-
- return newConfig;
- }
-
- /**
- * initializes the global remoteProxyConfig with values from plasmaSwitchboard (config)
- *
- * @param sb
- * @return
- */
- public static void init(final Switchboard sb) {
- // reading the proxy host name
- final String proxyHostName = sb.getConfig("remoteProxyHost", "").trim();
- // reading the proxy host port
- int proxyHostPort;
- try {
- proxyHostPort = Integer.parseInt(sb.getConfig("remoteProxyPort", "3128"));
- } catch (final NumberFormatException e) {
- proxyHostPort = 3128;
- }
- // create new config
- final RemoteProxyConfig newConfig = createRemoteProxyConfig(proxyHostName, proxyHostPort);
-
- // determining if remote proxy usage is enabled
- newConfig.remoteProxyUse = newConfig.remoteProxyUse && sb.getConfigBool("remoteProxyUse", false);
-
- // determining if remote proxy should be used for yacy -> yacy communication
- newConfig.remoteProxyUse4Yacy = sb.getConfig("remoteProxyUse4Yacy", "true").equalsIgnoreCase("true");
-
- // determining if remote proxy should be used for ssl connections
- newConfig.remoteProxyUse4SSL = sb.getConfig("remoteProxyUse4SSL", "true").equalsIgnoreCase("true");
-
- newConfig.remoteProxyUser = sb.getConfig("remoteProxyUser", "").trim();
- newConfig.remoteProxyPwd = sb.getConfig("remoteProxyPwd", "").trim();
-
- // determining addresses for which the remote proxy should not be used
- final String remoteProxyNoProxy = sb.getConfig("remoteProxyNoProxy","").trim();
- newConfig.remoteProxyNoProxyPatterns = remoteProxyNoProxy.split(",");
- // trim split entries
- int i = 0;
- for(final String pattern: newConfig.remoteProxyNoProxyPatterns) {
- newConfig.remoteProxyNoProxyPatterns[i] = pattern.trim();
- i++;
- }
-
- setRemoteProxyConfig(newConfig);
- sb.getLog().logConfig("Remote proxy configuration:\n" + getRemoteProxyConfig().toString());
- }
-
- public boolean useProxy() {
- return this.remoteProxyUse;
- }
-
- public boolean useProxy4Yacy() {
- return this.remoteProxyUse4Yacy;
- }
-
- public boolean useProxy4SSL() {
- return this.remoteProxyUse4SSL;
- }
-
- public String getProxyHost() {
- return this.remoteProxyHost;
- }
-
- public int getProxyPort() {
- return this.remoteProxyPort;
- }
-
- public String getProxyUser() {
- return this.remoteProxyUser;
- }
-
- public String getProxyPwd() {
- return this.remoteProxyPwd;
- }
-
- /**
- * checks if server matches the noProxyPattern and caches result as (Dis-)AllowedHost
- *
- * @param server
- * @return
- */
- public boolean matchesProxyNoProxyPatterns(final String server) {
- boolean noProxy = false;
- for (final String pattern :remoteProxyNoProxyPatterns) {
- if (server.matches(pattern)) {
- noProxy = true;
- break;
- }
- }
- // set either remoteProxyAllowProxySet or remoteProxyDisallowProxySet accordingly
- if(noProxy) {
- addDisallowedHost(server);
- } else {
- addAllowedHost(server);
- }
- return noProxy;
- }
-
- public String toString() {
- final StringBuilder toStrBuf = new StringBuilder(50);
-
- toStrBuf
- .append("Status: ").append(this.remoteProxyUse?"ON":"OFF").append(" | ")
- .append("Host: ");
- if ((this.remoteProxyUser != null) && (this.remoteProxyUser.length() > 0)) {
- toStrBuf.append(this.remoteProxyUser)
- .append("@");
- }
- toStrBuf
- .append((this.remoteProxyHost==null)?"unknown":this.remoteProxyHost).append(":").append(this.remoteProxyPort).append(" | ")
- .append("Usage: HTTP");
- if (this.remoteProxyUse4Yacy) toStrBuf.append(" YACY");
- if (this.remoteProxyUse4SSL) toStrBuf.append(" SSL");
- toStrBuf.append(" | ")
- .append("No Proxy for: ")
- .append(Arrays.toString(this.remoteProxyNoProxyPatterns));
-
-
- return toStrBuf.toString();
- }
-
- /**
- * @param host
- * @return
- */
- public boolean isHostAllowedToUseProxy(final String host) {
- return remoteProxyAllowProxySet.contains(host);
- }
-
- /**
- * @param host
- * @return
- */
- public boolean isHostNotAllowedToUseProxy(final String host) {
- return remoteProxyDisallowProxySet.contains(host);
- }
-
- /**
- * @param host
- */
- public void addAllowedHost(final String host) {
- remoteProxyAllowProxySet.add(host);
- }
-
- /**
- * @param host
- */
- public void addDisallowedHost(final String host) {
- remoteProxyDisallowProxySet.add(host);
- }
-
- /**
- * checks if proxy-config is allowed and not denied
- *
- * @param server
- * @param remProxyConfig
- * @return proxy which should be used or null if no proxy should be used for server
- */
- public boolean useForHost(final String server) {
- // possible remote proxy
- // check no-proxy rule
- boolean useProxy;
- if (useProxy()) {
- useProxy = true;
- if (!isHostAllowedToUseProxy(server)) {
- if (isHostNotAllowedToUseProxy(server)) {
- useProxy = false;
- } else {
- // analyse remoteProxyNoProxy;
- if(matchesProxyNoProxyPatterns(server)) {
- useProxy = false;
- }
- }
- }
- } else {
- // not enabled
- useProxy = false;
- }
-
- return useProxy;
- }
-
- /**
- * checks if proxy-config exists for server (is allowed and not denied)
- *
- * @param server
- * @return proxy which should be used or null if no proxy should be used
- */
- public static RemoteProxyConfig getProxyConfigForHost(final String server) {
- final RemoteProxyConfig proxyConfig = getRemoteProxyConfig();
- if(proxyConfig == null || !proxyConfig.useForHost(server)) {
- return null;
- }
- return proxyConfig;
- }
-
- /**
- * gets proxy config for full adress (without protocol) ie. "localhost:8080/path/file.html"
- *
- * @param address full address with host and optionally port or path <host>:<port>/<path>
- * @return null if no proxy should be used
- */
- public static RemoteProxyConfig getProxyConfigForURI(final String address) {
- // host goes to port
- int p = address.indexOf(":");
- if (p < 0) {
- // no port, so host goes to path
- p = address.indexOf("/");
- }
- // host should have minimum 1 character ;)
- if(p > 0) {
- final String server = address.substring(0, p);
- return getProxyConfigForHost(server);
- }
- // check if full address is in allow/deny-list
- return getProxyConfigForHost(address);
- }
-}
diff --git a/source/de/anomic/http/server/HTTPDProxyHandler.java b/source/de/anomic/http/server/HTTPDProxyHandler.java
index ee4549c03..ddae705a0 100644
--- a/source/de/anomic/http/server/HTTPDProxyHandler.java
+++ b/source/de/anomic/http/server/HTTPDProxyHandler.java
@@ -71,6 +71,7 @@ import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;
+import net.yacy.cora.protocol.ProxySettings;
import net.yacy.document.TextParser;
import net.yacy.document.parser.html.ContentTransformer;
import net.yacy.document.parser.html.Transformer;
@@ -87,7 +88,6 @@ import de.anomic.crawler.retrieval.Request;
import de.anomic.crawler.retrieval.Response;
import de.anomic.http.client.MultiOutputStream;
import de.anomic.http.client.Client;
-import de.anomic.http.client.RemoteProxyConfig;
import de.anomic.http.client.Cache;
import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
@@ -1071,8 +1071,6 @@ public final class HTTPDProxyHandler {
// setup HTTP-client
final Client client = new Client(timeout, requestHeader);
client.setFollowRedirects(false);
- // cookies are handled by the user's browser
- client.setProxy(RemoteProxyConfig.getProxyConfigForURI(connectHost));
return client;
}
@@ -1126,7 +1124,6 @@ public final class HTTPDProxyHandler {
*/
private static void prepareResponseHeader(final ResponseHeader responseHeader, final String httpVer) {
modifyProxyHeaders(responseHeader, httpVer);
-
correctContentEncoding(responseHeader);
}
@@ -1242,13 +1239,8 @@ public final class HTTPDProxyHandler {
}
// possibly branch into PROXY-PROXY connection
- final RemoteProxyConfig proxyConfig = RemoteProxyConfig.getRemoteProxyConfig();
- if (
- (proxyConfig != null) &&
- (proxyConfig.useProxy()) &&
- (proxyConfig.useProxy4SSL())
- ) {
- final Client remoteProxy = new Client(timeout, requestHeader, proxyConfig);
+ if (ProxySettings.use && ProxySettings.use4ssl) {
+ final Client remoteProxy = new Client(timeout, requestHeader);
remoteProxy.setFollowRedirects(false); // should not be needed, but safe is safe
ResponseContainer response = null;
@@ -1260,8 +1252,8 @@ public final class HTTPDProxyHandler {
final boolean success = response.getStatusCode() >= 200 && response.getStatusCode() <= 399;
if (success) {
// replace connection details
- host = proxyConfig.getProxyHost();
- port = proxyConfig.getProxyPort();
+ host = ProxySettings.host;
+ port = ProxySettings.port;
// go on (see below)
} else {
// pass error response back to client
diff --git a/source/de/anomic/search/MetadataRepository.java b/source/de/anomic/search/MetadataRepository.java
index 9551102b5..1fea3cb40 100644
--- a/source/de/anomic/search/MetadataRepository.java
+++ b/source/de/anomic/search/MetadataRepository.java
@@ -55,7 +55,6 @@ import net.yacy.kelondro.util.ScoreCluster;
import net.yacy.repository.Blacklist;
import de.anomic.http.client.Client;
-import de.anomic.http.client.RemoteProxyConfig;
import de.anomic.http.server.ResponseContainer;
public final class MetadataRepository implements Iterable<byte[]> {
@@ -249,7 +248,7 @@ public final class MetadataRepository implements Iterable<byte[]> {
*
* @param proxyConfig
*/
- public void deadlinkCleaner(final RemoteProxyConfig proxyConfig) {
+ public void deadlinkCleaner() {
final Log log = new Log("URLDBCLEANUP");
final HashSet<String> damagedURLS = new HashSet<String>();
try {
@@ -290,7 +289,6 @@ public final class MetadataRepository implements Iterable<byte[]> {
// doing a http head request to test if the url is correct
final Client client = new Client(10000);
- client.setProxy(proxyConfig);
ResponseContainer res = null;
try {
res = client.HEAD(newUrl.toString());
diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java
index ba6670001..a3d04e255 100644
--- a/source/de/anomic/search/Switchboard.java
+++ b/source/de/anomic/search/Switchboard.java
@@ -73,6 +73,7 @@ import java.util.zip.ZipInputStream;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.document.RSSFeed;
import net.yacy.cora.document.RSSMessage;
+import net.yacy.cora.protocol.ProxySettings;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
import net.yacy.document.TextParser;
@@ -134,7 +135,6 @@ import de.anomic.data.wiki.wikiBoard;
import de.anomic.data.wiki.wikiCode;
import de.anomic.data.wiki.wikiParser;
import de.anomic.http.client.Client;
-import de.anomic.http.client.RemoteProxyConfig;
import de.anomic.http.client.Cache;
import de.anomic.http.server.HTTPDemon;
import de.anomic.http.server.HeaderFramework;
@@ -266,7 +266,7 @@ public final class Switchboard extends serverSwitch {
Tray.init(this);
// remote proxy configuration
- RemoteProxyConfig.init(this);
+ initRemoteProxy();
// memory configuration
this.useTailCache = getConfigBool("ramcopy", true);
@@ -2236,6 +2236,49 @@ public final class Switchboard extends serverSwitch {
yacyCore.log.logInfo("BOOTSTRAP: " + (peers.sizeConnected() - sc) + " new seeds while bootstraping.");
}
+ public void initRemoteProxy() {
+ // reading the proxy host name
+ final String host = getConfig("remoteProxyHost", "").trim();
+ // reading the proxy host port
+ int port;
+ try {
+ port = Integer.parseInt(getConfig("remoteProxyPort", "3128"));
+ } catch (final NumberFormatException e) {
+ port = 3128;
+ }
+ // create new config
+ ProxySettings.use = true;
+ ProxySettings.use4ssl = true;
+ ProxySettings.use4YaCy = true;
+ ProxySettings.port = port;
+ ProxySettings.host = host;
+ if ((ProxySettings.host == null) || (ProxySettings.host.length() == 0)) {
+ ProxySettings.use = false;
+ }
+
+ // determining if remote proxy usage is enabled
+ ProxySettings.use = getConfigBool("remoteProxyUse", false);
+
+ // determining if remote proxy should be used for yacy -> yacy communication
+ ProxySettings.use4YaCy = getConfig("remoteProxyUse4Yacy", "true").equalsIgnoreCase("true");
+
+ // determining if remote proxy should be used for ssl connections
+ ProxySettings.use4ssl = getConfig("remoteProxyUse4SSL", "true").equalsIgnoreCase("true");
+
+ ProxySettings.user = getConfig("remoteProxyUser", "").trim();
+ ProxySettings.password = getConfig("remoteProxyPwd", "").trim();
+
+ // determining addresses for which the remote proxy should not be used
+ final String remoteProxyNoProxy = getConfig("remoteProxyNoProxy","").trim();
+ ProxySettings.noProxy = remoteProxyNoProxy.split(",");
+ // trim split entries
+ int i = 0;
+ for (final String pattern: ProxySettings.noProxy) {
+ ProxySettings.noProxy[i] = pattern.trim();
+ i++;
+ }
+ }
+
public void checkInterruption() throws InterruptedException {
final Thread curThread = Thread.currentThread();
if ((curThread instanceof WorkflowThread) && ((WorkflowThread)curThread).shutdownInProgress()) throw new InterruptedException("Shutdown in progress ...");
diff --git a/source/de/anomic/tools/loaderThreads.java b/source/de/anomic/tools/loaderThreads.java
index 134363451..6eb6dc2af 100644
--- a/source/de/anomic/tools/loaderThreads.java
+++ b/source/de/anomic/tools/loaderThreads.java
@@ -23,11 +23,11 @@ package de.anomic.tools;
import java.util.Hashtable;
+import net.yacy.cora.protocol.ProxySettings;
import net.yacy.kelondro.data.meta.DigestURI;
import de.anomic.crawler.retrieval.HTTPLoader;
import de.anomic.http.client.Client;
-import de.anomic.http.client.RemoteProxyConfig;
import de.anomic.http.server.HeaderFramework;
import de.anomic.http.server.RequestHeader;
@@ -37,7 +37,7 @@ public class loaderThreads {
protected int timeout;
protected String user;
protected String password;
- protected RemoteProxyConfig remoteProxyConfig;
+ protected ProxySettings remoteProxyConfig;
// management objects for collection of threads
Hashtable<String, Thread> threads;
diff --git a/source/de/anomic/yacy/yacyRelease.java b/source/de/anomic/yacy/yacyRelease.java
index 542116c34..b6f70304e 100644
--- a/source/de/anomic/yacy/yacyRelease.java
+++ b/source/de/anomic/yacy/yacyRelease.java
@@ -291,18 +291,18 @@ public final class yacyRelease extends yacyVersion {
byte[] signatureBytes = null;
// download signature first, if public key is available
- if (this.publicKey != null) {
- final byte[] signatureData = Client.wget(this.getUrl().toString() + ".sig", reqHeader, 6000);
- if (signatureData == null) {
- Log.logWarning("yacyVersion", "download of signature " + this.getUrl().toString() + " failed. ignoring signature file.");
- } else try {
- signatureBytes = Base64Order.standardCoder.decode(new String(signatureData, "UTF8").trim());
- } catch (UnsupportedEncodingException e) {
- Log.logWarning("yacyVersion", "download of signature " + this.getUrl().toString() + " failed: unsupported encoding");
- }
- // in case that the download of a signature file failed (can be caused by bad working http servers), then it is assumed that no signature exists
- }
try {
+ if (this.publicKey != null) {
+ final byte[] signatureData = Client.wget(this.getUrl().toString() + ".sig", reqHeader, 6000);
+ if (signatureData == null) {
+ Log.logWarning("yacyVersion", "download of signature " + this.getUrl().toString() + " failed. ignoring signature file.");
+ } else try {
+ signatureBytes = Base64Order.standardCoder.decode(new String(signatureData, "UTF8").trim());
+ } catch (UnsupportedEncodingException e) {
+ Log.logWarning("yacyVersion", "download of signature " + this.getUrl().toString() + " failed: unsupported encoding");
+ }
+ // in case that the download of a signature file failed (can be caused by bad working http servers), then it is assumed that no signature exists
+ }
final Client client = new Client(120000, reqHeader);
res = client.GET(this.getUrl().toString());
diff --git a/source/net/yacy/cora/document/MultiProtocolURI.java b/source/net/yacy/cora/document/MultiProtocolURI.java
index f9cda9317..6ddf898f8 100644
--- a/source/net/yacy/cora/document/MultiProtocolURI.java
+++ b/source/net/yacy/cora/document/MultiProtocolURI.java
@@ -776,7 +776,11 @@ public class MultiProtocolURI implements Serializable {
// checks for local/global IP range and local IP
public boolean isLocal() {
- return (this.host.startsWith("127.") || this.host.equals("localhost") || this.host.startsWith("0:0:0:0:0:0:0:1"));
+ return isLocal(this.host);
+ }
+
+ public static boolean isLocal(String host) {
+ return host.startsWith("127.") || host.equals("localhost") || host.startsWith("0:0:0:0:0:0:0:1");
}
// language calculation
diff --git a/source/net/yacy/cora/protocol/HttpConnector.java b/source/net/yacy/cora/protocol/HttpConnector.java
index ada2ec698..6e72d421d 100644
--- a/source/net/yacy/cora/protocol/HttpConnector.java
+++ b/source/net/yacy/cora/protocol/HttpConnector.java
@@ -28,7 +28,6 @@ import org.apache.commons.httpclient.methods.multipart.Part;
import de.anomic.crawler.retrieval.HTTPLoader;
import de.anomic.http.client.Client;
-import de.anomic.http.client.RemoteProxyConfig;
import de.anomic.http.server.HeaderFramework;
import de.anomic.http.server.RequestHeader;
import de.anomic.http.server.ResponseContainer;
@@ -65,7 +64,6 @@ public class HttpConnector {
header.put(HeaderFramework.USER_AGENT, HTTPLoader.yacyUserAgent);
header.put(HeaderFramework.HOST, vhost);
final Client client = new Client(timeout, header);
- client.setProxy(proxyConfig());
ResponseContainer res = null;
byte[] content = null;
@@ -82,9 +80,4 @@ public class HttpConnector {
return content;
}
-
- private static final RemoteProxyConfig proxyConfig() {
- final RemoteProxyConfig p = RemoteProxyConfig.getRemoteProxyConfig();
- return ((p != null) && (p.useProxy()) && (p.useProxy4Yacy())) ? p : null;
- }
}
diff --git a/source/net/yacy/cora/protocol/ProxySettings.java b/source/net/yacy/cora/protocol/ProxySettings.java
new file mode 100644
index 000000000..3b6fbc631
--- /dev/null
+++ b/source/net/yacy/cora/protocol/ProxySettings.java
@@ -0,0 +1,74 @@
+/**
+ * ProxySettings
+ * Copyright 2010 by Michael Peter Christen
+ * First released 25.05.2010 at http://yacy.net
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file COPYING.LESSER.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.yacy.cora.protocol;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+
+/**
+ * settings for a remote proxy
+ *
+ */
+public final class ProxySettings {
+
+ public static boolean use = false, use4YaCy = false, use4ssl = false;
+ public static String host = null, user = "", password = "";
+ public static int port = 0;
+ public static String[] noProxy = null;
+ public static final Set<String> allowProxy = new HashSet<String>();
+ public static final Set<String> disallowProxy = new HashSet<String>();
+
+ /**
+ * produce a HostConfiguration (apache object) with the proxy access information included
+ * @param apacheHttpClient
+ * @return a host configuration with proxy config if the proxy shall be used; a cloned configuration otherwise
+ */
+ public static HostConfiguration getProxyHostConfig(HttpClient apacheHttpClient) {
+ final HostConfiguration hostConfig;
+ if (!use) return null;
+ hostConfig = new HostConfiguration(apacheHttpClient.getHostConfiguration());
+ hostConfig.setProxy(host, port);
+ return hostConfig;
+ }
+
+ /**
+ * tell if a remote proxy will be used for the given host
+ * @param host
+ * @return true, if the proxy shall be used for the given host
+ */
+ public static boolean useForHost(final String host) {
+ if (!use) return false;
+ if (allowProxy.contains(host)) return true;
+ if (disallowProxy.contains(host)) return false;
+ for (String pattern: noProxy) {
+ if (host.matches(pattern)) {
+ disallowProxy.add(host);
+ return false;
+ }
+ }
+ allowProxy.add(host);
+ return true;
+ }
+
+}
diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java
index 15dfe248e..71e52d414 100644
--- a/source/net/yacy/yacy.java
+++ b/source/net/yacy/yacy.java
@@ -834,7 +834,7 @@ public final class yacy {
final File indexroot = new File(root, "DATA/INDEX");
try {Log.configureLogging(homePath, new File(homePath, "DATA/LOG/yacy.logging"));} catch (final Exception e) {}
final MetadataRepository currentUrlDB = new MetadataRepository(new File(new File(indexroot, networkName), "TEXT"), "text.urlmd", false, false);
- currentUrlDB.deadlinkCleaner(null);
+ currentUrlDB.deadlinkCleaner();
currentUrlDB.close();
}