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