Example #1
0
cafs::link cafs::import( const fc::path& p ) {
  if( !fc::exists(p) )  {
    FC_THROW_MSG( "Path does not exist %s", p.string() );
  }
  if( fc::is_regular_file( p ) ) {
    if( fc::file_size(p) > IMBED_THRESHOLD ) {
      auto file_head = import_file(p);
      fc::vector<char>      data(MAX_CHUNK_SIZE);
      fc::datastream<char*> ds(data.data()+1, data.size()-1);
      fc::raw::pack( ds, file_head );
      data[0] = cafs::file_header_type;
      
      //fc::datastream<const char*> ds2(data.data()+1, data.size()-1);
      //file_header tmp;
      //fc::raw::unpack( ds2, tmp );
      //slog( "test unpack %s", fc::json::to_string( tmp ).c_str() );
      data.resize( ds.tellp() );

      //slog( "pre randomized... '%s'", fc::to_hex( data.data(), 16 ).c_str() );
      size_t seed = randomize(data, *((uint64_t*)fc::sha1::hash(data.data(),data.size()).data()) );
      auto chunk_head = slice_chunk( data );
      //slog( "slice chunk %s", fc::json::to_string( chunk_head ).c_str() );
      store_chunk( chunk_head, data );
      
      return link( chunk_head.calculate_id(), seed );
    } else { // no header, just raw data from the file stored in the chunk
      fc::vector<char> data( fc::file_size(p)+1 );
      data[0] = file_data_type;
      fc::ifstream ifile( p.string(), fc::ifstream::binary );
      ifile.read( data.data()+1, data.size()-1 );
      size_t seed = randomize(data, *((uint64_t*)fc::sha1::hash(data.data(),data.size()).data()) );

      auto chunk_head = slice_chunk( data );

      store_chunk( chunk_head, data );
      return link( chunk_head.calculate_id(), seed );
    }
  }
  else if( fc::is_directory(p) ) {
    auto dir = import_directory(p);

    fc::vector<char> data(MAX_CHUNK_SIZE);
    fc::datastream<char*> ds(data.data()+1, data.size()-1);
    fc::raw::pack( ds, dir );
    data[0] = directory_type;
    data.resize( ds.tellp()+1 );

    size_t seed = randomize(data, *((uint64_t*)fc::sha1::hash(data.data(),data.size()).data()) );
    auto chunk_head = slice_chunk( data );
    link l( chunk_head.calculate_id(), seed );
    store_chunk( chunk_head, data );
    return l;
  }
  FC_THROW_MSG( "Unsupported file type while importing '%s'", p.string() );
  return cafs::link();
}
Example #2
0
 fc::string detail::process_impl::windows_shell_escape_command(const fc::path& exe, const vector<string>& args) {
   fc::stringstream command_line;
   command_line << windows_shell_escape(exe.string());
   for (unsigned i = 0; i < args.size(); ++i)
     command_line << " " << windows_shell_escape(args[i]);
   return command_line.str();
 }
