mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-21 04:05:51 +00:00
Rename functions to camelCase (#636)
This commit is contained in:
@@ -61,7 +61,7 @@ target_sources(clio PRIVATE
|
|||||||
src/subscriptions/SubscriptionManager.cpp
|
src/subscriptions/SubscriptionManager.cpp
|
||||||
## RPC
|
## RPC
|
||||||
src/rpc/Errors.cpp
|
src/rpc/Errors.cpp
|
||||||
src/rpc/RPC.cpp
|
src/rpc/Factories.cpp
|
||||||
src/rpc/RPCHelpers.cpp
|
src/rpc/RPCHelpers.cpp
|
||||||
src/rpc/Counters.cpp
|
src/rpc/Counters.cpp
|
||||||
src/rpc/WorkQueue.cpp
|
src/rpc/WorkQueue.cpp
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <etl/ETLSource.h>
|
#include <etl/ETLSource.h>
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Factories.h>
|
||||||
#include <rpc/common/impl/HandlerProvider.h>
|
#include <rpc/common/impl/HandlerProvider.h>
|
||||||
#include <webserver/HttpBase.h>
|
#include <webserver/HttpBase.h>
|
||||||
#include <webserver/WsBase.h>
|
#include <webserver/WsBase.h>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
#include <log/Logger.h>
|
#include <log/Logger.h>
|
||||||
#include <main/Build.h>
|
#include <main/Build.h>
|
||||||
#include <rpc/Counters.h>
|
#include <rpc/Counters.h>
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Factories.h>
|
||||||
#include <rpc/RPCEngine.h>
|
#include <rpc/RPCEngine.h>
|
||||||
#include <rpc/WorkQueue.h>
|
#include <rpc/WorkQueue.h>
|
||||||
#include <util/Profiler.h>
|
#include <util/Profiler.h>
|
||||||
@@ -101,7 +101,7 @@ class HttpBase : public util::Taggable
|
|||||||
self_.derived().stream(),
|
self_.derived().stream(),
|
||||||
*sp,
|
*sp,
|
||||||
boost::beast::bind_front_handler(
|
boost::beast::bind_front_handler(
|
||||||
&HttpBase::on_write, self_.derived().shared_from_this(), sp->need_eof()));
|
&HttpBase::onWrite, self_.derived().shared_from_this(), sp->need_eof()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_read()
|
doRead()
|
||||||
{
|
{
|
||||||
if (dead())
|
if (dead())
|
||||||
return;
|
return;
|
||||||
@@ -215,17 +215,17 @@ public:
|
|||||||
derived().stream(),
|
derived().stream(),
|
||||||
buffer_,
|
buffer_,
|
||||||
req_,
|
req_,
|
||||||
boost::beast::bind_front_handler(&HttpBase::on_read, derived().shared_from_this()));
|
boost::beast::bind_front_handler(&HttpBase::onRead, derived().shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_read(boost::beast::error_code ec, std::size_t bytes_transferred)
|
onRead(boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||||
{
|
{
|
||||||
boost::ignore_unused(bytes_transferred);
|
boost::ignore_unused(bytes_transferred);
|
||||||
|
|
||||||
// This means they closed the connection
|
// This means they closed the connection
|
||||||
if (ec == http::error::end_of_stream)
|
if (ec == http::error::end_of_stream)
|
||||||
return derived().do_close();
|
return derived().doClose();
|
||||||
|
|
||||||
if (ec)
|
if (ec)
|
||||||
return httpFail(ec, "read");
|
return httpFail(ec, "read");
|
||||||
@@ -253,9 +253,9 @@ public:
|
|||||||
// Disable the timeout.
|
// Disable the timeout.
|
||||||
// The websocket::stream uses its own timeout settings.
|
// The websocket::stream uses its own timeout settings.
|
||||||
boost::beast::get_lowest_layer(derived().stream()).expires_never();
|
boost::beast::get_lowest_layer(derived().stream()).expires_never();
|
||||||
return make_websocket_session(
|
return make_WebsocketSession(
|
||||||
ioc_,
|
ioc_,
|
||||||
derived().release_stream(),
|
derived().releaseStream(),
|
||||||
derived().ip(),
|
derived().ip(),
|
||||||
std::move(req_),
|
std::move(req_),
|
||||||
std::move(buffer_),
|
std::move(buffer_),
|
||||||
@@ -282,7 +282,7 @@ public:
|
|||||||
|
|
||||||
if (not rpcEngine_->post(
|
if (not rpcEngine_->post(
|
||||||
[this, ip, session](boost::asio::yield_context yield) {
|
[this, ip, session](boost::asio::yield_context yield) {
|
||||||
handle_request(
|
handleRequest(
|
||||||
yield,
|
yield,
|
||||||
std::move(req_),
|
std::move(req_),
|
||||||
lambda_,
|
lambda_,
|
||||||
@@ -309,7 +309,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_write(bool close, boost::beast::error_code ec, std::size_t bytes_transferred)
|
onWrite(bool close, boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||||
{
|
{
|
||||||
boost::ignore_unused(bytes_transferred);
|
boost::ignore_unused(bytes_transferred);
|
||||||
|
|
||||||
@@ -320,14 +320,14 @@ public:
|
|||||||
{
|
{
|
||||||
// This means we should close the connection, usually because
|
// This means we should close the connection, usually because
|
||||||
// the response indicated the "Connection: close" semantic.
|
// the response indicated the "Connection: close" semantic.
|
||||||
return derived().do_close();
|
return derived().doClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're done with the response so delete it
|
// We're done with the response so delete it
|
||||||
res_ = nullptr;
|
res_ = nullptr;
|
||||||
|
|
||||||
// Read another request
|
// Read another request
|
||||||
do_read();
|
doRead();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ public:
|
|||||||
// caller to pass a generic lambda for receiving the response.
|
// caller to pass a generic lambda for receiving the response.
|
||||||
template <class Body, class Allocator, class Send, class Session>
|
template <class Body, class Allocator, class Send, class Session>
|
||||||
void
|
void
|
||||||
handle_request(
|
handleRequest(
|
||||||
boost::asio::yield_context& yc,
|
boost::asio::yield_context& yc,
|
||||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req,
|
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req,
|
||||||
Send&& send,
|
Send&& send,
|
||||||
|
|||||||
@@ -79,8 +79,9 @@ public:
|
|||||||
{
|
{
|
||||||
return stream_;
|
return stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::beast::tcp_stream
|
boost::beast::tcp_stream
|
||||||
release_stream()
|
releaseStream()
|
||||||
{
|
{
|
||||||
return std::move(stream_);
|
return std::move(stream_);
|
||||||
}
|
}
|
||||||
@@ -99,11 +100,11 @@ public:
|
|||||||
// on the I/O objects in this HttpSession. Although not strictly
|
// on the I/O objects in this HttpSession. Although not strictly
|
||||||
// necessary for single-threaded contexts, this example code is written
|
// necessary for single-threaded contexts, this example code is written
|
||||||
// to be thread-safe by default.
|
// to be thread-safe by default.
|
||||||
net::dispatch(stream_.get_executor(), boost::beast::bind_front_handler(&HttpBase::do_read, shared_from_this()));
|
net::dispatch(stream_.get_executor(), boost::beast::bind_front_handler(&HttpBase::doRead, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_close()
|
doClose()
|
||||||
{
|
{
|
||||||
// Send a TCP shutdown
|
// Send a TCP shutdown
|
||||||
boost::beast::error_code ec;
|
boost::beast::error_code ec;
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ public:
|
|||||||
// Set the timeout.
|
// Set the timeout.
|
||||||
boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
|
boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
|
||||||
// Detect a TLS handshake
|
// Detect a TLS handshake
|
||||||
async_detect_ssl(stream_, buffer_, boost::beast::bind_front_handler(&Detector::on_detect, shared_from_this()));
|
async_detect_ssl(stream_, buffer_, boost::beast::bind_front_handler(&Detector::onDetect, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_detect(boost::beast::error_code ec, bool result)
|
onDetect(boost::beast::error_code ec, bool result)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
return fail(ec, "detect");
|
return fail(ec, "detect");
|
||||||
@@ -141,7 +141,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
make_websocket_session(
|
make_WebsocketSession(
|
||||||
boost::asio::io_context& ioc,
|
boost::asio::io_context& ioc,
|
||||||
boost::beast::tcp_stream stream,
|
boost::beast::tcp_stream stream,
|
||||||
std::optional<std::string> const& ip,
|
std::optional<std::string> const& ip,
|
||||||
@@ -172,7 +172,7 @@ make_websocket_session(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
make_websocket_session(
|
make_WebsocketSession(
|
||||||
boost::asio::io_context& ioc,
|
boost::asio::io_context& ioc,
|
||||||
boost::beast::ssl_stream<boost::beast::tcp_stream> stream,
|
boost::beast::ssl_stream<boost::beast::tcp_stream> stream,
|
||||||
std::optional<std::string> const& ip,
|
std::optional<std::string> const& ip,
|
||||||
@@ -275,20 +275,20 @@ public:
|
|||||||
void
|
void
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
do_accept();
|
doAccept();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
do_accept()
|
doAccept()
|
||||||
{
|
{
|
||||||
// The new connection gets its own strand
|
// The new connection gets its own strand
|
||||||
acceptor_.async_accept(
|
acceptor_.async_accept(
|
||||||
net::make_strand(ioc_), boost::beast::bind_front_handler(&Listener::on_accept, shared_from_this()));
|
net::make_strand(ioc_), boost::beast::bind_front_handler(&Listener::onAccept, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_accept(boost::beast::error_code ec, tcp::socket socket)
|
onAccept(boost::beast::error_code ec, tcp::socket socket)
|
||||||
{
|
{
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
@@ -309,7 +309,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accept another connection
|
// Accept another connection
|
||||||
do_accept();
|
doAccept();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <boost/beast/websocket/ssl.hpp>
|
#include <boost/beast/websocket/ssl.hpp>
|
||||||
|
|
||||||
#include <etl/ReportingETL.h>
|
#include <etl/ReportingETL.h>
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Factories.h>
|
||||||
#include <webserver/Listener.h>
|
#include <webserver/Listener.h>
|
||||||
#include <webserver/WsBase.h>
|
#include <webserver/WsBase.h>
|
||||||
|
|
||||||
@@ -121,6 +121,7 @@ public:
|
|||||||
, ip_(ip)
|
, ip_(ip)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WsUpgrader(
|
WsUpgrader(
|
||||||
boost::asio::io_context& ioc,
|
boost::asio::io_context& ioc,
|
||||||
boost::beast::tcp_stream&& stream,
|
boost::beast::tcp_stream&& stream,
|
||||||
@@ -158,12 +159,12 @@ public:
|
|||||||
// thread-safe by default.
|
// thread-safe by default.
|
||||||
|
|
||||||
net::dispatch(
|
net::dispatch(
|
||||||
http_.get_executor(), boost::beast::bind_front_handler(&WsUpgrader::do_upgrade, shared_from_this()));
|
http_.get_executor(), boost::beast::bind_front_handler(&WsUpgrader::doUpgrade, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
do_upgrade()
|
doUpgrade()
|
||||||
{
|
{
|
||||||
parser_.emplace();
|
parser_.emplace();
|
||||||
|
|
||||||
@@ -174,11 +175,11 @@ private:
|
|||||||
// Set the timeout.
|
// Set the timeout.
|
||||||
boost::beast::get_lowest_layer(http_).expires_after(std::chrono::seconds(30));
|
boost::beast::get_lowest_layer(http_).expires_after(std::chrono::seconds(30));
|
||||||
|
|
||||||
on_upgrade();
|
onUpgrade();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_upgrade()
|
onUpgrade()
|
||||||
{
|
{
|
||||||
// See if it is a WebSocket Upgrade
|
// See if it is a WebSocket Upgrade
|
||||||
if (!websocket::is_upgrade(req_))
|
if (!websocket::is_upgrade(req_))
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of clio: https://github.com/XRPLF/clio
|
|
||||||
Copyright (c) 2022, the clio developers.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <boost/asio/ssl.hpp>
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace ssl = boost::asio::ssl;
|
|
||||||
|
|
||||||
static std::optional<ssl::context>
|
|
||||||
parse_certs(const char* certFilename, const char* keyFilename)
|
|
||||||
{
|
|
||||||
std::ifstream readCert(certFilename, std::ios::in | std::ios::binary);
|
|
||||||
if (!readCert)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
std::stringstream contents;
|
|
||||||
contents << readCert.rdbuf();
|
|
||||||
readCert.close();
|
|
||||||
std::string cert = contents.str();
|
|
||||||
|
|
||||||
std::ifstream readKey(keyFilename, std::ios::in | std::ios::binary);
|
|
||||||
if (!readKey)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
contents.str("");
|
|
||||||
contents << readKey.rdbuf();
|
|
||||||
readKey.close();
|
|
||||||
std::string key = contents.str();
|
|
||||||
|
|
||||||
ssl::context ctx{ssl::context::tlsv12};
|
|
||||||
|
|
||||||
ctx.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2);
|
|
||||||
|
|
||||||
ctx.use_certificate_chain(boost::asio::buffer(cert.data(), cert.size()));
|
|
||||||
|
|
||||||
ctx.use_private_key(boost::asio::buffer(key.data(), key.size()), boost::asio::ssl::context::file_format::pem);
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
return stream_;
|
return stream_;
|
||||||
}
|
}
|
||||||
boost::beast::ssl_stream<boost::beast::tcp_stream>
|
boost::beast::ssl_stream<boost::beast::tcp_stream>
|
||||||
release_stream()
|
releaseStream()
|
||||||
{
|
{
|
||||||
return std::move(stream_);
|
return std::move(stream_);
|
||||||
}
|
}
|
||||||
@@ -108,33 +108,33 @@ public:
|
|||||||
self->stream_.async_handshake(
|
self->stream_.async_handshake(
|
||||||
ssl::stream_base::server,
|
ssl::stream_base::server,
|
||||||
self->buffer_.data(),
|
self->buffer_.data(),
|
||||||
boost::beast::bind_front_handler(&SslHttpSession::on_handshake, self));
|
boost::beast::bind_front_handler(&SslHttpSession::onHandshake, self));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_handshake(boost::beast::error_code ec, std::size_t bytes_used)
|
onHandshake(boost::beast::error_code ec, std::size_t bytes_used)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
return httpFail(ec, "handshake");
|
return httpFail(ec, "handshake");
|
||||||
|
|
||||||
buffer_.consume(bytes_used);
|
buffer_.consume(bytes_used);
|
||||||
|
|
||||||
do_read();
|
doRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_close()
|
doClose()
|
||||||
{
|
{
|
||||||
// Set the timeout.
|
// Set the timeout.
|
||||||
boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
|
boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
|
||||||
|
|
||||||
// Perform the SSL shutdown
|
// Perform the SSL shutdown
|
||||||
stream_.async_shutdown(boost::beast::bind_front_handler(&SslHttpSession::on_shutdown, shared_from_this()));
|
stream_.async_shutdown(boost::beast::bind_front_handler(&SslHttpSession::onShutdown, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_shutdown(boost::beast::error_code ec)
|
onShutdown(boost::beast::error_code ec)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
return httpFail(ec, "shutdown");
|
return httpFail(ec, "shutdown");
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public:
|
|||||||
, ws_(std::move(stream))
|
, ws_(std::move(stream))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::beast::websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>>&
|
boost::beast::websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>>&
|
||||||
ws()
|
ws()
|
||||||
{
|
{
|
||||||
@@ -115,6 +116,7 @@ public:
|
|||||||
, dosGuard_(dosGuard)
|
, dosGuard_(dosGuard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SslWsUpgrader(
|
SslWsUpgrader(
|
||||||
boost::asio::io_context& ioc,
|
boost::asio::io_context& ioc,
|
||||||
boost::beast::ssl_stream<boost::beast::tcp_stream> stream,
|
boost::beast::ssl_stream<boost::beast::tcp_stream> stream,
|
||||||
@@ -152,12 +154,12 @@ public:
|
|||||||
boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
|
boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
|
||||||
|
|
||||||
net::dispatch(
|
net::dispatch(
|
||||||
https_.get_executor(), boost::beast::bind_front_handler(&SslWsUpgrader::do_upgrade, shared_from_this()));
|
https_.get_executor(), boost::beast::bind_front_handler(&SslWsUpgrader::doUpgrade, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
on_handshake(boost::beast::error_code ec, std::size_t bytes_used)
|
onHandshake(boost::beast::error_code ec, std::size_t bytes_used)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
return logError(ec, "handshake");
|
return logError(ec, "handshake");
|
||||||
@@ -165,11 +167,11 @@ private:
|
|||||||
// Consume the portion of the buffer used by the handshake
|
// Consume the portion of the buffer used by the handshake
|
||||||
buffer_.consume(bytes_used);
|
buffer_.consume(bytes_used);
|
||||||
|
|
||||||
do_upgrade();
|
doUpgrade();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_upgrade()
|
doUpgrade()
|
||||||
{
|
{
|
||||||
parser_.emplace();
|
parser_.emplace();
|
||||||
|
|
||||||
@@ -180,11 +182,11 @@ private:
|
|||||||
// Set the timeout.
|
// Set the timeout.
|
||||||
boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
|
boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
|
||||||
|
|
||||||
on_upgrade();
|
onUpgrade();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_upgrade()
|
onUpgrade()
|
||||||
{
|
{
|
||||||
// See if it is a WebSocket Upgrade
|
// See if it is a WebSocket Upgrade
|
||||||
if (!websocket::is_upgrade(req_))
|
if (!websocket::is_upgrade(req_))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <etl/ReportingETL.h>
|
#include <etl/ReportingETL.h>
|
||||||
#include <log/Logger.h>
|
#include <log/Logger.h>
|
||||||
#include <rpc/Counters.h>
|
#include <rpc/Counters.h>
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Factories.h>
|
||||||
#include <rpc/RPCEngine.h>
|
#include <rpc/RPCEngine.h>
|
||||||
#include <rpc/WorkQueue.h>
|
#include <rpc/WorkQueue.h>
|
||||||
#include <subscriptions/Message.h>
|
#include <subscriptions/Message.h>
|
||||||
@@ -185,16 +185,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_write()
|
doWrite()
|
||||||
{
|
{
|
||||||
sending_ = true;
|
sending_ = true;
|
||||||
derived().ws().async_write(
|
derived().ws().async_write(
|
||||||
net::buffer(messages_.front()->data(), messages_.front()->size()),
|
net::buffer(messages_.front()->data(), messages_.front()->size()),
|
||||||
boost::beast::bind_front_handler(&WsSession::on_write, derived().shared_from_this()));
|
boost::beast::bind_front_handler(&WsSession::onWrite, derived().shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_write(boost::system::error_code ec, std::size_t)
|
onWrite(boost::system::error_code ec, std::size_t)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
@@ -204,17 +204,17 @@ public:
|
|||||||
{
|
{
|
||||||
messages_.pop();
|
messages_.pop();
|
||||||
sending_ = false;
|
sending_ = false;
|
||||||
maybe_send_next();
|
maybeSendNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
maybe_send_next()
|
maybeSendNext()
|
||||||
{
|
{
|
||||||
if (ec_ || sending_ || messages_.empty())
|
if (ec_ || sending_ || messages_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do_write();
|
doWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -223,7 +223,7 @@ public:
|
|||||||
net::dispatch(
|
net::dispatch(
|
||||||
derived().ws().get_executor(), [this, self = derived().shared_from_this(), msg = std::move(msg)]() {
|
derived().ws().get_executor(), [this, self = derived().shared_from_this(), msg = std::move(msg)]() {
|
||||||
messages_.push(std::move(msg));
|
messages_.push(std::move(msg));
|
||||||
maybe_send_next();
|
maybeSendNext();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,11 +246,11 @@ public:
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
derived().ws().async_accept(
|
derived().ws().async_accept(
|
||||||
req, boost::beast::bind_front_handler(&WsSession::on_accept, this->shared_from_this()));
|
req, boost::beast::bind_front_handler(&WsSession::onAccept, this->shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_accept(boost::beast::error_code ec)
|
onAccept(boost::beast::error_code ec)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
return wsFail(ec, "accept");
|
return wsFail(ec, "accept");
|
||||||
@@ -258,11 +258,11 @@ public:
|
|||||||
perfLog_.info() << tag() << "accepting new connection";
|
perfLog_.info() << tag() << "accepting new connection";
|
||||||
|
|
||||||
// Read a message
|
// Read a message
|
||||||
do_read();
|
doRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
do_read()
|
doRead()
|
||||||
{
|
{
|
||||||
if (dead())
|
if (dead())
|
||||||
return;
|
return;
|
||||||
@@ -272,11 +272,11 @@ public:
|
|||||||
buffer_.consume(buffer_.size());
|
buffer_.consume(buffer_.size());
|
||||||
// Read a message into our buffer
|
// Read a message into our buffer
|
||||||
derived().ws().async_read(
|
derived().ws().async_read(
|
||||||
buffer_, boost::beast::bind_front_handler(&WsSession::on_read, this->shared_from_this()));
|
buffer_, boost::beast::bind_front_handler(&WsSession::onRead, this->shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_request(boost::json::object const&& request, boost::json::value const& id, boost::asio::yield_context& yield)
|
handleRequest(boost::json::object const&& request, boost::json::value const& id, boost::asio::yield_context& yield)
|
||||||
{
|
{
|
||||||
auto ip = derived().ip();
|
auto ip = derived().ip();
|
||||||
if (!ip)
|
if (!ip)
|
||||||
@@ -371,7 +371,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_read(boost::beast::error_code ec, std::size_t bytes_transferred)
|
onRead(boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||||
{
|
{
|
||||||
boost::ignore_unused(bytes_transferred);
|
boost::ignore_unused(bytes_transferred);
|
||||||
|
|
||||||
@@ -431,12 +431,12 @@ public:
|
|||||||
|
|
||||||
if (not rpcEngine_->post(
|
if (not rpcEngine_->post(
|
||||||
[self = shared_from_this(), req = std::move(request), id](boost::asio::yield_context yield) {
|
[self = shared_from_this(), req = std::move(request), id](boost::asio::yield_context yield) {
|
||||||
self->handle_request(std::move(req), id, yield);
|
self->handleRequest(std::move(req), id, yield);
|
||||||
},
|
},
|
||||||
ip.value()))
|
ip.value()))
|
||||||
sendError(RPC::RippledError::rpcTOO_BUSY, id, request);
|
sendError(RPC::RippledError::rpcTOO_BUSY, id, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_read();
|
doRead();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <util/Fixtures.h>
|
#include <util/Fixtures.h>
|
||||||
|
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Factories.h>
|
||||||
#include <rpc/common/AnyHandler.h>
|
#include <rpc/common/AnyHandler.h>
|
||||||
#include <rpc/common/Specs.h>
|
#include <rpc/common/Specs.h>
|
||||||
#include <rpc/common/Validators.h>
|
#include <rpc/common/Validators.h>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Errors.h>
|
||||||
|
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <rpc/RPC.h>
|
#include <rpc/Factories.h>
|
||||||
#include <rpc/common/Specs.h>
|
#include <rpc/common/Specs.h>
|
||||||
#include <rpc/common/Validators.h>
|
#include <rpc/common/Validators.h>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user