⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startstoprulesdefaultplugin.java

📁 Azureus is a powerful, full-featured, cross-platform java BitTorrent client
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	          {
	            if (bDebugLog)
	              sDebugLine += "\nShare Ratio Met";
	            dlData.setSeedingRank(SR_SHARERATIOMET);
	          }
	  
	          // Ignore when P:S ratio met
	          if (iIgnoreRatioPeers != 0 && 
	              dlData.getSeedingRank() != SR_RATIOMET) 
	          {
	            if (numPeersAsFullCopy != 0 && numSeeds >= iFakeFullCopySeedStart)
	                numSeeds += numPeers / numPeersAsFullCopy;
	            //If there are no seeds, avoid / by 0
	            if (numSeeds != 0 && numSeeds >= iIgnoreRatioPeers_SeedStart) {
	              float ratio = (float) numPeers / numSeeds;
	              if (ratio <= iIgnoreRatioPeers) {
	                sDebugLine += "\nP:S Met";
	                dlData.setSeedingRank(SR_RATIOMET);
	              }
	            }
	          }
	
	        // Change to waiting if queued and we have an open slot
	        } else if ((state == Download.ST_QUEUED) &&
	                   (numWaitingOrSeeding < maxSeeders) && 
	                   ((activeSeedingCount + totalStalledSeeders - total0PeerSeeders + totalDownloading) < maxTorrents) &&
	                   (dlData.getSeedingRank() > -2) && 
	                   !higherQueued) {
	          try {
	            if (bDebugLog)
	              sDebugLine += "\nrestart() numWaitingOrSeeding < maxSeeders";
	            download.restart(); // set to Waiting
	            okToQueue = false;
	            totalWaitingToSeed++;
	            numWaitingOrSeeding++;
	            if (iRankType == RANK_TIMED)
	              dlData.recalcSeedingRank();
	          } catch (Exception ignore) {/*ignore*/}
	          state = download.getState();
	        }
	        
	        // Start download if ready and slot is available
	        if (state == Download.ST_READY && activeSeedingCount < maxSeeders) {
	
	          if (dlData.getSeedingRank() > -2) {
	            try {
	              if (bDebugLog)
	                sDebugLine += "\nstart(); activeSeedingCount < maxSeeders";
	              download.start();
	              okToQueue = false;
	            } catch (Exception ignore) {/*ignore*/}
	            state = download.getState();
	            activeSeedingCount++;
	
	          } else if (okToQueue) {
	            // In between switching from STATE_WAITING and STATE_READY,
	            // and ignore rule was met, so move it back to Queued
	            try {
	              if (bDebugLog)
	                sDebugLine += "\nstopAndQueue()";
	              download.stopAndQueue();
	              bStopAndQueued = true;
	              totalWaitingToSeed--;
	              if (bActivelySeeding)
	                numWaitingOrSeeding--;
	            } catch (Exception ignore) {/*ignore*/}
	            state = download.getState();
	          }
	        }
	
	
	        // if there's more torrents waiting/seeding than our max, or if
	        // there's a higher ranked torrent queued, stop this one
	        if (okToQueue &&
	            (bActivelySeeding || state != Download.ST_SEEDING) &&
	            ((numWaitingOrSeeding > maxSeeders) || 
	             higherQueued || 
	             dlData.getSeedingRank() <= -2)) 
	        {
	          try {
	            if (bDebugLog) {
	              sDebugLine += "\nstopAndQueue()";
	              if (numWaitingOrSeeding > maxSeeders)
	                sDebugLine += "; > Max";
	              if (higherQueued)
	                sDebugLine += "; higherQueued (it should be seeding instead of this one)";
	              if (dlData.getSeedingRank() <= -2)
	                sDebugLine += "; ignoreRule met";
	            }
	
	            if (state == Download.ST_READY)
	              totalWaitingToSeed--;
	
	            download.stopAndQueue();
	            bStopAndQueued = true;
	            // okToQueue only allows READY and SEEDING state.. and in both cases
	            // we have to reduce counts
	            if (bActivelySeeding) {
	              activeSeedingCount--;
	              numWaitingOrSeeding--;
	            }
	          } catch (Exception ignore) {/*ignore*/}
	          state = download.getState();
	        }
	
	        // move completed timed rank types to bottom of the list
	        if (bStopAndQueued && iRankType == RANK_TIMED) {
	          for (int j = 0; j < dlDataArray.length; j++) {
	            int sr = dlDataArray[j].getSeedingRank();
	            if (sr > 0 && sr < SR_TIMED_QUEUED_ENDS_AT) {
	              // Move everyone up
	              // We always start by setting SR to SR_TIMED_QUEUED_ENDS_AT - position
	              // then, the torrent with the biggest starts seeding which is
	              // (SR_TIMED_QUEUED_ENDS_AT - 1), leaving a gap.
	              // when it's time to stop the torrent, move everyone up, and put 
	              // us at the end
	              dlDataArray[j].setSeedingRank(sr + 1);
	            }
	          }
	          dlData.setSeedingRank(SR_TIMED_QUEUED_ENDS_AT - totalComplete);
	        }
	
	        if (download.getState() == Download.ST_QUEUED && 
	            dlData.getSeedingRank() >= 0)
	          higherQueued = true;
	
	        if (bDebugLog) {
	          String[] debugEntries2 = new String[] { "state="+sStates.charAt(download.getState()),
	                           "shareR="+download.getStats().getShareRatio(),
	                           "nWorCDing="+numWaitingOrSeeding,
	                           "nWorDLing="+numWaitingOrDLing,
	                           "ok2Q="+okToQueue,
	                           "sr="+dlData.getSeedingRank(),
	                           "hgherQd="+higherQueued,
	                           "maxCDrs="+maxSeeders,
	                           "1stP="+dlData.isFirstPriority(),
	                           "actCDingCount="+activeSeedingCount,
	                           "ActCDing="+bActivelySeeding
	                          };
	          printDebugChanges(download.getName() + "] ", debugEntries, debugEntries2, sDebugLine, "  ", true, dlData);
	        }
	
	      } // getDownloadCompleted == 1000
	    } // Loop 2/2 (Start/Stopping)
	    
	    if (bDebugLog) {
	      String[] mainDebugEntries2 = new String[] { 
	          "bHasSR="+bSeedHasRanking,
	          "tFrcdCding="+totalForcedSeeding,
	          "actvCDs="+activeSeedingCount,
	          "tW8tingToCd="+totalWaitingToSeed,
	          "tDLing="+totalDownloading,
	          "actvDLs="+activeDLCount,
	          "tW8tingToDL="+totalWaitingToDL,
	          "tCom="+totalComplete,
	          "tIncQd="+totalIncompleteQueued,
	          "mxCdrs="+maxSeeders,
	          "t1stPr="+totalFirstPriority,
	          "maxT="+maxTorrents
	                  };
	      printDebugChanges("<<process() ", mainDebugEntries, mainDebugEntries2, "", "", true, null);
	    }
  	}finally{
  		
  		this_mon.exit();
  	}
  } // process()
  
  private void printDebugChanges(String sPrefixFirstLine, 
                                 String[] oldEntries, 
                                 String[] newEntries,
                                 String sDebugLine,
                                 String sPrefix, 
                                 boolean bAlwaysPrintNoChangeLine,
                                 downloadData dlData) {
      boolean bAnyChanged = false;
      String sDebugLineNoChange = sPrefixFirstLine;
      String sDebugLineOld = "";
      String sDebugLineNew = "";
      for (int j = 0; j < oldEntries.length; j++) {
        if (oldEntries[j].equals(newEntries[j]))
          sDebugLineNoChange += oldEntries[j] + ";";
        else {
          sDebugLineOld += oldEntries[j] + ";";
          sDebugLineNew += newEntries[j] + ";";
          bAnyChanged = true;
        }
      }
      String sDebugLineOut = ((bAlwaysPrintNoChangeLine || bAnyChanged) ? sDebugLineNoChange : "") +
                             (bAnyChanged ? "\nOld:"+sDebugLineOld+"\nNew:"+sDebugLineNew : "") + 
                             sDebugLine;
      if (!sDebugLineOut.equals("")) {
        String[] lines = sDebugLineOut.split("\n");
        for (int i = 0; i < lines.length; i++) {
          String s = sPrefix + ((i>0)?"  ":"") + lines[i];
          log.log(LoggerChannel.LT_INFORMATION, s);
          if (dlData != null) dlData.sTrace += s + "\n";
        }
      }
  }

  public boolean getAlreadyAllocatingOrChecking() {
    Download[]  downloads = download_manager.getDownloads(false);
    for (int i=0;i<downloads.length;i++){
      Download  download = downloads[i];
      int state = download.getState();
      if (state == Download.ST_PREPARING)
        return true;
    }
    return false;
  }



  /*
   * Get # of peers not including us
   *
   * I don't trust AccounceResult.getReportedPeerCount because we pass
   * num_peers=50 in the URL.. which means we only get 50 back (??)
   *
  */
  public int calcPeersNoUs(Download download) {
    int numPeers = 0;
    DownloadScrapeResult sr = download.getLastScrapeResult();
    if (sr.getScrapeStartTime() > 0) {
      numPeers = sr.getNonSeedCount();
      // If we've scraped after we started downloading
      // Remove ourselves from count
      if ((numPeers > 0) &&
          (download.getState() == Download.ST_DOWNLOADING) &&
          (sr.getScrapeStartTime() > download.getStats().getTimeStarted()))
        numPeers--;
    }
    if (numPeers == 0) {
      DownloadAnnounceResult ar = download.getLastAnnounceResult();
      if (ar != null && ar.getResponseType() == DownloadAnnounceResult.RT_SUCCESS)
        numPeers = ar.getNonSeedCount();
    }
    return numPeers;
  }
  
  public boolean scrapeResultOk(Download download) {
    DownloadScrapeResult sr = download.getLastScrapeResult();
    return (sr.getResponseType() == DownloadScrapeResult.RT_SUCCESS);
  }

  public int calcSeedsNoUs(Download download) {
    int numSeeds = 0;
    DownloadScrapeResult sr = download.getLastScrapeResult();
    if (sr.getScrapeStartTime() > 0) {
      long seedingStartedOn = download.getStats().getTimeStartedSeeding();
      numSeeds = sr.getSeedCount();
      // If we've scraped after we started seeding
      // Remove ourselves from count
      if ((numSeeds > 0) &&
          (seedingStartedOn > 0) &&
          (download.getState() == Download.ST_SEEDING) &&
          (sr.getScrapeStartTime() > seedingStartedOn))
        numSeeds--;
    }
    if (numSeeds == 0) {
      DownloadAnnounceResult ar = download.getLastAnnounceResult();
      if (ar != null && ar.getResponseType() == DownloadAnnounceResult.RT_SUCCESS)
        numSeeds = ar.getSeedCount();
    }
    return numSeeds;
  }


  private class downloadData implements Comparable
  {
    protected int sr;
    protected int iSeedingPos;
    protected Download dl;
    private boolean bActivelyDownloading;
    private boolean bActivelySeeding;
    public String sExplainFP = "";
    public String sTrace = "";
    
    private AEMonitor		downloadData_this_mon	= new AEMonitor( "StartStopRules:downloadData" );

    
    /** Sort first by SeedingRank Descending, then by Position Ascending.
      */
    public int compareTo(Object obj)
    {
      int value = ((downloadData)obj).getSeedingRank() - sr;
      if (value == 0) {
        return dl.getPosition() -
               ((downloadData)obj).getDownloadObject().getPosition();
      }
      return value;
    }

    public downloadData(Download _dl)
    {
      dl = _dl;
      iSeedingPos = 100000 - dl.getPosition();
      //recalcSeedingRank();
    }
    
    public int getSeedingPos() {
      return iSeedingPos;
    }
    
    public void setSeedingPos(int iPos) {
      iSeedingPos = iPos;
    }
    
    Download getDownloadObject() {
      return dl;
    }
    
    public boolean getActivelyDownloading() {
      boolean bIsActive = false;
      DownloadStats stats = dl.getStats();
      int state = dl.getState();
      
      // In order to be active,
      // - Must be downloading (and thus incomplete)
      // - Must be above speed threshold, or started less than 30s ago
      if ((state == Download.ST_DOWNLOADING) &&
          ((stats.getDownloadAverage() >= minSpeedForActiveDL) ||
           (SystemTime.getCurrentTime() - stats.getTimeStarted() <= FORCE_ACTIVE_FOR)))
          bIsActive = true;

      if (bActivelyDownloading != bIsActive) {
        bActivelyDownloading = bIsActive;
        somethingChanged = true;
        if (bDebugLog) 
          log.log(LoggerChannel.LT_INFORMATION,
                  "somethingChanged: ActivelyDownloading changed for " + dl.getName());
      }
      return bActivelyDownloading;
    }
    
    public boolean getActivelySeeding() {
      boolean bIsActive = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -