rippled
Loading...
Searching...
No Matches
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 <xrpld/app/rdb/PeerFinder.h>
24#include <xrpld/core/SociDB.h>
25#include <xrpld/peerfinder/detail/Store.h>
26
27namespace ripple {
28namespace PeerFinder {
29
31class StoreSqdb : public Store
32{
33private:
35 soci::session m_sqlDb;
36
37public:
38 enum {
39 // This determines the on-database format of the data
41 };
42
43 explicit StoreSqdb(
45 : m_journal(journal)
46 {
47 }
48
50 {
51 }
52
53 void
54 open(BasicConfig const& config)
55 {
56 init(config);
57 update();
58 }
59
60 // Loads the bootstrap cache, calling the callback for each entry
61 //
63 load(load_callback const& cb) override
64 {
65 std::size_t n(0);
66
67 readPeerFinderDB(m_sqlDb, [&](std::string const& s, int valence) {
68 beast::IP::Endpoint const endpoint(
70
71 if (!is_unspecified(endpoint))
72 {
73 cb(endpoint, valence);
74 ++n;
75 }
76 else
77 {
78 JLOG(m_journal.error())
79 << "Bad address string '" << s << "' in Bootcache table";
80 }
81 });
82
83 return n;
84 }
85
86 // Overwrites the stored bootstrap cache with the specified array.
87 //
88 void
89 save(std::vector<Entry> const& v) override
90 {
92 }
93
94 // Convert any existing entries from an older schema to the
95 // current one, if appropriate.
96 void
101
102private:
103 void
104 init(BasicConfig const& config)
105 {
107 }
108};
109
110} // namespace PeerFinder
111} // namespace ripple
112
113#endif
A version-independent IP address and port combination.
Definition IPEndpoint.h:38
static Endpoint from_string(std::string const &s)
A generic endpoint for log messages.
Definition Journal.h:60
Stream error() const
Definition Journal.h:346
static Sink & getNullSink()
Returns a Sink which does nothing.
Holds unparsed configuration information.
Database persistence for PeerFinder using SQLite.
Definition StoreSqdb.h:32
std::size_t load(load_callback const &cb) override
Definition StoreSqdb.h:63
void save(std::vector< Entry > const &v) override
Definition StoreSqdb.h:89
void open(BasicConfig const &config)
Definition StoreSqdb.h:54
void init(BasicConfig const &config)
Definition StoreSqdb.h:104
StoreSqdb(beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
Definition StoreSqdb.h:43
Abstract persistence for PeerFinder data.
Definition Store.h:29
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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...
void updatePeerFinderDB(soci::session &session, int currentSchemaVersion, beast::Journal j)
updatePeerFinderDB Updates the peer finder database to a new version.
void initPeerFinderDB(soci::session &session, BasicConfig const &config, beast::Journal j)
initPeerFinderDB Opens a session with the peer finder database.
void savePeerFinderDB(soci::session &session, std::vector< PeerFinder::Store::Entry > const &v)
savePeerFinderDB Saves a new entry to the peer finder database.