void peer_database_impl::open(const fc::path& peer_database_filename) { _peer_database_filename = peer_database_filename; if (fc::exists(_peer_database_filename)) { try { std::vector<potential_peer_record> peer_records = fc::json::from_file(_peer_database_filename).as<std::vector<potential_peer_record> >(); std::copy(peer_records.begin(), peer_records.end(), std::inserter(_potential_peer_set, _potential_peer_set.end())); #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); _potential_peer_set.erase(iter, _potential_peer_set.end()); } } catch (const fc::exception& e) { elog("error opening peer database file ${peer_database_filename}, starting with a clean database", ("peer_database_filename", _peer_database_filename)); } } }
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::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::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::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(); }
size_t peer_database_impl::size() const { return _potential_peer_set.size(); }
void peer_database_impl::close() { _leveldb.close(); _potential_peer_set.clear(); }
void peer_database_impl::clear() { _potential_peer_set.clear(); }