Package com.aelitis.net.udp.uc

Examples of com.aelitis.net.udp.uc.PRUDPPacket


     
      Logger.log(new LogEvent(LOGID,
          "TRTrackerServerProcessorUDP: packet received: "
              + request.getString()));
       
      PRUDPPacket          reply   = null;
      TRTrackerServerTorrentImpl  torrent  = null;
     
      if ( auth_user_bytes != null ){
       
        // user name is irrelevant as we only have one at the moment
 
        //<parg_home> so <new_packet> = <old_packet> + <user_padded_to_8_bytes> + <hash>
        //<parg_home> where <hash> = first 8 bytes of sha1(<old_packet> + <user_padded_to_8> + sha1(pass))
        //<XTF> Yes
       
               
        byte[] sha1_pw = null;
       
        if ( server.hasExternalAuthorisation()){
         
          try{
            URL  resource = new URL( "udp://" + server.getHost() + ":" + server.getPort() + "/" );
         
            sha1_pw = server.performExternalAuthorisation( resource, auth_user );
           
          }catch( MalformedURLException e ){
           
            Debug.printStackTrace( e );
           
          }
         
          if ( sha1_pw == null ){
       
            Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR,
                "TRTrackerServerProcessorUDP: auth fails for user '"
                    + auth_user + "'"));

            reply = new PRUDPPacketReplyError( request.getTransactionId(), "Access Denied" );
          }
        }else{
         
          sha1_pw = server.getPassword();
        }
       
          // if we haven't already failed then check the PW
       
        if ( reply == null ){
         
          SHA1Hasher  hasher = new SHA1Hasher();
         
          hasher.update( input_buffer, 0, packet_data_length);
          hasher.update( auth_user_bytes );
          hasher.update( sha1_pw );
         
          byte[]  digest = hasher.getDigest();
         
          for (int i=0;i<auth_hash.length;i++){
           
            if ( auth_hash[i] != digest[i] ){
         
              Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR,
                  "TRTrackerServerProcessorUDP: auth fails for user '"
                      + auth_user + "'"));
 
              reply = new PRUDPPacketReplyError( request.getTransactionId(), "Access Denied" );
             
              break;
            }
          }
        }
      }
     
      int request_type = TRTrackerServerRequest.RT_UNKNOWN;
     
      if ( reply == null ){
       
        if ( server.isEnabled()){
         
          try{
            int  type = request.getAction();
           
            if ( type == PRUDPPacketTracker.ACT_REQUEST_CONNECT ){
             
              reply = handleConnect( client_ip_address, request );
             
            }else if (type == PRUDPPacketTracker.ACT_REQUEST_ANNOUNCE ){
             
              Object[] x = handleAnnounceAndScrape( client_ip_address, request, TRTrackerServerRequest.RT_ANNOUNCE );
             
              if ( x == null ){
               
                throw( new Exception( "Connection ID mismatch" ));
              }
             
              reply   = (PRUDPPacket)x[0];
              torrent  = (TRTrackerServerTorrentImpl)x[1];
         
              request_type = TRTrackerServerRequest.RT_ANNOUNCE;
             
            }else if ( type == PRUDPPacketTracker.ACT_REQUEST_SCRAPE ){
             
              Object[] x = handleAnnounceAndScrape( client_ip_address, request, TRTrackerServerRequest.RT_SCRAPE );
             
              if ( x == null ){
               
                throw( new Exception( "Connection ID mismatch" ));
              }

              reply   = (PRUDPPacket)x[0];
              torrent  = (TRTrackerServerTorrentImpl)x[1];
   
              request_type = TRTrackerServerRequest.RT_SCRAPE;
             
            }else{
             
              reply = new PRUDPPacketReplyError( request.getTransactionId(), "unsupported action");
            }
          }catch( Throwable e ){
           
            // e.printStackTrace();
           
            String  error = e.getMessage();
           
            if ( error == null ){
             
              error = e.toString();
            }
           
            reply = new PRUDPPacketReplyError( request.getTransactionId(), error );
          }
        }else{
                   
          System.out.println( "UDP Tracker: replying 'disabled' to " + client_ip_address );
                         
          reply = new PRUDPPacketReplyError( request.getTransactionId(), "UDP Tracker disabled" );
        }
      }
     
      if ( reply != null ){
       
        InetAddress address = request_dg.getAddress();
       
        ByteArrayOutputStream  baos = new ByteArrayOutputStream();
       
        DataOutputStream os = new DataOutputStream( baos );
                   
        reply.serialise(os);
       
        byte[]  output_buffer = baos.toByteArray();
       
        DatagramPacket reply_packet = new DatagramPacket(output_buffer, output_buffer.length,address,request_dg.getPort());
             
View Full Code Here


    String          client_ip_address,
    PRUDPPacketRequest    request )
  {
    long  conn_id = allocateConnectionId( client_ip_address );
   
    PRUDPPacket reply = new PRUDPPacketReplyConnect(request.getTransactionId(), conn_id );
   
    return( reply );
  }
View Full Code Here

      String  failure_reason = null;
     
      for (int retry_loop=0;retry_loop<PRUDPPacketTracker.DEFAULT_RETRY_COUNT;retry_loop++){
     
        try{
          PRUDPPacket connect_request = new PRUDPPacketRequestConnect();
         
          PRUDPPacket reply = handler.sendAndReceive( auth, connect_request, destination );
         
          if ( reply.getAction() == PRUDPPacketTracker.ACT_REPLY_CONNECT ){
           
            PRUDPPacketReplyConnect connect_reply = (PRUDPPacketReplyConnect)reply;
           
            long  my_connection = connect_reply.getConnectionId();
           
            PRUDPPacketRequestScrape scrape_request = new PRUDPPacketRequestScrape( my_connection, hashes );
                   
            reply = handler.sendAndReceive( auth, scrape_request, destination );
           
            if ( reply.getAction() == PRUDPPacketTracker.ACT_REPLY_SCRAPE ){
   
              auth_ok  = true;
   
              if ( PRUDPPacketTracker.VERSION == 1 ){
                PRUDPPacketReplyScrape  scrape_reply = (PRUDPPacketReplyScrape)reply;
View Full Code Here

TOP

Related Classes of com.aelitis.net.udp.uc.PRUDPPacket

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.