Package org.gudy.azureus2.core3.peer.impl

Examples of org.gudy.azureus2.core3.peer.impl.PEPeerControl


            if (item != null)
              item.setExpanded(!item.getExpanded());
        }
      });
    } catch (Exception e) {
      Logger.log(new LogEvent(LOGID, "Error initializing ConfigView", e));
    }

    scResizeListener = new Listener() {
      public void handleEvent(Event event) {
        setupSC((ScrolledComposite)event.widget);
      }
    };


    // Add sections
    /** How to add a new section
     * 1) Create a new implementation of ConfigSectionSWT in a new file
     *    (Use the ConfigSectionTMP.java as a template if it's still around)
     * 2) import it into here
     * 3) add it to the internal sections list
     */
    pluginSections = ConfigSectionRepository.getInstance().getList();

    ConfigSection[] internalSections = {
                                         new ConfigSectionMode(),
                                         new ConfigSectionStartShutdown(),
                                         new ConfigSectionConnection(),
                                         new ConfigSectionConnectionProxy(),
                                         new ConfigSectionConnectionAdvanced(),
                                         new ConfigSectionConnectionEncryption(),
                                         new ConfigSectionTransfer(),
                                         new ConfigSectionTransferAutoSpeedSelect(),
                                         new ConfigSectionTransferAutoSpeed(),
                                         new ConfigSectionTransferAutoSpeedBeta(),
                                         new ConfigSectionTransferLAN(),
                                         new ConfigSectionFile(),
                                         new ConfigSectionFileMove(),
                                         new ConfigSectionFileTorrents(),
                                         new ConfigSectionFileTorrentsDecoding(),
                                         new ConfigSectionFilePerformance(),
                                         new ConfigSectionInterface(),
                                         new ConfigSectionInterfaceLanguage(),
                                         new ConfigSectionInterfaceStart(),
                                         new ConfigSectionInterfaceDisplay(),
                                         new ConfigSectionInterfaceTables(),
                                         new ConfigSectionInterfaceColor(),
                                         new ConfigSectionInterfaceAlerts(),
                                         new ConfigSectionInterfacePassword(),
                                         new ConfigSectionInterfaceLegacy(),
                                         new ConfigSectionIPFilter(),
                                         new ConfigSectionPlugins(this),
                                         new ConfigSectionStats(),
                                         new ConfigSectionTracker(),
                                         new ConfigSectionTrackerClient(),
                                         new ConfigSectionTrackerServer(),
                                         new ConfigSectionSecurity(),
                                         new ConfigSectionSharing(),
                                         new ConfigSectionLogging()
                                        };
   
    pluginSections.addAll(0, Arrays.asList(internalSections));

    for (int i = 0; i < pluginSections.size(); i++) {
  
      // slip the non-standard "plugins" initialisation inbetween the internal ones
      // and the plugin ones so plugin ones can be children of it
     
      boolean  plugin_section = i >= internalSections.length;
     
      ConfigSection section = pluginSections.get(i);
     
      if (section instanceof ConfigSectionSWT || section instanceof UISWTConfigSection ) {
        String name;
        try {
          name = section.configSectionGetName();
         } catch (Exception e) {
           Logger.log(new LogEvent(LOGID, "A ConfigSection plugin caused an "
              + "error while trying to call its "
              + "configSectionGetName function", e));
          name = "Bad Plugin";
        }

         String  section_key = name;
        
         if ( plugin_section ){
             // if resource exists without prefix then use it as plugins don't
             // need to start with the prefix
          
           if ( !MessageText.keyExists(section_key)){
            
             section_key = sSectionPrefix + name;
           }
          
         }else{
          
           section_key = sSectionPrefix + name;
         }
        
         String  section_name = MessageText.getString( section_key );
        
         try {
          TreeItem treeItem;
          String location = section.configSectionGetParentSection();
 
          if ( location.length() == 0 || location.equalsIgnoreCase(ConfigSection.SECTION_ROOT)){
            //int position = findInsertPointFor(section_name, tree);
            //if ( position == -1 ){
              treeItem = new TreeItem(tree, SWT.NULL);
            // }else{
            //    treeItem = new TreeItem(tree, SWT.NULL, position);
            //}
         }else{
            TreeItem treeItemFound = findTreeItem(tree, location);
            if (treeItemFound != null){
              if (location.equalsIgnoreCase(ConfigSection.SECTION_PLUGINS)) {
                // Force ordering by name here.
                int position = findInsertPointFor(section_name, treeItemFound);
                if (position == -1) {
                  treeItem = new TreeItem(treeItemFound, SWT.NULL);
                }
                else {
                  treeItem = new TreeItem(treeItemFound, SWT.NULL, position);
                }
              }
              else {
                treeItem = new TreeItem(treeItemFound, SWT.NULL);
              }
            }else{
              treeItem = new TreeItem(tree, SWT.NULL);
            }
          }
 
          ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
          sc.setExpandHorizontal(true);
          sc.setExpandVertical(true);
          sc.setLayoutData(new GridData(GridData.FILL_BOTH));
          sc.getVerticalBar().setIncrement(16);
          sc.addListener(SWT.Resize, scResizeListener);
         
          if(i == 0) {
            Composite c;
            if ( section instanceof ConfigSectionSWT ){
             
              c = ((ConfigSectionSWT)section).configSectionCreate(sc);
             
            }else{
  
                c = ((UISWTConfigSection)section).configSectionCreate(sc);
            }
            sectionsCreated.add(section);
            sc.setContent(c);
          }
         
          Messages.setLanguageText(treeItem, section_key);
          treeItem.setData("Panel", sc);
          treeItem.setData("ID", name);
          treeItem.setData("ConfigSectionSWT", section);
         
          sections.put(treeItem, section);
         
          // ConfigSectionPlugins is special because it has to handle the
          // PluginConfigModel config pages
          if (section instanceof ConfigSectionPlugins)
            ((ConfigSectionPlugins)section).initPluginSubSections();
        } catch (Exception e) {
          Logger.log(new LogEvent(LOGID, "ConfigSection plugin '" + name
              + "' caused an error", e));
        }
      }
    }
   
