xrpld
Loading...
Searching...
No Matches
StoreSqdb.h
1#pragma once
2
3#include <xrpld/app/rdb/PeerFinder.h>
4#include <xrpld/peerfinder/detail/Store.h>
5
6#include <xrpl/rdb/SociDB.h>
7
8namespace xrpl::PeerFinder {
9
11class StoreSqdb : public Store
12{
13private:
15 soci::session sqlDb_;
16
17public:
18 static constexpr auto kCurrentSchemaVersion = 4; // on-database format version
19
21 : journal_(journal)
22 {
23 }
24
25 ~StoreSqdb() override = default;
26
27 void
28 open(BasicConfig const& config)
29 {
30 init(config);
31 update();
32 }
33
34 // Loads the bootstrap cache, calling the callback for each entry
35 //
37 load(load_callback const& cb) override
38 {
39 std::size_t n(0);
40
41 readPeerFinderDB(sqlDb_, [&](std::string const& s, int valence) {
43
44 if (!isUnspecified(endpoint))
45 {
46 cb(endpoint, valence);
47 ++n;
48 }
49 else
50 {
51 JLOG(journal_.error()) << "Bad address string '" << s << "' in Bootcache table";
52 }
53 });
54
55 return n;
56 }
57
58 // Overwrites the stored bootstrap cache with the specified array.
59 //
60 void
61 save(std::vector<Entry> const& v) override
62 {
64 }
65
66 // Convert any existing entries from an older schema to the
67 // current one, if appropriate.
68 void
73
74private:
75 void
76 init(BasicConfig const& config)
77 {
79 }
80};
81
82} // namespace xrpl::PeerFinder
A version-independent IP address and port combination.
Definition IPEndpoint.h:17
static Endpoint fromString(std::string const &s)
A generic endpoint for log messages.
Definition Journal.h:38
static Sink & getNullSink()
Returns a Sink which does nothing.
Holds unparsed configuration information.
beast::Journal journal_
Definition StoreSqdb.h:14
static constexpr auto kCurrentSchemaVersion
Definition StoreSqdb.h:18
void open(BasicConfig const &config)
Definition StoreSqdb.h:28
~StoreSqdb() override=default
std::size_t load(load_callback const &cb) override
Definition StoreSqdb.h:37
void init(BasicConfig const &config)
Definition StoreSqdb.h:76
StoreSqdb(beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
Definition StoreSqdb.h:20
void save(std::vector< Entry > const &v) override
Definition StoreSqdb.h:61
Abstract persistence for PeerFinder data.
Definition Store.h:7
std::function< void(beast::IP::Endpoint, int)> load_callback
Definition Store.h:12
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.