- Thread task to open tunnel and improve UI feedback while open is pending

This commit is contained in:
zzz
2012-06-18 21:07:34 +00:00
parent 4dcfe3e434
commit 4b3ccabb44
4 changed files with 124 additions and 23 deletions

View File

@@ -250,6 +250,7 @@ public class Snark
private String rootDataDir = ".";
private final CompleteListener completeListener;
private boolean stopped;
private boolean starting;
private byte[] id;
private byte[] infoHash;
private String additionalTrackerURL;
@@ -509,9 +510,19 @@ public class Snark
}
/**
* Start up contacting peers and querying the tracker
* Start up contacting peers and querying the tracker.
* Blocks if tunnel is not yet open.
*/
public void startTorrent() {
public synchronized void startTorrent() {
starting = true;
try {
x_startTorrent();
} finally {
starting = false;
}
}
private void x_startTorrent() {
boolean ok = _util.connect();
if (!ok) fatal("Unable to connect to I2P");
if (coordinator == null) {
@@ -585,7 +596,7 @@ public class Snark
* @param fast if true, limit the life of the unannounce threads
* @since 0.9.1
*/
public void stopTorrent(boolean fast) {
public synchronized void stopTorrent(boolean fast) {
stopped = true;
TrackerClient tc = trackerclient;
if (tc != null)
@@ -680,6 +691,22 @@ public class Snark
return stopped;
}
/**
* Startup in progress.
* @since 0.9.1
*/
public boolean isStarting() {
return starting && stopped;
}
/**
* Set startup in progress.
* @since 0.9.1
*/
public void setStarting() {
starting = true;
}
/**
* @since 0.8.4
*/