View Full Code Here


   
    if ( verbose ){
     
      out.println( "Pieces" );
     
      PEPeerManager pm = dm.getPeerManager();
     
      if ( pm != null ){
       
        PiecePicker picker = pm.getPiecePicker();
       
        PEPiece[] pieces = pm.getPieces();
       
        String  line = "";
       
        for (int i=0;i<pieces.length;i++){
         
View Full Code Here

      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

 
    throws IOException
  {
    last_http_activity_time  = SystemTime.getCurrentTime();
   
    PEPeerControl  control = getPeerControl();
   
    if ( !sent_handshake ){
     
      sent_handshake  = true;
     
      decoder.addMessage( new BTHandshake( control.getHash(), peer_id, false, (byte)1 ));
     
      byte[]  bits = new byte[(control.getPieces().length +7) /8];
     
      DirectByteBuffer buffer = new DirectByteBuffer( ByteBuffer.wrap( bits ));
     
      decoder.addMessage( new BTBitfield( buffer, (byte)1 ));
    }
View Full Code Here

  protected void
  submitBTRequests()
 
    throws IOException
  {
    PEPeerControl  control = getPeerControl();

    long  piece_size = control.getPieceLength(0);
 
    synchronized( outstanding_requests ){

      while( outstanding_requests.size() < MAX_OUTSTANDING_BT_REQUESTS && http_requests.size() > 0 ){
       
        httpRequest  http_request = (httpRequest)http_requests.get(0);
       
        long[]  offsets  = http_request.getModifiableOffsets();
        long[]  lengths  = http_request.getModifiableLengths();
       
        int  index  = http_request.getIndex();
       
        long  offset   = offsets[index];
        long  length  = lengths[index];
       
        int    this_piece_number   = (int)(offset / piece_size);
        int    this_piece_size    = control.getPieceLength( this_piece_number );
       
        int    offset_in_piece   = (int)( offset - ( this_piece_number * piece_size ));
       
        int    space_this_piece   = this_piece_size - offset_in_piece;
       
View Full Code Here

    if ( !isSeed()){
     
      return;
    }
   
    PEPeerControl  control = getPeerControl();
   
    try{
      int  pos = header.indexOf( NL );
     
      String  line = header.substring(4,pos);
     
      pos = line.lastIndexOf( ' ' );
     
      String  url = line.substring( 0, pos ).trim();
     
      pos = url.indexOf( '?' );
     
      if ( pos != -1 ){
       
        url = url.substring( pos+1 );
      }
     
      StringTokenizer  tok = new StringTokenizer( url, "&" );
     
      int    piece   = -1;
      List  ranges   = new ArrayList();
     
      while( tok.hasMoreElements()){
       
        String  token = tok.nextToken();
       
        pos = token.indexOf('=');
       
        if ( pos != -1 ){
         
          String  lhs = token.substring(0,pos).toLowerCase( MessageText.LOCALE_ENGLISH );
          String  rhs = token.substring(pos+1);
         
          if ( lhs.equals( "info_hash" )){
           
              final byte[]  old_hash = control.getHash();
             
              final byte[]  new_hash = URLDecoder.decode( rhs, "ISO-8859-1" ).getBytes( "ISO-8859-1" );

            if ( !Arrays.equals( new_hash, old_hash )){
                             
              switching    = true;
             
              decoder.pauseInternally();
               
              flushRequests(
                new flushListener()
                {
                  private boolean triggered;
                 
                  public void
                  flushed()
                  {
                    synchronized( this ){
                     
                      if ( triggered ){
                       
                        return;
                      }
                     
                      triggered = true;
                    }
                   
                    getManager().reRoute(
                        HTTPNetworkConnectionWebSeed.this,
                        old_hash, new_hash, header );
                  }
                });
               
              return;
            }
          }else if ( lhs.equals( "piece" )){
           
            try{
              piece = Integer.parseInt( rhs );
             
            }catch( Throwable e ){
             
              throw( new IOException( "Invalid piece number '" + rhs +"'" ));
            }
          }else if ( lhs.equals( "ranges" )){
           
            StringTokenizer  range_tok = new StringTokenizer( rhs, "," );
           
            while( range_tok.hasMoreTokens()){
             
              String  range = range_tok.nextToken();
             
              int  sep = range.indexOf( '-' );
             
              if ( sep == -1 ){
               
                throw( new IOException( "Invalid range specification '" + rhs + "'" ));
              }
             
              try{
                ranges.add(
                    new int[]{
                      Integer.parseInt( range.substring(0,sep)),
                      Integer.parseInt( range.substring( sep+1 ))});
               
              }catch( Throwable e ){
               
                throw( new IOException( "Invalid range specification '" + rhs + "'" ));
              }
            }
          }
        }
      }
     
      if ( piece == -1 ){
       
        throw( new IOException( "Piece number not specified" ));
      }
     
      boolean  keep_alive = header.toLowerCase( MessageText.LOCALE_ENGLISH ).indexOf( "keep-alive" ) != -1;
     
      int  this_piece_size = control.getPieceLength( piece );
     
      if ( ranges.size() == 0 ){
       
        ranges.add( new int[]{ 0, this_piece_size-1});
      }
         
      long[]  offsets  = new long[ranges.size()];
      long[]  lengths  = new long[ranges.size()];
     
      long  piece_offset = piece * control.getPieceLength(0);
     
      for (int i=0;i<ranges.size();i++){
       
        int[]  range = (int[])ranges.get(i);
       
View Full Code Here

    if ( !isSeed()){
     
      return;
    }   
   
    PEPeerControl  control = getPeerControl();
   
    DiskManager  dm = control.getDiskManager();
   
    if ( dm == null ){
     
      Debug.out( "Disk manager is null" );
     
      throw( new IOException( "Disk manager unavailable" ));
    }
         
    TOTorrent  to_torrent = dm.getTorrent();
       
    char[]  chars = header.toCharArray();
   
    int  last_pos   = 0;
    int  line_num  = 0;
   
    String        target_str  = null;
   
    DiskManagerFileInfo  target_file = null;
   
    long  file_offset  = 0;
   
    List<long[]>  ranges = new ArrayList<long[]>();
   
    boolean  keep_alive  = false;
   
    for (int i=1;i<chars.length;i++){
     
      if ( chars[i-1] == '\r' && chars[i] == '\n' ){
       
        String  line = new String( chars, last_pos, i - last_pos ).trim();
       
        last_pos = i;
       
        line_num++;
       
        // System.out.println( "line " + line_num + " -> " + line );
       
        if ( line_num == 1 ){
         
          line = line.substring( line.indexOf( "files/" ) + 6 );
         
          int  hash_end = line.indexOf( "/" );
         
          final byte[] old_hash = control.getHash();

          final byte[] new_hash = URLDecoder.decode(line.substring(0, hash_end), "ISO-8859-1").getBytes( "ISO-8859-1" );
         
          if ( !Arrays.equals( new_hash, old_hash )){
           
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

TOP

Related Classes of org.gudy.azureus2.core3.peer.impl.PEPeerControl

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.