コード例 #1
0
ファイル: rpc_client.cpp プロジェクト: BitMoneta/bitshares
    void rpc_client_impl::connect_to(const fc::ip::endpoint& remote_endpoint,
                                     const bts::blockchain::public_key_type& remote_public_key)
    {
       fc::buffered_istream_ptr buffered_istream;
       fc::buffered_ostream_ptr buffered_ostream;

       if( remote_public_key != bts::blockchain::public_key_type() )
       {
          net::stcp_socket_ptr socket = std::make_shared<bts::net::stcp_socket>();

          try
          {
             socket->connect_to(remote_endpoint);
          }
          catch ( const fc::exception& e )
          {
             elog( "fatal: error opening RPC socket to endpoint ${endpoint}: ${e}", ("endpoint", remote_endpoint)("e", e.to_detail_string() ) );
             throw;
          }

          std::vector<char> packed_signature(80, ' ');
          FC_ASSERT( socket->readsome(packed_signature.data(), packed_signature.size()) == 80, "Unexpected number of bytes read from RPC socket" );
          fc::ecc::compact_signature signature;
          signature = fc::raw::unpack<fc::ecc::compact_signature>(packed_signature);
          wdump((signature));
          FC_ASSERT(blockchain::public_key_type(fc::ecc::public_key(signature, fc::digest(socket->get_shared_secret())))
                    == remote_public_key,
                    "Unable to establish secure connection with server.");

          buffered_istream = std::make_shared<fc::buffered_istream>(socket);
          buffered_ostream = std::make_shared<utilities::padding_ostream<>>(socket);
       } else {
          fc::tcp_socket_ptr socket = std::make_shared<fc::tcp_socket>();

          try
          {
             socket->connect_to(remote_endpoint);
          }
          catch ( const fc::exception& e )
          {
             elog( "fatal: error opening RPC socket to endpoint ${endpoint}: ${e}", ("endpoint", remote_endpoint)("e", e.to_detail_string() ) );
             throw;
          }

          buffered_istream = std::make_shared<fc::buffered_istream>(socket);
          buffered_ostream = std::make_shared<fc::buffered_ostream>(socket);
       }

       _json_connection = std::make_shared<fc::rpc::json_connection>(std::move(buffered_istream),
                                                                     std::move(buffered_ostream));
       _json_exec_loop_complete = fc::async([=](){ _json_connection->exec(); }, "json exec loop");
    }
コード例 #2
0
    void rpc_client_impl::connect_to(const fc::ip::endpoint& remote_endpoint)
    {
      fc::tcp_socket_ptr socket = std::make_shared<fc::tcp_socket>();
      try 
      {
        socket->connect_to(remote_endpoint);
      }
      catch ( const fc::exception& e )
      {
        elog( "fatal: error opening RPC socket to endpoint ${endpoint}: ${e}", ("endpoint", remote_endpoint)("e", e.to_detail_string() ) );
        throw;
      }

      fc::buffered_istream_ptr buffered_istream = std::make_shared<fc::buffered_istream>(socket);
      fc::buffered_ostream_ptr buffered_ostream = std::make_shared<fc::buffered_ostream>(socket);

      _json_connection = std::make_shared<fc::rpc::json_connection>(std::move(buffered_istream), 
                                                                    std::move(buffered_ostream));
      _json_exec_loop_complete = fc::async([=](){ _json_connection->exec(); }, "json exec loop");
    }