Beispiel #1
0
    void peer_database_impl::open(const fc::path& databaseFilename)
    {
      try
      {
        _leveldb.open(databaseFilename);
      }
      catch (const graphene::db::level_pod_map_open_failure&) 
      {
        fc::remove_all(databaseFilename);
        _leveldb.open(databaseFilename);
      }

      _potential_peer_set.clear();

      for (auto iter = _leveldb.begin(); iter.valid(); ++iter)
        _potential_peer_set.insert(potential_peer_database_entry(iter.key(), iter.value()));
#define MAXIMUM_PEERDB_SIZE 1000
      if (_potential_peer_set.size() > MAXIMUM_PEERDB_SIZE)
      {
        // prune database to a reasonable size
        auto iter = _potential_peer_set.begin();
        std::advance(iter, MAXIMUM_PEERDB_SIZE);
        while (iter != _potential_peer_set.end())
        {
          _leveldb.remove(iter->database_key);
          iter = _potential_peer_set.erase(iter);
        }
      }
    }
    void peer_database_impl::open(const fc::path& databaseFilename)
    {
      _leveldb.open(databaseFilename, true);
      _potential_peer_set.clear();

      for (auto iter = _leveldb.begin(); iter.valid(); ++iter)
        _potential_peer_set.insert(potential_peer_database_entry(iter.key(), iter.value()));
    }
 void peer_database_impl::clear()
 {
   auto iter = _leveldb.begin();
   while (iter.valid())
   {
     uint32_t key_to_remove = iter.key();
     ++iter;
     try
     {
       _leveldb.remove(key_to_remove);
     }
     catch (fc::exception&)
     {
       // shouldn't happen, and if it does there's not much we can do
     }
   }
   _potential_peer_set.clear();
 }
Beispiel #4
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 peer_database_impl::close()
 {
   _leveldb.close();
   _potential_peer_set.clear();
 }
Beispiel #6
0
 void peer_database_impl::clear()
 {
   _potential_peer_set.clear();
 }