rippled
StoreSqdb.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_PEERFINDER_STORESQDB_H_INCLUDED
21 #define RIPPLE_PEERFINDER_STORESQDB_H_INCLUDED
22 
23 #include <ripple/app/rdb/PeerFinder.h>
24 #include <ripple/basics/contract.h>
25 #include <ripple/core/SociDB.h>
26 #include <ripple/peerfinder/impl/Store.h>
27 #include <boost/optional.hpp>
28 
29 namespace ripple {
30 namespace PeerFinder {
31 
33 class StoreSqdb : public Store
34 {
35 private:
37  soci::session m_sqlDb;
38 
39 public:
40  enum {
41  // This determines the on-database format of the data
43  };
44 
45  explicit StoreSqdb(
47  : m_journal(journal)
48  {
49  }
50 
52  {
53  }
54 
55  void
56  open(BasicConfig const& config)
57  {
58  init(config);
59  update();
60  }
61 
62  // Loads the bootstrap cache, calling the callback for each entry
63  //
65  load(load_callback const& cb) override
66  {
67  std::size_t n(0);
68 
69  readPeerFinderDB(m_sqlDb, [&](std::string const& s, int valence) {
70  beast::IP::Endpoint const endpoint(
72 
73  if (!is_unspecified(endpoint))
74  {
75  cb(endpoint, valence);
76  ++n;
77  }
78  else
79  {
80  JLOG(m_journal.error())
81  << "Bad address string '" << s << "' in Bootcache table";
82  }
83  });
84 
85  return n;
86  }
87 
88  // Overwrites the stored bootstrap cache with the specified array.
89  //
90  void
91  save(std::vector<Entry> const& v) override
92  {
94  }
95 
96  // Convert any existing entries from an older schema to the
97  // current one, if appropriate.
98  void
100  {
102  }
103 
104 private:
105  void
106  init(BasicConfig const& config)
107  {
109  }
110 };
111 
112 } // namespace PeerFinder
113 } // namespace ripple
114 
115 #endif
ripple::PeerFinder::StoreSqdb::StoreSqdb
StoreSqdb(beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
Definition: StoreSqdb.h:45
std::string
STL class.
ripple::initPeerFinderDB
void initPeerFinderDB(soci::session &session, BasicConfig const &config, beast::Journal j)
initPeerFinderDB Opens a session with the peer finder database.
Definition: PeerFinder.cpp:25
ripple::PeerFinder::StoreSqdb
Database persistence for PeerFinder using SQLite.
Definition: StoreSqdb.h:33
ripple::PeerFinder::StoreSqdb::m_journal
beast::Journal m_journal
Definition: StoreSqdb.h:36
std::vector
STL class.
ripple::PeerFinder::StoreSqdb::m_sqlDb
soci::session m_sqlDb
Definition: StoreSqdb.h:37
ripple::updatePeerFinderDB
void updatePeerFinderDB(soci::session &session, int currentSchemaVersion, beast::Journal j)
updatePeerFinderDB Updates the peer finder database to a new version.
Definition: PeerFinder.cpp:61
std::function
ripple::PeerFinder::Store
Abstract persistence for PeerFinder data.
Definition: Store.h:27
ripple::PeerFinder::StoreSqdb::save
void save(std::vector< Entry > const &v) override
Definition: StoreSqdb.h:91
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:72
ripple::readPeerFinderDB
void readPeerFinderDB(soci::session &session, std::function< void(std::string const &, int)> const &func)
readPeerFinderDB Reads all entries from the peer finder database and invokes the given callback for e...
Definition: PeerFinder.cpp:217
ripple::PeerFinder::StoreSqdb::~StoreSqdb
~StoreSqdb()
Definition: StoreSqdb.h:51
beast::Journal::error
Stream error() const
Definition: Journal.h:333
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::PeerFinder::StoreSqdb::init
void init(BasicConfig const &config)
Definition: StoreSqdb.h:106
ripple::PeerFinder::StoreSqdb::open
void open(BasicConfig const &config)
Definition: StoreSqdb.h:56
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
beast::IP::Endpoint::from_string
static Endpoint from_string(std::string const &s)
Definition: IPEndpoint.cpp:49
ripple::savePeerFinderDB
void savePeerFinderDB(soci::session &session, std::vector< PeerFinder::Store::Entry > const &v)
savePeerFinderDB Saves a new entry to the peer finder database.
Definition: PeerFinder.cpp:239
ripple::PeerFinder::StoreSqdb::currentSchemaVersion
@ currentSchemaVersion
Definition: StoreSqdb.h:42
std::size_t
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
ripple::PeerFinder::StoreSqdb::load
std::size_t load(load_callback const &cb) override
Definition: StoreSqdb.h:65
ripple::BasicConfig
Holds unparsed configuration information.
Definition: BasicConfig.h:215
ripple::PeerFinder::StoreSqdb::update
void update()
Definition: StoreSqdb.h:99