From 072052f150848dd86c568571c8d89307abbe836e Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 11 Apr 2005 22:44:40 +0000 Subject: [PATCH] fixed bugs (dns, seedDB) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@13 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/httpc.java | 20 +++++++++++++++++++- source/de/anomic/kelondro/kelondroDyn.java | 5 ++++- source/de/anomic/kelondro/kelondroMap.java | 2 ++ source/de/anomic/kelondro/kelondroTree.java | 8 +++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java index c9b1f9f1f..747caa9e6 100644 --- a/source/de/anomic/http/httpc.java +++ b/source/de/anomic/http/httpc.java @@ -92,7 +92,13 @@ public class httpc { private static HashMap nameCacheHit = new HashMap(); //private static HashSet nameCacheMiss = new HashSet(); - public static String dnsResolve(String host) { + static { + // set time-out of InetAddress.getByName cache ttl + java.security.Security.setProperty("networkaddress.cache.ttl" , "60"); + java.security.Security.setProperty("networkaddress.cache.negative.ttl" , "0"); + } + + private static String dnsResolveX(String host) { // looks for the ip of host and returns ip number as string String ip = (String) nameCacheHit.get(host); if (ip != null) return ip; @@ -111,6 +117,18 @@ public class httpc { return null; } + public static String dnsResolve(String host) { + String ip = null; + for (int i = 0; i < 50; i++) { + ip = dnsResolveX(host); + if (ip != null) { + //if (i > 0) System.out.println(i + " attempts for " + host); + return ip; + } + } + return ip; + } + public static boolean dnsFetch(String host) { // looks for the ip of host and returns false if the host was in the cache // if it is not in the cache the ip is fetched and this resturns true diff --git a/source/de/anomic/kelondro/kelondroDyn.java b/source/de/anomic/kelondro/kelondroDyn.java index 0d2808290..6102a5fdc 100644 --- a/source/de/anomic/kelondro/kelondroDyn.java +++ b/source/de/anomic/kelondro/kelondroDyn.java @@ -158,8 +158,11 @@ public class kelondroDyn extends kelondroTree { String k; String v; int c; + byte[][] nt; while (ri.hasNext()) { - g = ((byte[][]) ri.next())[0]; + nt = (byte[][]) ri.next(); + if (nt == null) return null; + g = nt[0]; if (g == null) return null; k = new String(g, 0, keylen); v = new String(g, keylen, counterlen); diff --git a/source/de/anomic/kelondro/kelondroMap.java b/source/de/anomic/kelondro/kelondroMap.java index a92186c41..7044b1677 100644 --- a/source/de/anomic/kelondro/kelondroMap.java +++ b/source/de/anomic/kelondro/kelondroMap.java @@ -96,6 +96,7 @@ public class kelondroMap { Map map; while (it.hasNext()) { key = (String) it.next(); + //System.out.println("kelondroMap: enumerating key " + key); map = get(key); if (sortfields != null) for (int i = 0; i < sortfields.length; i++) { @@ -422,6 +423,7 @@ public class kelondroMap { } try { Map map = get(nextKey); + if (map == null) return null; map.put("key", nextKey); return map; } catch (IOException e) { diff --git a/source/de/anomic/kelondro/kelondroTree.java b/source/de/anomic/kelondro/kelondroTree.java index 24a91f9a9..fcf6f60c3 100644 --- a/source/de/anomic/kelondro/kelondroTree.java +++ b/source/de/anomic/kelondro/kelondroTree.java @@ -251,12 +251,14 @@ public class kelondroTree extends kelondroRecords implements Comparator { Node nextNode = null; boolean up, rot; LinkedList nodeStack; + int count; public nodeIterator(boolean up, boolean rotating) throws IOException { this(up, rotating, (up) ? firstNode() : lastNode()); } public nodeIterator(boolean up, boolean rotating, Node start) throws IOException { + this.count = 0; this.up = up; this.rot = rotating; this.nextNode = start; @@ -289,7 +291,9 @@ public class kelondroTree extends kelondroRecords implements Comparator { } public Object next() { + count++; if (nextNode == null) return null; + if (count > size()) return null; Object ret = nextNode; // middle-case @@ -890,7 +894,9 @@ public class kelondroTree extends kelondroRecords implements Comparator { public Object next() { try { - return ((Node) nodeIterator.next()).getValues(); + Node nextNode = (Node) nodeIterator.next(); + if (nextNode == null) return null; // this is an error case of the nodeIterator + return nextNode.getValues(); } catch (IOException e) { return null; }