BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface 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 
60  const fc::ip::endpoint& endpoint,
61  const fc::time_point_sec& last_seen_time = fc::time_point_sec(),
63  : endpoint(endpoint),
64  last_seen_time(last_seen_time),
65  last_connection_disposition(last_connection_disposition)
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);
108  potential_peer_record lookup_or_create_entry_for_ep(const fc::ip::endpoint& endpointToLookup)const;
109  fc::optional<potential_peer_record> lookup_entry_for_endpoint(const fc::ip::endpoint& endpointToLookup)const;
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 
fc::optional< fc::exception > last_error
Definition: api.cpp:48
Defines types and macros used to provide reflection.
FC_REFLECT_TYPENAME(fc::log_message)
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
fc::enum_type< uint8_t, potential_peer_last_connection_disposition > last_connection_disposition
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)
Defines exception&#39;s used by fc.
potential_peer_last_connection_disposition
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
fc::time_point_sec last_connection_attempt_time