i2psnark: Fix torrent ignoring priority settings when autostart is enabled (ticket #2229)

This commit is contained in:
zzz
2018-06-09 13:42:12 +00:00
parent 7b3791627c
commit 20145333f4
6 changed files with 27 additions and 16 deletions

View File

@ -300,20 +300,25 @@ public class Snark
/**
* multitorrent
*
* Will not start itself. Caller must call startTorrent() if desired.
*
* @throws RuntimeException via fatal()
*/
public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port,
StorageListener slistener, CoordinatorListener clistener,
CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor, boolean start, String rootDir)
ConnectionAcceptor connectionAcceptor, String rootDir)
{
this(util, torrent, ip, user_port, slistener, clistener, complistener,
peerCoordinatorSet, connectionAcceptor, start, rootDir, null);
peerCoordinatorSet, connectionAcceptor, rootDir, null);
}
/**
* multitorrent
*
* Will not start itself. Caller must call startTorrent() if desired.
*
* @param baseFile if null, use rootDir/torrentName; if non-null, use it instead
* @throws RuntimeException via fatal()
* @since 0.9.11
@ -321,7 +326,7 @@ public class Snark
public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port,
StorageListener slistener, CoordinatorListener clistener,
CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor, boolean start, String rootDir, File baseFile)
ConnectionAcceptor connectionAcceptor, String rootDir, File baseFile)
{
if (slistener == null)
slistener = this;
@ -482,14 +487,13 @@ public class Snark
savedUploaded = (completeListener != null) ? completeListener.getSavedUploaded(this) : 0;
if (completeListener != null)
_comments = completeListener.getSavedComments(this);
if (start)
startTorrent();
}
/**
* multitorrent, magnet
*
* Will not start itself. Caller must call startTorrent() if desired.
*
* @param torrent a fake name for now (not a file name)
* @param ih 20-byte info hash
* @param trackerURL may be null
@ -498,7 +502,7 @@ public class Snark
*/
public Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL,
CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor, boolean start, String rootDir)
ConnectionAcceptor connectionAcceptor, String rootDir)
{
completeListener = complistener;
_util = util;
@ -516,9 +520,6 @@ public class Snark
// All we have is an infoHash
// meta remains null
// storage remains null
if (start)
startTorrent();
}
private static byte[] generateID() {

View File

@ -1555,11 +1555,13 @@ public class SnarkManager implements CompleteListener, ClientApp {
_log.info("New Snark, torrent: " + filename + " base: " + baseFile);
torrent = new Snark(_util, filename, null, -1, null, null, this,
_peerCoordinatorSet, _connectionAcceptor,
shouldAutoStart(), dataDir.getPath(), baseFile);
dataDir.getPath(), baseFile);
loadSavedFilePriorities(torrent);
synchronized (_snarks) {
_snarks.put(filename, torrent);
}
if (shouldAutoStart())
torrent.startTorrent();
} catch (IOException ioe) {
// close before rename/delete for windows
if (fis != null) try { fis.close(); fis = null; } catch (IOException ioe2) {}
@ -1660,7 +1662,7 @@ public class SnarkManager implements CompleteListener, ClientApp {
String dirPath = dataDir != null ? dataDir.getAbsolutePath() : getDataDir().getPath();
Snark torrent = new Snark(_util, name, ih, trackerURL, listener,
_peerCoordinatorSet, _connectionAcceptor,
false, dirPath);
dirPath);
synchronized (_snarks) {
Snark snark = getTorrentByInfoHash(ih);

View File

@ -72,7 +72,7 @@ public class FetchAndAdd extends Snark implements EepGet.StatusListener, Runnabl
public FetchAndAdd(I2PAppContext ctx, SnarkManager mgr, String url, File dataDir) {
// magnet constructor
super(mgr.util(), "Torrent download",
null, null, null, null, null, false, null);
null, null, null, null, null, null);
_ctx = ctx;
_log = ctx.logManager().getLog(FetchAndAdd.class);
_mgr = mgr;

View File

@ -3914,7 +3914,7 @@ public class I2PSnarkServlet extends BasicServlet {
} catch (Throwable t) { t.printStackTrace(); }
}
}
snark.updatePiecePriorities();
snark.updatePiecePriorities();
_manager.saveTorrentStatus(snark);
}