BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
peer_database.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 #include <boost/iterator/iterator_facade.hpp>
26 
28 
29 #include <fc/network/ip.hpp>
30 #include <fc/time.hpp>
31 #include <fc/io/enum_type.hpp>
32 #include <fc/reflect/reflect.hpp>
33 #include <fc/reflect/variant.hpp>
35 
36 namespace graphene { namespace net {
37 
39  {
45  };
46 
48  {
56 
57  potential_peer_record() = default;
58 
63  : endpoint(endpoint),
66  {}
67  };
68 
69  namespace detail
70  {
71  class peer_database_impl;
72 
73  class peer_database_iterator_impl;
74  class peer_database_iterator : public boost::iterator_facade< peer_database_iterator,
75  const potential_peer_record,
76  boost::forward_traversal_tag>
77  {
78  public:
81  explicit peer_database_iterator( std::unique_ptr<peer_database_iterator_impl>&& impl );
83 
84  private:
85  friend class boost::iterator_core_access;
86  void increment();
87  bool equal(const peer_database_iterator& other) const;
88  const potential_peer_record& dereference() const;
89  private:
90  std::unique_ptr<peer_database_iterator_impl> my;
91  };
92  }
93 
94 
96  {
97  public:
98  peer_database();
99  virtual ~peer_database();
100 
101  void open(const fc::path& databaseFilename);
102  void close();
103  void clear();
104 
105  void erase(const fc::ip::endpoint& endpointToErase);
106 
107  void update_entry(const potential_peer_record& updatedRecord);
110 
112  iterator begin() const;
113  iterator end() const;
114  size_t size() const;
115  private:
116  std::unique_ptr<detail::peer_database_impl> my;
117  };
118 
119 } } // end namespace graphene::net
120 
122 
graphene::net::peer_database::clear
void clear()
Definition: peer_database.cpp:242
graphene::net::potential_peer_last_connection_disposition
potential_peer_last_connection_disposition
Definition: peer_database.hpp:38
ip.hpp
graphene::net::last_connection_failed
@ last_connection_failed
Definition: peer_database.hpp:41
graphene::net::peer_database::end
iterator end() const
Definition: peer_database.cpp:274
graphene::net::potential_peer_record::last_seen_time
fc::time_point_sec last_seen_time
Definition: peer_database.hpp:50
graphene::net::peer_database::lookup_or_create_entry_for_ep
potential_peer_record lookup_or_create_entry_for_ep(const fc::ip::endpoint &endpointToLookup) const
Definition: peer_database.cpp:257
graphene::net::peer_database::size
size_t size() const
Definition: peer_database.cpp:279
graphene::net::detail::peer_database_iterator::~peer_database_iterator
~peer_database_iterator()
Definition: peer_database.cpp:198
graphene::net::peer_database
Definition: peer_database.hpp:95
variant.hpp
graphene::net::potential_peer_record::last_error
fc::optional< fc::exception > last_error
Definition: peer_database.hpp:55
graphene::net::peer_database::open
void open(const fc::path &databaseFilename)
Definition: peer_database.cpp:232
graphene::net::peer_database::erase
void erase(const fc::ip::endpoint &endpointToErase)
Definition: peer_database.cpp:247
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
graphene::net::last_connection_rejected
@ last_connection_rejected
Definition: peer_database.hpp:42
fc::enum_type< uint8_t, potential_peer_last_connection_disposition >
graphene::net::potential_peer_record::endpoint
fc::ip::endpoint endpoint
Definition: peer_database.hpp:49
reflect.hpp
Defines types and macros used to provide reflection.
graphene::net::potential_peer_record
Definition: peer_database.hpp:47
fc::ip::endpoint
Definition: ip.hpp:65
graphene::net::potential_peer_record::potential_peer_record
potential_peer_record(const fc::ip::endpoint &endpoint, const fc::time_point_sec &last_seen_time=fc::time_point_sec(), potential_peer_last_connection_disposition last_connection_disposition=never_attempted_to_connect)
Definition: peer_database.hpp:59
graphene::net::detail::peer_database_iterator
Definition: peer_database.hpp:74
graphene::net::potential_peer_record::number_of_successful_connection_attempts
uint32_t number_of_successful_connection_attempts
Definition: peer_database.hpp:53
types.hpp
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
graphene::net::potential_peer_record::potential_peer_record
potential_peer_record()=default
fc::time_point_sec
Definition: time.hpp:74
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::net::detail::peer_database_iterator::peer_database_iterator
peer_database_iterator()
Definition: peer_database.cpp:194
graphene::net::last_connection_succeeded
@ last_connection_succeeded
Definition: peer_database.hpp:44
graphene::net::peer_database::lookup_entry_for_endpoint
fc::optional< potential_peer_record > lookup_entry_for_endpoint(const fc::ip::endpoint &endpointToLookup) const
Definition: peer_database.cpp:263
graphene::net::last_connection_handshaking_failed
@ last_connection_handshaking_failed
Definition: peer_database.hpp:43
graphene::net::peer_database::~peer_database
virtual ~peer_database()
Definition: peer_database.cpp:229
graphene::net::never_attempted_to_connect
@ never_attempted_to_connect
Definition: peer_database.hpp:40
exception.hpp
Defines exception's used by fc.
graphene::net::peer_database::update_entry
void update_entry(const potential_peer_record &updatedRecord)
Definition: peer_database.cpp:252
enum_type.hpp
graphene::net::potential_peer_record::last_connection_attempt_time
fc::time_point_sec last_connection_attempt_time
Definition: peer_database.hpp:52
fc::optional< fc::exception >
time.hpp
graphene::net::peer_database::begin
iterator begin() const
Definition: peer_database.cpp:269
graphene::net::peer_database::peer_database
peer_database()
Definition: peer_database.cpp:224
graphene::net::potential_peer_record::number_of_failed_connection_attempts
uint32_t number_of_failed_connection_attempts
Definition: peer_database.hpp:54
graphene
Definition: api.cpp:48
graphene::net::peer_database::close
void close()
Definition: peer_database.cpp:237
graphene::net::potential_peer_record::last_connection_disposition
fc::enum_type< uint8_t, potential_peer_last_connection_disposition > last_connection_disposition
Definition: peer_database.hpp:51