when searching the network, do not search on robinson peers with the old

DHT search interface. Now use the solr interface.
pull/1/head
Michael Peter Christen 12 years ago
parent 6f6ddaf7e7
commit e1da39245a

@ -55,7 +55,7 @@ import net.yacy.peers.operation.yacyVersion;
public class DHTSelection { public class DHTSelection {
public static Seed[] selectClusterPeers(final SeedDB seedDB, final SortedMap<byte[], String> peerhashes) { public static List<Seed> selectClusterPeers(final SeedDB seedDB, final SortedMap<byte[], String> peerhashes) {
final Iterator<Map.Entry<byte[], String>> i = peerhashes.entrySet().iterator(); final Iterator<Map.Entry<byte[], String>> i = peerhashes.entrySet().iterator();
final List<Seed> l = new ArrayList<Seed>(); final List<Seed> l = new ArrayList<Seed>();
Map.Entry<byte[], String> entry; Map.Entry<byte[], String> entry;
@ -68,10 +68,10 @@ public class DHTSelection {
l.add(s); l.add(s);
} }
} }
return l.toArray(new Seed[l.size()]); return l;
} }
public static Seed[] selectNodeSearchTargets(final SeedDB seedDB, int maxCount, Set<Seed> omit) { public static List<Seed> selectNodeSearchTargets(final SeedDB seedDB, int maxCount, Set<Seed> omit) {
if (seedDB == null) { return null; } if (seedDB == null) { return null; }
final List<Seed> goodSeeds = new ArrayList<Seed>(); final List<Seed> goodSeeds = new ArrayList<Seed>();
@ -93,13 +93,10 @@ public class DHTSelection {
goodSeeds.add(optionalSeeds.remove(r.nextInt(optionalSeeds.size()))); goodSeeds.add(optionalSeeds.remove(r.nextInt(optionalSeeds.size())));
} }
// produce return set return goodSeeds;
Seed[] result = new Seed[goodSeeds.size()];
result = goodSeeds.toArray(result);
return result;
} }
public static Seed[] selectSearchTargets( public static List<Seed> selectSearchTargets(
final SeedDB seedDB, final SeedDB seedDB,
final HandleSet wordhashes, final HandleSet wordhashes,
int redundancy, int redundancy,
@ -186,8 +183,8 @@ public class DHTSelection {
} }
// produce return set // produce return set
Seed[] result = new Seed[regularSeeds.size()]; List<Seed> result = new ArrayList<Seed>(regularSeeds.size());
result = regularSeeds.values().toArray(result); result.addAll(regularSeeds.values());
return result; return result;
} }

@ -26,6 +26,7 @@ package net.yacy.peers;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.SortedMap; import java.util.SortedMap;
@ -145,7 +146,7 @@ public class RemoteSearch extends Thread {
//if (wordIndex.seedDB.mySeed() == null || wordIndex.seedDB.mySeed().getPublicAddress() == null) { return null; } //if (wordIndex.seedDB.mySeed() == null || wordIndex.seedDB.mySeed().getPublicAddress() == null) { return null; }
// prepare seed targets and threads // prepare seed targets and threads
final Seed[] targetPeers = final List<Seed> dhtPeers =
(clusterselection == null) ? (clusterselection == null) ?
DHTSelection.selectSearchTargets( DHTSelection.selectSearchTargets(
event.peers, event.peers,
@ -154,21 +155,33 @@ public class RemoteSearch extends Thread {
burstRobinsonPercent, burstRobinsonPercent,
burstMultiwordPercent) burstMultiwordPercent)
: DHTSelection.selectClusterPeers(event.peers, clusterselection); : DHTSelection.selectClusterPeers(event.peers, clusterselection);
if (targetPeers == null) return; if (dhtPeers == null) return;
// start solr searches // find nodes
Set<Seed> omit = new HashSet<Seed>(); Set<Seed> omit = new HashSet<Seed>();
for (Seed s: targetPeers) omit.add(s); for (Seed s: dhtPeers) omit.add(s);
Seed[] nodes = DHTSelection.selectNodeSearchTargets(event.peers, 20, omit); List<Seed> nodePeers = DHTSelection.selectNodeSearchTargets(event.peers, 20, omit);
for (Seed s: nodes) {
// remove all robinson peers from the dhtPeers and put them to the nodes
Iterator<Seed> si = dhtPeers.iterator();
while (si.hasNext()) {
Seed s = si.next();
if (!s.getFlagAcceptRemoteIndex()) {
si.remove();
nodePeers.add(s);
}
}
// start solr searches
for (Seed s: nodePeers) {
solrRemoteSearch(event, count, s, blacklist); solrRemoteSearch(event, count, s, blacklist);
} }
// start search to YaCy peers // start search to YaCy DHT peers
final int targets = targetPeers.length; final int targets = dhtPeers.size();
if (targets == 0) return; if (targets == 0) return;
for (int i = 0; i < targets; i++) { for (int i = 0; i < targets; i++) {
if (targetPeers[i] == null || targetPeers[i].hash == null) continue; if (dhtPeers.get(i) == null || dhtPeers.get(i).hash == null) continue;
try { try {
RemoteSearch rs = new RemoteSearch( RemoteSearch rs = new RemoteSearch(
event, event,
@ -183,7 +196,7 @@ public class RemoteSearch extends Thread {
time, time,
event.query.maxDistance, event.query.maxDistance,
targets, targets,
targetPeers[i], dhtPeers.get(i),
event.secondarySearchSuperviser, event.secondarySearchSuperviser,
blacklist); blacklist);
rs.start(); rs.start();

Loading…
Cancel
Save