* i2psnark: Don't create a new PeerCoordinator after restart, as the

TrackerClient holds on to the old one and that causes it
             to not get peers. Possibly fixes ticket #563.
This commit is contained in:
zzz
2012-06-24 19:26:23 +00:00
parent 1671e3b126
commit ff0bfb9f12
4 changed files with 20 additions and 13 deletions

View File

@ -125,7 +125,7 @@ class PeerCoordinator implements PeerListener
/** partial pieces - lock by synching on wantedPieces - TODO store Requests, not PartialPieces */
private final List<PartialPiece> partialPieces;
private boolean halted = false;
private volatile boolean halted;
private final MagnetState magnetState;
private final CoordinatorListener listener;
@ -429,6 +429,14 @@ class PeerCoordinator implements PeerListener
}
}
/**
* @since 0.9.1
*/
public void restart() {
halted = false;
timer.schedule((CHECK_PERIOD / 2) + _random.nextInt((int) CHECK_PERIOD));
}
public void connected(Peer peer)
{
if (halted)

View File

@ -553,21 +553,14 @@ public class Snark
}
stopped = false;
boolean coordinatorChanged = false;
if (coordinator.halted()) {
// ok, we have already started and stopped, but the coordinator seems a bit annoying to
// restart safely, so lets build a new one to replace the old
coordinator.restart();
if (_peerCoordinatorSet != null)
_peerCoordinatorSet.remove(coordinator);
PeerCoordinator newCoord = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
if (_peerCoordinatorSet != null)
_peerCoordinatorSet.add(newCoord);
coordinator = newCoord;
coordinatorChanged = true;
_peerCoordinatorSet.add(coordinator);
}
if (!trackerclient.started() && !coordinatorChanged) {
if (!trackerclient.started()) {
trackerclient.start();
} else if (trackerclient.halted() || coordinatorChanged) {
} else if (trackerclient.halted()) {
if (storage != null) {
try {
storage.reopen(rootDataDir);