Пример #1
0
void NewIdentityDialog::onUserNameChanged( const QString& name )
{
   if( name != QString() )
   {
      auto pro = bts::application::instance()->get_profile();
      auto keys = pro->get_keychain();

      auto trim_name = fc::trim(name.toUtf8().constData());
      auto ident_key = keys.get_identity_key( trim_name );
      auto key_addr  = /*bts::*/public_key_address( ident_key.get_public_key() );
      ui->publickey->setText( std::string(key_addr).c_str() );

      // make sure the key is unique..
      try {
          bts::addressbook::wallet_identity cur_ident = pro->get_identity( trim_name );
          ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false);
          ui->status_label->setText( tr( "Status: You have already created this identity." ) );
      } 
      catch ( fc::key_not_found_exception& e )
      {
          ui->status_label->setText( tr( "Status: Unknown" ) );
          ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(true);
      }
   }
   else
   {
      ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false);
   }
}
void NewIdentityDialog::onUserNameChanged( const QString& name )
{
   if( name.trimmed() != QString() )
   {
      auto pro = bts::application::instance()->get_profile();
      auto keys = pro->get_keychain();

      auto trim_name = fc::trim(name.toUtf8().constData());
      auto ident_key = keys.get_identity_key( trim_name );
      auto key_addr  = /*bts::*/public_key_address( ident_key.get_public_key() );
      ui->publickey->setText( std::string(key_addr).c_str() );

      // make sure the key is unique..
      try {
          bts::addressbook::wallet_identity cur_ident = pro->get_identity( trim_name );
          ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false);
          ui->status_label->setStyleSheet("QLabel { color : red; }");
          if (cur_ident.dac_id_string == trim_name)
              ui->status_label->setText( tr( "Status: You have already created this identity." ) );
          else
              ui->status_label->setText( tr( "Status: You have already created a similar id." ) );
      } 
      catch ( fc::key_not_found_exception& )
      {
          fc::optional<bts::bitname::name_record> current_record = bts::application::instance()->lookup_name(trim_name);
          if(current_record)
          {
             ui->status_label->setStyleSheet("QLabel { color : red; }");
             ui->status_label->setText(tr("Status: This Keyhotee ID was already registered by someone else."));
             ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false);
          }
          else
          {
             ui->status_label->setStyleSheet("QLabel { color : black; }");
             ui->status_label->setText( tr( "Status: Unknown" ) );
             ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(true);
          }
      }
      catch ( fc::assert_exception& )
      {
          ui->status_label->setStyleSheet("QLabel { color : red; }");
          ui->status_label->setText(tr("Status: Invalid ID. This ID cannot be registered."));
          ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false);
      }
   }
   else
   {
      ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false);
   }
}
Пример #3
0
  profile_ptr                 application::load_profile( const std::string& password )
  { try {
    FC_ASSERT( my->_config );

    // note: stored in temp incase open throws.
    auto tmp_profile = std::make_shared<profile>();
    tmp_profile->open( my->_profile_dir / "default", password );

    std::vector<fc::ecc::private_key> recv_keys;
    auto keychain =  tmp_profile->get_keychain();

    std::vector<identity>   idents = tmp_profile->identities();
    for( auto itr = idents.begin(); itr != idents.end(); ++itr )
    {
       recv_keys.push_back( keychain.get_identity_key( itr->dac_id ) );
    }
    my->_bitchat_client->set_receive_keys( recv_keys );

    return my->_profile = tmp_profile;
  } FC_RETHROW_EXCEPTIONS( warn, "" ) }
fc::string register_key_on_server(const QString& keyhotee_id, const QString& key)
{
  fc::string trimmed_keyhotee_id = keyhotee_id.trimmed().toStdString();
  fc::string trimmed_key = key.trimmed().toStdString();
  auto pro = bts::application::instance()->get_profile();
  auto keys = pro->get_keychain();
  auto ident_key       = keys.get_identity_key( trimmed_keyhotee_id );
  std::string key_addr = public_key_address( ident_key.get_public_key() );

  fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>();
  sock->connect_to( fc::ip::endpoint( fc::ip::address("162.243.67.4"), 3879 ) );
  fc::buffered_istream_ptr isock = std::make_shared<fc::buffered_istream>(sock);
  fc::buffered_ostream_ptr osock = std::make_shared<fc::buffered_ostream>(sock);
  fc::rpc::json_connection_ptr con = std::make_shared<fc::rpc::json_connection>( isock, osock );
  con->exec();

  auto result = con->async_call( "register_key", trimmed_keyhotee_id, trimmed_key, key_addr ).wait();
  auto points = result.get_object()["points"].as_string();
  auto pub    = result.get_object()["pub_key"].as_string();
  return points;
}
Пример #5
0
void NewIdentityDialog::onKey( const QString& key )
{
   try {
      auto pro = bts::application::instance()->get_profile();
      auto keys = pro->get_keychain();
      auto trim_name       = fc::trim(ui->username->text().toStdString());
      auto ident_key       = keys.get_identity_key( trim_name );
      std::string key_addr = public_key_address( ident_key.get_public_key() );

      fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>();
      sock->connect_to( fc::ip::endpoint( fc::ip::address("162.243.67.4"), 3879 ) );
      fc::buffered_istream_ptr isock = std::make_shared<fc::buffered_istream>(sock);
      fc::buffered_ostream_ptr osock = std::make_shared<fc::buffered_ostream>(sock);
      fc::rpc::json_connection_ptr con = std::make_shared<fc::rpc::json_connection>( isock, osock );
      con->exec();

      auto trim_key = key.trimmed();

      auto result = con->async_call( "register_key", trim_name, trim_key.toStdString(), key_addr ).wait();
      auto points = result.get_object()["points"].as_string();
      auto pub    = result.get_object()["pub_key"].as_string();
      fc::usleep(fc::seconds(1));

      ui->status_label->setText( ("Status: Registered with " + points + " points").c_str() );
   } 
   catch ( fc::eof_exception&  )
   {
   }
   catch ( fc::exception& e )
   {
      ui->status_label->setText( ("Status: Error Registering Founder ID: " + e.to_detail_string()).c_str() );
   }
   catch ( ... )
   {
      ui->status_label->setText( "Status: Error Registering Founder ID" );
   }
}
Пример #6
0
/** Based on our interval and our estimated bandwidth, choose a
 * deterministic (but random-ish) time to wake up. */
