Examples of PEPeerControl


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

 
    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

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

  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

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

    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

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

    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
TOP
Copyright © 2018 www.massapi.com. 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.