Example #3
0
   std::vector<fc::ecc::private_key> import_bitcoin_wallet( const fc::path& wallet_dat, const std::string& passphrase )
   { try {

      wallet_db db( wallet_dat.to_native_ansi_path().c_str() );
      return collect_keys( db, passphrase );

   } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Example #4
0
      signed_transaction load_genesis( const fc::path& csv, uint64_t& total_coins )
      {
          total_coins = 0;
          signed_transaction coinbase;
          coinbase.version = 0;
        //  coinbase.valid_after = 0;
        //  coinbase.valid_blocks = 0;

          std::ifstream in(csv.generic_string().c_str(), std::ios::binary);
          std::string line;
          std::getline( in, line );
          while( in.good() )
          {
            std::stringstream ss(line);
            std::string addr;
            uint64_t amnt;
            ss >> addr >> amnt;
            total_coins += amnt;
            coinbase.outputs.push_back( 
              trx_output( claim_by_pts_output( bts::pts_address(addr) ), amnt, asset::bts) );
            std::getline( in, line );
          }

          return coinbase;
      }
bool test_file::compare_files()
{
  //first check if files are equal size, if not, files are different
  size_t result_file_size = boost::filesystem::file_size(_result_file.string());
  size_t expected_result_file_size = boost::filesystem::file_size(_expected_result_file.string());
  bool file_sizes_equal = (result_file_size == expected_result_file_size);
  if (!file_sizes_equal)
    return false;

  //files may be equal since they have the same size, so check further
  std::ifstream lhs(_result_file.string().c_str());
  std::ifstream rhs(_expected_result_file.string().c_str());

  typedef std::istreambuf_iterator<char> istreambuf_iterator;
  return std::equal( istreambuf_iterator(lhs),  istreambuf_iterator(), istreambuf_iterator(rhs));
}
Example #6
0
void compile_json_to_source(
    const fc::path& source_file_name,
    const fc::path& prologue_file_name,
    const fc::path& json_file_name,
    const fc::path& epilogue_file_name
    )
{
  fc::mutable_variant_object template_context;

  template_context[  "source_file_name"] =   source_file_name.string();
  template_context["prologue_file_name"] = prologue_file_name.string();
  template_context[    "json_file_name"] =     json_file_name.string();
  template_context["epilogue_file_name"] = epilogue_file_name.string();

  std::ofstream source_file(source_file_name.string());

  if (prologue_file_name.string() != "")
  {
    std::ifstream prologue_file(prologue_file_name.string());
    std::stringstream ss_prologue_file;
    ss_prologue_file << prologue_file.rdbuf();
    source_file << format_string(ss_prologue_file.str(), template_context);
  }

  std::ifstream json_file(json_file_name.string());

  std::string line;
  bool first = true;
  while (std::getline(json_file, line))
  {
    if (first)
      first = false;
    else
      source_file << ",\n";
    source_file << "  " << bts::utilities::escape_string_for_c_source_code(line);
  }

  if (epilogue_file_name.string() != "")
  {
    std::ifstream epilogue_file(epilogue_file_name.string());
    std::stringstream ss_epilogue_file;
    ss_epilogue_file << epilogue_file.rdbuf();
    source_file << format_string(ss_epilogue_file.str(), template_context);
  }

  return;
}
Example #7
0
std::vector<fc::ecc::private_key> import_electrum_wallet( const fc::path& wallet_dat, const std::string& passphrase )
{ try {
  std::vector<fc::ecc::private_key> keys;
  electrumwallet wallet( wallet_dat.to_native_ansi_path());
  if( !wallet.ok() ) FC_THROW_EXCEPTION( fc::invalid_arg_exception, "invalid electrum wallet");
  wallet.derivekeys( passphrase );
  return wallet.keys();
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
void create_genesis_block(fc::path genesis_json_file)
{
   vector<fc::ecc::private_key> delegate_private_keys;

   genesis_block_config config;
   config.precision         = BTS_BLOCKCHAIN_PRECISION;
   config.timestamp         = bts::blockchain::now();
   config.base_symbol       = BTS_BLOCKCHAIN_SYMBOL;
   config.base_name         = BTS_BLOCKCHAIN_NAME;
   config.base_description  = BTS_BLOCKCHAIN_DESCRIPTION;
   config.supply            = BTS_BLOCKCHAIN_INITIAL_SHARES;

   // set our fake random number generator to generate deterministic keys
   set_random_seed_for_testing(fc::sha512());
   std::ofstream key_stream( genesis_json_file.string() + ".keypairs" );
   //create a script for importing the delegate keys
   std::ofstream delegate_key_import_stream(genesis_json_file.string() + ".log");
   delegate_key_import_stream << CLI_PROMPT_SUFFIX " enable_output false" << std::endl;
   std::cout << "*** creating delegate public/private key pairs ***" << std::endl;
   for( uint32_t i = 0; i < BTS_BLOCKCHAIN_NUM_DELEGATES; ++i )
   {
      name_config delegate_account;
      delegate_account.name = "delegate" + fc::to_string(i);
      fc::ecc::private_key delegate_private_key = fc::ecc::private_key::generate();
      delegate_private_keys.push_back( delegate_private_key );
      
      auto delegate_public_key =delegate_private_key.get_public_key();
      delegate_account.owner = delegate_public_key;
      delegate_account.is_delegate = true;

      config.names.push_back(delegate_account);
      config.balances.push_back( std::make_pair( pts_address(fc::ecc::public_key_data(delegate_account.owner)), BTS_BLOCKCHAIN_INITIAL_SHARES/BTS_BLOCKCHAIN_NUM_DELEGATES) );

      //output public/private key pair for each delegate to a file
      string wif_key = bts::utilities::key_to_wif( delegate_private_key );
      key_stream << std::string(delegate_account.owner) << "   " << wif_key << std::endl;
      //add command to import the delegate keys into a client
      delegate_key_import_stream << CLI_PROMPT_SUFFIX " wallet_import_private_key " << wif_key << " " << delegate_account.name << " false" << std::endl;
   }
   delegate_key_import_stream << CLI_PROMPT_SUFFIX " enable_output true" << std::endl;

   fc::json::save_to_file( config, genesis_json_file);
}
  bts_xt_client_test_config() 
  {
    // parse command-line options
    boost::program_options::options_description option_config("Allowed options");
    option_config.add_options()("bts-client-exe", boost::program_options::value<std::string>(), "full path to the executable to test")
                               ("bts-server-exe", boost::program_options::value<std::string>(), "full path to the server executable for testing client-server mode")
                               ("extra-help", "display this help message");


    boost::program_options::variables_map option_variables;
    try
    {
      boost::program_options::store(boost::program_options::command_line_parser(boost::unit_test::framework::master_test_suite().argc, 
                                                                                boost::unit_test::framework::master_test_suite().argv).
        options(option_config).run(), option_variables);
      boost::program_options::notify(option_variables);
    }
    catch (boost::program_options::error&)
    {
      std::cerr << "Error parsing command-line options\n\n";
      std::cerr << option_config << "\n";
      exit(1);
    }

    if (option_variables.count("extra-help"))
    {
      std::cout << option_config << "\n";
      exit(0);
    }

    if (option_variables.count("bts-client-exe"))
      bts_client_exe = option_variables["bts-client-exe"].as<std::string>().c_str();

    if (option_variables.count("bts-server-exe"))
      bts_server_exe = option_variables["bts-server-exe"].as<std::string>().c_str();

    std::cout << "Testing " << bts_client_exe.string() << "\n";
    std::cout << "Using config directory " << config_directory.string() << "\n";
    fc::create_directories(config_directory);

    boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages);
  }
Example #10
0
  void profile::open( const fc::path& profile_dir, const std::string& password )
  { try {
      ilog("opening profile: ${profile_dir}",("profile_dir",profile_dir));
      my->_profile_name = profile_dir.filename().generic_wstring();

      fc::create_directories( profile_dir );
      fc::create_directories( profile_dir / "addressbook" );
      fc::create_directories( profile_dir / "idents" );
      fc::create_directories( profile_dir / "mail" );
      fc::create_directories( profile_dir / "mail" / "inbox" );
      fc::create_directories( profile_dir / "mail" / "draft" );
      fc::create_directories( profile_dir / "mail" / "pending" );
      fc::create_directories( profile_dir / "mail" / "sent" );
      fc::create_directories( profile_dir / "chat" );
      fc::create_directories( profile_dir / "request" );
      fc::create_directories( profile_dir / "authorization" );

      ilog("loading master key file:" KEYHOTEE_MASTER_KEY_FILE);
      auto profile_cfg_key         = fc::sha512::hash( password.c_str(), password.size() );
      std::vector<char> stretched_seed_data;
      try {
        stretched_seed_data     = fc::aes_load( profile_dir / KEYHOTEE_MASTER_KEY_FILE, profile_cfg_key );
      }
      catch (fc::exception& /* e */)
      { //try to open legacy name for key file
        wlog("Could not open " KEYHOTEE_MASTER_KEY_FILE ", trying to open legacy key file (.strecthed_seed).");
        stretched_seed_data     = fc::aes_load( profile_dir / ".stretched_seed", profile_cfg_key );
      }

      ilog("opening profile databases");
      my->_keychain.set_seed( fc::raw::unpack<fc::sha512>(stretched_seed_data) );
      my->_addressbook->open( profile_dir / "addressbook", profile_cfg_key );
      my->_idents.open( profile_dir / "idents" );
      my->_inbox_db->open( profile_dir / "mail" / "inbox", profile_cfg_key );
      my->_draft_db->open( profile_dir / "mail" / "draft", profile_cfg_key );
      my->_pending_db->open( profile_dir / "mail" / "pending", profile_cfg_key );
      my->_sent_db->open( profile_dir / "mail" / "sent", profile_cfg_key );
      my->_chat_db->open( profile_dir / "chat", profile_cfg_key );
      my->_request_db->open( profile_dir / "request", profile_cfg_key );
      my->_auth_db->open( profile_dir / "authorization", profile_cfg_key );
      my->_last_sync_time.open( profile_dir / "mail" / "last_recv", true );
      if( *my->_last_sync_time == fc::time_point())
      {
          *my->_last_sync_time = fc::time_point::now() - fc::days(5);
          ilog("set last_sync_time to ${t}",("t",*my->_last_sync_time));
      }
      else
          ilog("loaded last_sync_time = ${t}",("t",*my->_last_sync_time));
    ilog("finished opening profile");
  } FC_RETHROW_EXCEPTIONS( warn, "", ("profile_dir",profile_dir) ) }
Example #11
0
        void open( const fc::path& dir, bool create = true, size_t cache_size = 0 )
        { try {
           FC_ASSERT( !is_open(), "Database is already open!" );

           ldb::Options opts;
           opts.comparator = &_comparer;
           opts.create_if_missing = create;
           opts.max_open_files = 64;
           opts.compression = leveldb::kNoCompression;

           if( cache_size > 0 )
           {
               opts.write_buffer_size = cache_size / 4; // up to two write buffers may be held in memory simultaneously
               _cache.reset( leveldb::NewLRUCache( cache_size / 2 ) );
               opts.block_cache = _cache.get();
           }

           if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) )
           {
               // LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
               // on corruption in later versions.
               opts.paranoid_checks = true;
           }

           _read_options.verify_checksums = true;
           _iter_options.verify_checksums = true;
           _iter_options.fill_cache = false;
           _sync_options.sync = true;

           // Given path must exist to succeed toNativeAnsiPath
           fc::create_directories( dir );
           std::string ldbPath = dir.to_native_ansi_path();

           ldb::DB* ndb = nullptr;
           const auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
           if( !ntrxstat.ok() )
           {
               elog( "Failure opening database: ${db}\nStatus: ${msg}", ("db",dir)("msg",ntrxstat.ToString()) );
               FC_THROW_EXCEPTION( level_pod_map_open_failure, "Failure opening database: ${db}\nStatus: ${msg}",
                                   ("db",dir)("msg",ntrxstat.ToString()) );
           }
           _db.reset( ndb );

           try_upgrade_db( dir, ndb, fc::get_typename<Value>::name(), sizeof( Value ) );
        } FC_CAPTURE_AND_RETHROW( (dir)(create)(cache_size) ) }