static void
accounting_set_wakeup_time(void)
{
  char buf[ISO_TIME_LEN+1];
  char digest[DIGEST_LEN];
  crypto_digest_env_t *d_env;
  int time_in_interval;
  uint64_t time_to_exhaust_bw;
  int time_to_consider;

  if (! identity_key_is_set()) {
    if (init_keys() < 0) {
      log_err(LD_BUG, "Error initializing keys");
      tor_assert(0);
    }
  }

  format_iso_time(buf, interval_start_time);
  crypto_pk_get_digest(get_identity_key(), digest);

  d_env = crypto_new_digest_env();
  crypto_digest_add_bytes(d_env, buf, ISO_TIME_LEN);
  crypto_digest_add_bytes(d_env, digest, DIGEST_LEN);
  crypto_digest_get_digest(d_env, digest, DIGEST_LEN);
  crypto_free_digest_env(d_env);

  if (!expected_bandwidth_usage) {
    char buf1[ISO_TIME_LEN+1];
    char buf2[ISO_TIME_LEN+1];
    format_local_iso_time(buf1, interval_start_time);
    format_local_iso_time(buf2, interval_end_time);
    time_to_exhaust_bw = GUESS_TIME_TO_USE_BANDWIDTH;
    interval_wakeup_time = interval_start_time;

    log_notice(LD_ACCT,
           "Configured hibernation.  This interval begins at %s "
           "and ends at %s.  We have no prior estimate for bandwidth, so "
           "we will start out awake and hibernate when we exhaust our quota.",
           buf1, buf2);
    return;
  }

  time_in_interval = (int)(interval_end_time - interval_start_time);

  time_to_exhaust_bw =
    (get_options()->AccountingMax/expected_bandwidth_usage)*60;
  if (time_to_exhaust_bw > TIME_MAX) {
    time_to_exhaust_bw = TIME_MAX;
    time_to_consider = 0;
  } else {
    time_to_consider = time_in_interval - (int)time_to_exhaust_bw;
  }

  if (time_to_consider<=0) {
    interval_wakeup_time = interval_start_time;
  } else {
    /* XXX can we simplify this just by picking a random (non-deterministic)
     * time to be up? If we go down and come up, then we pick a new one. Is
     * that good enough? -RD */

    /* This is not a perfectly unbiased conversion, but it is good enough:
     * in the worst case, the first half of the day is 0.06 percent likelier
     * to be chosen than the last half. */
    interval_wakeup_time = interval_start_time +
      (get_uint32(digest) % time_to_consider);

    format_iso_time(buf, interval_wakeup_time);
  }

  {
    char buf1[ISO_TIME_LEN+1];
    char buf2[ISO_TIME_LEN+1];
    char buf3[ISO_TIME_LEN+1];
    char buf4[ISO_TIME_LEN+1];
    time_t down_time;
    if (interval_wakeup_time+time_to_exhaust_bw > TIME_MAX)
      down_time = TIME_MAX;
    else
      down_time = (time_t)(interval_wakeup_time+time_to_exhaust_bw);
    if (down_time>interval_end_time)
      down_time = interval_end_time;
    format_local_iso_time(buf1, interval_start_time);
    format_local_iso_time(buf2, interval_wakeup_time);
    format_local_iso_time(buf3, down_time);
    format_local_iso_time(buf4, interval_end_time);

    log_notice(LD_ACCT,
           "Configured hibernation.  This interval began at %s; "
           "the scheduled wake-up time %s %s; "
           "we expect%s to exhaust our quota for this interval around %s; "
           "the next interval begins at %s (all times local)",
           buf1,
           time(NULL)<interval_wakeup_time?"is":"was", buf2,
           time(NULL)<down_time?"":"ed", buf3,
           buf4);
  }
}