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> 50 indexed_by<ordered_non_unique<tag<last_seen_time_index>,
51 member<potential_peer_record,
54 std::greater<fc::time_point_sec> >,
55 hashed_unique<tag<endpoint_index>,
56 member<potential_peer_record,
62 potential_peer_set _potential_peer_set;
66 void open(
const fc::path& databaseFilename);
69 void erase(
const fc::ip::endpoint& endpointToErase);
70 void update_entry(
const potential_peer_record& updatedRecord);
71 potential_peer_record lookup_or_create_entry_for_ep(
const fc::ip::endpoint& endpointToLookup)
const;
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()
214 return my->_iterator == other.my->_iterator;
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) )
boost::multi_index_container< potential_peer_record, indexed_by< ordered_non_unique< tag< last_seen_time_index >, member< potential_peer_record, fc::time_point_sec, &potential_peer_record::last_seen_time >, std::greater< fc::time_point_sec > >, hashed_unique< tag< endpoint_index >, member< potential_peer_record, fc::ip::endpoint, &potential_peer_record::endpoint >, std::hash< fc::ip::endpoint > > > > potential_peer_set
void update_entry(const potential_peer_record &updatedRecord)
fc::path parent_path() const
bool exists(const path &p)
fc::ip::endpoint endpoint
peer_database::iterator end() const
~peer_database_iterator()
#define GRAPHENE_NET_MAX_NESTED_OBJECTS
detail::peer_database_iterator iterator
fc::optional< potential_peer_record > lookup_entry_for_endpoint(const fc::ip::endpoint &endpointToLookup) const
peer_database_iterator_impl(const last_seen_time_index_iterator &iterator)
#define FC_REFLECT_DERIVED_NO_TYPENAME(TYPE, INHERITS, MEMBERS)
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
void create_directories(const path &p)
static variant from_file(const fc::path &p, parse_type ptype=legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
provides stack-based nullable value similar to boost::optional
FC_REFLECT_ENUM(graphene::net::core_message_type_enum,(trx_message_type)(block_message_type)(core_message_type_first)(item_ids_inventory_message_type)(blockchain_item_ids_inventory_message_type)(fetch_blockchain_item_ids_message_type)(fetch_items_message_type)(item_not_available_message_type)(hello_message_type)(connection_accepted_message_type)(connection_rejected_message_type)(address_request_message_type)(address_message_type)(closing_connection_message_type)(current_time_request_message_type)(current_time_reply_message_type)(check_firewall_message_type)(check_firewall_reply_message_type)(get_current_connections_request_message_type)(get_current_connections_reply_message_type)(core_message_type_last))(different_chain)(already_connected)(connected_to_self)(not_accepting_connections)(blocked)(invalid_hello_message)(client_too_old))(inbound)(outbound))(firewalled)(not_firewalled))(unable_to_connect)(connection_successful)) namespace std
peer_database_impl::potential_peer_set::index< peer_database_impl::last_seen_time_index >::type::iterator last_seen_time_index_iterator
void erase(const fc::ip::endpoint &endpointToErase)
potential_peer_record lookup_or_create_entry_for_ep(const fc::ip::endpoint &endpointToLookup) const
T as(uint32_t max_depth) const
void update_entry(const potential_peer_record &updatedRecord)
boost::asio::ip::tcp::endpoint endpoint
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
peer_database::iterator begin() const
potential_peer_record lookup_or_create_entry_for_ep(const fc::ip::endpoint &endpointToLookup) const
potential_peer_last_connection_disposition
std::string to_detail_string(log_level ll=log_level::all) const
fc::time_point_sec last_seen_time
void erase(const fc::ip::endpoint &endpointToErase)
last_seen_time_index_iterator _iterator
fc::optional< potential_peer_record > lookup_entry_for_endpoint(const fc::ip::endpoint &endpointToLookup) const
void copy(const path &from, const path &to)
#define MAXIMUM_PEERDB_SIZE
wraps boost::filesystem::path to provide platform independent path manipulation.
void open(const fc::path &databaseFilename)
void open(const fc::path &databaseFilename)
static void save_to_file(const T &v, const fc::path &fi, bool pretty=true, output_formatting format=stringify_large_ints_and_doubles, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)