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

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


  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

          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

      final int  stream_crypto   = MessageManager.STREAM_ENCRYPTION_RC4_REQUIRED;
      final boolean  use_sts    = true;
      final int  block_crypto   = SESecurityManager.BLOCK_ENCRYPTION_AES;
     
      GenericMessageRegistration  reg =
        plugin_interface.getMessageManager().registerGenericMessageType(
          "GENTEST", "Gen test desc",
          stream_crypto,
          new GenericMessageHandler()
          {
            public boolean
            accept(
              GenericMessageConnection  connection )
           
              throws MessageException
            {
              System.out.println( "accept" );
             
              try{
                if ( use_sts ){
                 
                  connection = sec_man.getSTSConnection(
                      connection,
                      my_key,
                      new SEPublicKeyLocator()
                      {
                        public boolean
                        accept(
                          Object    context,
                          SEPublicKey  other_key )
                        {
                          System.out.println( "acceptKey" );
                         
                          return( true );
                        }
                      },
                      "test",
                      block_crypto );
                }
                   
                connection.addListener(
                  new GenericMessageConnectionListener()
                  {
                    public void
                    connected(
                      GenericMessageConnection  connection )
                    {
                    }
                   
                    public void
                    receive(
                      GenericMessageConnection  connection,
                      PooledByteBuffer      message )
                   
                      throws MessageException
                    {
                      System.out.println( "receive: " + message.toByteArray().length );
                     
                      PooledByteBuffer  reply =
                        plugin_interface.getUtilities().allocatePooledByteBuffer(
                            new byte[connection.getMaximumMessageSize()]);
                     
                      connection.send( reply );
                    }
                   
                    public void
                    failed(
                      GenericMessageConnection  connection,
                      Throwable           error )
                   
                      throws MessageException
                    {
                      System.out.println( "Responder connection error:" );

                      error.printStackTrace();
                   
                  });
               
              }catch( Throwable e ){
               
                connection.close();
               
                e.printStackTrace();
              }
             
              return( true );
            }
          });
     
      InetSocketAddress  tcp_target = new InetSocketAddress( "127.0.0.1",     6889 );
      InetSocketAddress  udp_target = new InetSocketAddress( "212.159.18.92",   6881 );
     
      GenericMessageEndpoint  endpoint = reg.createEndpoint( tcp_target );
     
      endpoint.addTCP( tcp_target );
      endpoint.addUDP( udp_target );
     
      while( true ){
       
        try{
          for (int i=0;i<1000;i++){
           
            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,
View Full Code Here

  protected GenericMessageConnection
  outgoingConnection()
 
    throws BuddyPluginException
  {
    GenericMessageRegistration msg_registration = plugin.getMessageRegistration();

    if ( msg_registration == null ){
           
      throw( new BuddyPluginException( "Messaging system unavailable" ));
    }
   
    InetAddress ip = getIP();
   
    if ( ip == null ){
           
      throw( new BuddyPluginException( "Friend offline (no usable IP address)" ));
    }
   
    InetSocketAddress  tcp_target  = null;
    InetSocketAddress  udp_target  = null;
   
    int  tcp_port = getTCPPort();
   
    if ( tcp_port > 0 ){
     
      tcp_target = new InetSocketAddress( ip, tcp_port );
    }
   
    int  udp_port = getUDPPort();
   
    if ( udp_port > 0 ){
     
      udp_target = new InetSocketAddress( ip, udp_port );
    }

    InetSocketAddress  notional_target = tcp_target;
   
    if ( notional_target == null ){
   
      notional_target = udp_target;
    }
   
    if ( notional_target == null ){
           
      throw( new BuddyPluginException( "Friend offline (no usable protocols)" ));
    }
   
    GenericMessageEndpoint  endpoint = msg_registration.createEndpoint( notional_target );
   
    if ( tcp_target != null ){
   
      endpoint.addTCP( tcp_target );
    }
   
    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";
 
View Full Code Here

    }
    else {
      plug_msg = new MessageAdapter( message )//core created
    }
   
    RawMessage raw_plug = plug_encoder.encodeMessage( plug_msg );
    return new com.aelitis.azureus.core.networkmanager.RawMessage[]{ new RawMessageAdapter( raw_plug )};
  }
View Full Code Here

TOP

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

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.