Skip to content

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

fix for http://www.yacy-forum.de/viewtopic.php?p=31553#31553

orbiter313f6a768004
diff --git a/source/de/anomic/plasma/plasmaDHTChunk.java b/source/de/anomic/plasma/plasmaDHTChunk.java
index a7eefc376..afdc75aa2 100644
--- a/source/de/anomic/plasma/plasmaDHTChunk.java
+++ b/source/de/anomic/plasma/plasmaDHTChunk.java
@@ -168,15 +168,25 @@ public class plasmaDHTChunk {
String startPointHash;
// first try to select with increasing probality a good start point
double minimumDistance = ((double) peerRedundancy) / ((double) yacyCore.seedDB.sizeConnected());
- if (Math.round(Math.random() * 6) != 4)
- for (int i = 9; i > 0; i--) {
- startPointHash = kelondroBase64Order.enhancedCoder.encode(serverCodings.encodeMD5Raw(Long.toString(i + System.currentTimeMillis()))).substring(2, 2 + yacySeedDB.commonHashLength);
- if (yacyDHTAction.dhtDistance(yacyCore.seedDB.mySeed.hash, startPointHash) > (minimumDistance + ((double) i / (double) 10)))
- return startPointHash;
+ double d, bestDistance = 0.0;
+ String bestHash = null;
+ for (int i = yacyCore.seedDB.sizeConnected() / 8; i > 0; i--) {
+ startPointHash = kelondroBase64Order.enhancedCoder.encode(serverCodings.encodeMD5Raw(Long.toString(i + System.currentTimeMillis()))).substring(2, 2 + yacySeedDB.commonHashLength);
+ d = yacyDHTAction.dhtDistance(yacyCore.seedDB.mySeed.hash, startPointHash);
+ if (d > (minimumDistance + ((double) i / (double) 10))) {
+ return startPointHash;
}
- // if that fails, take simply the best start point (this is usually avoided, since that leads to always the same target peers)
- startPointHash = yacyCore.seedDB.mySeed.hash.substring(0, 11) + "z";
- return startPointHash;
+ if (d > bestDistance) {
+ bestDistance = d;
+ bestHash = startPointHash;
+ }
+ }
+ // if that fails, take simply the best start point
+ if (bestHash == null) {
+ return yacyCore.seedDB.mySeed.hash.substring(0, 11) + "z";
+ } else {
+ return bestHash;
+ }
}
private void selectTransferContainers(String hash, int mincount, int maxcount, int maxtime) throws InterruptedException {