Example #12
0
            void peer_database_impl::close() {
                std::vector<potential_peer_record> peer_records;
                peer_records.reserve(_potential_peer_set.size());
                std::copy(_potential_peer_set.begin(), _potential_peer_set.end(), std::back_inserter(peer_records));

                try {
                    fc::path peer_database_filename_dir = _peer_database_filename.parent_path();
                    if (!fc::exists(peer_database_filename_dir)) {
                        fc::create_directories(peer_database_filename_dir);
                    }
                    fc::json::save_to_file(peer_records, _peer_database_filename);
                }
                catch (const fc::exception &e) {
                    elog("error saving peer database to file ${peer_database_filename}",
                            ("peer_database_filename", _peer_database_filename));
                }
                _potential_peer_set.clear();
            }
        void open( const fc::path& dir, bool create = true, size_t cache_size = 0 )
        { try {
           ldb::Options opts;
           opts.comparator = &_comparer;
           opts.create_if_missing = create;

           if (cache_size) {
               _cache.reset(leveldb::NewLRUCache(cache_size));
               opts.block_cache = _cache.get();
           }
           /*
           if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) )
           {
               // LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
               // on corruption in later versions.
               opts.paranoid_checks = true;
           }
           opts.max_open_files = 64;

           _read_options.verify_checksums = true;
           _iter_options.verify_checksums = true;
           _iter_options.fill_cache = false;
           _sync_options.sync = true;
           */

           /// \warning Given path must exist to succeed toNativeAnsiPath
           fc::create_directories(dir);

           std::string ldbPath = dir.to_native_ansi_path();

           ldb::DB* ndb = nullptr;
           auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
           if( !ntrxstat.ok() )
           {
               FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}",
                    ("db",dir)
                    ("msg",ntrxstat.ToString())
                    );
           }
           _db.reset(ndb);
           try_upgrade_db( dir,ndb, fc::get_typename<Value>::name(),sizeof(Value) );
        } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Example #14
