24 #include <boost/multi_index_container.hpp>
25 #include <boost/multi_index/ordered_index.hpp>
26 #include <boost/multi_index/hashed_index.hpp>
27 #include <boost/multi_index/member.hpp>
28 #include <boost/multi_index/mem_fun.hpp>
29 #include <boost/multi_index/tag.hpp>
42 using namespace boost::multi_index;
50 indexed_by<ordered_non_unique<tag<last_seen_time_index>,
54 std::greater<fc::time_point_sec> >,
55 hashed_unique<tag<endpoint_index>,
66 void open(
const fc::path& databaseFilename);
93 _peer_database_filename = peer_database_filename;
99 std::copy(peer_records.begin(), peer_records.end(), std::inserter(_potential_peer_set, _potential_peer_set.end()));
103 auto iter = _potential_peer_set.begin();
105 _potential_peer_set.erase(iter, _potential_peer_set.end());
110 elog(
"error opening peer database file ${peer_database_filename}, starting with a clean database",
111 (
"peer_database_filename", _peer_database_filename));
118 std::vector<potential_peer_record> peer_records;
119 peer_records.reserve(_potential_peer_set.size());
120 std::copy(_potential_peer_set.begin(), _potential_peer_set.end(), std::back_inserter(peer_records));
128 dlog(
"Saved peer database to file ${filename}", (
"filename", _peer_database_filename) );
132 wlog(
"error saving peer database to file ${peer_database_filename}: ${error}",
133 (
"peer_database_filename", _peer_database_filename)(
"error", e.
to_detail_string()) );
135 _potential_peer_set.clear();
140 _potential_peer_set.clear();
145 auto iter = _potential_peer_set.get<
endpoint_index>().find(endpointToErase);
162 auto iter = _potential_peer_set.get<
endpoint_index>().find(endpointToLookup);
171 auto iter = _potential_peer_set.get<
endpoint_index>().find(endpointToLookup);
191 return _potential_peer_set.size();
203 my(
std::move(impl) )
207 void peer_database_iterator::increment()
212 bool peer_database_iterator::equal(
const peer_database_iterator& other)
const
214 return my->_iterator == other.my->_iterator;
217 const potential_peer_record& peer_database_iterator::dereference()
const
219 return *my->_iterator;
225 my(
std::make_unique<detail::peer_database_impl>() )
234 my->open(databaseFilename);
249 my->erase(endpointToErase);
254 my->update_entry(updatedRecord);
260 return my->lookup_or_create_entry_for_ep(endpointToLookup);
266 return my->lookup_entry_for_endpoint(endpoint_to_lookup);
291 (
endpoint)(last_seen_time)(last_connection_disposition)
292 (last_connection_attempt_time)(number_of_successful_connection_attempts)
293 (number_of_failed_connection_attempts)(last_error) )