*) make DHT DoS check configurable (requested by KoH)

- check can be disabled via property indexDistribution.dhtReceiptLimitEnabled
   - upper bound can be configured via indexDistribution.dhtReceiptLimit

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2234 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
theli 2006-06-21 19:28:42 +00:00
parent 650c7e9e55
commit b20496e42b
3 changed files with 18 additions and 4 deletions

View File

@ -78,6 +78,8 @@ public final class transferRWI {
final int entryc = Integer.parseInt(post.get("entryc", "")); // number of entries in indexes
byte[] indexes = post.get("indexes", "").getBytes(); // the indexes, as list of word entries
boolean granted = sb.getConfig("allowReceiveIndex", "false").equals("true");
boolean checkLimit = sb.getConfigBool("indexDistribution.dhtReceiptLimitEnabled", true);
final long cachelimit = sb.getConfigLong("indexDistribution.dhtReceiptLimit", 1000);
final yacySeed otherPeer = yacyCore.seedDB.get(iam);
final String otherPeerName = iam + ":" + ((otherPeer == null) ? "NULL" : (otherPeer.getName() + "/" + otherPeer.getVersion()));
@ -91,7 +93,7 @@ public final class transferRWI {
sb.getLog().logInfo("Rejecting RWIs from peer " + otherPeerName + ". Not granted.");
result = "not_granted";
pause = 0;
} else if (sb.wordIndex.kSize() > 1000) {
} else if (checkLimit && sb.wordIndex.kSize() > cachelimit) {
// we are too busy to receive indexes
sb.getLog().logInfo("Rejecting RWIs from peer " + otherPeerName + ". We are too busy (buffersize=" + sb.wordIndex.kSize() + ").");
granted = false; // don't accept more words if there are too many words to flush
@ -171,8 +173,11 @@ public final class transferRWI {
sb.getLog().logInfo("Received " + received + " Words [" + wordhashes[0] + " .. " + wordhashes[received - 1] + "]/" + avdist + " from " + otherPeerName + ", processed in " + (System.currentTimeMillis() - startProcess) + " milliseconds, requesting " + unknownURL.size() + " URLs");
}
result = "ok";
if (checkLimit) {
pause = (sb.wordIndex.kSize() < 500) ? 0 : 60 * sb.wordIndex.kSize(); // estimation of necessary pause time
}
}
prop.put("unknownURL", unknownURLs.toString());
prop.put("result", result);

View File

@ -258,13 +258,14 @@ public class plasmaDHTTransfer extends Thread {
if (transferRWIResult != null && transferRWIResult.containsKey("pause")) {
String pauseStr = (String) transferRWIResult.get("pause");
try { pause = Integer.valueOf(pauseStr).intValue(); } catch (NumberFormatException numEx){}
if (pause <= 0) pause = 60000;
if (pause < 0) pause = 60000;
else if (pause > 1800000) pause = 1800000;
}
return pause;
}
private void pause(long sleepTime) throws InterruptedException {
if (sleepTime == 0) return;
long sleepCounter = sleepTime / 1000;
long sleepRest = sleepTime % 1000;
while (!this.isAborted() && sleepCounter > 0) {

View File

@ -649,6 +649,14 @@ indexDistribution.minChunkSize = 5
indexDistribution.maxChunkSize = 1000
indexDistribution.startChunkSize = 50
# defines if the peer should reject incoming index transfer
# request if a given limit is reached
indexDistribution.dhtReceiptLimitEnabled = false
# defines the word cache for DHT reaches this level
# the peer reports itself as busy
indexDistribution.dhtReceiptLimit = 1000
# Distribution of Citation-Reference (CR-) files
# The distribution is done in two steps:
# first step to anonymize the records