0
      void mmap_struct_base::open( const fc::path& file, size_t s, bool create )
      {
         if( !fc::exists( file ) || fc::file_size(file) != s )
         {
            fc::ofstream out( file );
            char buffer[1024];
            memset( buffer, 0, sizeof(buffer) );

            size_t bytes_left = s;
            while( bytes_left > 0 )
            {
               size_t to_write = std::min<size_t>(bytes_left, sizeof(buffer) );
               out.write( buffer, to_write );
               bytes_left -= to_write;
            }
         }

         std::string filePath = file.to_native_ansi_path(); 

         _file_mapping.reset( new fc::file_mapping( filePath.c_str(), fc::read_write ) );
         _mapped_region.reset( new fc::mapped_region( *_file_mapping, fc::read_write, 0, s ) );
      }
Example #15
0
        void open( const fc::path& dir, bool create = true )
        {
           ldb::Options opts;
           opts.create_if_missing = create;
           opts.comparator = & _comparer;

           /// \waring Given path must exist to succeed toNativeAnsiPath
           fc::create_directories(dir);

           std::string ldbPath = dir.to_native_ansi_path();

           ldb::DB* ndb = nullptr;
           auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
           if( !ntrxstat.ok() )
           {
               FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}", 
                    ("db",dir)
                    ("msg",ntrxstat.ToString()) 
                    );
           }
           _db.reset(ndb);
           UpgradeDbIfNecessary(dir,ndb, fc::get_typename<Value>::name(),sizeof(Value));
        }
