Package org.gudy.azureus2.plugins.messaging.generic

Examples of org.gudy.azureus2.plugins.messaging.generic.GenericMessageConnection


  public MessageStreamEncoderAdapter( MessageStreamEncoder plug_encoder ) {
    this.plug_encoder = plug_encoder;
  }
 
  public com.aelitis.azureus.core.networkmanager.RawMessage[] encodeMessage( com.aelitis.azureus.core.peermanager.messaging.Message message ) {
    Message plug_msg;
   
    if( message instanceof MessageAdapter ) {  //original message created by plugin, unwrap
      plug_msg = ((MessageAdapter)message).getPluginMessage();
    }
    else {
View Full Code Here


 
    throws MessageException
  {
    if ( incoming ){
     
      throw( new MessageException( "Already connected" ));
    }
   
    if ( connecting ){
     
      throw( new MessageException( "Connect already performed" ));
    }
   
    connecting  = true;
   
    if ( closed ){
     
      throw( new MessageException( "Connection has been closed" ));
    }
   
    InetSocketAddress  tcp_ep = endpoint.getTCP();
       
    if ( tcp_ep != null ){
     
      connectTCP( initial_data, tcp_ep );
     
    }else{
     
      InetSocketAddress  udp_ep = endpoint.getUDP();

      if ( udp_ep != null ){
       
        connectUDP( initial_data, udp_ep, false );
       
      }else{
       
        throw( new MessageException( "No protocols availabld" ));
      }
    }
  }
View Full Code Here

                delegate.close();
               
              }catch( Throwable e ){
              }
             
              reportFailed( new MessageException( "Connection has been closed" ));

            }else{
             
              reportConnected();
            }
