BitShares-Core  5.0.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 
58  number_of_successful_connection_attempts(0),
59  number_of_failed_connection_attempts(0){}
60 
62  fc::time_point_sec last_seen_time = fc::time_point_sec(),
64  endpoint(endpoint),
65  last_seen_time(last_seen_time),
66  last_connection_disposition(last_connection_disposition),
67  number_of_successful_connection_attempts(0),
68  number_of_failed_connection_attempts(0)
69  {}
70  };
71 
72  namespace detail
73  {
74  class peer_database_impl;
75 
76  class peer_database_iterator_impl;
77  class peer_database_iterator : public boost::iterator_facade<peer_database_iterator, const potential_peer_record, boost::forward_traversal_tag>
78  {
79  public:
84 
85  private:
86  friend class boost::iterator_core_access;
87  void increment();
88  bool equal(const peer_database_iterator& other) const;
89  const potential_peer_record& dereference() const;
90  private:
91  std::unique_ptr<peer_database_iterator_impl> my;
92  };
93  }
94 
95 
97  {
98  public:
99  peer_database();
100  ~peer_database();
101 
102  void open(const fc::path& databaseFilename);
103  void close();
104  void clear();
105 
106  void erase(const fc::ip::endpoint& endpointToErase);
107 
108  void update_entry(const potential_peer_record& updatedRecord);
109  potential_peer_record lookup_or_create_entry_for_endpoint(const fc::ip::endpoint& endpointToLookup);
110  fc::optional<potential_peer_record> lookup_entry_for_endpoint(const fc::ip::endpoint& endpointToLookup);
111 
113  iterator begin() const;
114  iterator end() const;
115  size_t size() const;
116  private:
117  std::unique_ptr<detail::peer_database_impl> my;
118  };
119 
120 } } // end namespace graphene::net
121 
123 
fc::optional< fc::exception > last_error
potential_peer_record(fc::ip::endpoint endpoint, fc::time_point_sec last_seen_time=fc::time_point_sec(), potential_peer_last_connection_disposition last_connection_disposition=never_attempted_to_connect)
Definition: api.cpp:56
Defines types and macros used to provide reflection.
FC_REFLECT_TYPENAME(fc::log_message)
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
detail::peer_database_iterator iterator
fc::enum_type< uint8_t, potential_peer_last_connection_disposition > last_connection_disposition
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