|
|
|
@ -81,24 +81,23 @@ public class yacyCore {
|
|
|
|
|
|
|
|
|
|
// statics
|
|
|
|
|
public static final ThreadGroup publishThreadGroup = new ThreadGroup("publishThreadGroup");
|
|
|
|
|
public static yacySeedDB seedDB = null;
|
|
|
|
|
public static yacyNewsPool newsPool = null;
|
|
|
|
|
public static final HashMap<String, String> seedUploadMethods = new HashMap<String, String>();
|
|
|
|
|
public static yacyPeerActions peerActions = null;
|
|
|
|
|
public static yacyDHTAction dhtAgent = null;
|
|
|
|
|
public static yacySeedDB seedDB;
|
|
|
|
|
public static yacyNewsPool newsPool;
|
|
|
|
|
public static final HashMap seedUploadMethods = new HashMap();
|
|
|
|
|
public static yacyPeerActions peerActions;
|
|
|
|
|
public static yacyDHTAction dhtAgent;
|
|
|
|
|
public static serverLog log;
|
|
|
|
|
public static long lastOnlineTime = 0;
|
|
|
|
|
/** pseudo-random key derived from a time-interval while YaCy startup*/
|
|
|
|
|
public static long speedKey = 0;
|
|
|
|
|
public static long lastOnlineTime;
|
|
|
|
|
/** pseudo-random key derived from a time-interval while YaCy startup. */
|
|
|
|
|
public static long speedKey;
|
|
|
|
|
public static File yacyDBPath;
|
|
|
|
|
public static final Map<String, yacyAccessible> amIAccessibleDB = Collections.synchronizedMap(new HashMap<String, yacyAccessible>()); // Holds PeerHash / yacyAccessible Relations
|
|
|
|
|
public static final Map amIAccessibleDB = Collections.synchronizedMap(new HashMap()); // Holds PeerHash / yacyAccessible Relations
|
|
|
|
|
// constants for PeerPing behaviour
|
|
|
|
|
private static final int PING_INITIAL = 16;
|
|
|
|
|
private static final int PING_MAX_RUNNING = 8;
|
|
|
|
|
private static final int PING_MIN_RUNNING = 4;
|
|
|
|
|
private static final int PING_INITIAL = 64;
|
|
|
|
|
private static final int PING_MIN_LASTSEEN = 240000; // in milliseconds
|
|
|
|
|
private static final int PING_MIN_PEERSEEN = 2; // min. accessible to force senior
|
|
|
|
|
private static final long PING_MAX_DBAGE = 15 * 60 * 1000; // in milliseconds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public static yacyShare shareManager = null;
|
|
|
|
|
// public static boolean terminate = false;
|
|
|
|
|
|
|
|
|
@ -372,8 +371,8 @@ public class yacyCore {
|
|
|
|
|
int attempts = seedDB.sizeConnected();
|
|
|
|
|
|
|
|
|
|
// getting a list of peers to contact
|
|
|
|
|
if (seedDB.mySeed().get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN).equals(yacySeed.PEERTYPE_VIRGIN)) {
|
|
|
|
|
if (attempts > PING_INITIAL) { attempts = PING_INITIAL; }
|
|
|
|
|
if (seedDB.mySeed().isVirgin()) {
|
|
|
|
|
attempts = Math.min(attempts, PING_INITIAL);
|
|
|
|
|
final Map<String, String> ch = plasmaSwitchboard.getSwitchboard().clusterhashes;
|
|
|
|
|
seeds = seedDB.seedsByAge(true, attempts - ((ch == null) ? 0 : ch.size())); // best for fast connection
|
|
|
|
|
// add also all peers from cluster if this is a public robinson cluster
|
|
|
|
@ -395,20 +394,10 @@ public class yacyCore {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (amIAccessibleDB.size() > PING_MAX_RUNNING) {
|
|
|
|
|
attempts = PING_MAX_RUNNING;
|
|
|
|
|
} else {
|
|
|
|
|
attempts = Math.min(attempts, PING_MIN_RUNNING);
|
|
|
|
|
}
|
|
|
|
|
seeds = seedDB.seedsByAge(false, attempts); // best for seed list maintenance/cleaning
|
|
|
|
|
seeds = seedDB.getOldestSeeds(attempts / 5, PING_MIN_LASTSEEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (seeds == null || seeds.size() == 0) { return 0; }
|
|
|
|
|
if (seeds.size() < attempts) { attempts = seeds.size(); }
|
|
|
|
|
|
|
|
|
|
// This will try to get Peers that are not currently in amIAccessibleDB
|
|
|
|
|
Iterator<yacySeed> si = seeds.values().iterator();
|
|
|
|
|
yacySeed seed;
|
|
|
|
|
attempts = seeds.size();
|
|
|
|
|
|
|
|
|
|
// include a YaCyNews record to my seed
|
|
|
|
|
try {
|
|
|
|
@ -433,10 +422,14 @@ public class yacyCore {
|
|
|
|
|
final List<Thread> syncList = Collections.synchronizedList(new LinkedList<Thread>()); // memory for threads
|
|
|
|
|
final serverSemaphore sync = new serverSemaphore(attempts);
|
|
|
|
|
|
|
|
|
|
// This will try to get Peers that are not currently in amIAccessibleDB
|
|
|
|
|
Iterator<yacySeed> si = seeds.values().iterator();
|
|
|
|
|
yacySeed seed;
|
|
|
|
|
|
|
|
|
|
// going through the peer list and starting a new publisher thread for each peer
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (si.hasNext()) {
|
|
|
|
|
seed = (yacySeed) si.next();
|
|
|
|
|
seed = si.next();
|
|
|
|
|
if (seed == null) {
|
|
|
|
|
sync.P();
|
|
|
|
|
continue;
|
|
|
|
@ -445,8 +438,8 @@ public class yacyCore {
|
|
|
|
|
|
|
|
|
|
final String address = seed.getClusterAddress();
|
|
|
|
|
log.logFine("HELLO #" + i + " to peer '" + seed.get(yacySeed.NAME, "") + "' at " + address); // debug
|
|
|
|
|
String seederror = seed.isProper();
|
|
|
|
|
if ((address == null) || (seederror != null)) {
|
|
|
|
|
final String seederror = seed.isProper();
|
|
|
|
|
if (address == null || seederror != null) {
|
|
|
|
|
// we don't like that address, delete it
|
|
|
|
|
peerActions.peerDeparture(seed, "peer ping to peer resulted in address = " + address + "; seederror = " + seederror);
|
|
|
|
|
sync.P();
|
|
|
|
@ -489,9 +482,9 @@ public class yacyCore {
|
|
|
|
|
final int dbSize;
|
|
|
|
|
synchronized (amIAccessibleDB) {
|
|
|
|
|
dbSize = amIAccessibleDB.size();
|
|
|
|
|
Iterator<String> ai = amIAccessibleDB.keySet().iterator();
|
|
|
|
|
final Iterator<String> ai = amIAccessibleDB.keySet().iterator();
|
|
|
|
|
while (ai.hasNext()) {
|
|
|
|
|
yacyAccessible ya = (yacyAccessible) amIAccessibleDB.get(ai.next());
|
|
|
|
|
final yacyAccessible ya = (yacyAccessible) amIAccessibleDB.get(ai.next());
|
|
|
|
|
if (ya.lastUpdated < cutofftime) {
|
|
|
|
|
ai.remove();
|
|
|
|
|
} else {
|
|
|
|
@ -507,11 +500,11 @@ public class yacyCore {
|
|
|
|
|
log.logInfo("PeerPing: I am accessible for " + accessible +
|
|
|
|
|
" peer(s), not accessible for " + notaccessible + " peer(s).");
|
|
|
|
|
|
|
|
|
|
if ((accessible + notaccessible) > 0) {
|
|
|
|
|
if (accessible + notaccessible > 0) {
|
|
|
|
|
final String newPeerType;
|
|
|
|
|
// At least one other Peer told us our type
|
|
|
|
|
if ((accessible >= PING_MIN_PEERSEEN) ||
|
|
|
|
|
(accessible >= notaccessible)) {
|
|
|
|
|
if (accessible >= PING_MIN_PEERSEEN ||
|
|
|
|
|
accessible >= notaccessible) {
|
|
|
|
|
// We can be reached from a majority of other Peers
|
|
|
|
|
if (yacyCore.seedDB.mySeed().isPrincipal()) {
|
|
|
|
|
newPeerType = yacySeed.PEERTYPE_PRINCIPAL;
|
|
|
|
@ -522,11 +515,11 @@ public class yacyCore {
|
|
|
|
|
// We cannot be reached from the outside
|
|
|
|
|
newPeerType = yacySeed.PEERTYPE_JUNIOR;
|
|
|
|
|
}
|
|
|
|
|
if (yacyCore.seedDB.mySeed().orVirgin().equals(newPeerType)) {
|
|
|
|
|
if (yacyCore.seedDB.mySeed().isType(newPeerType)) {
|
|
|
|
|
log.logInfo("PeerPing: myType is " + yacyCore.seedDB.mySeed().orVirgin());
|
|
|
|
|
} else {
|
|
|
|
|
log.logInfo("PeerPing: changing myType from '" + yacyCore.seedDB.mySeed().orVirgin() + "' to '" + newPeerType + "'");
|
|
|
|
|
yacyCore.seedDB.mySeed().put(yacySeed.PEERTYPE, newPeerType);
|
|
|
|
|
yacyCore.seedDB.mySeed().setType(newPeerType);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.logInfo("PeerPing: No data, staying at myType: " + yacyCore.seedDB.mySeed().orVirgin());
|
|
|
|
|