20 #include <ripple/app/rdb/PeerFinder.h>
26 soci::session& session,
30 DBConfig m_sociConfig(config,
"peerfinder");
31 m_sociConfig.
open(session);
36 soci::transaction tr(session);
37 session <<
"PRAGMA encoding=\"UTF-8\";";
39 session <<
"CREATE TABLE IF NOT EXISTS SchemaVersion ( "
40 " name TEXT PRIMARY KEY, "
44 session <<
"CREATE TABLE IF NOT EXISTS PeerFinder_BootstrapCache ( "
45 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
46 " address TEXT UNIQUE NOT NULL, "
50 session <<
"CREATE INDEX IF NOT EXISTS "
51 " PeerFinder_BootstrapCache_Index ON "
52 "PeerFinder_BootstrapCache "
62 soci::session& session,
63 int currentSchemaVersion,
66 soci::transaction tr(session);
71 boost::optional<int> vO;
74 "FROM SchemaVersion WHERE "
75 " name = 'PeerFinder';",
78 version = vO.value_or(0);
80 JLOG(j.
info()) <<
"Opened version " << version <<
" database";
84 if (version < currentSchemaVersion)
86 JLOG(j.
info()) <<
"Updating database to version "
87 << currentSchemaVersion;
89 else if (version > currentSchemaVersion)
91 Throw<std::runtime_error>(
92 "The PeerFinder database version is higher than expected");
102 session <<
"CREATE TABLE IF NOT EXISTS "
103 "PeerFinder_BootstrapCache_Next ( "
104 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
105 " address TEXT UNIQUE NOT NULL, "
109 session <<
"CREATE INDEX IF NOT EXISTS "
110 " PeerFinder_BootstrapCache_Next_Index ON "
111 " PeerFinder_BootstrapCache_Next "
115 session <<
"SELECT COUNT(*) FROM PeerFinder_BootstrapCache;",
125 (session.prepare <<
"SELECT "
128 "FROM PeerFinder_BootstrapCache;",
130 soci::into(valence));
137 if (!is_unspecified(entry.
endpoint))
144 JLOG(j.
error()) <<
"Bad address string '" << s
145 <<
"' in Bootcache table";
157 for (
auto iter(list.
cbegin()); iter != list.
cend(); ++iter)
163 session <<
"INSERT INTO PeerFinder_BootstrapCache_Next ( "
169 soci::use(s), soci::use(valence);
172 session <<
"DROP TABLE IF EXISTS PeerFinder_BootstrapCache;";
174 session <<
"DROP INDEX IF EXISTS PeerFinder_BootstrapCache_Index;";
176 session <<
"ALTER TABLE PeerFinder_BootstrapCache_Next "
177 " RENAME TO PeerFinder_BootstrapCache;";
179 session <<
"CREATE INDEX IF NOT EXISTS "
180 " PeerFinder_BootstrapCache_Index ON "
181 "PeerFinder_BootstrapCache "
193 session <<
"DROP TABLE IF EXISTS LegacyEndpoints;";
195 session <<
"DROP TABLE IF EXISTS PeerFinderLegacyEndpoints;";
197 session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints;";
199 session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints_Index;";
203 int const v(currentSchemaVersion);
204 session <<
"INSERT OR REPLACE INTO SchemaVersion ("
208 " 'PeerFinder', :version "
218 soci::session& session,
224 (session.prepare <<
"SELECT "
227 "FROM PeerFinder_BootstrapCache;",
229 soci::into(valence));
240 soci::session& session,
243 soci::transaction tr(session);
244 session <<
"DELETE FROM PeerFinder_BootstrapCache;";
253 for (
auto const& e : v)
259 session <<
"INSERT INTO PeerFinder_BootstrapCache ( "
265 soci::use(s), soci::use(valence);
std::string connectionString() const
void initPeerFinderDB(soci::session &session, BasicConfig const &config, beast::Journal j)
initPeerFinderDB Opens a session with the peer finder database.
void open(soci::session &s) const
void updatePeerFinderDB(soci::session &session, int currentSchemaVersion, beast::Journal j)
updatePeerFinderDB Updates the peer finder database to a new version.
DBConfig is used when a client wants to delay opening a soci::session after parsing the config parame...
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...
A generic endpoint for log messages.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static Endpoint from_string(std::string const &s)
void savePeerFinderDB(soci::session &session, std::vector< PeerFinder::Store::Entry > const &v)
savePeerFinderDB Saves a new entry to the peer finder database.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
beast::IP::Endpoint endpoint
Holds unparsed configuration information.