📄 startstoprulesdefaultplugin.java
字号:
"tDLing="+totalDownloading,
"actvDLs="+activeDLCount,
"tW8tingToDL="+totalWaitingToDL,
"tCom="+totalComplete,
"tIncQd="+totalIncompleteQueued,
"mxCdrs="+maxSeeders,
"t1stPr="+totalFirstPriority,
"maxT="+maxTorrents
};
}
somethingChanged = false;
// Sort by SeedingRank
if (iRankType != RANK_NONE)
Arrays.sort(dlDataArray);
else
Arrays.sort(dlDataArray, new Comparator () {
public final int compare (Object a, Object b) {
Download aDL = ((downloadData)a).getDownloadObject();
Download bDL = ((downloadData)b).getDownloadObject();
boolean aIsComplete = aDL.getStats().getDownloadCompleted(false) == 1000;
boolean bIsComplete = bDL.getStats().getDownloadCompleted(false) == 1000;
if (aIsComplete && !bIsComplete)
return 1;
if (!aIsComplete && bIsComplete)
return -1;
boolean aIsFP = ((downloadData)a).isFirstPriority();
boolean bIsFP = ((downloadData)b).isFirstPriority();
if (aIsFP && !bIsFP)
return -1;
if (!aIsFP && bIsFP)
return 1;
return aDL.getPosition() - bDL.getPosition();
}
} );
// pre-included Forced Start torrents so a torrent "above" it doesn't
// start (since normally it would start and assume the torrent below it
// would stop)
int numWaitingOrSeeding = totalForcedSeeding; // Running Count
int numWaitingOrDLing = 0; // Running Count
/**
* store whether there's a torrent higher in the list that is queued
* We don't want to start a torrent lower in the list if there's a higherQueued
*/
boolean higherQueued = false;
/**
* Tracks the position we should be at in the Completed torrents list
* Updates position.
*/
int posComplete = 0;
int iSeedingPos = 0;
// Loop 2 of 2:
// - Start/Stop torrents based on criteria
// find the smallest entry ready to be initialised so that we hash-check
// the smallest files first
long smallest_size = 0x7fffffffffffffffL;
int smallest_size_index = -1;
for (int i = 0; i < dlDataArray.length; i++) {
downloadData dlData = dlDataArray[i];
Download download = dlData.getDownloadObject();
if ( download.getState() == Download.ST_WAITING &&
( download.getStats().getDownloadCompleted(false) == 1000 || // PARG - kick off all seeders straight away
// as we don't want time-consuming rechecking
// to hold up seeding
!getAlreadyAllocatingOrChecking())) {
Torrent t = download.getTorrent();
if ( t == null ){
// broken torrent, set index in case nothing else matches
smallest_size_index = i;
}else{
long size = t.getSize();
if ( size < smallest_size ){
smallest_size = size;
smallest_size_index = i;
}
}
}
}
for (int i = 0; i < dlDataArray.length; i++) {
downloadData dlData = dlDataArray[i];
Download download = dlData.getDownloadObject();
boolean bStopAndQueued = false;
dlData.sTrace = "";
// Initialize STATE_WAITING torrents
if ( i == smallest_size_index ){
try{
download.initialize();
}catch (Exception ignore) {/*ignore*/}
}
if (bAutoReposition &&
(iRankType != RANK_NONE) &&
download.getStats().getDownloadCompleted(false) == 1000 &&
bSeedHasRanking)
download.setPosition(++posComplete);
if (download.getStats().getDownloadCompleted(false) == 1000)
dlData.setSeedingPos(++iSeedingPos);
// Never do anything to stopped entries
if (download.getState() == Download.ST_STOPPING ||
download.getState() == Download.ST_STOPPED ||
download.getState() == Download.ST_ERROR) {
continue;
}
// Handle incomplete DLs
if (download.getStats().getDownloadCompleted(false) != 1000) {
if (bDebugLog) {
String s = ">> "+download.getTorrent().getName()+
"]: state="+sStates.charAt(download.getState())+
";shareRatio="+download.getStats().getShareRatio()+
";numW8tngorDLing="+numWaitingOrDLing+
";maxCDrs="+maxSeeders+
";forced="+download.isForceStart()+
";forcedStart="+download.isForceStart()+
";actvDLs="+activeDLCount+
"";
log.log(LoggerChannel.LT_INFORMATION, s);
dlData.sTrace += s + "\n";
}
if (download.isForceStart())
continue;
int state = download.getState();
if (state == Download.ST_PREPARING) {
// Don't mess with preparing torrents. they could be in the
// middle of resume-data building, or file allocating.
numWaitingOrDLing++;
} else if (state == Download.ST_READY ||
state == Download.ST_DOWNLOADING ||
state == Download.ST_WAITING) {
boolean bActivelyDownloading = dlData.getActivelyDownloading();
// Stop torrent if over limit
if ((maxDownloads != 0) &&
(numWaitingOrDLing >= maxDownloads - iExtraFPs) &&
(bActivelyDownloading || state != Download.ST_DOWNLOADING)) {
try {
if (bDebugLog) {
String s = " stopAndQueue() > maxDownloads";
log.log(LoggerChannel.LT_INFORMATION, s);
dlData.sTrace += s + "\n";
}
download.stopAndQueue();
// reduce counts
if (state == Download.ST_DOWNLOADING) {
totalDownloading--;
if (bActivelyDownloading)
activeDLCount--;
} else {
totalWaitingToDL--;
}
maxSeeders = calcMaxSeeders(activeDLCount + totalWaitingToDL);
} catch (Exception ignore) {/*ignore*/}
state = download.getState();
} else if (bActivelyDownloading) {
numWaitingOrDLing++;
}
}
if (state == Download.ST_QUEUED) {
if ((maxDownloads == 0) || (numWaitingOrDLing < maxDownloads - iExtraFPs)) {
try {
if (bDebugLog) {
String s = " restart()";
log.log(LoggerChannel.LT_INFORMATION, s);
dlData.sTrace += s + "\n";
}
download.restart();
// increase counts
totalWaitingToDL++;
numWaitingOrDLing++;
maxSeeders = calcMaxSeeders(activeDLCount + totalWaitingToDL);
} catch (Exception ignore) {/*ignore*/}
state = download.getState();
}
}
if (state == Download.ST_READY) {
if ((maxDownloads == 0) || (activeDLCount < maxDownloads - iExtraFPs)) {
try {
if (bDebugLog) {
String s = " start() activeDLCount < maxDownloads";
log.log(LoggerChannel.LT_INFORMATION, s);
dlData.sTrace += s + "\n";
}
download.start();
// adjust counts
totalWaitingToDL--;
activeDLCount++;
numWaitingOrDLing++;
maxSeeders = calcMaxSeeders(activeDLCount + totalWaitingToDL);
} catch (Exception ignore) {/*ignore*/}
state = download.getState();
}
}
if (bDebugLog) {
String s = "<< "+download.getTorrent().getName()+
"]: state="+sStates.charAt(download.getState())+
";shareRatio="+download.getStats().getShareRatio()+
";numW8tngorDLing="+numWaitingOrDLing+
";maxCDrs="+maxSeeders+
";forced="+download.isForceStart()+
";forcedStart="+download.isForceStart()+
";actvDLs="+activeDLCount+
"";
log.log(LoggerChannel.LT_INFORMATION, s);
dlData.sTrace += s + "\n";
}
}
else if (bSeedHasRanking || totalFirstPriority > 0) { // completed
String[] debugEntries = null;
String sDebugLine = "";
// Queuing process:
// 1) Torrent is Queued (Stopped)
// 2) Slot becomes available
// 3) Queued Torrent changes to Waiting
// 4) Waiting Torrent changes to Ready
// 5) Ready torrent changes to Seeding (with startDownload)
// 6) Trigger stops Seeding torrent
// a) Queue Ranking drops
// b) User pressed stop
// c) other
// 7) Seeding Torrent changes to Queued. Go to step 1.
boolean isFP = dlData.isFirstPriority();
if (!bSeedHasRanking && !isFP)
continue;
int state = download.getState();
int numPeers = calcPeersNoUs(download);
// Ignore rules and other auto-starting rules do not apply when
// bAutoStart0Peers and peers == 0. So, handle starting 0 peers
// right at the beginning, and loop early
if (bAutoStart0Peers && numPeers == 0 && scrapeResultOk(download)) {
if (state == Download.ST_QUEUED) {
try {
if (bDebugLog)
sDebugLine += "\nrestart() 0Peers";
download.restart(); // set to Waiting
state = download.getState();
if (state == Download.ST_READY) {
if (bDebugLog)
sDebugLine += "\nstart(); 0Peers";
download.start();
}
} catch (Exception ignore) {/*ignore*/}
}
if (state == Download.ST_READY) {
try {
if (bDebugLog)
sDebugLine += "\nstart(); 0Peers";
download.start();
} catch (Exception ignore) {/*ignore*/}
}
continue;
}
int shareRatio = download.getStats().getShareRatio();
boolean bActivelySeeding = dlData.getActivelySeeding();
boolean okToQueue = (state == Download.ST_READY || state == Download.ST_SEEDING) &&
(!download.isForceStart()) &&
(!isFP);
// in RANK_TIMED mode, we use minTimeAlive for rotation time, so
// skip check
if (okToQueue && (state == Download.ST_SEEDING) && iRankType != RANK_TIMED) {
long timeAlive = (SystemTime.getCurrentTime() - download.getStats().getTimeStarted());
okToQueue = (timeAlive >= minTimeAlive);
}
if (state != Download.ST_QUEUED && // Short circuit.
(state == Download.ST_READY ||
state == Download.ST_WAITING ||
state == Download.ST_PREPARING ||
// Forced Start torrents are pre-included in count
(state == Download.ST_SEEDING && bActivelySeeding && !download.isForceStart())
)) {
numWaitingOrSeeding++;
}
if (bDebugLog) {
debugEntries = new String[] { "state="+sStates.charAt(state),
"shareR="+shareRatio,
"nWorCDing="+numWaitingOrSeeding,
"nWorDLing="+numWaitingOrDLing,
"ok2Q="+okToQueue,
"sr="+dlData.getSeedingRank(),
"hgherQd="+higherQueued,
"maxCDrs="+maxSeeders,
"1stP="+isFP,
"actCDingCount="+activeSeedingCount,
"ActCDing="+bActivelySeeding
};
}
// Note: First Priority have the highest SeedingRank,
// so they will always start first
// Process some ignore rules
// If torrent maches criteria, the SeedingRank will be <= -2 and will be
// stopped later in the code
if (okToQueue) {
int numSeeds = calcSeedsNoUs(download);
// ignore when Share Ratio reaches # in config
//0 means unlimited
if (iIgnoreShareRatio != 0 &&
shareRatio > iIgnoreShareRatio &&
numSeeds >= iIgnoreShareRatio_SeedStart &&
shareRatio != -1 &&
dlData.getSeedingRank() != SR_SHARERATIOMET)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -