1#include <xrpld/app/rdb/PeerFinder.h>
7 soci::session& session,
11 DBConfig m_sociConfig(config,
"peerfinder");
12 m_sociConfig.
open(session);
17 soci::transaction tr(session);
18 session <<
"PRAGMA encoding=\"UTF-8\";";
20 session <<
"CREATE TABLE IF NOT EXISTS SchemaVersion ( "
21 " name TEXT PRIMARY KEY, "
25 session <<
"CREATE TABLE IF NOT EXISTS PeerFinder_BootstrapCache ( "
26 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
27 " address TEXT UNIQUE NOT NULL, "
31 session <<
"CREATE INDEX IF NOT EXISTS "
32 " PeerFinder_BootstrapCache_Index ON "
33 "PeerFinder_BootstrapCache "
43 soci::session& session,
44 int currentSchemaVersion,
47 soci::transaction tr(session);
52 boost::optional<int> vO;
55 "FROM SchemaVersion WHERE "
56 " name = 'PeerFinder';",
59 version = vO.value_or(0);
61 JLOG(j.
info()) <<
"Opened version " << version <<
" database";
65 if (version < currentSchemaVersion)
67 JLOG(j.
info()) <<
"Updating database to version "
68 << currentSchemaVersion;
70 else if (version > currentSchemaVersion)
72 Throw<std::runtime_error>(
73 "The PeerFinder database version is higher than expected");
83 session <<
"CREATE TABLE IF NOT EXISTS "
84 "PeerFinder_BootstrapCache_Next ( "
85 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
86 " address TEXT UNIQUE NOT NULL, "
90 session <<
"CREATE INDEX IF NOT EXISTS "
91 " PeerFinder_BootstrapCache_Next_Index ON "
92 " PeerFinder_BootstrapCache_Next "
96 session <<
"SELECT COUNT(*) FROM PeerFinder_BootstrapCache;",
106 (session.prepare <<
"SELECT "
109 "FROM PeerFinder_BootstrapCache;",
111 soci::into(valence));
118 if (!is_unspecified(entry.endpoint))
120 entry.valence = valence;
125 JLOG(j.
error()) <<
"Bad address string '" << s
126 <<
"' in Bootcache table";
138 for (
auto iter(list.
cbegin()); iter != list.
cend(); ++iter)
144 session <<
"INSERT INTO PeerFinder_BootstrapCache_Next ( "
150 soci::use(s), soci::use(valence);
153 session <<
"DROP TABLE IF EXISTS PeerFinder_BootstrapCache;";
155 session <<
"DROP INDEX IF EXISTS PeerFinder_BootstrapCache_Index;";
157 session <<
"ALTER TABLE PeerFinder_BootstrapCache_Next "
158 " RENAME TO PeerFinder_BootstrapCache;";
160 session <<
"CREATE INDEX IF NOT EXISTS "
161 " PeerFinder_BootstrapCache_Index ON "
162 "PeerFinder_BootstrapCache "
174 session <<
"DROP TABLE IF EXISTS LegacyEndpoints;";
176 session <<
"DROP TABLE IF EXISTS PeerFinderLegacyEndpoints;";
178 session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints;";
180 session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints_Index;";
184 int const v(currentSchemaVersion);
185 session <<
"INSERT OR REPLACE INTO SchemaVersion ("
189 " 'PeerFinder', :version "
199 soci::session& session,
205 (session.prepare <<
"SELECT "
208 "FROM PeerFinder_BootstrapCache;",
210 soci::into(valence));
221 soci::session& session,
224 soci::transaction tr(session);
225 session <<
"DELETE FROM PeerFinder_BootstrapCache;";
234 for (
auto const& e : v)
240 session <<
"INSERT INTO PeerFinder_BootstrapCache ( "
246 soci::use(s), soci::use(valence);
static Endpoint from_string(std::string const &s)
A generic endpoint for log messages.
Holds unparsed configuration information.
DBConfig is used when a client wants to delay opening a soci::session after parsing the config parame...
void open(soci::session &s) const
std::string connectionString() const
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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.
std::string to_string(base_uint< Bits, Tag > const &a)
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.