1#ifndef joedb_rpc_Server_declared
2#define joedb_rpc_Server_declared
20 const std::vector<Signature> &signatures;
21 const std::vector<Procedure *> &procedures;
30 boost::asio::awaitable<bool> handshake()
36 const bool correct_hash = hash ==
get_hash(get_server().signatures);
43 log(correct_hash ?
"correct hash" :
"incorrect hash");
46 co_return correct_hash;
50 boost::asio::awaitable<void> call()
55 const size_t id =
static_cast<size_t>(
buffer.
read<int64_t>());
61 if (
id >= get_server().procedures.size())
64 auto &signature = get_server().signatures[
id];
65 auto &procedure = *get_server().procedures[
id];
68 log(
"procedure[" + std::to_string(
id) +
"]: " + signature.name);
77 data.reserve(
size_t(until));
78 data = signature.prolog;
80 int64_t remaining = until - file.
get_size();
100 procedure.execute(file);
102 catch (
const std::exception &e)
104 const std::string_view message(e.what());
107 log(
"error: " + std::string(message));
109 const size_t n = std::min(message.size(),
buffer.
size - 9);
127 size_t offset = size_t(until);
128 size_t remaining = file.
get_data().size() - offset;
148 boost::asio::local::stream_protocol::socket &&
socket
155 boost::asio::awaitable<void>
run() override
158 if (!
co_await handshake())
191 boost::asio::local::stream_protocol::socket &&socket
194 return std::make_unique<Session>(*
this, std::move(socket));
206 const std::vector<Signature> &signatures,
207 const std::vector<Procedure *> &procedures
216 signatures(signatures),
217 procedures(procedures)
char data[size+extra_size]
static constexpr size_t size
size_t pread(char *buffer, size_t size, int64_t offset) const override
Read a range of bytes.
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
std::array< uint32_t, 8 > Hash
void log(std::string_view s)
boost::asio::awaitable< void > write_buffer()
boost::asio::awaitable< size_t > read_buffer(size_t offset, size_t size)
boost::asio::local::stream_protocol::socket socket
Superclass for asio servers.
const std::string endpoint_path
int get_log_level() const
boost::asio::awaitable< void > run() override
std::unique_ptr< joedb::asio::Server::Session > new_session(boost::asio::local::stream_protocol::socket &&socket) override
SHA_256::Hash get_hash(const std::vector< Signature > &signatures)
Compute hash code for a collection of procedure signatures.