Package com.aelitis.azureus.core.peermanager

Examples of com.aelitis.azureus.core.peermanager.PeerManagerRegistration


               
                if ( hash_str != null ){
                 
                  byte[]  hash = URLDecoder.decode( hash_str, "ISO-8859-1" ).getBytes( "ISO-8859-1" );
                                     
                  PeerManagerRegistration reg_data = PeerManager.getSingleton().manualMatchHash( address, hash );
                 
                  if ( reg_data != null ){
                   
                      // trim back URL as it currently has header in it too
                   
                    int  pos = url.indexOf( ' ' );
                   
                    String  trimmed = pos==-1?url:url.substring(0,pos);
                   
                    ok  = true;
                   
                    return( new Object[]{ trimmed, reg_data });
                  }
                }else{
                 
                  int  link_pos = url.indexOf( "/links/" );
                 
                  if ( link_pos != -1 ){
                 
                    int  pos = url.indexOf( ' ', link_pos );

                    if ( pos == -1 ){
                     
                      return( null );
                    }
                   
                    String link = url.substring(0,pos).substring( link_pos+7 );
                   
                    link = URLDecoder.decode( link, "UTF-8" );
                   
                    PeerManagerRegistration reg_data = PeerManager.getSingleton().manualMatchLink( address, link );
                   
                    if ( reg_data != null ){

                      TOTorrentFile  file = reg_data.getLink( link );
                     
                      if ( file != null ){
                       
                        StringBuffer  target_url = new StringBuffer( 512 );
                       
                        target_url.append( "/files/" );
                       
                        target_url.append( URLEncoder.encodenew String( file.getTorrent().getHash(), "ISO-8859-1" ), "ISO-8859-1" ));
                       
                        byte[][]  bits = file.getPathComponents();
                       
                        for (int i=0;i<bits.length;i++){
                         
                          target_url.append( "/" );
                         
                          target_url.append( URLEncoder.encode( new String( bits[i], "ISO-8859-1" ), "ISO-8859-1" ));
                        }
                       
                        ok  = true;
                       
                        return( new Object[]{ target_url.toString(), reg_data });
                      }
                    }
                  }
                }
               
                String trimmed = url;
               
                int  pos = trimmed.indexOf( ' ' );
               
                if ( pos != -1 ){
                 
                  trimmed = trimmed.substring( 0, pos );
                }
               
                for ( URLHandler handler: url_handlers ){
                 
                  if ( handler.matches( trimmed )){
                                       
                    ok  = true;
                   
                    return( new Object[]{ handler, transport, "GET " + url });
                  }
                }
                 if (Logger.isEnabled()){
                  Logger.log(new LogEvent(LOGID, "HTTP decode from " + address + " failed: no match for " + url ));
                }
                
                return( new Object[]{ transport, getNotFound() });
               
              }catch( Throwable e ){
               
                 if (Logger.isEnabled()){
                  Logger.log(new LogEvent(LOGID, "HTTP decode from " + address + " failed, " + e.getMessage()));
                }
 
                 return( null );
              }
            }finally{
           
              if ( ok ){
               
                total_ok_requests++;
               
              }else{
               
                total_invalid_requests++;
              }
                //  restore buffer structure
             
              to_compare.limit( old_limit );
              to_compare.position( old_position );
            }
          }
         
          public Object
          minMatches(
            TransportHelper    transport,
            ByteBuffer       to_compare,
            int         port )
          {
            byte[]  head = new byte[3];
           
            to_compare.get( head );
           
            if (head[0] != 'G' || head[1] != 'E' || head[2] != 'T' ){
             
              return( null );
            }

            return( "" );
          }

          public byte[][]
          getSharedSecrets()
          {
            return( null )
          }
         
           public int
           getSpecificPort()
           {
             return( http_incoming_manager.getTCPListeningPortNumber());
           }
        };
       
      // register for incoming connection routing
      NetworkManager.getSingleton().requestIncomingConnectionRouting(
          matcher,
          new NetworkManager.RoutingListener()
          {
            public void
            connectionRouted(
              final NetworkConnection   connection,
              Object             _routing_data )
            {
              Object[]  x = (Object[])_routing_data;
             
              Object  entry1 = x[0];
             
              if ( entry1 instanceof TransportHelper ){
               
                  // routed on failure
               
                writeReply(connection, (TransportHelper)x[0], (String)x[1]);
               
                return;
               
              }else if ( entry1 instanceof URLHandler ){
               
                ((URLHandler)entry1).handle(
                    (TransportHelper)x[1],
                    (String)x[2] );
             
                return;
              }
             
              final String          url       = (String)entry1;
              final PeerManagerRegistration  routing_data   = (PeerManagerRegistration)x[1];
             
             if (Logger.isEnabled()){
            Logger.log(new LogEvent(LOGID, "HTTP connection from " + connection.getEndpoint().getNotionalAddress() + " routed successfully on '" + url + "'" ));
             }            
                         
View Full Code Here


    final byte[]          new_hash,
    final String          header )
  {
    final NetworkConnection  old_connection = old_http_connection.getConnection();
   
    PeerManagerRegistration reg_data =
      PeerManager.getSingleton().manualMatchHash(
          old_connection.getEndpoint().getNotionalAddress(),
          new_hash );

    if ( reg_data == null ){
View Full Code Here

TOP

Related Classes of com.aelitis.azureus.core.peermanager.PeerManagerRegistration

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.