Ejemplo n.º 1
0
      void chain_connect_loop()
      {
         _chain_connected = false;
         while( true ) //!_quit_promise->ready() )
         {
            //for( auto itr = _config->default_mail_nodes.begin(); itr != _config->default_mail_nodes.end(); ++itr )
            {
                 try {
                    //ilog( "mail connect ${e}", ("e",*itr) );
                    _chain_con.connect(fc::ip::endpoint::from_string("127.0.0.1:4567"));
                  //  _chain_con.set_last_sync_time( _profile->get_last_sync_time() );

                    subscribe_message msg;
                    msg.version        = 0;
                    if( chain.head_block_num() != uint32_t(-1) )
                       msg.last_block     = chain.head_block_id();
                    _chain_con.send( mail::message( msg ) );
                    _chain_connected = true;
                    return;
                 } 
                 catch ( const fc::exception& e )
                 {
                    wlog( "${e}", ("e",e.to_detail_string()));
                 }
            }
            fc::usleep( fc::seconds(5) );
         }
      }
Ejemplo n.º 2
0
      void chain_connect_loop()
      {
         _chain_connected = false;
         while( !chain_connect_loop_complete.canceled() )
         {
            for( auto itr = _config.unique_node_list.begin(); itr != _config.unique_node_list.end(); ++itr )
            {
                 try {
                    std::cout<< "\rconnecting to bitshares network: "<<itr->first<<"\n";
                    // TODO: pass public key to connection so we can avoid man-in-the-middle attacks
                    _chain_con.connect( fc::ip::endpoint::from_string(itr->first) );

                    subscribe_message msg;
                    msg.version        = 0;
                    if( chain.head_block_num() != uint32_t(-1) )
                    {
                       msg.last_block     = chain.head_block_id();
                    }
                    _chain_con.send( mail::message( msg ) );
                    std::cout<< "\rconnected to bitshares network\n";
                    _chain_connected = true;
                    return;
                 } 
                 catch ( const fc::exception& e )
                 {
                    std::cout<< "\runable to connect to bitshares network at this time.\n";
                    wlog( "${e}", ("e",e.to_detail_string()));
                 }
            }

            // sleep in .5 second increments so we can quit quickly without hanging
            for( uint32_t i = 0; i < 30 && !chain_connect_loop_complete.canceled(); ++i )
               fc::usleep( fc::microseconds(500000) );
         }
      }