0n: modified the p2p bootstraping process - rules had been too tight and

did not support the re-start of a network with just one principal peer.
pull/46/head
Michael Peter Christen 9 years ago
parent d05ffa1c51
commit 849ab671a9

@ -197,20 +197,9 @@ public class Network
{
private Map<String, String> result;
private final Seed seed;
private final Semaphore sync;
private final List<Thread> syncList;
public publishThread(
final ThreadGroup tg,
final Seed seed,
final Semaphore sync,
final List<Thread> syncList) throws InterruptedException {
super(tg, "PublishSeed_" + seed.getName());
this.sync = sync;
this.sync.acquire();
this.syncList = syncList;
public publishThread(final ThreadGroup tg, final Seed seed) {
super(tg, "PublishSeed_" + seed.getName());
this.seed = seed;
this.result = null;
}
@ -266,9 +255,6 @@ public class Network
log.severe(
"publishThread: error with target seed " + this.seed.toString() + ": " + e.getMessage(),
e);
} finally {
this.syncList.add(this);
this.sync.release();
}
}
}
@ -300,7 +286,7 @@ public class Network
if ( this.sb.peers.mySeed().get(Seed.PEERTYPE, Seed.PEERTYPE_VIRGIN).equals(Seed.PEERTYPE_VIRGIN) ) {
if (attempts > PING_INITIAL) attempts = PING_INITIAL;
final Set<byte[]> ch = Switchboard.getSwitchboard().clusterhashes;
seeds = DHTSelection.seedsByAge(this.sb.peers, true, attempts - ((ch == null) ? 0 : ch.size())); // best for fast connection
seeds = DHTSelection.seedsByAge(this.sb.peers, true, Math.max(1, attempts - ((ch == null) ? 0 : ch.size()))); // best for fast connection
// add also all peers from cluster if this is a public robinson cluster
if ( ch != null ) {
String hash;
@ -351,16 +337,13 @@ public class Network
this.sb.peers.mySeed().setUnusedFlags();
//if (seeds.length > 1) {
// holding a reference to all started threads
int contactedSeedCount = 0;
final List<Thread> syncList = Collections.synchronizedList(new LinkedList<Thread>()); // memory for threads
final Semaphore sync = new Semaphore(attempts);
final List<publishThread> syncList = Collections.synchronizedList(new LinkedList<publishThread>()); // memory for threads
// go through the peer list and starting a new publisher thread for each peer
int i = 0;
while ( si.hasNext() ) {
seed = si.next();
if ( seed == null || seed.hash.equals(this.sb.peers.mySeed().hash)) {
sync.acquire();
continue;
}
i++;
@ -372,29 +355,18 @@ public class Network
if ( (address == null) || (seederror != null) ) {
// we don't like that address, delete it
this.sb.peers.peerActions.interfaceDeparture(seed, ip);
sync.acquire();
} else {
// starting a new publisher thread
contactedSeedCount++;
(new publishThread(Network.publishThreadGroup, seed, sync, syncList)).start();
publishThread t = new publishThread(Network.publishThreadGroup, seed);
t.start();
syncList.add(t);
}
}
// receiving the result of all started publisher threads
for ( int j = 0; j < contactedSeedCount; j++ ) {
for (publishThread t: syncList) {
// waiting for the next thread to finish
sync.acquire();
// if this is true something is wrong ...
if ( syncList.isEmpty() ) {
log.warn("PeerPing: syncList.isEmpty()==true");
continue;
//return 0;
}
// getting a reference to the finished thread
final publishThread t = (publishThread) syncList.remove(0);
t.join();
}
int accessible = 0;

@ -103,9 +103,9 @@ public class PeerActions {
ctimeUTC0 = nowUTC0Time;
assert (seed.getLastSeenUTC() - ctimeUTC0 < 100);
}
if (Math.abs(nowUTC0Time - ctimeUTC0) / 1000 / 60 > 60 * 6 ) {
if (Math.abs(nowUTC0Time - ctimeUTC0) / 1000 / 60 > 1440 ) {
// the new connection is out-of-age, we reject the connection
if (Network.log.isFine()) Network.log.fine("connect: rejecting out-dated peer '" + seed.getName() + "' from " + seed.getIPs() + "; nowUTC0=" + nowUTC0Time + ", seedUTC0=" + ctimeUTC0 + ", TimeDiff=" + formatInterval(Math.abs(nowUTC0Time - ctimeUTC0)));
if (Network.log.isFine()) Network.log.info("connect: rejecting out-dated peer '" + seed.getName() + "' from " + seed.getIPs() + "; nowUTC0=" + nowUTC0Time + ", seedUTC0=" + ctimeUTC0 + ", TimeDiff=" + formatInterval(Math.abs(nowUTC0Time - ctimeUTC0)));
return false;
}
@ -139,6 +139,7 @@ public class PeerActions {
// has been disconnected then we compare the dates:
// if the new peer has a LastSeen date, and that date is before
// the disconnection date, then we ignore the new peer
/*
if (!direct) {
if (ctimeUTC0 < dtimeUTC0) {
// the disconnection was later, we reject the connection
@ -146,6 +147,7 @@ public class PeerActions {
return false;
}
}
*/
// this is a return of a lost peer
if (Network.log.isFine()) Network.log.fine("connect: returned KNOWN " + peerType + " peer '" + seed.getName() + "' from " + seed.getIPs());
@ -158,10 +160,12 @@ public class PeerActions {
try {
// if the old LastSeen date is later then the other
// info, then we reject the info
if ((ctimeUTC0 < (connectedSeed.getLastSeenUTC())) && (!direct)) {
if (Network.log.isFine()) Network.log.fine("connect: rejecting old info about peer '" + seed.getName() + "'");
return false;
}
/*if (connectedSeed.getName() != seed.getName()) {
// TODO: update seed name lookup cache

@ -1675,9 +1675,8 @@ public final class Switchboard extends serverSwitch {
// we need to take care that search requests and remote indexing requests go only
// to the peers in the same cluster, if we run a robinson cluster.
return (this.peers != null && this.peers.sizeConnected() == 0)
|| (!getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, false) && !getConfigBool(
SwitchboardConstants.INDEX_RECEIVE_ALLOW,
false));
|| (!getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, false) &&
!getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false));
}
public boolean isPublicRobinson() {
@ -4007,7 +4006,7 @@ public final class Switchboard extends serverSwitch {
if ( (ys != null)
&& (!peers.mySeedIsDefined() || !peers.mySeed().hash.equals(ys.hash)) ) {
final long lastseen = Math.abs((System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60);
if ( lastseen < 60 ) {
if ( lastseen < 1440 || lc < 10 ) {
if ( peers.peerActions.connectPeer(ys, false) ) {
lc++;
}

Loading…
Cancel
Save