Package org.gudy.azureus2.core3.peer

Examples of org.gudy.azureus2.core3.peer.PEPeerManager$StatsReceiver


  public int
  getNATStatus()
  {
    int  state = getState();
   
    PEPeerManager  peerManager   = controller.getPeerManager();
   
    TRTrackerAnnouncer tc = getTrackerClient();
   
    if ( tc != null && peerManager != null && (state == STATE_DOWNLOADING || state == STATE_SEEDING)) {
           
      if ( peerManager.getNbRemoteTCPConnections() > 0 ){
       
        return( ConnectionManager.NAT_OK );
      }
     
      long  last_good_time = peerManager.getLastRemoteConnectionTime();
   
      if ( last_good_time > 0 ){
       
          // half an hour's grace
       
        if ( SystemTime.getCurrentTime() - last_good_time < 30*60*1000 ){
       
          return( ConnectionManager.NAT_OK );
         
        }else{
         
          return( ConnectionManager.NAT_PROBABLY_OK );
        }
      }
     
      TRTrackerAnnouncerResponse  announce_response = tc.getLastResponse();
     
      int trackerStatus = announce_response.getStatus();
     
      if(   trackerStatus == TRTrackerAnnouncerResponse.ST_OFFLINE ||
          trackerStatus == TRTrackerAnnouncerResponse.ST_REPORTED_ERROR){
         
        return ConnectionManager.NAT_UNKNOWN;
      }
     
        // tracker's ok but no remotes - give it some time
     
      if ( SystemTime.getCurrentTime() - peerManager.getTimeStarted() < 3*60*1000 ){
       
        return ConnectionManager.NAT_UNKNOWN;
      }
     
      TRTrackerScraperResponse scrape_response = getTrackerScrapeResponse();
       
      if ( scrape_response != null && scrape_response.isValid()){
         
          // if we're connected to everyone then report OK as we can't get
          // any incoming connections!
         
        if (   peerManager.getNbSeeds() == scrape_response.getSeeds() &&
            peerManager.getNbPeers() == scrape_response.getPeers()){
           
          return ConnectionManager.NAT_UNKNOWN;
        }
      }
       
View Full Code Here


  }
 
  public boolean
  seedPieceRecheck()
  {
    PEPeerManager pm = controller.getPeerManager();
   
    if ( pm != null ){
     
      return( pm.seedPieceRecheck());
    }
   
    return( false );
  }
View Full Code Here

            private TrackerPeerSource  _delegate;
           
            private TrackerPeerSource
            fixup()
            {
              PEPeerManager pm = getPeerManager();
             
              if ( pm == null ){
               
                _delegate   = null;
                _pm      = null;
               
              }else if ( pm != _pm ){
               
                _pm  = pm;
               
                _delegate = pm.getTrackerPeerSource();
              }
             
              return( _delegate );
            }
           
            public int
            getType()
            {
              return( TP_PEX );
            }
           
            public int
            getStatus()
            {
              TrackerPeerSource delegate = fixup();
             
              if ( delegate == null ){
               
                return( ST_STOPPED );
               
              }else{
               
                return( delegate.getStatus());
              }
            }
           
            public String
            getName()
            {
              TrackerPeerSource delegate = fixup();
             
              if ( delegate == null ){
               
                return( "" );
               
              }else{
               
                return( delegate.getName());
             
            }
           
            public int
            getPeers()
            {
              TrackerPeerSource delegate = fixup();
             
              if ( delegate == null ){
               
                return( -1 );
               
              }else{
               
                return( delegate.getPeers());
             
            }
          });
       
          // incoming
       
        tps.add(
            new TrackerPeerSourceAdapter()
            {
              private long        fixup_time;
           
              private PEPeerManager    _pm;
              private int          tcp;
              private int          udp;
              private int          total;
              private boolean        enabled;
             
              private PEPeerManager
              fixup()
              {
                long  now = SystemTime.getMonotonousTime();
               
                if ( now - fixup_time > 1000 ){
 
                  PEPeerManager pm = _pm = getPeerManager();
                 
                  if ( pm != null ){
                   
                    tcp   = pm.getNbRemoteTCPConnections();
                    udp    = pm.getNbRemoteUDPConnections();
                    total  = pm.getStats().getTotalIncomingConnections();
                  }
                 
                  enabled = controller.isPeerSourceEnabled( PEPeerSource.PS_INCOMING );
                 
                  fixup_time = now;
                }
               
                return( _pm );
              }
             
              public int
              getType()
              {
                return( TP_INCOMING );
              }
             
              public int
              getStatus()
              {
                PEPeerManager delegate = fixup();
               
                if ( delegate == null ){
                 
                  return( ST_STOPPED );
                 
                }else if ( !enabled ){
                 
                  return( ST_DISABLED );
                   
                }else{
               
                  return( ST_ONLINE );
                }
              }
             
              public String
              getName()
              {
                PEPeerManager delegate = fixup();
               
                if ( delegate == null || !enabled ){
                 
                  return( "" );
                 
                }else{
                 
                  return(
                    MessageText.getString(
                      "tps.incoming.details",
                      new String[]{ String.valueOf( tcp ), String.valueOf( udp ), String.valueOf( total )} ));
               
              }
             
              public int
              getPeers()
              {
                PEPeerManager delegate = fixup();
               
                if ( delegate == null || !enabled ){
                 
                  return( -1 );
                 
View Full Code Here

  generateEvidence(
    IndentWriter    writer )
  {
    writer.println(toString());

    PEPeerManager pm = getPeerManager();

    try {
      writer.indent();

      writer.println("Save Dir: "
          + Debug.secretFileName(getSaveLocation().toString()));
     
      if (current_peers.size() > 0) {
        writer.println("# Peers: " + current_peers.size());
      }
     
      if (current_pieces.size() > 0) {
        writer.println("# Pieces: " + current_pieces.size());
      }
     
      writer.println("Listeners: DownloadManager=" + listeners.size() + "; Disk="
        + controller.getDiskListenerCount() + "; Peer=" + peer_listeners.size()
        + "; Tracker=" + tracker_listeners.size());
     
      writer.println("SR: " + iSeedingRank);
     
     
      String sFlags = "";
      if (open_for_seeding) {
        sFlags += "Opened for Seeding; ";
      }
     
      if (data_already_allocated) {
        sFlags += "Data Already Allocated; ";
      }
     
      if (assumedComplete) {
        sFlags += "onlySeeding; ";
      }
     
      if (persistent) {
        sFlags += "persistent; ";
      }
     
      if (sFlags.length() > 0) {
        writer.println("Flags: " + sFlags);
      }

      stats.generateEvidence( writer );
     
      download_manager_state.generateEvidence( writer );

      if (pm != null) {
        pm.generateEvidence(writer);
      }
     
        // note, PeerManager generates DiskManager evidence
     
      controller.generateEvidence(writer);
View Full Code Here

          continue;
        }
       
        log( download.getName() + " - connecting to peer " + ip.getHostAddress());

        PEPeerManager c_pm = PluginCoreUtils.unwrap( pm );
       
        Map  user_data = new LightHashMap();
       
        user_data.put( PEER_KEY, download );
       
        user_data.put( Peer.PR_PRIORITY_CONNECTION, new Boolean( true ));
       
        c_pm.addPeer( ip.getHostAddress(), tcp_port, udp_port, true, user_data );
      }
    }
  }
View Full Code Here

       
      }else{
     
        if ( state == DownloadManager.STATE_DOWNLOADING ){
         
          PEPeerManager pm = manager.getPeerManager();
         
          if ( pm != null ){
           
            if ( pm.hasDownloadablePiece()){
             
              is_downloading = true;
             
            }else{
       
View Full Code Here

           
      if ( runtime >= 30*1000 ){
       
        boolean  rotate = false;

        PEPeerManager pm = current_transfer.getDownload().getPeerManager();
       
        if ( pm == null ){
         
          rotate = true;
         
        }else{
         
          if ( runtime > 3*60*1000 ){
         
            List<PEPeer> peers = pm.getPeers( service_ip );
           
            if ( peers.size() == 0 ){
             
              rotate = true;
             
            }else{
           
              PEPeer peer = peers.get(0);
             
              if ( peer.getStats().getDataReceiveRate() < 1024 ){
               
                rotate = true;
              }
            }
          }
        }
       
        if ( rotate ){
         
          current_transfer.deactivate();
         
          current_transfer = null;
        }
      }
    }
   
    if ( current_transfer == null ){
     
      Iterator<TransferableDownload> it2 = transferable.values().iterator();
     
      current_transfer = it2.next();
     
      it2.remove();
     
      transferable.put( current_transfer.getHash(), current_transfer );
    }
   
    if ( current_transfer != null ){
     
      if ( !current_transfer.isActive()){
       
        current_transfer.activate();
      }
     
      if ( current_transfer.isForced()){
       
        Map<String,Map> xfer_cache = new HashMap<String,Map>();
       
        Map m = new HashMap();
       
        m.put( "f", new Long(1));
       
        xfer_cache.put( current_transfer.getHash(), m );
       
        setPersistentMapProperty( PP_OD_XFER_CACHE, xfer_cache );
      }
     
      DownloadManager  download = current_transfer.getDownload();
     
      int  data_port = current_transfer.getDataPort();
     
      if ( data_port <= 0 ){
               
        try{
          String[] start_results = service.startDownload( client_id, current_transfer.getHash());
         
          String start_status = start_results[1];
         
          if ( !start_status.equals( "OK" )){
           
            throw( new Exception( "Failing result returned: " + start_status ));
          }
         
          data_port = Integer.parseInt( start_results[0] );
         
          log( download, "StartDownload succeeded - data port=" + data_port );

        }catch( Throwable e ){
         
          log( download, "StartDownload failed", e );
        }
      }
     
      if ( data_port > 0 ){
       
        current_transfer.setDataPort( data_port );
      }
     
      final TransferableDownload transfer = current_transfer;

      dispatcher.dispatch(
        new AERunnable()
        {
          private final int[]  count = { 0 };
         
          public void
          runSupport()
          {
            count[0]++;
           
            if ( current_transfer != transfer || !transfer.isActive()){
             
              return;
            }
           
            PEPeerManager pm = transfer.getDownload().getPeerManager();
           
            if ( pm == null ){
             
              return;
            }
           
            List<PEPeer> peers = pm.getPeers( service_ip );
               
            if ( peers.size() > 0 ){
     
              return;
            }
           
            Map  user_data = new LightHashMap();
                       
            user_data.put( Peer.PR_PRIORITY_CONNECTION, new Boolean( true ));
           
            pm.addPeer( service_ip, transfer.getDataPort(), 0, false, user_data );
           
            if ( count[0] < 3 ){
             
              final AERunnable target = this;
             
View Full Code Here

            }else if ( response.getScrapeIncompleteCount() > 0 ){
             
              ensureActive( "Tracker[scrape]", ACT_TRACKER_SCRAPE );
            }
           
            PEPeerManager  pm = peer_manager;
           
            if ( pm != null ){
                             
              pm.processTrackerResponse( response );
            }
          }
 
          public void
          urlChanged(
            TRTrackerAnnouncer  announcer,
            URL          old_url,
            URL          new_url,
            boolean        explicit )
          {
          }
           
          public void
          urlRefresh()
          { 
          }
        });
     
    result.setAnnounceDataProvider(
        new TRTrackerAnnouncerDataProvider()
        {
          public String
          getName()
          {
            return( LightWeightSeed.this.getName());
          }
         
          public long
          getTotalSent()
          {
            return( 0 );
          }
         
          public long
          getTotalReceived()
          {
            return( 0 );
          }
         
            public long
            getFailedHashCheck()
            {
              return( 0 );
            }
           
          public long
          getRemaining()
          {
            return( 0 );
          }
         
          public String
          getExtensions()
          {
            return( null );
          }
         
          public int
          getMaxNewConnectionsAllowed()
          {
            PEPeerManager  pm = peer_manager;

            if ( pm == null ){
             
                // got to ask for at least one to trigger activation!
             
              return( 8 );
            }
           
            return( PeerUtils.numNewConnectionsAllowed( pm.getPeerIdentityDataID(),0));
          }
         
          public int
          getPendingConnectionCount()
          {
            PEPeerManager  pm = peer_manager;

            if ( pm == null ){
             
              return( 0 );
            }
           
            return( pm.getPendingPeerCount());
          }
         
          public int
          getConnectedConnectionCount()
          {
            PEPeerManager  pm = peer_manager;

            if ( pm == null ){
             
              return( 0 );
            }
           
            return( pm.getNbPeers() + pm.getNbSeeds());
          }
         
          public int
          getUploadSpeedKBSec(
            boolean estimate)
View Full Code Here

  }
 
   public PeerManager
  getPeerManager()
   {
     PEPeerManager  pm = download_manager.getPeerManager();
    
     if ( pm == null ){
      
       return( null );
     }
View Full Code Here

    if ( value == 0 ){
     
        // zero means no recorded last bad availability time (bad=transition from >=1 -> < 1)
     
      PEPeerManager pm = dm.getPeerManager();
     
      if ( pm  == null || pm.getMinAvailability() < 1.0 ){
       
        long stopped = dm.getDownloadState().getLongAttribute( DownloadManagerState.AT_TIME_STOPPED );
       
        if ( stopped > 0 ){
         
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.peer.PEPeerManager$StatsReceiver

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.