mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 08:46:46 +00:00
Reverts 259 files that carried unrelated upstream changes through the phase-6 merge: enum class removals (cppcoreguidelines-use-enum-class), scoped_lock→lock_guard conversions (modernize-use-scoped-lock), nodestore Backend API changes (void const* key), .clang-tidy config, test infrastructure deletions, and miscellaneous develop changes. These changes belong on develop, not in the telemetry PR chain. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <xrpl/beast/hash/hash_append.h>
|
|
#include <xrpl/beast/hash/uhash.h>
|
|
#include <xrpl/beast/utility/Journal.h>
|
|
#include <xrpl/protocol/PublicKey.h>
|
|
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
namespace xrpl {
|
|
|
|
class DatabaseCon;
|
|
|
|
// Value type for reservations.
|
|
struct PeerReservation final
|
|
{
|
|
public:
|
|
PublicKey nodeId;
|
|
std::string description = {}; // NOLINT(readability-redundant-member-init)
|
|
|
|
[[nodiscard]] auto
|
|
toJson() const -> Json::Value;
|
|
|
|
template <typename Hasher>
|
|
friend void
|
|
hash_append(Hasher& h, PeerReservation const& x) noexcept
|
|
{
|
|
using beast::hash_append;
|
|
hash_append(h, x.nodeId);
|
|
}
|
|
|
|
friend bool
|
|
operator<(PeerReservation const& a, PeerReservation const& b)
|
|
{
|
|
return a.nodeId < b.nodeId;
|
|
}
|
|
};
|
|
|
|
// TODO: When C++20 arrives, take advantage of "equivalence" instead of
|
|
// "equality". Add an overload for `(PublicKey, PeerReservation)`, and just
|
|
// pass a `PublicKey` directly to `unordered_set.find`.
|
|
struct KeyEqual final
|
|
{
|
|
bool
|
|
operator()(PeerReservation const& lhs, PeerReservation const& rhs) const
|
|
{
|
|
return lhs.nodeId == rhs.nodeId;
|
|
}
|
|
};
|
|
|
|
class PeerReservationTable final
|
|
{
|
|
public:
|
|
explicit PeerReservationTable(
|
|
beast::Journal journal = beast::Journal(beast::Journal::getNullSink()))
|
|
: journal_(journal)
|
|
{
|
|
}
|
|
|
|
std::vector<PeerReservation>
|
|
list() const;
|
|
|
|
bool
|
|
contains(PublicKey const& nodeId)
|
|
{
|
|
std::scoped_lock const lock(this->mutex_);
|
|
return table_.contains({.nodeId = nodeId, .description = {}});
|
|
}
|
|
|
|
// Because `ApplicationImp` has two-phase initialization, so must we.
|
|
// Our dependencies are not prepared until the second phase.
|
|
bool
|
|
load(DatabaseCon& connection);
|
|
|
|
/**
|
|
* @return the replaced reservation if it existed
|
|
* @throw soci::soci_error
|
|
*/
|
|
std::optional<PeerReservation>
|
|
insert_or_assign(PeerReservation const& reservation);
|
|
|
|
/**
|
|
* @return the erased reservation if it existed
|
|
*/
|
|
std::optional<PeerReservation>
|
|
erase(PublicKey const& nodeId);
|
|
|
|
private:
|
|
beast::Journal mutable journal_;
|
|
std::mutex mutable mutex_;
|
|
DatabaseCon* connection_{};
|
|
std::unordered_set<PeerReservation, beast::uhash<>, KeyEqual> table_;
|
|
};
|
|
|
|
} // namespace xrpl
|