Package org.gudy.azureus2.core3.tracker.client.impl

Examples of org.gudy.azureus2.core3.tracker.client.impl.TRTrackerScraperResponseImpl


      long totalReceived = 0;
      long totalSent = 0;
      long totalDiscarded = 0;
      int connectedSeeds = 0;
      int connectedPeers = 0;
      PEPeerManagerStats ps;
      boolean bShowOnlyActive = false;
      boolean bShowOnlyComplete = false;
      boolean bShowOnlyIncomplete = false;
      boolean bShowOnlyTransferring = false;
      for (Iterator iter = args.iterator(); iter.hasNext();) {
        String arg = (String) iter.next();
        if ("active".equalsIgnoreCase(arg) || "a".equalsIgnoreCase(arg)) {
          bShowOnlyActive = true;
          iter.remove();
        } else if ("complete".equalsIgnoreCase(arg) || "c".equalsIgnoreCase(arg)) {
          bShowOnlyComplete = true;
          iter.remove();
        } else if ("incomplete".equalsIgnoreCase(arg) || "i".equalsIgnoreCase(arg)) {
          bShowOnlyIncomplete = true;
          iter.remove();
        } else if ("transferring".equalsIgnoreCase(arg) || "x".equalsIgnoreCase(arg)) {
          bShowOnlyTransferring = true;
          bShowOnlyActive = true;
          iter.remove();
        }
       
      }
     
      Iterator torrent;
      if( args.size() > 0 )
      {
        List matchedTorrents = new TorrentFilter().getTorrents(ci.torrents, args);
        torrent = matchedTorrents.iterator();
      }
      else
        torrent = ci.torrents.iterator();
     
      List shown_torrents = new ArrayList();

      while (torrent.hasNext()) {
               
        DownloadManager dm = (DownloadManager) torrent.next();
               
        DownloadManagerStats stats = dm.getStats();

        boolean bDownloadCompleted = stats.getDownloadCompleted(false) == 1000;
        boolean bCanShow = ((bShowOnlyComplete == bShowOnlyIncomplete) || (bDownloadCompleted && bShowOnlyComplete) || (!bDownloadCompleted && bShowOnlyIncomplete));

        if (bCanShow && bShowOnlyActive) {
          int dmstate = dm.getState();
          bCanShow = (dmstate == DownloadManager.STATE_SEEDING) || (dmstate == DownloadManager.STATE_DOWNLOADING) || (dmstate == DownloadManager.STATE_CHECKING) || (dmstate == DownloadManager.STATE_INITIALIZING) || (dmstate == DownloadManager.STATE_ALLOCATING);
        }
       
        if (bCanShow && bShowOnlyTransferring) {
          try {
            ps = dm.getPeerManager().getStats();
            bCanShow = ps.getDataSendRate() > 0 || ps.getDataReceiveRate() > 0;
          }
          catch (Exception e) {}
        }

        if (bCanShow) {
         
          shown_torrents.add( dm );

          try {
            ps = dm.getPeerManager().getStats();
          } catch (Exception e) {
            ps = null;
          }
          if (ps != null) {
            totalReceived += dm.getStats().getTotalDataBytesReceived();
            totalSent += dm.getStats().getTotalDataBytesSent();
            totalDiscarded += ps.getTotalDiscarded();
            connectedSeeds += dm.getNbSeeds();
            connectedPeers += dm.getNbPeers();
          }       
          ci.out.print(((shown_torrents.size() < 10) ? " " : "") + shown_torrents.size() + " ");
          ci.out.println(getTorrentSummary(dm));
View Full Code Here


         
          String str = picker.getPieceString( i );
         
          line += (line.length()==0?(i + " "):",") + str;
         
          PEPiece piece = pieces[i];

          if ( piece != null ){
         
            line += ":" + piece.getString();
          }
         
          if ( (i+1)%10 == 0 ){
           
            out.println( line );
View Full Code Here

  {
    super("publish", null, "Publishing");
  }

  protected boolean performCommand(ConsoleInput ci, DownloadManager dm, List args) {
    TOTorrent torrent = dm.getTorrent();
        if (torrent != null) {
          try {
          TRHost  host = ci.azureus_core.getTrackerHost();
         
          TRHostTorrent  existing = host.getHostTorrent( torrent );
View Full Code Here

            StringBuffer sb = new StringBuffer();
            Object[] selectedDataSources = tv.getSelectedDataSources(true);
            for (Object ds : selectedDataSources) {
              if (ds instanceof DownloadManager) {
                DownloadManager dm = (DownloadManager) ds;
                TOTorrent torrent = dm.getTorrent();
                if (torrent != null) {
                  try {
                    sb.append(torrent.getHashWrapper().toBase32String());
                    sb.append('\n');
                  } catch (TOTorrentException e) {
                  }
                }
              } else if (ds instanceof DiskManagerFileInfo) {
                DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
                DownloadManager dm = fileInfo.getDownloadManager();
                TOTorrent torrent = dm.getTorrent();
                if (torrent != null) {
                  try {
                    sb.append(torrent.getHashWrapper().toBase32String());
                    sb.append(';');
                    sb.append(fileInfo.getIndex());
                    sb.append('\n');
                    onlyDMs = false;
                  } catch (TOTorrentException e) {
View Full Code Here

    String  error_title;
    String  error_detail;
   
    try{
   
      TOTorrent  torrent;
     
      try{
       
        torrent = TOTorrentFactory.deserialiseFromBEncodedFile( input_file );
 
        try{
         
          torrent.serialiseToXMLFile( output_file );
         
          return( true );
               
        }catch( TOTorrentException e ){
       
View Full Code Here

  }

  private TorrentInfo addTorrent(String sFileName,
      final String sOriginatingLocation) {
    TorrentInfo info = null;
    TOTorrent torrent = null;
    File torrentFile;
    boolean bDeleteFileOnCancel = false;

    // Make a copy if user wants that.  We'll delete it when we cancel, if we
    // actually made a copy.
    try {
      if (sFileName.startsWith("file://localhost/")) {
        sFileName = UrlUtils.decode(sFileName.substring(16));
      }

      final File fOriginal = new File(sFileName);

      if (!fOriginal.isFile() || !fOriginal.exists()) {
        Utils.execSWTThread(new AERunnable() {
          public void runSupport() {
            if (shell == null)
              new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,
                  "OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] {
                    UrlUtils.decode(sOriginatingLocation),
                    "Not a File"
                  }, -1 );
            else {
              MessageBoxShell mb = new MessageBoxShell(SWT.OK,
                  "OpenTorrentWindow.mb.openError", new String[] {
                    sOriginatingLocation,
                    "Not a File"
                  });
              mb.open(null);
            }
          }
        });
        return null;
      }

      if (fOriginal.length() > 20*1024*1024) {
        Utils.execSWTThread(new AERunnable() {
          public void runSupport() {
            if (shell == null)
              new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,
                  "OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] {
                    UrlUtils.decode(sOriginatingLocation),
                    "Too large to be a torrent"
                  }, -1 );
            else {
              MessageBoxShell mb = new MessageBoxShell(SWT.OK,
                  "OpenTorrentWindow.mb.openError", new String[] {
                    sOriginatingLocation,
                    "Too large to be a torrent"
                  });
              mb.open(null);
            }
          }
        });
        return null;
      }

      torrentFile = TorrentUtils.copyTorrentFileToSaveDir(fOriginal, true);
      bDeleteFileOnCancel = !fOriginal.equals(torrentFile);
      // TODO if the files are still equal, and it isn't in the save
      //       dir, we should copy it to a temp file in case something
      //       re-writes it.  No need to copy a torrent coming from the
      //       downloader though..
    } catch (IOException e1) {
      // Use torrent in wherever it is and hope for the best
      // XXX Should error instead?
      torrentFile = new File(sFileName);
    }

    VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
   
    VuzeFile vf = vfh.loadVuzeFile( torrentFile );
   
    if ( vf != null ){
     
        vfh.handleFiles( new VuzeFile[]{ vf }, VuzeFileComponent.COMP_TYPE_NONE );

        return null;
    }
   
    // Do a quick check to see if it's a torrent
    if (!TorrentUtil.isFileTorrent(torrentFile, shellForChildren,
        torrentFile.getName())) {
      if (bDeleteFileOnCancel) {
        torrentFile.delete();
      }
      return null;
    }

    // Load up the torrent, see it it's real
    try {
      torrent = TorrentUtils.readFromFile(torrentFile, false);
    } catch (final TOTorrentException e) {
     
      Utils.execSWTThread(new AERunnable() {
        public void runSupport() {
          if (shell == null)
            new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,
                "OpenTorrentWindow.mb.openError", Debug.getStackTrace(e),
                new String[] {
                  sOriginatingLocation,
                  e.getMessage()
                }, -1 );
          else {
            MessageBoxShell mb = new MessageBoxShell(SWT.OK,
                "OpenTorrentWindow.mb.openError", new String[] {
                  sOriginatingLocation,
                  e.getMessage()
                });
            mb.open(null);
          }
        }
      });

      if (bDeleteFileOnCancel)
        torrentFile.delete();

      return null;
    }

    String sExistingName = null;
    try {
      HashWrapper hash = torrent.getHashWrapper();
      if (hash != null) {
        for (int i = 0; i < torrentList.size(); i++) {
          try {
            TorrentInfo existing = (TorrentInfo) torrentList.get(i);
            if (existing.torrent.getHashWrapper().equals(hash)) {
View Full Code Here

    out.println("Torrent Filename: " + dm.getTorrentFileName());
    out.println("Saving to: " + dm.getSaveLocation());
    out.println("Created By: " + dm.getTorrentCreatedBy());
    out.println("Comment: " + dm.getTorrentComment());
    out.println("- Tracker Info -");
    TRTrackerAnnouncer trackerclient = dm.getTrackerClient();
    if (trackerclient != null) {
      out.println("URL: " + trackerclient.getTrackerURL());
      String timestr;
      try {
        int time = trackerclient.getTimeUntilNextUpdate();
        if (time < 0) {
          timestr = MessageText.getString("GeneralView.label.updatein.querying");
        } else {
          int minutes = time / 60;
          int seconds = time % 60;
          String strSeconds = "" + seconds;
          if (seconds < 10) {
            strSeconds = "0" + seconds; //$NON-NLS-1$
          }
          timestr = minutes + ":" + strSeconds;
        }
      } catch (Exception e) {
        timestr = "unknown";
      }
      out.println("Time till next Update: " + timestr);
      out.println("Status: " + trackerclient.getStatusString());
    } else
      out.println("  Not available");
   
    out.println("- Files Info -");
    DiskManagerFileInfo files[] = dm.getDiskManagerFileInfo();
View Full Code Here

          return "";
        return "(max " + DisplayFormatters.formatByteCountToKiBEtcPerSec(uploadSpeed) + ")";
       
      case 'S':
      case 'P':
        TRTrackerScraperResponse hd = dm.getTrackerScrapeResponse();
        if (hd == null || !hd.isValid())
          return "?";
        else
        {
          if( variable == 'S' )
            return Integer.toString(hd.getSeeds());
          else
            return Integer.toString(hd.getPeers());
        }
      default:
        return "??" + variable + "??";
    }
  }
View Full Code Here

    URL            url,
    DownloadScrapeResult  result )
  {
    if ( torrent != null && result != null ){
     
      TRTrackerScraperResponseImpl resp =  tracker_checker.getHashData( torrent, url );
     
      boolean  update_is_dht  = TorrentUtils.isDecentralised( result.getURL());
     
        // only override details if underlying scrape is failing or this is an update
        // to an existing dht-backup result
     
      if (   resp != null &&
          (   resp.getStatus() == TRTrackerScraperResponse.ST_ERROR ) ||
            resp.isDHTBackup() && update_is_dht ){
       
        resp.setDHTBackup( update_is_dht );
       
        resp.setScrapeStartTime( result.getScrapeStartTime());
       
          // leave nextScrapeStartTime alone as we still want the existing
          // scraping mechanism to kick in and check the torrent's tracker
       
        resp.setStatus(
            result.getResponseType()==DownloadScrapeResult.RT_SUCCESS?
                TRTrackerScraperResponse.ST_ONLINE:
                TRTrackerScraperResponse.ST_ERROR,
            result.getStatus() + " (" + result.getURL() + ")");

        // call this last before dispatching listeners as it does another dispatch by itself ~~
        resp.setSeedsPeers( result.getSeedCount(), result.getNonSeedCount());
     
        scraper.scrapeReceived( resp );
      }
    }
  }
View Full Code Here

      }
   
      try {
        ArrayList responsesToUpdate = new ArrayList();

        TRTrackerScraperResponseImpl response;
   
        try{
          hashes_mon.enter();
      
          response = (TRTrackerScraperResponseImpl)hashes.get( hash );
       
        }finally{
       
          hashes_mon.exit();
        }
 
        if ( response == null ){
         
          response = addHash(hash);
        }
       
        long lMainNextScrapeStartTime = response.getNextScrapeStartTime();
 
        if( !force && lMainNextScrapeStartTime > SystemTime.getCurrentTime() ) {
          if (Logger.isEnabled()) {
            Logger.log(new LogEvent(TorrentUtils.getDownloadManager(hash), LOGID,
              "TrackerStatus: scrape cancelled.. not forced and still "
                  + (lMainNextScrapeStartTime - SystemTime.getCurrentTime())
                  + "ms"));
          }
          return;
        }
   
          // Set status id to SCRAPING, but leave status string until we actually
          // do the scrape
       
        response.setStatus(TRTrackerScraperResponse.ST_SCRAPING,
          MessageText.getString(SS + "scraping.queued"));
        if (Logger.isEnabled()) {
          Logger.log(new LogEvent(TorrentUtils.getDownloadManager(hash), LOGID,
            "TrackerStatus: setting to scraping"));
        }

        responsesToUpdate.add(response);
     
          // Go through hashes and pick out other scrapes that are "close to" wanting a new scrape.
     
        if (!bSingleHashScrapes){
         
          try{
            hashes_mon.enter();
           
            Iterator iterHashes = hashes.values().iterator();
           
              // if we hit trackers with excessive scrapes they respond in varying fashions - from no reply
              // to returning 414 to whatever. Rather than hit trackers with large payloads that they then
              // reject we limit to MULTI_SCRAPE_LIMIT in one go
           
            while( iterHashes.hasNext() && responsesToUpdate.size() < GROUP_SCRAPES_LIMIT ){
             
              TRTrackerScraperResponseImpl r = (TRTrackerScraperResponseImpl)iterHashes.next();
             
              if ( !r.getHash().equals( hash )) {
               
                long lTimeDiff = Math.abs(lMainNextScrapeStartTime - r.getNextScrapeStartTime());
               
                if (lTimeDiff <= GROUP_SCRAPES_MS && r.getStatus() != TRTrackerScraperResponse.ST_SCRAPING) {
                 
                  r.setStatus(TRTrackerScraperResponse.ST_SCRAPING,
                      MessageText.getString(SS + "scraping.queued"));
                  if (Logger.isEnabled()) {
                    Logger.log(new LogEvent(TorrentUtils.getDownloadManager(r.getHash()), LOGID,
                      "TrackerStatus: setting to scraping via group scrape"));
                  }
                 
                  responsesToUpdate.add(r);
                }
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.tracker.client.impl.TRTrackerScraperResponseImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.