1#include <xrpld/app/rdb/PeerFinder.h>
8 DBConfig m_sociConfig(config,
"peerfinder");
9 m_sociConfig.
open(session);
13 soci::transaction tr(session);
14 session <<
"PRAGMA encoding=\"UTF-8\";";
16 session <<
"CREATE TABLE IF NOT EXISTS SchemaVersion ( "
17 " name TEXT PRIMARY KEY, "
21 session <<
"CREATE TABLE IF NOT EXISTS PeerFinder_BootstrapCache ( "
22 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
23 " address TEXT UNIQUE NOT NULL, "
27 session <<
"CREATE INDEX IF NOT EXISTS "
28 " PeerFinder_BootstrapCache_Index ON "
29 "PeerFinder_BootstrapCache "
40 soci::transaction tr(session);
45 boost::optional<int> vO;
48 "FROM SchemaVersion WHERE "
49 " name = 'PeerFinder';",
52 version = vO.value_or(0);
54 JLOG(j.
info()) <<
"Opened version " << version <<
" database";
58 if (version < currentSchemaVersion)
60 JLOG(j.
info()) <<
"Updating database to version " << currentSchemaVersion;
62 else if (version > currentSchemaVersion)
64 Throw<std::runtime_error>(
"The PeerFinder database version is higher than expected");
74 session <<
"CREATE TABLE IF NOT EXISTS "
75 "PeerFinder_BootstrapCache_Next ( "
76 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
77 " address TEXT UNIQUE NOT NULL, "
81 session <<
"CREATE INDEX IF NOT EXISTS "
82 " PeerFinder_BootstrapCache_Next_Index ON "
83 " PeerFinder_BootstrapCache_Next "
87 session <<
"SELECT COUNT(*) FROM PeerFinder_BootstrapCache;", soci::into(count);
96 (session.prepare <<
"SELECT "
99 "FROM PeerFinder_BootstrapCache;",
101 soci::into(valence));
108 if (!is_unspecified(entry.endpoint))
110 entry.valence = valence;
115 JLOG(j.
error()) <<
"Bad address string '" << s <<
"' in Bootcache table";
127 for (
auto iter(list.
cbegin()); iter != list.
cend(); ++iter)
133 session <<
"INSERT INTO PeerFinder_BootstrapCache_Next ( "
139 soci::use(s), soci::use(valence);
142 session <<
"DROP TABLE IF EXISTS PeerFinder_BootstrapCache;";
144 session <<
"DROP INDEX IF EXISTS PeerFinder_BootstrapCache_Index;";
146 session <<
"ALTER TABLE PeerFinder_BootstrapCache_Next "
147 " RENAME TO PeerFinder_BootstrapCache;";
149 session <<
"CREATE INDEX IF NOT EXISTS "
150 " PeerFinder_BootstrapCache_Index ON "
151 "PeerFinder_BootstrapCache "
163 session <<
"DROP TABLE IF EXISTS LegacyEndpoints;";
165 session <<
"DROP TABLE IF EXISTS PeerFinderLegacyEndpoints;";
167 session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints;";
169 session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints_Index;";
173 int const v(currentSchemaVersion);
174 session <<
"INSERT OR REPLACE INTO SchemaVersion ("
178 " 'PeerFinder', :version "
192 (session.prepare <<
"SELECT "
195 "FROM PeerFinder_BootstrapCache;",
197 soci::into(valence));
209 soci::transaction tr(session);
210 session <<
"DELETE FROM PeerFinder_BootstrapCache;";
219 for (
auto const& e : v)
225 session <<
"INSERT INTO PeerFinder_BootstrapCache ( "
231 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...
std::string to_string(base_uint< Bits, Tag > const &a)
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.