View Full Code Here

              final InetSocketAddress  target,
              Map            reply )
            {
              if ( closed ){
                             
                reportFailed( new MessageException( "Connection has been closed" ));

              }else{
               
                connect_method_count++;

                if ( TEST_TUNNEL ){
                 
                  initial_data.rewind();
                 
                  connectTunnel( initial_data, gen_udp, rendezvous, target );
                 
                }else{
               
                  udp_delegate.connect(
                      initial_data,
                      new GenericMessageConnectionAdapter.ConnectionListener()
                      {
                        private boolean  connected;
                       
                        public void
                        connectSuccess()
                        {
                          connected  = true;
                         
                          setDelegate( udp_delegate );
                         
                          if ( closed ){
                           
                            try{
                              delegate.close();
                             
                            }catch( Throwable e ){                         
                            }
                           
                            reportFailed( new MessageException( "Connection has been closed" ));
                           
                          }else{
                           
                            reportConnected();
                          }                       
                        }
                       
                        public void
                        connectFailure(
                          Throwable failure_msg )
                        {
                          if ( connected ){
                           
                            reportFailed( failure_msg );
                           
                          }else{
                           
                            initial_data.rewind();
 
                            connectTunnel( initial_data, gen_udp, rendezvous, target );
                          }
                        }
                      });
                }
              }
            }
           
            public void
            failed(
              int      failure_type )
            {
              reportFailed( new MessageException( "UDP connection attempt failed - NAT traversal failed (" + NATTraversalObserver.FT_STRINGS[ failure_type ] + ")"));
            }
           
            public void
            failed(
              Throwable   cause )
            {
              reportFailed( cause );
            }
           
            public void
            disabled()
            {
              reportFailed( new MessageException( "UDP connection attempt failed as DDB is disabled" ));
            }
          });
    }else{
 
      udp_delegate.connect(
          initial_data,
          new GenericMessageConnectionAdapter.ConnectionListener()
          {
            private boolean  connected;
           
            public void
            connectSuccess()
            {
              connected  = true;
             
              setDelegate( udp_delegate );
             
              if ( closed ){
               
                try{
                  delegate.close();
                 
                }catch( Throwable e ){ 
                }
               
                reportFailed( new MessageException( "Connection has been closed" ));

              }else{
               
                reportConnected();
              }
View Full Code Here

               
              }catch( Throwable e ){
               
              }
             
              reportFailed( new MessageException( "Connection has been closed" ));

            }else{
             
              reportConnected();
            }
View Full Code Here

  {
    int  size = ((PooledByteBufferImpl)message).getBuffer().remaining( DirectByteBuffer.SS_EXTERNAL );
   
    if ( size > getMaximumMessageSize()){
     
      throw( new MessageException( "Message is too large: supplied is " + size + ", maximum is " + getMaximumMessageSize()));
    }
   
    delegate.send( message );
  }
View Full Code Here

           
            System.out.println( "Test: initiating connection" );
           
            final AESemaphore  sem = new AESemaphore( "wait!" );
           
            GenericMessageConnection  con = reg.createConnection( endpoint );
           
            if ( use_sts ){
             
              con = sec_man.getSTSConnection(
                con, my_key,
                new SEPublicKeyLocator()
                {
                  public boolean
                  accept(
                    Object      context,
                    SEPublicKey    other_key )
                  {
                    System.out.println( "acceptKey" );
                   
                    return( true );
                  }
                },
                "test", block_crypto );
            }
           
            con.addListener(
              new GenericMessageConnectionListener()
              {
                public void
                connected(
                  GenericMessageConnection  connection )
                {
                  System.out.println( "connected" );
                 
                  PooledByteBuffer  data = plugin_interface.getUtilities().allocatePooledByteBuffer( "1234".getBytes());
                 
                  try{
                    connection.send( data );
                   
                  }catch( Throwable e ){
                   
                    e.printStackTrace();
                  }
                }
               
                public void
                receive(
                  GenericMessageConnection  connection,
                  PooledByteBuffer      message )
               
                  throws MessageException
                {
                  System.out.println( "receive: " + message.toByteArray().length );
                 
                 
                  try{
                    Thread.sleep(30000);
                  }catch( Throwable e ){
                   
                  }
               
                  /*
                  PooledByteBuffer  reply =
                    plugin_interface.getUtilities().allocatePooledByteBuffer( new byte[16*1024]);
                 
                 
                  connection.send( reply );
                  */
                 
                  System.out.println( "closing connection" );
                 
                  connection.close();
                 
                  sem.release();
                }
               
                public void
                failed(
                  GenericMessageConnection  connection,
                  Throwable           error )
               
                  throws MessageException
                {
                  System.out.println( "Initiator connection error:" );
                 
                  error.printStackTrace();
                 
                  sem.release();
                }
              });
           
     
            con.connect();
           
            sem.reserve();
           
            Thread.sleep( 1000 );
          }
View Full Code Here

         
          try{
              // can't perform connect op while synchronized as may deadlock on password
              // aquisition
           
            GenericMessageConnection generic_connection = outgoingConnection();

            synchronized( this ){

              if ( current_message != allocated_message ){
               
                failed_msg_error = new BuddyPluginException( "current message no longer active" );
               
                generic_connection.close();
               
              }else{
               
                bc = new buddyConnection( generic_connection, true );
               
View Full Code Here

    if ( udp_target != null ){
   
      endpoint.addUDP( udp_target );
    }
       
    GenericMessageConnection  con = null;
   
    try{
      last_connect_attempt = SystemTime.getCurrentTime();
     
      con = msg_registration.createConnection( endpoint );
       
      plugin.addRateLimiters( con );
     
      String reason = "Friend: Outgoing connection establishment";
 
      SESecurityManager sec_man = plugin.getSecurityManager();
     
      con = sec_man.getSTSConnection(
          con,
          sec_man.getPublicKey( SEPublicKey.KEY_TYPE_ECC_192, reason ),
 
          new SEPublicKeyLocator()
          {
            public boolean
            accept(
              Object      context,
              SEPublicKey    other_key )
            {
              String  other_key_str = Base32.encode( other_key.encodeRawPublicKey());

              if ( other_key_str.equals( public_key )){
               
                consec_connect_fails  = 0;
               
                return( true );
               
              }else{
               
                log( getString() + ": connection failed due to pk mismatch" );
             
                return( false );
              }
            }
          },
          reason,
          BuddyPlugin.BLOCK_CRYPTO );   
       
      con.connect();
     
      return( con );
     
    }catch( Throwable e ){
     
      if ( con != null ){
     
        consec_connect_fails++;
       
        try{
          con.close();
         
        }catch( Throwable f ){
         
          log( "Failed to close connection", f );
        }
View Full Code Here

          public MessageStreamEncoder createEncoder() {  return new GenericMessageEncoder();}
          public MessageStreamDecoder createDecoder() {  return new GenericMessageDecoder(type, description);}
        });
   
  return(
    new GenericMessageRegistration()
    {
      public GenericMessageEndpoint
      createEndpoint(
        InetSocketAddress  notional_target )
      {
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.plugins.messaging.generic.GenericMessageConnection

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.