本文整理汇总了C++中potential_peer_set类的典型用法代码示例。如果您正苦于以下问题:C++ potential_peer_set类的具体用法?C++ potential_peer_set怎么用?C++ potential_peer_set使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了potential_peer_set类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
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));
}
}
}
示例2: open
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()));
}
示例3: catch
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();
}
示例4: catch
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);
}
}
}
示例5: while
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();
}
示例6: size
size_t peer_database_impl::size() const
{
return _potential_peer_set.size();
}
示例7: close
void peer_database_impl::close()
{
_leveldb.close();
_potential_peer_set.clear();
}
示例8: clear
void peer_database_impl::clear()
{
_potential_peer_set.clear();
}