예제 #1
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();
            }
예제 #2
0
파일: cafs.cpp 프로젝트: Zhang-Yi/tornet
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() ) );
 }
}