Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
prevent too high search request frequency submitted from the same peer
orbiter3aa69dab9451
diff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex b91304f32..a9bc53bf3 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -121,6 +121,29 @@ public final class search {return prop;}+ // check the search tracker+ TreeSet<Long> trackerHandles = sb.remoteSearchTracker.get(client);+ if (trackerHandles == null) trackerHandles = new TreeSet<Long>();+ boolean block = false;+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 6000)).size() > 1) try {+ Thread.sleep(3000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 60000)).size() > 12) try {+ Thread.sleep(10000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 600000)).size() > 36) try {+ Thread.sleep(30000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (block) {+ prop.put("links", "");+ prop.put("linkcount", "0");+ prop.put("references", "");+ return prop;+ }+// tell all threads to do nothing for a specific timesb.intermissionAllThreads(3000);@@ -291,10 +314,11 @@ public final class search {theQuery.urlretrievaltime = (theSearch == null) ? 0 : theSearch.getURLRetrievalTime();theQuery.snippetcomputationtime = (theSearch == null) ? 0 : theSearch.getSnippetComputationTime();sb.remoteSearches.add(theQuery);- TreeSet<Long> handles = sb.remoteSearchTracker.get(client);- if (handles == null) handles = new TreeSet<Long>();- handles.add(theQuery.handle);- sb.remoteSearchTracker.put(client, handles);++ // update the search tracker+ trackerHandles.add(theQuery.handle);+ sb.remoteSearchTracker.put(client, trackerHandles);+// logyacyCore.log.logInfo("EXIT HASH SEARCH: " +diff --git a/htroot/yacy/ui/result.java b/htroot/yacy/ui/result.javaindex 16e27ac05..118d11d94 100644--- a/htroot/yacy/ui/result.java+++ b/htroot/yacy/ui/result.java@@ -58,7 +58,8 @@ public class result {String promoteSearchPageGreeting = env.getConfig("promoteSearchPageGreeting", "");if (env.getConfigBool("promoteSearchPageGreeting.useNetworkName", false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");if (promoteSearchPageGreeting.length() == 0) promoteSearchPageGreeting = "P2P WEB SEARCH";-+ String client = (String) header.get(httpHeader.CONNECTION_PROP_CLIENTIP); // the search client who initiated the search+// get queryString querystring = (post == null) ? "" : post.get("search", "").trim();final serverObjects prop = new serverObjects();@@ -143,7 +144,24 @@ public class result {// patch until better search profiles are availableif ((contentdomCode != plasmaSearchQuery.CONTENTDOM_TEXT) && (itemsPerPage <= 32)) itemsPerPage = 32;- if (post.get("cat", "href").equals("href")) {+ // check the search tracker+ TreeSet<Long> trackerHandles = sb.localSearchTracker.get(client);+ if (trackerHandles == null) trackerHandles = new TreeSet<Long>();+ boolean block = false;+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 3000)).size() > 1) try {+ Thread.sleep(3000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 60000)).size() > 12) try {+ Thread.sleep(10000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 600000)).size() > 36) try {+ Thread.sleep(30000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }++ if ((!block) && (post.get("cat", "href").equals("href"))) {final TreeSet<String>[] query = plasmaSearchQuery.cleanQuery(querystring); // converts also umlauteboolean near = (query[0].contains("near")) && (querystring.indexOf("NEAR") >= 0);@@ -166,7 +184,6 @@ public class result {final boolean globalsearch = (global) && (yacyonline) && (sb.getConfigBool(plasmaSwitchboard.INDEX_RECEIVE_ALLOW, false));// do the search- String client = (String) header.get(httpHeader.CONNECTION_PROP_CLIENTIP); // the search client who initiated the searchTreeSet<String> queryHashes = indexWord.words2hashes(query[0]);plasmaSearchQuery theQuery = new plasmaSearchQuery(querystring,@@ -226,10 +243,10 @@ public class result {theQuery.urlretrievaltime = theSearch.getURLRetrievalTime();theQuery.snippetcomputationtime = theSearch.getSnippetComputationTime();sb.localSearches.add(theQuery);- TreeSet<Long> handles = sb.localSearchTracker.get(client);- if (handles == null) handles = new TreeSet<Long>();- handles.add(theQuery.handle);- sb.localSearchTracker.put(client, handles);++ // update the search tracker+ trackerHandles.add(theQuery.handle);+ sb.localSearchTracker.put(client, trackerHandles);int totalcount = theSearch.getRankingResult().getLocalResourceSize() + theSearch.getRankingResult().getRemoteResourceSize();prop.put("num-results_offset", offset);diff --git a/htroot/yacy/user/ysearch.java b/htroot/yacy/user/ysearch.javaindex b835bfecb..db65bc1ea 100644--- a/htroot/yacy/user/ysearch.java+++ b/htroot/yacy/user/ysearch.java@@ -58,7 +58,8 @@ public class ysearch {String promoteSearchPageGreeting = env.getConfig("promoteSearchPageGreeting", "");if (env.getConfigBool("promoteSearchPageGreeting.useNetworkName", false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");if (promoteSearchPageGreeting.length() == 0) promoteSearchPageGreeting = "P2P WEB SEARCH";-+ String client = (String) header.get(httpHeader.CONNECTION_PROP_CLIENTIP); // the search client who initiated the search+// get queryString querystring = (post == null) ? "" : post.get("search", "").trim();final serverObjects prop = new serverObjects();@@ -143,7 +144,24 @@ public class ysearch {// patch until better search profiles are availableif ((contentdomCode != plasmaSearchQuery.CONTENTDOM_TEXT) && (itemsPerPage <= 32)) itemsPerPage = 32;- if (post.get("cat", "href").equals("href")) {+ // check the search tracker+ TreeSet<Long> trackerHandles = sb.localSearchTracker.get(client);+ if (trackerHandles == null) trackerHandles = new TreeSet<Long>();+ boolean block = false;+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 3000)).size() > 1) try {+ Thread.sleep(3000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 60000)).size() > 12) try {+ Thread.sleep(10000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 600000)).size() > 36) try {+ Thread.sleep(30000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }++ if ((!block) && (post.get("cat", "href").equals("href"))) {final TreeSet<String>[] query = plasmaSearchQuery.cleanQuery(querystring); // converts also umlauteboolean near = (query[0].contains("near")) && (querystring.indexOf("NEAR") >= 0);@@ -166,7 +184,6 @@ public class ysearch {final boolean globalsearch = (global) && (yacyonline) && (sb.getConfigBool(plasmaSwitchboard.INDEX_RECEIVE_ALLOW, false));// do the search- String client = (String) header.get(httpHeader.CONNECTION_PROP_CLIENTIP); // the search client who initiated the searchTreeSet<String> queryHashes = indexWord.words2hashes(query[0]);plasmaSearchQuery theQuery = new plasmaSearchQuery(querystring,@@ -226,10 +243,10 @@ public class ysearch {theQuery.urlretrievaltime = theSearch.getURLRetrievalTime();theQuery.snippetcomputationtime = theSearch.getSnippetComputationTime();sb.localSearches.add(theQuery);- TreeSet<Long> handles = sb.localSearchTracker.get(client);- if (handles == null) handles = new TreeSet<Long>();- handles.add(theQuery.handle);- sb.localSearchTracker.put(client, handles);++ // update the search tracker+ trackerHandles.add(theQuery.handle);+ sb.localSearchTracker.put(client, trackerHandles);int totalcount = theSearch.getRankingResult().getLocalResourceSize() + theSearch.getRankingResult().getRemoteResourceSize();prop.put("num-results_offset", offset);diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex 078ff071a..266bb77b2 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -93,11 +93,11 @@ public class yacysearch {// get queryString querystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim(); // SRU compliance+ final serverObjects prop = new serverObjects();boolean rss = (post == null) ? false : post.get("rss", "false").equals("true");if ((post == null) || (env == null) || (querystring.length() == 0) || (!searchAllowed)) {// we create empty entries for template strings- final serverObjects prop = new serverObjects();prop.put("searchagain", "0");prop.put("input", input);prop.put("display", display);@@ -174,8 +174,24 @@ public class yacysearch {// patch until better search profiles are availableif ((contentdomCode != plasmaSearchQuery.CONTENTDOM_TEXT) && (itemsPerPage <= 32)) itemsPerPage = 32;- serverObjects prop = new serverObjects();- if (post.get("cat", "href").equals("href")) {+ // check the search tracker+ TreeSet<Long> trackerHandles = sb.localSearchTracker.get(client);+ if (trackerHandles == null) trackerHandles = new TreeSet<Long>();+ boolean block = false;+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 3000)).size() > 1) try {+ Thread.sleep(3000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 60000)).size() > 12) try {+ Thread.sleep(10000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }+ if (trackerHandles.tailSet(new Long(System.currentTimeMillis() - 600000)).size() > 36) try {+ Thread.sleep(30000);+ block = true;+ } catch (InterruptedException e) { e.printStackTrace(); }++ if ((!block) && (post.get("cat", "href").equals("href"))) {final TreeSet<String>[] query = plasmaSearchQuery.cleanQuery(querystring); // converts also umlauteboolean near = (query[0].contains("near")) && (querystring.indexOf("NEAR") >= 0);@@ -302,12 +318,11 @@ public class yacysearch {theQuery.urlretrievaltime = theSearch.getURLRetrievalTime();theQuery.snippetcomputationtime = theSearch.getSnippetComputationTime();sb.localSearches.add(theQuery);- TreeSet<Long> handles = sb.localSearchTracker.get(client);- if (handles == null) handles = new TreeSet<Long>();- handles.add(theQuery.handle);- sb.localSearchTracker.put(client, handles);- prop = new serverObjects();+ // update the search tracker+ trackerHandles.add(theQuery.handle);+ sb.localSearchTracker.put(client, trackerHandles);+int totalcount = theSearch.getRankingResult().getLocalResourceSize() + theSearch.getRankingResult().getRemoteResourceSize();prop.put("num-results_offset", offset);prop.put("num-results_itemscount", "0");