Example #16
0
/**
 *  Imports the file chunks into the database, but does not
 *  import the file_header itself as a chunk, as it may be
 *  imbedded within another chunk.
 *
 *  @pre is_regular_file(p) 
 */
cafs::file_header cafs::import_file( const fc::path& p ) {
  file_header head;  
  head.file_size = fc::file_size(p);

  fc::vector<char> chunk( MAX_CHUNK_SIZE );

  // divide file up into chunks and slices
  fc::ifstream in( p.string(), fc::ifstream::binary );
  uint32_t r = 0;
  while( r < head.file_size ) {
    size_t some = fc::min( size_t(chunk.size()), size_t(head.file_size-r) );
    in.read( chunk.data(), some );
    size_t seed = randomize(chunk, *((uint64_t*)fc::sha1::hash(chunk.data(),chunk.size()).data()) );

    chunk.resize(some);
    auto chunk_head = slice_chunk(chunk);
    auto chunk_id   = store_chunk( chunk_head, chunk );

    head.add_chunk( chunk_id, seed, chunk_head );
    r += some;
  }
  return head;
}
void run_regression_test(fc::path test_dir, bool with_network)
{
  set_random_seed_for_testing(fc::sha512());

  //  open testconfig file
  //  for each line in testconfig file
  //    add a verify_file object that knows the name of the input command file and the generated log file
  //    start a process with that command line
  //  wait for all processes to shutdown
  //  for each verify_file object,
  //    compare generated log files in datadirs to golden reference file (i.e. input command files)

  // caller of this routine should have made sure we are already in bitshares_toolkit/test dir.
  // so we pop dirs to create regression_tests_results as sibling to bitshares_toolkit source directory
  // (because we don't want the test results to be inadvertantly added to git repo).
  fc::path original_working_directory = boost::filesystem::current_path();
  fc::path regression_test_output_directory = original_working_directory.parent_path().parent_path();
  regression_test_output_directory /= "regression_tests_output";

  // Create an expected output file in the test subdir for the test output.
  fc::path test_output_dir = regression_test_output_directory / test_dir;
  boost::filesystem::create_directories(test_output_dir);
  fc::path expected_output_file = test_output_dir / "expected_output.log";
  std::ofstream expected_output_stream(expected_output_file.string());

  try 
  {
    std::cout << "*** Executing " << test_dir.string() << std::endl;

    boost::filesystem::current_path(test_dir.string());

    //create a small genesis block to reduce test startup time
    //fc::temp_directory temp_dir;
    //fc::path genesis_json_file =  temp_dir.path() / "genesis.json";
    //create_genesis_block(genesis_json_file);
    //DLN: now we just used the genesis file already committed to repo, update it
    //     using "-t make_genesis_block" if desired.
    fc::path genesis_json_file = "../../test_genesis.json";


    //open test configuration file (contains one line per client to create)
    fc::path test_config_file_name = "test.config";
    std::ifstream test_config_file(test_config_file_name.string());

    //create one client per line and run each client's input commands
    auto sim_network = std::make_shared<bts::net::simulated_network>();
    vector<test_file> tests;
    string line = " --min-delegate-connection-count=0 ";
    fc::future<void> client_done;
    while (std::getline(test_config_file,line))
    {
      //append genesis_file to load to command-line for now (later should be pre-created in test dir I think)
      line += " --genesis-config " + genesis_json_file.string();

      //if no data-dir specified, put in ../bitshares_toolkit/regression_tests/${test dir}/${client_name}
      string client_name = line.substr(0, line.find(' '));
      size_t data_dir_position = line.find("--data-dir");
      if (data_dir_position == string::npos)
      {
        fc::path default_data_dir = regression_test_output_directory / test_dir / client_name;
        line += " --data-dir=" + default_data_dir.string();
        fc::remove_all(default_data_dir);
      }


      //parse line into argc/argv format for boost program_options
      int argc = 0; 
      char** argv = nullptr;
    #ifndef WIN32 // then UNIX 
      //use wordexp to get argv/arc
      wordexp_t wordexp_result;
      wordexp(line.c_str(), &wordexp_result, 0);
      auto option_variables = parse_option_variables(wordexp_result.we_wordc, wordexp_result.we_wordv);
      argv = wordexp_result.we_wordv;
      argc = wordexp_result.we_wordc;
    #else
      //use ExpandEnvironmentStrings and CommandLineToArgv to get argv/arc
      char expanded_line[40000];
      ExpandEnvironmentStrings(line.c_str(),expanded_line,sizeof(expanded_line));
      argv = CommandLineToArgvA(expanded_line,&argc);
      auto option_variables = bts::client::parse_option_variables(argc, argv);
    #endif

      //extract input command files from cmdline options and concatenate into
      //one expected output file so that we can compare against output log
      std::vector<string> input_logs = option_variables["input-log"].as<std::vector<string>>();
      for (string input_log : input_logs)
        {
        std::ifstream input_stream(input_log);
        expected_output_stream << input_stream.rdbuf();
        }
      expected_output_stream.close();

      //run client with cmdline options
      if (with_network)
      {
        FC_ASSERT(false, "Not implemented yet!")
      }
      else
      {
        bts::client::client_ptr client = std::make_shared<bts::client::client>(sim_network);
        client->configure_from_command_line(argc,argv);
        client_done = client->start();
      }


    #ifndef WIN32 // then UNIX 
      wordfree(&wordexp_result);
    #else
      GlobalFree(argv);
    #endif

      //add a test that compares input command file to client's log file
      fc::path result_file = ::get_data_dir(option_variables) / "console.log";
      tests.push_back( test_file(client_done, result_file, expected_output_file) );
    } //end while not end of test config file

    //check each client's log file against it's golden reference log file
    for (test_file current_test : tests)
    {
      //current_test.compare_files();
      current_test.client_done.wait();
      BOOST_CHECK_MESSAGE(current_test.compare_files(), "Results mismatch with golden reference log");
    }
  } 
Example #18
0
 inline void pack( Stream& s, const fc::path& tp )
 {
    fc::raw::pack( s, tp.generic_string() );
 }
Example #19
0
 void ifstream::open( const fc::path& file, int m ) {
    my->ifs.open( file.string().c_str(), std::ios::binary );
 }
Example #20
0
fc::optional<fc::logging_config> load_logging_config_from_ini_file(const fc::path& config_ini_filename)
{
   try
   {
      fc::logging_config logging_config;
      bool found_logging_config = false;

      boost::property_tree::ptree config_ini_tree;
      boost::property_tree::ini_parser::read_ini(config_ini_filename.preferred_string().c_str(), config_ini_tree);
      for (const auto& section : config_ini_tree)
      {
         const std::string& section_name = section.first;
         const boost::property_tree::ptree& section_tree = section.second;

         const std::string console_appender_section_prefix = "log.console_appender.";
         const std::string file_appender_section_prefix = "log.file_appender.";
         const std::string logger_section_prefix = "logger.";

         if (boost::starts_with(section_name, console_appender_section_prefix))
         {
            std::string console_appender_name = section_name.substr(console_appender_section_prefix.length());
            std::string stream_name = section_tree.get<std::string>("stream");

            // construct a default console appender config here
            // stdout/stderr will be taken from ini file, everything else hard-coded here
            fc::console_appender::config console_appender_config;
            console_appender_config.level_colors.emplace_back(
               fc::console_appender::level_color(fc::log_level::debug,
                                                 fc::console_appender::color::green));
            console_appender_config.level_colors.emplace_back(
               fc::console_appender::level_color(fc::log_level::warn,
                                                 fc::console_appender::color::brown));
            console_appender_config.level_colors.emplace_back(
               fc::console_appender::level_color(fc::log_level::error,
                                                 fc::console_appender::color::cyan));
            console_appender_config.stream = fc::variant(stream_name).as<fc::console_appender::stream::type>();
            logging_config.appenders.push_back(fc::appender_config(console_appender_name, "console", fc::variant(console_appender_config)));
            found_logging_config = true;
         }
         else if (boost::starts_with(section_name, file_appender_section_prefix))
         {
            std::string file_appender_name = section_name.substr(file_appender_section_prefix.length());
            fc::path file_name = section_tree.get<std::string>("filename");
            if (file_name.is_relative())
               file_name = fc::absolute(config_ini_filename).parent_path() / file_name;


            // construct a default file appender config here
            // filename will be taken from ini file, everything else hard-coded here
            fc::file_appender::config file_appender_config;
            file_appender_config.filename = file_name;
            file_appender_config.flush = true;
            file_appender_config.rotate = true;
            file_appender_config.rotation_interval = fc::hours(1);
            file_appender_config.rotation_limit = fc::days(1);
            logging_config.appenders.push_back(fc::appender_config(file_appender_name, "file", fc::variant(file_appender_config)));
            found_logging_config = true;
         }
         else if (boost::starts_with(section_name, logger_section_prefix))
         {
            std::string logger_name = section_name.substr(logger_section_prefix.length());
            std::string level_string = section_tree.get<std::string>("level");
            std::string appenders_string = section_tree.get<std::string>("appenders");
            fc::logger_config logger_config(logger_name);
            logger_config.level = fc::variant(level_string).as<fc::log_level>();
            boost::split(logger_config.appenders, appenders_string,
                         boost::is_any_of(" ,"),
                         boost::token_compress_on);
            logging_config.loggers.push_back(logger_config);
            found_logging_config = true;
         }
      }
      if (found_logging_config)
         return logging_config;
      else
         return fc::optional<fc::logging_config>();
   }
   FC_RETHROW_EXCEPTIONS(warn, "")
}
Example #21
0
 bool rpc_client_impl::import_bitcoin_wallet(const fc::path& wallet_filename, const std::string& password)
 {
   return _json_connection->call<bool>("import_bitcoin_wallet", wallet_filename.string(), password);
 }
Example #22
0
void cafs::export_link( const cafs::link& l, const fc::path& d ) {
 try {
    if( !fc::exists( d.parent_path() ) ) { 
      slog( "create '%s'", d.generic_string().c_str() );
      fc::create_directories(d.parent_path()); 
    }
    fc::vector<char> ch = get_chunk( l.id );
    derandomize( l.seed, ch  );
    //  slog( "derandomized... '%s'", fc::to_hex( ch.data(), 16 ).c_str() );
    if( ch.size() == 0 ) {
      FC_THROW_MSG( "Empty Chunk!" );
    }
    switch( ch[0] ) {
      case file_data_type: {
        slog( "file data..." );
    //    slog( "post randomized... '%s'", fc::to_hex( ch.data(), ch.size() ).c_str() );
        fc::ofstream ofile( d, fc::ofstream::binary );
        ofile.write( ch.data()+1, ch.size()-1 );
        break;
      }
      case directory_type: {
        slog( "directory data..." );
        fc::datastream<const char*> ds(ch.data()+1, ch.size()-1);
        directory d;
        fc::raw::unpack( ds, d );
        slog( "%s", fc::json::to_string( d ).c_str() );
        for( auto itr = d.entries.begin(); itr != d.entries.end(); ++itr ) {
          slog( "entry: %s", itr->name.c_str() );
          /*
          fc::vector<char> fdat = get_file( itr->ref );
          switch( itr->ref.type ) {
            case file_data_type: {
              break;
            }
            case directory_type: {
              slog( "%s", fc::json::to_string( fc::raw::unpack<directory>(fdat) ).c_str() );
              break;
            }
            case file_header_type: {
              slog( "%s", fc::json::to_string( fc::raw::unpack<file_header>(fdat) ).c_str() );
              break;
            }
            default:
              wlog( "Unknown Type %d", int(itr->ref.type) );
          }
          */
        }
  
        break;
      }
      case file_header_type: {
        slog( "file header..." );
        fc::datastream<const char*> ds(ch.data()+1, ch.size()-1);
        slog( "data %s", fc::to_hex( ch.data(), 16 ).c_str() );
        file_header fh;
        fc::raw::unpack( ds, fh);
        slog( "%s", fc::json::to_string( fh ).c_str() );
  
        fc::ofstream ofile( d, fc::ofstream::binary );
        for( auto i = fh.chunks.begin(); i != fh.chunks.end(); ++i ) {
          fc::vector<char> c = get_chunk( i->hash );
          derandomize( i->seed, c );
          ofile.write( c.data(), c.size() );
        }
        break;
      }
      default:
        FC_THROW_MSG( "Unknown File Type %s", int(ch[0]) );
    }
 } catch ( fc::error_report& e ) {
   throw FC_REPORT_PUSH( e, "Unable to export link ${link} to ${path}", fc::value().set("link", fc::string(l)).set("path", d.generic_string() ) );
 }
}